Skip to content

Scan a hugepage bitmap in HugeRegion::Release instead of a linear walk. - #1009

Draft
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_983926156
Draft

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_983926156

Conversation

@copybara-service

Copy link
Copy Markdown

Scan a hugepage bitmap in HugeRegion::Release instead of a linear walk.

HugeRegion::Release selected free-but-backed hugepages by walking all
kNumHugePages (512) entries of backed_ and pages_used_, forwards or backwards
depending on adaptive_release, until enough candidates were found.

Track releasability directly in a Bitmap
(unreleasable_hugepages_): bit i is set iff hugepage i cannot be released
right now (unbacked, in use, or mid-unback in UnbackHugepages), so the clear
bits are exactly the free-but-backed hugepages. Inc/Dec/UnbackHugepages
maintain it alongside free_backed_count_, and a debug assert checks
CountBits() == kNumHugePages - free_backed_count_.

Release now walks free ranges of that bitmap with word-at-a-time scans:
NextFreeRange for the forward (non-adaptive) order and the new
Bitmap::PrevFreeRange for the reverse (adaptive) order, taking the highest
hugepages of a run first so the selected set is identical to the old reverse
scan. Release also returns early when nothing is free-but-backed, skipping
the UnbackHugepages pass over an all-false should_unback array.

Bitmap::PrevFreeRange mirrors NextFreeRange: it clamps end to N and is built
on FindClearBackwards/FindSetBackwards, so it never inspects individual bits.

Add tests for PrevFreeRange boundary cases (end == 0, end > N, all-set,
all-clear, ranges at index 0 and ending at N, word-boundary ranges) and for
Release across fragmented free runs in both orders.

HugeRegion::Release selected free-but-backed hugepages by walking all
kNumHugePages (512) entries of backed_ and pages_used_, forwards or backwards
depending on adaptive_release, until enough candidates were found.

Track releasability directly in a Bitmap<kNumHugePages>
(unreleasable_hugepages_): bit i is set iff hugepage i cannot be released
right now (unbacked, in use, or mid-unback in UnbackHugepages), so the clear
bits are exactly the free-but-backed hugepages.  Inc/Dec/UnbackHugepages
maintain it alongside free_backed_count_, and a debug assert checks
CountBits() == kNumHugePages - free_backed_count_.

Release now walks free ranges of that bitmap with word-at-a-time scans:
NextFreeRange for the forward (non-adaptive) order and the new
Bitmap::PrevFreeRange for the reverse (adaptive) order, taking the highest
hugepages of a run first so the selected set is identical to the old reverse
scan.  Release also returns early when nothing is free-but-backed, skipping
the UnbackHugepages pass over an all-false should_unback array.

Bitmap::PrevFreeRange mirrors NextFreeRange: it clamps end to N and is built
on FindClearBackwards/FindSetBackwards, so it never inspects individual bits.

Add tests for PrevFreeRange boundary cases (end == 0, end > N, all-set,
all-clear, ranges at index 0 and ending at N, word-boundary ranges) and for
Release across fragmented free runs in both orders.

PiperOrigin-RevId: 983926156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant