hpdata: early bailout for longest free range.
A number of common special cases allow us to stop iterating through an hpdata's bitmap earlier rather than later.
This commit is contained in:
parent
d21d5b46b6
commit
271a676dcd
38
src/hpdata.c
38
src/hpdata.c
@ -74,6 +74,7 @@ hpdata_reserve_alloc(hpdata_t *hpdata, size_t sz) {
|
|||||||
* to serve the allocation.
|
* to serve the allocation.
|
||||||
*/
|
*/
|
||||||
assert(found);
|
assert(found);
|
||||||
|
assert(len <= hpdata_longest_free_range_get(hpdata));
|
||||||
if (len >= npages) {
|
if (len >= npages) {
|
||||||
/*
|
/*
|
||||||
* We use first-fit within the page slabs; this gives
|
* We use first-fit within the page slabs; this gives
|
||||||
@ -103,25 +104,30 @@ hpdata_reserve_alloc(hpdata_t *hpdata, size_t sz) {
|
|||||||
hpdata->h_ntouched += new_dirty;
|
hpdata->h_ntouched += new_dirty;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We might have shrunk the longest free range. We have to keep
|
* If we allocated out of a range that was the longest in the hpdata, it
|
||||||
* scanning until the end of the hpdata to be sure.
|
* might be the only one of that size and we'll have to adjust the
|
||||||
*
|
* metadata.
|
||||||
* TODO: As an optimization, we should only do this when the range we
|
|
||||||
* just allocated from was equal to the longest free range size.
|
|
||||||
*/
|
*/
|
||||||
start = begin + npages;
|
if (len == hpdata_longest_free_range_get(hpdata)) {
|
||||||
while (start < HUGEPAGE_PAGES) {
|
start = begin + npages;
|
||||||
bool found = fb_urange_iter(hpdata->active_pages,
|
while (start < HUGEPAGE_PAGES) {
|
||||||
HUGEPAGE_PAGES, start, &begin, &len);
|
bool found = fb_urange_iter(hpdata->active_pages,
|
||||||
if (!found) {
|
HUGEPAGE_PAGES, start, &begin, &len);
|
||||||
break;
|
if (!found) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
assert(len <= hpdata_longest_free_range_get(hpdata));
|
||||||
|
if (len == hpdata_longest_free_range_get(hpdata)) {
|
||||||
|
largest_unchosen_range = len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (len > largest_unchosen_range) {
|
||||||
|
largest_unchosen_range = len;
|
||||||
|
}
|
||||||
|
start = begin + len;
|
||||||
}
|
}
|
||||||
if (len > largest_unchosen_range) {
|
hpdata_longest_free_range_set(hpdata, largest_unchosen_range);
|
||||||
largest_unchosen_range = len;
|
|
||||||
}
|
|
||||||
start = begin + len;
|
|
||||||
}
|
}
|
||||||
hpdata_longest_free_range_set(hpdata, largest_unchosen_range);
|
|
||||||
|
|
||||||
hpdata_assert_consistent(hpdata);
|
hpdata_assert_consistent(hpdata);
|
||||||
return (void *)(
|
return (void *)(
|
||||||
|
Loading…
Reference in New Issue
Block a user