KM_ALLOC(9) | Kernel Developer's Manual | KM_ALLOC(9) |
km_alloc
, km_free
— kernel memory allocator
#include
<sys/types.h>
#include
<uvm/uvm_extern.h>
void *
km_alloc
(size_t
sz, const struct
kmem_va_mode *kv, const
struct kmem_pa_mode *kp,
const struct kmem_dyn_mode
*kd);
void
km_free
(void
*v, size_t sz,
const struct kmem_va_mode
*kv, const struct
kmem_pa_mode *kp);
The
km_alloc
()
function allocates kernel virtual space optionally backed by physical pages.
The km_free
() function frees the space that was
previously allocated by km_alloc
().
The sz argument specifies the
size of the allocation and must be a multiple of
PAGE_SIZE
. The kv and
kp arguments specify the type of virtual and physical
memory to be allocated. The kd argument specifies
additional options for the allocation. The arguments passed to
km_free
()
must match those that were used to obtain the space in
km_alloc
().
Typically a user will use certain predefined modes for memory allocation. For virtual space the predefined modes are:
For physical pages the predefined modes are:
The other parameters for allocation are:
In case the predefined allocation modes are not sufficient, a custom allocation mode can be created. The structure controlling the virtual space allocation is:
struct kmem_va_mode { struct vm_map **kv_map; vsize_t kv_align; int kv_wait; int kv_singlepage; };
struct kmem_pa_mode { struct uvm_constraint_range *kp_constraint; struct uvm_object **kp_object; paddr_t kp_align; paddr_t kp_boundary; int kp_nomem; int kp_maxseg; int kp_zero; int kp_pageable; };
struct kmem_dyn_mode { int kd_waitok; int kd_trylock; voff_t kd_prefer; int *kd_slowdown; };
km_alloc
() returns a kernel virtual
address or NULL
if the allocation cannot be
satisfied.
December 6, 2019 | OpenBSD-7.0 |