This post is based on Unix v6 which is a root for current version of Linux
How UNIXv6 manage their memory
Definition of process is “Instance of a program in execution”. And in UNIXv6, they manage
- Code : store program code
- Data : store global & static variable, heap
- local static variable : its data is located in memory until the program exit, but can be only accessed inside the function
- global static variable : its also located in memory, and also can be accessed outside the function. But not outside the program.
- User Stack : store arguments, local variable, etc.
- User : store process information(file location, Registers, etc.)
- Kernel Stack : store system variable
- proc : store essential process information which is always located in memory(PID, priority, status, location of program in disk)
- PCB(Process Control Block) : User + proc, which has metadata for process
And Text & Data segments will be replaced when Context Switch is occured(by I/O interrupt, error, child process, cpu time scheduling, etc.)
We will now note
Text + Data segment
asswappable image
orprocess image
. It is little different withPCB
. Beacuse normally PCB contains PID and Status, etc. but here these essential information is always on memory. Thus, Swappable image = PCB - (PID, Satus, Priority, etc.) to reduce the cost of context switching
But in case of that other user access directly to your memory address space that you currently using, how can you handle?
With MMU(Memory management uniut), OS can prevent from misdirection.
MMU’s can gives you 3 advantage
3 advantages of MMU(Memory Management Unit)
- Protection
- prevent R/W/Jump to other process image in memory
- Scattered Allocation
- process image can be scattered, so user can manage their memory space more efficiently
With
Page Table
, Scattered Allocation can be managed efficiently. But in UNIXv6, APR(Active Page Register) is used.
- process image can be scattered, so user can manage their memory space more efficiently
- Relocation
- when using memory, you can swap image
Scattered Allocation could be trade-off comparing to Contignous Allocation
In Contignous Allocation, it is more easy to check memory protection fault
But nowadays, we use paging tech. in memory. Thus rather Contignous Allocation, Scattered Allocation is used in current days
UNIXv6’s MMU don’t use TLB
and Page Table
, but APR
for their translation between VA(Virtual Address) and PA(Physical Address)