git: 856415c36289 - stable/12 - MFC c743a6bd4fc0: Implement mallocarray_domainset(9) variant of mallocarray(9).
Hans Petter Selasky
hselasky at FreeBSD.org
Tue Mar 23 11:47:27 UTC 2021
The branch stable/12 has been updated by hselasky:
URL: https://cgit.FreeBSD.org/src/commit/?id=856415c36289a41826b565a97e3aa922e2412deb
commit 856415c36289a41826b565a97e3aa922e2412deb
Author: Hans Petter Selasky <hselasky at FreeBSD.org>
AuthorDate: 2021-03-06 10:25:12 +0000
Commit: Hans Petter Selasky <hselasky at FreeBSD.org>
CommitDate: 2021-03-23 11:41:05 +0000
MFC c743a6bd4fc0:
Implement mallocarray_domainset(9) variant of mallocarray(9).
Reviewed by: kib @
Sponsored by: Mellanox Technologies // NVIDIA Networking
(cherry picked from commit c743a6bd4fc0d1be30f9bc9996333ac0ba079563)
---
share/man/man9/Makefile | 1 +
share/man/man9/malloc.9 | 13 ++++++++++++-
sys/kern/kern_malloc.c | 11 +++++++++++
sys/sys/malloc.h | 3 +++
4 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 43f7d633cd70..8acf44f3dbeb 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1306,6 +1306,7 @@ MLINKS+=malloc.9 free.9 \
malloc.9 malloc_domainset.9 \
malloc.9 free_domain.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 b87c0e6887e1..bdfdaca6bba9 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 August 28, 2020
+.Dd March 6, 2021
.Dt MALLOC 9
.Os
.Sh NAME
@@ -64,6 +64,8 @@
.In sys/domainset.h
.Ft void *
.Fn malloc_domainset "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"
.Ft void
.Fn free_domain "void *addr" "struct malloc_type *type"
.Sh DESCRIPTION
@@ -93,6 +95,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 5e8af96cb1eb..41eef1d6a4ac 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -699,6 +699,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 fd50dbc495b4..bf7ec5c8e9c6 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -238,6 +238,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_init(void *);
int malloc_last_fail(void);
void malloc_type_allocated(struct malloc_type *type, unsigned long size);
More information about the dev-commits-src-branches
mailing list