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 | |
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')
-rw-r--r-- | sys/kern/kern_malloc.c | 14 | ||||
-rw-r--r-- | sys/sys/malloc.h | 3 |
2 files changed, 12 insertions, 5 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, diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index f30406b0100..878e556b1b8 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.h,v 1.86 2007/09/01 17:06:26 xsa Exp $ */ +/* $OpenBSD: malloc.h,v 1.87 2007/09/07 10:22:15 art Exp $ */ /* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */ /* @@ -55,6 +55,7 @@ #define M_WAITOK 0x0000 #define M_NOWAIT 0x0001 #define M_CANFAIL 0x0002 +#define M_ZERO 0x0004 /* * Types of memory to be allocated |