memremap(9)
β¨ memremap β the kernel API manual, but make it make sense β¨
okay so this is memremap(9) from the Kernel API Manual, and honestly bestie, if you've ever been like "hmm I need to map an iomem_resource but as cacheable memory," this is literally your girl π
π NAME π
memremap β remap an iomem_resource as cacheable memory π
π¦ SYNOPSIS π¦
void * memremap (resource_size_t offset , size_t size , unsigned long
flags );
like, that's the whole vibe. three args, one pointer out. slay.
πΈ ARGUMENTS πΈ
offsetβ the start address of the iomem resource. where the mapping begins, bestie πsizeβ how big the remap is. the size of it. yep π«Άflagsβ any ofMEMREMAP_WB,MEMREMAP_WT,MEMREMAP_WC,MEMREMAP_ENC,MEMREMAP_DECπ©
π DESCRIPTION π
so memremap is basically ioremap for the cases where you already know the resource you're mapping doesn't have i/o side effects, and the __iomem annotation just isn't applicable. it's the chill, no-drama version πβ¨
and here's the tea about multiple flags: if you pass more than one, the different mapping types get attempted in the order listed below until one of them succeeds. first come, first served, periodt π₯
π§ the flags, one by one π§
MEMREMAP_WBβ matches the default mapping for System RAM on the architecture, and that's usually a read-allocate write-back cache. AND, key detail: ifMEMREMAP_WBis specified and the requested remap region is RAM,memremapwill bypass establishing a new mapping and instead just return a pointer into the direct map. no new mapping, no problem π«MEMREMAP_WTβ establishes a mapping where writes either bypass the cache or are written through to memory, and never exist in a cache-dirty state with respect to program visibility. very "clean hands" of it honestly. β οΈ but attempts to map System RAM with this mapping type will fail. no cap.MEMREMAP_WCβ establishes a writecombine mapping, where writes may be coalesced together (e.g. in the CPU's write buffers), but is otherwise uncached. also β οΈ attempts to map System RAM with this mapping type will fail. it's giving picky, and we respect it.
lowkey important:MEMREMAP_ENCandMEMREMAP_DECare listed up in the flags, but the description only breaks down the three above. don't come for me, I'm just telling you what the page says π
π SEE ALSO π
- Kernel file
./kernel/iomem.cβ go read it, it's right there π
and that's the whole page, bestie! no notes, go map something cacheable π¦β¨
this lil masterpiece came from the ./kernel source, dated October 2026 β mwah, sending you love from the Kernel API Manual πππ«Ά
π¦ 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