aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2020-11-02 17:38:08 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2020-11-02 17:38:08 +0000
commit828afdda17cae119594b21cac689bbe681b5aa58 (patch)
treea135e30ccd5f0290c88ce4b2da6eead7f604b4d8 /sys
parent26c29e743bbdbb82762540f72d4bc449bae2e092 (diff)
downloadsrc-828afdda17cae119594b21cac689bbe681b5aa58.tar.gz
src-828afdda17cae119594b21cac689bbe681b5aa58.zip
malloc: export kernel zones instead of relying on them being power-of-2
Reviewed by: markj (previous version) Differential Revision: https://reviews.freebsd.org/D27026
Notes
Notes: svn path=/head/; revision=367274
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_malloc.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index b7d7e0c2d4b0..20a1d9bc0788 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -147,6 +147,8 @@ static int numzones = MALLOC_DEBUG_MAXZONES;
* Small malloc(9) memory allocations are allocated from a set of UMA buckets
* of various sizes.
*
+ * Warning: the layout of the struct is duplicated in libmemstat for KVM support.
+ *
* XXX: The comment here used to read "These won't be powers of two for
* long." It's possible that a significant amount of wasted memory could be
* recovered by tuning the sizes of these buckets.
@@ -213,6 +215,19 @@ SYSCTL_PROC(_vm, OID_AUTO, kmem_map_free,
CTLFLAG_RD | CTLTYPE_ULONG | CTLFLAG_MPSAFE, NULL, 0,
sysctl_kmem_map_free, "LU", "Free space in kmem");
+static SYSCTL_NODE(_vm, OID_AUTO, malloc, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
+ "Malloc information");
+
+static u_int vm_malloc_zone_count = nitems(kmemzones);
+SYSCTL_UINT(_vm_malloc, OID_AUTO, zone_count,
+ CTLFLAG_RD, &vm_malloc_zone_count, 0,
+ "Number of malloc zones");
+
+static int sysctl_vm_malloc_zone_sizes(SYSCTL_HANDLER_ARGS);
+SYSCTL_PROC(_vm_malloc, OID_AUTO, zone_sizes,
+ CTLFLAG_RD | CTLTYPE_OPAQUE | CTLFLAG_MPSAFE, NULL, 0,
+ sysctl_vm_malloc_zone_sizes, "S", "Zone sizes used by malloc");
+
/*
* The malloc_mtx protects the kmemstatistics linked list.
*/
@@ -274,6 +289,19 @@ sysctl_kmem_map_free(SYSCTL_HANDLER_ARGS)
return (sysctl_handle_long(oidp, &size, 0, req));
}
+static int
+sysctl_vm_malloc_zone_sizes(SYSCTL_HANDLER_ARGS)
+{
+ int sizes[nitems(kmemzones)];
+ int i;
+
+ for (i = 0; i < nitems(kmemzones); i++) {
+ sizes[i] = kmemzones[i].kz_size;
+ }
+
+ return (SYSCTL_OUT(req, &sizes, sizeof(sizes)));
+}
+
/*
* malloc(9) uma zone separation -- sub-page buffer overruns in one
* malloc type will affect only a subset of other malloc types.