svn commit: r367271 - stable/12/sys/kern

Mark Johnston markj at FreeBSD.org
Mon Nov 2 14:01:34 UTC 2020


Author: markj
Date: Mon Nov  2 14:01:33 2020
New Revision: 367271
URL: https://svnweb.freebsd.org/changeset/base/367271

Log:
  MFC r366837:
  vmem: Simplify bt_fill() callers a bit

Modified:
  stable/12/sys/kern/subr_vmem.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/subr_vmem.c
==============================================================================
--- stable/12/sys/kern/subr_vmem.c	Mon Nov  2 14:00:25 2020	(r367270)
+++ stable/12/sys/kern/subr_vmem.c	Mon Nov  2 14:01:33 2020	(r367271)
@@ -257,8 +257,8 @@ vmem_t *memguard_arena = &memguard_arena_storage;
  * allocation will not fail once bt_fill() passes.  To do so we cache
  * at least the maximum possible tag allocations in the arena.
  */
-static int
-bt_fill(vmem_t *vm, int flags)
+static __noinline int
+_bt_fill(vmem_t *vm, int flags)
 {
 	bt_t *bt;
 
@@ -298,6 +298,14 @@ bt_fill(vmem_t *vm, int flags)
 	return 0;
 }
 
+static inline int
+bt_fill(vmem_t *vm, int flags)
+{
+	if (vm->vm_nfreetags >= BT_MAXALLOC)
+		return (0);
+	return (_bt_fill(vm, flags));
+}
+
 /*
  * Pop a tag off of the freetag stack.
  */
@@ -1079,7 +1087,7 @@ retry:
 	/*
 	 * Make sure we have enough tags to complete the operation.
 	 */
-	if (vm->vm_nfreetags < BT_MAXALLOC && bt_fill(vm, flags) != 0)
+	if (bt_fill(vm, flags) != 0)
 		goto out;
 
 	/*
@@ -1361,11 +1369,9 @@ vmem_xalloc(vmem_t *vm, const vmem_size_t size0, vmem_
 		 * Make sure we have enough tags to complete the
 		 * operation.
 		 */
-		if (vm->vm_nfreetags < BT_MAXALLOC &&
-		    bt_fill(vm, flags) != 0) {
-			error = ENOMEM;
+		error = bt_fill(vm, flags);
+		if (error != 0)
 			break;
-		}
 
 		/*
 	 	 * Scan freelists looking for a tag that satisfies the
@@ -1484,13 +1490,12 @@ vmem_add(vmem_t *vm, vmem_addr_t addr, vmem_size_t siz
 {
 	int error;
 
-	error = 0;
 	flags &= VMEM_FLAGS;
+
 	VMEM_LOCK(vm);
-	if (vm->vm_nfreetags >= BT_MAXALLOC || bt_fill(vm, flags) == 0)
+	error = bt_fill(vm, flags);
+	if (error == 0)
 		vmem_add1(vm, addr, size, BT_TYPE_SPAN_STATIC);
-	else
-		error = ENOMEM;
 	VMEM_UNLOCK(vm);
 
 	return (error);


More information about the svn-src-all mailing list