Introduce the M_ZERO flag to malloc(9)

Instead of:

        foo = malloc(sizeof(foo), M_WAIT);
        bzero(foo, sizeof(foo));

You can now (and please do) use:

        foo = malloc(sizeof(foo), M_WAIT | M_ZERO);

In the future this will enable us to do idle-time pre-zeroing of
malloc-space.
This commit is contained in:
phk 2000-10-20 17:54:55 +00:00
parent 02af04a1fb
commit 55e86a81b7
3 changed files with 6 additions and 0 deletions

View File

@ -88,6 +88,8 @@ argument further qualifies
.Fn malloc No Ns 's
operational characteristics as follows:
.Bl -tag -width indent
.It Dv M_ZERO
Causes the allocated memory to be set to all zeros.
.It Dv M_NOWAIT
Causes
.Fn malloc

View File

@ -280,6 +280,9 @@ out:
ksp->ks_maxused = ksp->ks_memuse;
splx(s);
mtx_exit(&malloc_mtx, MTX_DEF);
/* XXX: Do idle pre-zeroing. */
if (va != NULL && (flags & M_ZERO))
bzero(va, size);
return ((void *) va);
}

View File

@ -46,6 +46,7 @@
#define M_NOWAIT 0x0001 /* do not block */
#define M_USE_RESERVE 0x0002 /* can alloc out of reserve memory */
#define M_ASLEEP 0x0004 /* async sleep on failure */
#define M_ZERO 0x0008 /* bzero the allocation */
#define M_MAGIC 877983977 /* time when first defined :-) */