COP4600
Quiz 5 Key
29 October 2012
1.Describe two significant advantages of segmentation over paging. Explain.
2.Describe two significant disadvantages of segmentation compared to paging. Explain.
3.Describe how a logical address is translated to a physical address in pure segmentation. Include all tests/checks.
KEY
1.Significant advantages: (any two will do, need to explain why it is an advantage) (3 pts)
a)Can protect data, text from incorrect access type (rwx). Segment table entry can specify access type(s) allowed, prevent execution of data, e.g.
b)Can control access to segments separately (privilege level). Segment table entry can specify privilege level needed to access segment (e.g., can prevent user level code from accessing kernel data structures directly – require calling system routine to access them with switch to higher privilege when routine is called).
c)Can support multiple data structures that may grow/shrink independently of each other. Each variable sized data structure can have its own segment.
d)Can share text (code) segment amongst multiple processes easily. Different processes can have a segment table entry that points at the same physical memory location.
e)Can easily define shared data segment (for shared variables like locks). Different processes can have a segment table entry that points at the same physical memory location.
f)Supports threads naturally. Easy to share text segment(s) and data segment. (See above two).
g)Makes relinking programs with multiple relocatable object files. Each relocatable object file can have its own text segment, so if the code changes, only the offsets for references to objects/instructions in that segment need to be changed, as opposed to all references to objects/instructions in that segment or any that come after it in the linked executable.
h)Programmer is given power to define segments and take advantage of the multiple linear address spaces. The programmer knows locality better than the system does, and can design the code and data structures so that it has better locality and the segmentation system can work more efficiently.
i)Fixed sized segments can be give exactly the space they need – no internal fragmentation. Pages are fixed size, and so one can expect that half of the last page in an allocation will be unused. If a segment does not need room to grow (e.g., stack, data segments), then it can be given an allocation that fits it precisely.
Note that having a larger virtual address space than the physical address space is NOT an advantage over paging, since paging also has this benefit.
Note that faster loading with demand segmentation is also NOT an advantage over paging, since demand paging also has this benefit.
2.Significant disadvantages: (any two will do, but need to explain why it is a disadvantage) (3 pts)
a)Programmer needs to be aware of segmented addressing – more complex.
b)Pure segmentation has various sized segments, which makes finding a free contiguous space in memory more complicated than paging where any page frame will do. The whole segment has to be fit into RAM.
c)Pure segmentation leads to checkerboarding (external fragmentation). As segments are allocated and deallocated, many small holes can develop, which may require compaction to consolidate the holes, which is very costly.
d)Pure segmentation has variable sized holes in memory, so free space management is more complex than it is in paging, where one only has to note whether a page frame is free or not.
e)Pure segmentation requires that the whole segment be loaded into memory before use, making it slower than loading a few pages (if the segment is large) and also possibly wasting memory, if only a small part of the segment is actually accessed.
3.(4 pts) The logical address (LA) consists of a segment number and an offset.
a)The segment number is used to index into the segment table to get the segment table entry (descriptor), which has the base address, limit, protection, privilege, referenced bit, modified bit, valid (present) bit, etc. (1 pt)
b)The valid bit is checked to verify that the segment is in memory. If not, a segment fault is generated causing the segment to be loaded into memory before the process can continue. (1 pt)
c)The offset is compared to the limit value for the segment. If the offset is not less than the limit, then the offset is illegal (attempt to access memory outside of allocation for segment); an illegal memory access fault is generated, terminating the process. (1 pt)
d)If the segment is in memory and the offset is within the limit, then the offset is ADDED to the segment base address to generate the physical address. (1 pt)
e)Other checks include testing for appropriate type of access (rwx) and testing for privilege level required vs. mode bits. (bonus pt)