aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2021-03-06 10:25:12 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2021-03-23 10:50:29 +0000
commit7d7ed0223c0a8a40c242650532e1e70e1f3946fb (patch)
treeeb0d4585c0619f3828103ae1f21c62cd19117276
parent7cde0b06f94cfa06ca7869a040e753e09b7c2ef0 (diff)
downloadsrc-7d7ed0223c0a8a40c242650532e1e70e1f3946fb.tar.gz
src-7d7ed0223c0a8a40c242650532e1e70e1f3946fb.zip
MFC c743a6bd4fc0:
Implement mallocarray_domainset(9) variant of mallocarray(9). Reviewed by: kib @ Sponsored by: Mellanox Technologies // NVIDIA Networking (cherry picked from commit c743a6bd4fc0d1be30f9bc9996333ac0ba079563)
-rw-r--r--share/man/man9/Makefile1
-rw-r--r--share/man/man9/malloc.913
-rw-r--r--sys/kern/kern_malloc.c11
-rw-r--r--sys/sys/malloc.h3
4 files changed, 27 insertions, 1 deletions
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 50e760d3e047..edb87de6a35f 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1390,6 +1390,7 @@ MLINKS+=make_dev.9 destroy_dev.9 \
MLINKS+=malloc.9 free.9 \
malloc.9 malloc_domainset.9 \
malloc.9 mallocarray.9 \
+ malloc.9 mallocarray_domainset.9 \
malloc.9 MALLOC_DECLARE.9 \
malloc.9 MALLOC_DEFINE.9 \
malloc.9 realloc.9 \
diff --git a/share/man/man9/malloc.9 b/share/man/man9/malloc.9
index 097688d7ea38..b8c6e504e0c0 100644
--- a/share/man/man9/malloc.9
+++ b/share/man/man9/malloc.9
@@ -29,7 +29,7 @@
.\" $NetBSD: malloc.9,v 1.3 1996/11/11 00:05:11 lukem Exp $
.\" $FreeBSD$
.\"
-.Dd October 30, 2020
+.Dd March 6, 2021
.Dt MALLOC 9
.Os
.Sh NAME
@@ -70,6 +70,8 @@
.Fn malloc_domainset "size_t size" "struct malloc_type *type" "struct domainset *ds" "int flags"
.Ft void *
.Fn malloc_domainset_exec "size_t size" "struct malloc_type *type" "struct domainset *ds" "int flags"
+.Ft void *
+.Fn mallocarray_domainset "size_t nmemb" "size_t size" "struct malloc_type *type" "struct domainset *ds" "int flags"
.Sh DESCRIPTION
The
.Fn malloc
@@ -102,6 +104,15 @@ entries whose size is specified by
.Fa size .
.Pp
The
+.Fn mallocarray_domainset
+variant allocates memory from a specific
+.Xr numa 4
+domain using the specified domain selection policy.
+See
+.Xr domainset 9
+for some example policies.
+.Pp
+The
.Fn free
function releases memory at address
.Fa addr
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index eff9e62c9a10..48383358e3ad 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -804,6 +804,17 @@ mallocarray(size_t nmemb, size_t size, struct malloc_type *type, int flags)
return (malloc(size * nmemb, type, flags));
}
+void *
+mallocarray_domainset(size_t nmemb, size_t size, struct malloc_type *type,
+ struct domainset *ds, int flags)
+{
+
+ if (WOULD_OVERFLOW(nmemb, size))
+ panic("mallocarray_domainset: %zu * %zu overflowed", nmemb, size);
+
+ return (malloc_domainset(size * nmemb, type, ds, flags));
+}
+
#ifdef INVARIANTS
static void
free_save_type(void *addr, struct malloc_type *mtp, u_long size)
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
index a11dd767efc5..52a17b5171bc 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -245,6 +245,9 @@ void *malloc_domainset(size_t size, struct malloc_type *type,
void *mallocarray(size_t nmemb, size_t size, struct malloc_type *type,
int flags) __malloc_like __result_use_check
__alloc_size2(1, 2);
+void *mallocarray_domainset(size_t nmemb, size_t size, struct malloc_type *type,
+ struct domainset *ds, int flags) __malloc_like __result_use_check
+ __alloc_size2(1, 2);
void *malloc_exec(size_t size, struct malloc_type *type, int flags) __malloc_like
__result_use_check __alloc_size(1);
void *malloc_domainset_exec(size_t size, struct malloc_type *type,