memory abstraction
Summary
Memory abstraction methods
| Method | Core Idea | Blocks | Fragmentation | Advantages | Disadvantages |
|---|---|---|---|---|---|
| physical | physical memory addresses | dynamic | - | - simple - no overhead | - clashing load/store - no protection |
| address relocation | logical addresses + relocation register | dynamic | - | - programs can be loaded anywhere - improves flexibility | - limited protection - still assumes contiguous allocation |
| base + limit | logical address + base register, checked against limit for protection | dynamic | - | - memory protection | - additional compute and check |
| fixed partitioning | process occupies one fixed partition | fixed | internal | - easy to implement - fast access | - partition need to contain large processes, some space is wasted |
| dynamic partitioning | process occupies one partition of the exact size needed | dynamic | external | - removes internal fragmentation - flexible | - need size info in OS - difficult memory allocation over time |
| buddy blocks | memory split into power-of-two sized blocks | dynamic (2ⁿ) | both | - efficient allocation/deallocation - reduces fragmentation | - small blocks are not cost effective |
Disjoint memory schemes
| Method | Core Idea | Blocks | Fragmentation Type | Advantages | Disadvantages |
|---|---|---|---|---|---|
| paging | memory split into fixed-size pages/frames, process divided into pages | fixed | internal | - simple allocation | - page table overhead, extra memory access (unless cached via TLB) |
| segmentation | memory divided into logical segments | dynamic | external | - segments are contiguous - can be protected/shared independently | - more complex allocation |
| segmentation + paging | combines segmentation and paging | fixed, dynmic number | both | - reduces fragmentation - dynamic growth | - high overhead (multiple lookups) |
Concept
RAM
- array of bytes with unique physical addresses
- contiguous region - interval of consecutive addresses
Data
- transient - valid for limited time
- persistent - valid for the duration of the program
- both types can grow or shrink during execution
Role of the OS
- allocate memory space to a new process
- manage memory space for process
- protect memory space of processes from each other
- provide syscalls for processes to access memory
- manage memory for internal use within the process
Physical addressing
- processes load and store from physical addresses
- direct addressing
- hard to run multiple processes
- load and stores may clash
- hard to protect memory space
Relative addressing
Logical address
- physical addressing is bad
- each process has a self-containted logical memory space
- OS manages the mapping from logical to physical memory
Address relocation
- when loading the process into memory
- add an offset to all memory references for a particular process
- slow -> need to calculate everything
- hard to distinguish memory refernce from other instructions
Base + Limit registers
- base register -> points to the start of the space allocated to the process
- limit register -> size of the space allocated to the process
- at compile time, memory references are compiled as an offset from the base register
- need to compute
physical = base + offsetand checkoffset < limitfor every access