summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_malloc.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-12-30 11:45:07 +0000
committerpjd <pjd@FreeBSD.org>2005-12-30 11:45:07 +0000
commit3cc29e6ebff10906cf1f84a6cc2d518dcecf219c (patch)
tree6405d9feea45121dd7a557dfddbab470a5306b7e /sys/kern/kern_malloc.c
parent530bf89f140b005c1cc1706d6d7bcfa392bbf202 (diff)
downloadFreeBSD-src-3cc29e6ebff10906cf1f84a6cc2d518dcecf219c.zip
FreeBSD-src-3cc29e6ebff10906cf1f84a6cc2d518dcecf219c.tar.gz
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.
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 4864277..6b2e73d 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)
{
OpenPOWER on IntegriCloud