Kernel – Is the MMU Inside Unix/Linux Kernel or Hardware Device?

kernelmemoryvirtual-memory

So i always thought MMU is part of the unix kernel that translates addresses to physical addresses but in the MMU wiki page it says its a computer hardware that usually have its own memory, but that page doesn't talk much about Unix/Linux operating systems

So I'm confused, does the all the translation happen in hardware and kernel doesn't do any translation? and basically the operating system doesn't know anything about the real physical address?

I'm asking about Unix based operating systems, but if you know about other operating systems as well like windows or if its a general thing in modern computers let me know, thanks.

Best Answer

The MMU (memory management unit) is a physical component of the computer system, typically part of the CPU (but not necessarily). It translates virtual addresses (also known as linear addresses in the x86 world) to physical addresses; it can also enforce memory access control, cache control, and bus arbitration. It doesn’t usually have its own memory, it relies on data in the system’s main memory to operate.

The MMU performs this translation by using information stored in data structures such as page tables; these specify which physical address ranges correspond to linear address ranges (if any — a page can be “not present”). The page tables are set up by the kernel, and the kernel determines what the mappings should be — so the ultimate authority on physical addresses is the kernel, however it always operates with the help of the MMU. Put another way, the CPU always operates on linear addresses, which are translated to physical addresses by the MMU, but the kernel is aware of the translations and programs the MMU to perform them.

User-space processes are oblivious to all this and aren’t (normally) aware of the physical addresses corresponding to the linear addresses they use, and typically can’t access the mappings either. There are some cases where physical mappings leak, but those are usually considered to be security vulnerabilities and quickly addressed. However, in Linux, processes with sufficient privileges can see their physical map in /proc/<pid>/pagemap.

For Linux specifically, see the memory management documentation, and in particular the section on examining page tables.

Related Question