UVM_KM(9)
okay bestie, welcome to uvm_km(9) from the Kernel Developer's Manual β the raw kernel memory or address space allocator. Sheβs giving low-level power-tool energy: cute page, very serious job. β¨
πΈ NAME πΈ
uvm_km β raw kernel memory or address space allocator. π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <uvm/uvm.h>
vaddr_t
uvm_km_alloc(struct vm_map *map, vsize_t size, vsize_t align,
uvm_flag_t flags);
void
uvm_km_free(struct vm_map *map, vaddr_t addr, vsize_t size,
uvm_flag_t flags);
struct vm_map *
uvm_km_suballoc(struct vm_map *map, vaddr_t *min, vaddr_t *max,
vsize_t size, int flags, bool fixed, struct vm_map *submap);
π¦ DESCRIPTION π¦
The UVM facility for allocation of kernel memory or address space in pages. Both wired and pageable memory can be allocated by this facility, as well as kernel address space. Note that this is a raw allocator. For general purpose memory allocation, the kmem(9) interface should be used. No cap.
β οΈ raw allocator alert, bestie: this is not the general-purpose-allocation vibe. For general purpose memory allocation, use kmem(9). π«Ά
π FUNCTIONS π
β¨ uvm_km_alloc() β¨
uvm_km_alloc() allocates a contiguous range of size bytes of kernel memory in map map and returns the virtual address of the range, or returns zero on failure. The first address of the allocated memory range will be aligned according to the align argument (specify 0 if no alignment is necessary). The alignment must be a multiple of page size. The flags is a bitwise inclusive OR of the allocation type and operation flags.
The allocation type should be one of:
UVM_KMF_WIREDβ Wired memory. πͺUVM_KMF_PAGEABLEβ Demand-paged zero-filled memory. πΈUVM_KMF_VAONLYβ Virtual address only. No physical pages are mapped in the allocated region. If necessary, it is the callerβs responsibility to enter page mappings. It is also the callerβs responsibility to clean up the mappings before freeing the address range. π
The following operation flags are available:
UVM_KMF_CANFAILβ Can fail even ifUVM_KMF_NOWAITis not specified andUVM_KMF_WAITVAis specified.UVM_KMF_ZEROβ Request zero-filled memory. Only supported forUVM_KMF_WIRED. Should not be used with other types.UVM_KMF_EXECβ Request memory with executable rights.UVM_KMF_TRYLOCKβ Fail if cannot lock the map without sleeping.UVM_KMF_NOWAITβ Fail immediately if no memory is available.UVM_KMF_WAITVAβ Sleep to wait for the virtual address resources if needed.
If neither UVM_KMF_NOWAIT nor UVM_KMF_CANFAIL are specified and UVM_KMF_WAITVA is specified, uvm_km_alloc() will never fail, but rather sleep indefinitely until the allocation succeeds. π΄
Pageability of the pages allocated with UVM_KMF_PAGEABLE can be changed by uvm_map_pageable(). In that case, the entire range must be changed atomically. Changing a part of the range is not supported. π«
π uvm_km_free() π
uvm_km_free() frees the memory range allocated by uvm_km_alloc(). addr must be an address returned by uvm_km_alloc(). map and size must be the same as the ones used for the corresponding uvm_km_alloc(). flags must be the allocation type used for the corresponding uvm_km_alloc(). Note that uvm_km_free() is the only way to free memory ranges allocated by uvm_km_alloc(). uvm_unmap() must not be used.
π¨ hard no, bestie:uvm_unmap()must not be used for these ranges.uvm_km_free()is the only way. periodt.
π uvm_km_suballoc() π
uvm_km_suballoc() allocates submap from map, creating a new map if submap is NULL. The addresses of the submap can be specified explicitly by setting the fixed argument to true, which causes the min argument to specify the beginning of the address in the submap. If fixed is false, any address of size size will be allocated from map and the start and end addresses returned in min and max. The flags are used to initialize the created submap. The following flags can be set:
VM_MAP_PAGEABLEβ Entries in the map may be paged out. π¦VM_MAP_INTRSAFEβ Map should be interrupt-safe. β‘VM_MAP_TOPDOWNβ A top-down mapping should be arranged. π
π SEE ALSO π
the squad: kmem(9), pmap(9), pool_cache(9), uvm(9), uvm_map(9), vmem(9). π«Ά
β HISTORY β
UVM and uvm_km first appeared in NetBSD 1.4. π
mwah π this oneβs from Debian, dated August 15, 2015, and the manual footer marks it UVM_KM(9). bye bestie π«Ά
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 1998 Matthew R. Green
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms