Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set memory as uncacheable through x86 PAT table

Tags:

linux

x86

I want to set a range of memory as uncacheable (Linux, x86-86) from within a user-space process. This question comes close, but only mentions the MTRR registers which work with physical memory. I want to do this using the PAT tables as they offer finer-grained control, they allow virtual memory to be set uncacheable on a page-by-page basis.

The Linux documentation, Documentation/x86/pat.txt, suggests there should be something with mmap and a SYNC flag, but I can't find how to do this in practice. Ideally, I'd like to use a call such as mprotect(address, range, O_UNCACHABLE).

like image 627
Wim Avatar asked Feb 09 '12 11:02

Wim


1 Answers

I would recommend writing a kernel module to provide the necessary interface for a user–level process. Inside the kernel module you can use set_memory_uc to control the page attributes.

Regarding the simulator: it should be around ten to thousand times slower—not a million times—unless you simulate at the gate level. Don't forget to consider the time it takes you to write the kernel module. If it takes you a few weeks to write and debug the module you may be better off using a simulator for a one time experiment.

like image 101
Mackie Messer Avatar answered Oct 21 '22 09:10

Mackie Messer