aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2005-12-30 11:45:07 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2005-12-30 11:45:07 +0000
commitd362c40d3a43c5e377ec90dd140a98e109e6b285 (patch)
tree6405d9feea45121dd7a557dfddbab470a5306b7e /sys/kern/kern_malloc.c
parent855921cec5900773baaef65f91fd5640e54f34bb (diff)
downloadsrc-d362c40d3a43c5e377ec90dd140a98e109e6b285.tar.gz
src-d362c40d3a43c5e377ec90dd140a98e109e6b285.zip
Improve memguard a bit:
- Provide tunable vm.memguard.desc, so one can specify memory type without changing the code and recompiling the kernel. - Allow to use memguard for kernel modules by providing sysctl vm.memguard.desc, which can be changed to short description of memory type before module is loaded. - Move as much memguard code as possible to memguard.c. - Add sysctl node vm.memguard. and move memguard-specific sysctl there. - Add malloc_desc2type() function for finding memory type based on its short description (ks_shortdesc field). - Memory type can be changed (via vm.memguard.desc sysctl) only if it doesn't exist (will be loaded later) or when no memory is allocated yet. If there is allocated memory for the given memory type, return EBUSY. - Implement two ways of memory types comparsion and make safer/slower the default.
Notes
Notes: svn path=/head/; revision=153880
Diffstat (limited to 'sys/kern/kern_malloc.c')
-rw-r--r--sys/kern/kern_malloc.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 4864277dd7d7..6b2e73d86fd2 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -142,12 +142,6 @@ struct {
static uma_zone_t mt_zone;
-#ifdef DEBUG_MEMGUARD
-u_int vm_memguard_divisor;
-SYSCTL_UINT(_vm, OID_AUTO, memguard_divisor, CTLFLAG_RD, &vm_memguard_divisor,
- 0, "(kmem_size/memguard_divisor) == memguard submap size");
-#endif
-
u_int vm_kmem_size;
SYSCTL_UINT(_vm, OID_AUTO, kmem_size, CTLFLAG_RD, &vm_kmem_size, 0,
"Size of kernel memory");
@@ -304,8 +298,7 @@ malloc(unsigned long size, struct malloc_type *mtp, int flags)
("malloc(M_WAITOK) in interrupt context"));
#ifdef DEBUG_MEMGUARD
- /* XXX CHANGEME! */
- if (mtp == M_SUBPROC)
+ if (memguard_cmp(mtp))
return memguard_alloc(size, flags);
#endif
@@ -359,8 +352,7 @@ free(void *addr, struct malloc_type *mtp)
return;
#ifdef DEBUG_MEMGUARD
- /* XXX CHANGEME! */
- if (mtp == M_SUBPROC) {
+ if (memguard_cmp(mtp)) {
memguard_free(addr);
return;
}
@@ -423,8 +415,7 @@ realloc(void *addr, unsigned long size, struct malloc_type *mtp, int flags)
*/
#ifdef DEBUG_MEMGUARD
-/* XXX: CHANGEME! */
-if (mtp == M_SUBPROC) {
+if (memguard_cmp(mtp)) {
slab = NULL;
alloc = size;
} else {
@@ -549,7 +540,7 @@ kmeminit(void *dummy)
* scenarios as they occur. It is only used for debugging.
*/
vm_memguard_divisor = 10;
- TUNABLE_INT_FETCH("vm.memguard_divisor", &vm_memguard_divisor);
+ TUNABLE_INT_FETCH("vm.memguard.divisor", &vm_memguard_divisor);
/* Pick a conservative value if provided value sucks. */
if ((vm_memguard_divisor <= 0) ||
@@ -649,6 +640,19 @@ malloc_uninit(void *data)
uma_zfree(mt_zone, mtip);
}
+struct malloc_type *
+malloc_desc2type(const char *desc)
+{
+ struct malloc_type *mtp;
+
+ mtx_assert(&malloc_mtx, MA_OWNED);
+ for (mtp = kmemstatistics; mtp != NULL; mtp = mtp->ks_next) {
+ if (strcmp(mtp->ks_shortdesc, desc) == 0)
+ return (mtp);
+ }
+ return (NULL);
+}
+
static int
sysctl_kern_malloc(SYSCTL_HANDLER_ARGS)
{