mtrr_add(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… 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 is true, 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 whenever
  • MTRR_TYPE_WRCOMB โ€” write data back soon but allow bursts
  • MTRR_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