Autosave: 2024-07-09 07:00:03

This commit is contained in:
thomasabishop 2024-07-09 07:00:03 +01:00
parent 9f6e7329fe
commit 3d40d6868c
2 changed files with 26 additions and 19 deletions

Binary file not shown.

View file

@ -4,14 +4,16 @@ tags:
- Linux - Linux
--- ---
# Virtual memory and the Memory Management Unit # Virtual memory
## What is virtual memory? Virtual memory is an abstracted and idealised representation of the physical
memory capacity of the machine that is presented to user space for its memory
operations.
Virtual memory is an abstraction of physical memory capacity and allocation that When an OS implements virtual memory, processes in user space cannot directly
is accessible to user space. The kernel handles physical memory allocation and read or write to the actual memory. Instead they execute memory operations
presents this to user space as a simplified and idealised representation of the against virtual memory and the kernel translates these into actual operations
available memory of the system. against the memory hardware.
The main benefits: The main benefits:
@ -20,20 +22,25 @@ The main benefits:
- There is a buffer between user mode processes and physical memory, meaning - There is a buffer between user mode processes and physical memory, meaning
that memory cannot be accidentally corrupted by other processes in user space. that memory cannot be accidentally corrupted by other processes in user space.
When a process writes or reads from a virtual memory address this does not Because the physical memory is abstracted, it can be the case that the physical
directly refer to a hardware memory location. The kernel translates this into a memory addresses are non-contiguous or even distributed accross different
physical memory address but this is opaque to the user space process. In fact, hardware components (such as the cache and swap). Despite this, the memory
the physical memory addresses could be distributed accross multiple addresses will appear contiguous in virtual memory. Each user space process is
non-contiguous locations such as cache and swap memory, not just DRAM. presented with the same range of available memory addresses and the same total
capacity.
Although the physical memory may be distributed and non-contiguous, from the It is possible for the kernel to present user space with an available virtual
viewpoint of user space, the available virtual memory is contiguous. Each user memory capcacity that actually exceeds the current physical capacity of the
space process is presented with the same range of available memory addresses and machine:
the same total capacity.
Because this is virtual, there is no risk of one process reading or overwriting > _It's possible for the kernel and all running processes to request more bytes
the address of another. The same virtual address for multiple programs maps to > of virtual memory than the total size of RAM. In that situation, the OS can
different physical addresses. > move move bytes of memory to secondary storage to make room in RAM for newly
> requested memory._
_How Computers Really Work_ (2021) p.206
// Next: the kernel also uses virtual memory however isn't also responsible for
the appportioning of virtual memory. Confused.
// Next: more memory offered than is physically available.
![](/img/virtual-memory-diagram.jpg) ![](/img/virtual-memory-diagram.jpg)