git: 45e2357113e6 - main - malloc: Pass the allocation size to malloc_large() by value

Mark Johnston markj at FreeBSD.org
Tue Jul 13 22:17:26 UTC 2021


The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=45e2357113e65537feabb7c872053b5ea5f7a0f1

commit 45e2357113e65537feabb7c872053b5ea5f7a0f1
Author:     Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-07-13 21:47:02 +0000
Commit:     Mark Johnston <markj at FreeBSD.org>
CommitDate: 2021-07-13 21:47:02 +0000

    malloc: Pass the allocation size to malloc_large() by value
    
    Its callers do not make use the modified size that malloc_large() was
    returning, so there's no need to pass a pointer.  No functional change
    intended.
    
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
---
 sys/kern/kern_malloc.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 75cbc2a0fd04..bd0f46ea5220 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -584,23 +584,21 @@ malloc_large_size(uma_slab_t slab)
 }
 
 static caddr_t __noinline
-malloc_large(size_t *size, struct malloc_type *mtp, struct domainset *policy,
+malloc_large(size_t size, struct malloc_type *mtp, struct domainset *policy,
     int flags DEBUG_REDZONE_ARG_DEF)
 {
 	vm_offset_t kva;
 	caddr_t va;
-	size_t sz;
 
-	sz = roundup(*size, PAGE_SIZE);
-	kva = kmem_malloc_domainset(policy, sz, flags);
+	size = roundup(size, PAGE_SIZE);
+	kva = kmem_malloc_domainset(policy, size, flags);
 	if (kva != 0) {
 		/* The low bit is unused for slab pointers. */
-		vsetzoneslab(kva, NULL, (void *)((sz << 1) | 1));
-		uma_total_inc(sz);
-		*size = sz;
+		vsetzoneslab(kva, NULL, (void *)((size << 1) | 1));
+		uma_total_inc(size);
 	}
 	va = (caddr_t)kva;
-	malloc_type_allocated(mtp, va == NULL ? 0 : sz);
+	malloc_type_allocated(mtp, va == NULL ? 0 : size);
 	if (__predict_false(va == NULL)) {
 		KASSERT((flags & M_WAITOK) == 0,
 		    ("malloc(M_WAITOK) returned NULL"));
@@ -608,7 +606,7 @@ malloc_large(size_t *size, struct malloc_type *mtp, struct domainset *policy,
 #ifdef DEBUG_REDZONE
 		va = redzone_setup(va, osize);
 #endif
-		kasan_mark((void *)va, osize, sz, KASAN_MALLOC_REDZONE);
+		kasan_mark((void *)va, osize, size, KASAN_MALLOC_REDZONE);
 	}
 	return (va);
 }
@@ -648,7 +646,7 @@ void *
 #endif
 
 	if (__predict_false(size > kmem_zmax))
-		return (malloc_large(&size, mtp, DOMAINSET_RR(), flags
+		return (malloc_large(size, mtp, DOMAINSET_RR(), flags
 		    DEBUG_REDZONE_ARG));
 
 	if (size & KMEM_ZMASK)
@@ -718,7 +716,7 @@ malloc_domainset(size_t size, struct malloc_type *mtp, struct domainset *ds,
 #endif
 
 	if (__predict_false(size > kmem_zmax))
-		return (malloc_large(&size, mtp, DOMAINSET_RR(), flags
+		return (malloc_large(size, mtp, DOMAINSET_RR(), flags
 		    DEBUG_REDZONE_ARG));
 
 	vm_domainset_iter_policy_init(&di, ds, &domain, &flags);
@@ -770,7 +768,7 @@ malloc_domainset_exec(size_t size, struct malloc_type *mtp, struct domainset *ds
 		return (va);
 #endif
 
-	return (malloc_large(&size, mtp, ds, flags DEBUG_REDZONE_ARG));
+	return (malloc_large(size, mtp, ds, flags DEBUG_REDZONE_ARG));
 }
 
 void *


More information about the dev-commits-src-all mailing list