kmap_local_page(9)
πΈ kmap_local_page β Kernel API Manual, section 9 πΈ
okay so bestie, welcome to kmap_local_page(9), straight out of the Kernel API Manual. this is the page about mapping a page for temporary usage, and honestly? it's giving "small function, big rules" energy. let's get into it π
β¨ NAME β¨
kmap_local_page β map a page for temporary usage πΊοΈ
π SYNOPSIS π
void * kmap_local_page (const struct page *page );
π¦ ARGUMENTS π¦
pageβ pointer to the page to be mapped. that's it, that's the whole argument, she's lowkey simple like that π«Ά
β RETURN β
the virtual address of the mapping. slay, that's what you get back β¨
π DESCRIPTION π
okay so here's the tea. you can invoke this from any context, including interrupts. any context, bestie, no cap π«Ά
but β and this is the important part β it requires careful handling when nesting multiple mappings, because the map management is stack based. the unmap has to happen in the reverse order of the map operation:
addr1 = kmap_local_page(page1); addr2 = kmap_local_page(page2); ...
kunmap_local(addr2); kunmap_local(addr1);
β οΈ unmappingaddr1beforeaddr2is invalid and causes malfunction. not a vibe. do not do this. π
contrary to kmap mappings, the mapping is only valid in the context of the caller and cannot be handed to other contexts. it's main character energy: it stays in its own lane π
on CONFIG_HIGHMEM=n kernels and for low memory pages, this returns the virtual address of the direct mapping. only real highmem pages are temporarily mapped π₯
while kmap_local_page is significantly faster than kmap for the highmem case, it comes with restrictions about the pointer validity. fast, yes. free, no. the tradeoff is real π
on HIGHMEM enabled systems, mapping a highmem page has the side effect of disabling migration in order to keep the virtual address stable across preemption. and listen β no caller of kmap_local_page can rely on this side effect. it's a side effect, not a promise, bestie, don't build your whole personality on it π
π SEE ALSO π
kernel file ./include/linux/highmem.h, plus this whole iconic friend group:
kmap(9)kunmap(9)kmap_to_page(9)kmap_flush_unused(9)kmap_local_folio(9)kmap_atomic(9)clear_user_page(9)clear_user_pages(9)clear_user_highpage(9)clear_user_highpages(9)vma_alloc_zeroed_movable_folio(9)memcpy_from_folio(9)memcpy_to_folio(9)folio_zero_tail(9)folio_fill_tail(9)memcpy_from_file_folio(9)folio_zero_segments(9)folio_zero_segment(9)folio_zero_range(9)folio_release_kmap(9)
and that's the whole page, bestie π§π this one lives in ./include/linux, dated October 2026, and it's filed under kmap_local_page(9). go forth and unmap in reverse order, i'm begging you ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms