The intention of the blist cursor is for the search for free blocks to

resume where the last search left off. Suppose that there are no free
blocks of size 32, but plenty of size 16. If we repeatedly request
size 32 blocks, fail, and retry with size 16 blocks, then the failures
all reset the cursor to the beginning of memory, making the 16 block
allocation use a first fit, rather than next fit, strategy.

This change has blist_alloc make a copy of the cursor for its own
decision making, and only updates the real blist cursor after a
successful allocation, making those 16 block searches behave like
next-fit searches.

Approved by: markj (mentor)
Differential Revision: https://reviews.freebsd.org/D20177
This commit is contained in:
Doug Moore 2019-05-06 22:12:15 +00:00
parent 1722eeac95
commit 27d172bb12

View File

@ -286,7 +286,7 @@ blist_destroy(blist_t bl)
daddr_t
blist_alloc(blist_t bl, daddr_t count)
{
daddr_t blk;
daddr_t blk, cursor;
if (count > BLIST_MAX_ALLOC)
panic("allocation too large");
@ -297,8 +297,9 @@ blist_alloc(blist_t bl, daddr_t count)
* non-zero. When the cursor is zero, an allocation failure will
* stop further iterations.
*/
cursor = bl->bl_cursor;
for (;;) {
blk = blst_meta_alloc(bl->bl_root, bl->bl_cursor, count,
blk = blst_meta_alloc(bl->bl_root, cursor, count,
bl->bl_radix);
if (blk != SWAPBLK_NONE) {
bl->bl_avail -= count;
@ -306,9 +307,9 @@ blist_alloc(blist_t bl, daddr_t count)
if (bl->bl_cursor == bl->bl_blocks)
bl->bl_cursor = 0;
return (blk);
} else if (bl->bl_cursor == 0)
} else if (cursor == 0)
return (SWAPBLK_NONE);
bl->bl_cursor = 0;
cursor = 0;
}
}