kmem_zalloc(D3) kmem_zalloc(D3)
NAME
kmem_zalloc - allocate and clear space from kernel free memory
SYNOPSIS
#include <sys/types.h>
#include <sys/kmem.h>
#include <sys/ddi.h>
void *kmem_zalloc(size_t size, int flag);
Arguments
size Number of bytes to allocate.
flag Specifies whether the caller is willing to sleep
waiting for memory.
DESCRIPTION
kmem_zalloc allocates size bytes of kernel memory, clears the
memory by filling it with zeros, and returns a pointer to the
allocated memory. If flag is set to KM_SLEEP, the caller will
sleep if necessary until the specified amount of memory is
available. If flag is set to KM_NOSLEEP, the caller will not
sleep, but kmem_zalloc will return NULL if the specified
amount of memory is not immediately available.
Return Values
Upon successful completion, kmem_zalloc returns a pointer to
the allocated memory. If KM_NOSLEEP is specified and
sufficient memory is not immediately available, kmem_zalloc
returns a NULL pointer. If size is set to 0, kmem_zalloc
returns NULL regardless of the value of flag.
USAGE
Kernel memory is a limited resource and should be used
judiciously. Memory allocated using kmem_zalloc should be
freed as soon as possible. Drivers should not use local
freelists for memory or similar schemes that cause the memory
to be held for longer than necessary.
Since holding memory allocated using kmem_zalloc for extended
periods of time (e.g allocating memory at system startup and
never freeing it) can have an adverse effect on overall memory
usage and system performance, memory needed for such extended
periods should be statically allocated whenever possible.
Copyright 1994 Novell, Inc. Page 1
kmem_zalloc(D3) kmem_zalloc(D3)
The address returned by a successful call to kmem_zalloc is
word-aligned.
Warnings
Drivers should not assume that memory allocated by kmem_zalloc
is usable for DMA operations, nor should drivers assume that
the memory has any specific physical properties such as
starting address alignment, physical address range, or
physical contiguity. Beginning with ddi version 6, memory
with specific physical properties can be obtained through
kmem_alloc_physreq(D3), or kmem_zalloc_physreq(D3). In ddi
version 5, contiguous memory with specific physical properties
can be obtained through kmem_alloc_physcontig(D3).
Level
Initialization or Base if flag is set to KM_SLEEP.
Initialization, Base or Interrupt if flag is set to
KM_NOSLEEP.
Synchronization Constraints
May sleep if flag is set to KM_SLEEP. If KM_SLEEP is used
during Initialization before the system is fully running and
no memory is available, kmem_zalloc may generate a panic
rather than futilely waiting forever.
Driver-defined basic locks, read/write locks, and sleep locks
may be held across calls to this function if flag is
KM_NOSLEEP, but may not be held if flag is KM_SLEEP.
Driver-defined sleep locks may be held across calls to this
function regardless of the value of flag.
REFERENCES
kmem_alloc(D3), kmem_alloc_physcontig(D3),
kmem_alloc_physreq(D3), kmem_free(D3),
kmem_free_physcontig(D3), kmem_zalloc_physreq(D3)
NOTICES
Portability
All processors
Applicability
ddi: 1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp
Copyright 1994 Novell, Inc. Page 2
kmem_zalloc(D3) kmem_zalloc(D3)
In versions 1, 2, 3, 4, 5, and 5mp, the memory returned by
kmem_zalloc will be DMA-able; that is, it will satisfy worst-
case DMA-ability requirements on systems with restricted DMA;
see phys_dmasize of physreq(D4). In versions 1, 2, 3, and 4,
the memory returned will also be physically contiguous, if
possible (guaranteed if size is less than or equal to
ptob(1)). For other versions, there are no guarantees on the
memory properties.
Copyright 1994 Novell, Inc. Page 3