Segmentation Flashcards
Why is segmentation useful?
If we did not do segmentation, then there would be lots of wasted space, for example between the stack and the heap, in each address space.
What is the basic premise of segmentation?
For each logical segment, e.g. stack, heap, code etc. we have one base and bounds register pair in our Memory Management Unit.
How do we translate from a segmented heap address to the physical address?
Take the segmented address (say 4200), and find where the virtual heap starts (say 4100), and compute the difference (100). Then, add this value to the base register for the heap (say 0x23492837 + 100), and check it is within bounds.
How does the MMU know which segment we are referring to? What is the problem with this?
Often, the first few bits of a virtual address will refer to which segment we are trying to access. For example, 01 might mean that it is the heap segment, and 11 might mean it is the stack segment etc.
The problem with this is that it limits how many virtual addresses we can have in an address space.
What might we need to specify in the MMU, to show that the stack is different from the heap segment?
Aside from using the first few bits to indicate this, we also must record that the stack grows negatively.
Why might the MMU need to include protection bits for each of its segments?
This is important if we are sharing memory. For example, it would be useful to be able to share code memory, but we must make sure that this can only be read and executed.
What is external fragmentation?
When the physical memory becomes full of little holes between segments, making it hard to allocate new segments.