diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2007-09-07 10:22:16 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2007-09-07 10:22:16 +0000 |
commit | e57d9a75bb3df7dabbfdcacffb5c0d74970031d5 (patch) | |
tree | 1c57e3fd7ecd3af975e582906135b5e9f04b64a7 /sys/kern | |
parent | 56960c2d892859acb900feb45f2bb6d25638b142 (diff) |
Add the long requested M_ZERO flag to malloc(9).
But the reason for this isn't some kind of "we can make it use the
pre-zeroed pages and zero the freelist in the idle loop and OMG I can
has optimisatiuns" which would require tons of infrastructure and make
everything slower.
The reason is that it shrinks other code. And that's good.
dlg@ ok, henning@ ok (before he read the diff)
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_malloc.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 9cb2f7ce2ca..d0bdf1bba23 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_malloc.c,v 1.71 2007/09/01 15:14:44 martin Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.72 2007/09/07 10:22:15 art Exp $ */ /* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */ /* @@ -158,8 +158,11 @@ malloc(unsigned long size, int type, int flags) #endif #ifdef MALLOC_DEBUG - if (debug_malloc(size, type, flags, (void **)&va)) + if (debug_malloc(size, type, flags, (void **)&va)) { + if ((flags & M_ZERO) && va != NULL) + memset(va, 0, size); return (va); + } #endif if (size > 65535 * PAGE_SIZE) { @@ -329,6 +332,9 @@ out: out: #endif splx(s); + + if ((flags & M_ZERO) && va != NULL) + memset(va, 0, size); return (va); } @@ -600,8 +606,8 @@ sysctl_malloc(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, totlen += strlen(memname[i]); totlen++; } - memall = malloc(totlen + M_LAST, M_SYSCTL, M_WAITOK); - bzero(memall, totlen + M_LAST); + memall = malloc(totlen + M_LAST, M_SYSCTL, + M_WAITOK|M_ZERO); for (siz = 0, i = 0; i < M_LAST; i++) { snprintf(memall + siz, totlen + M_LAST - siz, |