svn commit: r347214 - head/sys/kern

Douglas William Moore dougm at FreeBSD.org
Mon May 6 22:12:17 UTC 2019


Author: dougm
Date: Mon May  6 22:12:15 2019
New Revision: 347214
URL: https://svnweb.freebsd.org/changeset/base/347214

Log:
  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

Modified:
  head/sys/kern/subr_blist.c

Modified: head/sys/kern/subr_blist.c
==============================================================================
--- head/sys/kern/subr_blist.c	Mon May  6 21:31:02 2019	(r347213)
+++ head/sys/kern/subr_blist.c	Mon May  6 22:12:15 2019	(r347214)
@@ -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;
 	}
 }
 


More information about the svn-src-head mailing list