mtrr_add(9)
๐ NAME ๐
mtrr_add โ add a memory type region โจ (yes bestie, we're registering cache regions today, it's giving hardware whisperer)
This one lives in the Kernel API Manual, section 9 of the kernel docs โ driver-dev territory, iykyk ๐ซถ
โจ SYNOPSIS โจ
int mtrr_add (unsigned long base , unsigned long size , unsigned int
type , bool increment );
๐ ARGUMENTS ๐
baseโ the physical base address of the region, like the street address of your little memory neighborhood ๐กsizeโ the physical size of the region, how many blocks we're claiming ๐typeโ which flavour of MTRR you want, the vibe of caching you're requesting ๐incrementโ if this istrue, do usage counting on the region (we keep tally, no cap ๐งฎ)
๐ฆ DESCRIPTION ๐ฆ
okay so. Memory type region registers are the girlypops that control caching on newer Intel and non-Intel processors ๐ This function is literally how a driver slides into the kernel and requests that an MTRR gets added.
The details and hardware specifics of each processor's implementation? Completely hidden from the caller ๐ The caller doesn't need to know. But โ and this is the part you cannot skip โ the caller should expect to need to provide a power of two size on an equivalent power of two boundary. That's the deal, bestie. Non-negotiable ๐
If the region can't be added, whether it's because all the regions are already in use or because the CPU just cannot support it, you get a negative value back ๐ญ no exceptions.
On success you get the register number for this entry returned โ but lowkey treat that as a cookie only ๐ช Don't go reading meaning into it, it's just a little guy to hand back later.
On a multiprocessor machine, the changes are made to all processors. And on x86 this is straight up required by the Intel processors โ everybody gets the update, periodt ๐
๐ฌ the available types ๐ฌ
MTRR_TYPE_UNCACHABLEโ no caching. None, nada, zero, the cold shoulder ๐งMTRR_TYPE_WRBACKโ write data back in bursts wheneverMTRR_TYPE_WRCOMBโ write data back soon but allow burstsMTRR_TYPE_WRTHROUGHโ cache reads but not writes (reads get the love, writes get nothing ๐)
๐ BUGS ๐
Needs a quiet flag for the cases where drivers do not mind failures and do not wish system log messages to be sent.
Like, sometimes a driver is fully fine with a failure and does not want the system log getting all loud and messy about it ๐ซ We need a quiet flag for that. It's not here yet. Note it, love it, ship it.
๐ SEE ALSO ๐
Kernel file ./arch/x86/kernel/cpu/mtrr/mtrr.c
mtrr_rendezvous_handler(9), set_mtrr(9), mtrr_add_page(9), mtrr_del_page(9), mtrr_del(9), arch_phys_wc_add(9), mtrr_bp_init(9), mtrr_save_state(9)
๐ mwah, that's the whole page bestie ๐ this one comes to you courtesy of ./arch/x86/kernel/cpu/mtrr and the October 2026 edition of the kernel API manual โ dated and documented with love, go add those regions responsibly ๐ โจ ๐ธ
๐ฆ 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