16. Segmentation Flashcards
What is the issue with base and bounds that segmentation tries to solve? How does it solve it?
Internal fragmentation because of unused space between stack and heap. Instead of allocation a contigious chunk of memory, a segment per logical segment of program is allocated (for code, heap, stack).
What registers does segmentation use?
It uses three pairs or base/bounds register (1 pair per segment)
How does hardware knows an offset into segment and to which segment the reference is made in explicit approach?
Use top bits of virtual address to distinguish between segments. The rest of bits in address is offset.
What are downsides of explicit approach?
- 1 bit goes unused as there are 4 variations and only 3 segments (some systems put code in the same segment as heap to solve this)
- Each segment is limited to a maximum size
How does hardware knows an offset into segment and to which segment the reference is made in implicit approach?
Hardware determines the segment by noticing how address was formed (i.e from program counter, based off of the stack, else is heap)
What additional hardware information is required to have with stack and why?
Because stack grows upwards (to lower addresses), an extra bit that indicates whether it grows upwards or downwards is required.
How is physical translation performed for a stack?
Instead of just adding the offset to base, the maximum size segment is subtracted from offset, and then this value is added to base
What kind of efficiency (among others) exist in segmentation that required new support from hardware in form of protection bits? What is protection bit?
Code sharing. Protection bits indicate whether or not program can read, write or execute segment
How is segmentation where address space is chopped up into relatively large, coarse chunks is called? What is the opposite?
Coarse-grained. Opposite is fine-grained where address space consists of a large number of smaller segments.
What does fine-grained segmentation approach requires?
Some kind of segmentation table to manage large number of segments
Segmentation solves internal fragmentation, but brings an issue of …
External fragmentation due to variable sized chunks of memory.
What technique can be used to fix external fragmentation?
Compacting physical memory (rearranging segments)
What OS should do with virtual memory variables on context switch?
All base/bounds register must be saved/restored
What OS should do when the memory is requested in heap, but heap is too small?
Grow the heap size (e.g with sbrk() or brk() system call) and update segment size register (bounds)