kmap_local_page(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 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);
⚠️ unmapping addr1 before addr2 is 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:


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