16. Segmentation Flashcards
What is segmentation?
Dividing the address space by having a base and bounds pair per logical segment. The segments are code, stack and heap.
What is a sparse address space?
A virtual address space that contains unused areas of memory
What is segmentation fault?
Accessing an address that is out of bounds
How many bits do we use to address segments?
Two bits, because there are three segments (code, stack, heap)
How to calculate offset in code and heap segment?
(Virtual address minus previous segment address) + base address
How to calculate virtual address in stack segment?
(Offset - maximum segment size) + base address
What are protection bits?
Bits to indicate whether the program can read, write or execute the segment.
What is coarse-grained segmentation?
Address space of a process is divided into a small number of large segments
What is fine-grained segmentation?
Address space of a process is divided into a large number of small segments
What is a segment table?
A data structure used in memory management to keep track of segments in process address space. For each segment, there will be a base and bounds value
What is external fragmentation?
When there are gaps between the address spaces
What are some ways to fix external fragmentation?
Reorder and compact the existing segments
What are some algorithms for free-list management?
- Best-fit: Traverse the whole list and find the smallest slot that can fit it
- Worst-fit: Traverse the whole list and find the largest slot that can fit it
- First-fit: Fit it in the first slot that can fit it
- Last-fit: Start traversing from the last slotted position and fit it in like first-fit
What are some problems of segmentation?
- Context switch: save the registers and restore them
- Malloc: no solution to grow it dynamically
- Variable sizing: every segment has different sizes