Segmentation

A user program can be subdivided using segmentation, in which the program and its associated data are divided into a number of segments.

Not required that all segments of all programs be of the same length. There is a maximum segment length.

A logical address using segmentation consists of two parts, in this case a segment number and an offset.

Because of the use of unequal-size segments, segmentation is similar to Dynamic Partitioning. In the absence of an overlay scheme or the use of virtual memory, it would be required that all of a program’s segments be loaded into memory for execution.

Consequences:

  • Another consequence of unequal-size segments is that there is no simple relationship between logical addresses and physical addresses. Analogous to paging, a simple segmentation scheme would make use of a segment table for each process and a list of free blocks of main memory.

Segment Table

  • Segment table for each process
  • Each segment table entry would have to give the starting address in main memory of the corresponding segment
  • Entry should also provide the length of the segment to assure that invalid addresses are not use
  • When a process enters the Running state, the address of its segment table is loaded into a special register used by the memory management hardware

Steps for address translation:

  •  Extract the segment number as the leftmost n bits of the logical address.
  •  Use the segment number as an index into the process segment table to find the starting physical address of the segment.
  •  Compare the offset, expressed in the right most m bits, to the length of the segment. If the offset is greater than or equal to the length, the address is invalid.
  •  The desired physical address is the sum of the starting physical address of the segment plus the offset.