Operating-Systems-Notes

Memory Management

Operating systems:

Memory Management Goals

mmgoals.png

Virtual vs Physical memory

Page-based Memory Management

Segment-based Memory Management

Hardware Support

hardwaresupport.png

Memory Management Unit (MMU)

Registers

Cache

Translation

Page Tables

pagetables.png

Page Table Entry (PTE)

pfn.png

Flags

Page Table Entry on x86

pfnx86.png

Flags

Page faults

pagefaults.png

Page Table Size

pts.png

Therefore Page Table Size = (2^32 * 2^12)*4B = 4MB (per process)

Page Table Size = (2^64 * 2^12)*8B = 32PB (per process!)

But Page Table assumes an entry per VPN regardless, of whether corresponding virtual memory is needed or not.

Hierarchical Page Tables

hierarchicalpt.png

On malloc, a new internal page table may be allocated.

Address split:

Page Number offset
P1 P2 d
12 10 10

Additional Layers

hierarchicalpt2.png

Tradeoffs of Multilevel Page Tables

Advantages

Disadvantages

Overheads of Address Translation

For each memory reference :

Single level page table Four level page table
x1 access to PTE x4 accesses to PTE
x1 access to mem x1 access to mem

which results in slowdown.

Page Table Cache

ptcache.png

Translation Lookaside Buffer

Inverted Page Tables

invertedpt.png

Hashing Page Tables

hashingpt.png

Segmentation

Segmentation is the process of mapping virtual to physical memory using segments.

segmentation.png

Segmentation + Paging

segmentationpaging.png

Page Size

In real world examples,

  Large Huge
page size 2 MB 1 GB
offset bits 21 bits 30 bits
reduction factor on page table size x512 x1024

Advantages

Disadvantages

Memory Allocation

Demand Paging

Demand paging:

demandpaging.png

When pages should be swapped?

Which page should be swapped out?

Checkpointing

Simple Approach

Better Approach

Checkpointing can also be used in other services: