UVM_KM_ALLOC(9) Kernel Developer's Manual UVM_KM_ALLOC(9)

uvm_km_alloc, uvm_km_zalloc, uvm_km_alloc1, uvm_km_kmemalloc, uvm_km_valloc, uvm_km_valloc_wait, uvm_km_suballoc, uvm_km_free, uvm_km_free_wakeupraw kernel memory or address space allocator

#include <sys/param.h>
#include <uvm/uvm.h>

uvm_km_alloc(vm_map_t map, vsize_t size);

uvm_km_zalloc(vm_map_t map, vsize_t size);

uvm_km_alloc1(vm_map_t map, vsize_t size, vsize_t align, boolean_t zeroit);

uvm_km_kmemalloc(vm_map_t map, struct uvm_object *obj, vsize_t size, int flags);

uvm_km_valloc(vm_map_t map, vsize_t size);

uvm_km_valloc_wait(vm_map_t map, vsize_t size);

struct vm_map *
uvm_km_suballoc(vm_map_t map, vaddr_t *min, vaddr_t *max , vsize_t size, int flags, boolean_t fixed, vm_map_t submap);

uvm_km_free(vm_map_t map, vaddr_t addr, vsize_t size);

uvm_km_free_wakeup(vm_map_t map, vaddr_t addr, vsize_t size);

The () and () functions allocate size bytes of wired kernel memory in map map. In addition to allocation, uvm_km_zalloc() zeros the memory. Both of these functions are defined as macros in terms of uvm_km_alloc1(), and should almost always be used in preference to uvm_km_alloc1().

The () function allocates and returns size bytes of wired memory in the kernel map aligned to the align boundary, zeroing the memory if the zeroit argument is non-zero.

The () function allocates and returns size bytes of wired kernel memory into obj. The flags can be any of:

#define UVM_KMF_NOWAIT  0x1                     /* matches M_NOWAIT */
#define UVM_KMF_VALLOC  0x2                     /* allocate VA only */
#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK        /* try locking only */

The UVM_KMF_NOWAIT flag causes () to return immediately if no memory is available. UVM_KMF_VALLOC causes no pages to be allocated, only a virtual address. UVM_KMF_TRYLOCK causes uvm_km_kmemalloc() to only try and not sleep when locking maps.

The () and () functions return a newly allocated zero-filled address in the kernel map of size size. uvm_km_valloc_wait() will also wait for kernel memory to become available, if there is a memory shortage.

The () function allocates submap (with the specified flags, as described above) from map, creating a new map if submap is NULL. The addresses of the submap can be specified exactly by setting the fixed argument to non-zero, which causes the min argument to specify the beginning of the address in the submap. If fixed is zero, any address of size size will be allocated from map and the start and end addresses returned in min and max.

The () and () functions free size bytes of memory in the kernel map, starting at address addr. uvm_km_free_wakeup() calls () on the map before unlocking the map.


December 5, 2019 OpenBSD 7.5