Segmentation

Segmentation is a non-contiguous memory management technique. Here the program is divided into variable size parts called segments. So far, we have read about paging, which supports the operating system view of memory. Paging divides the secondary memory into fixed-size partition called pages. Whereas segmentation is a variable size partitioning technique that supports the user’s view of memory. As a user, we view the process as consisting of functions or modules. Therefore in segmentation, the system divides the memory requirement of a process into modules. The modules may be allocated to different locations inside the memory. But, all the addresses of one particular module are together.

A segment is a logical unit such as the main program, function, stacks, common blocks, symbol table etc.

User's view of Memory
Figure-1 User’s view of Memory

As shown in the figure above, the process consists of four segments. So, the segments can be given different memory location. But, the addresses of one particular segment are together.

The logical address space is a collection of segments. Each segment has a
1. Name
2. Length

Name specifies the segment name. For example S1 or Segment 1. The length tells the total number of addresses in the segment.

The address specifies both the segment name and the offset within the segment. Thus, a logical address consists of two things
1. segment number
2. offset
The syntax of writing a logical address is as shown below

<segment-number, offset> 

For example, <2,100> means the segment number is 2 while the offset is 100.

Hardware Support using Segment Table

For every process, the system maintains a segment table. This segment table is used to map the logical address into a physical address. Each entry in the segment table has a segment base and segment limit. The segment base contains the starting physical address while the segment limit specifies the length of the segment.

Mapping of logical Address to physical address
Figure-2 Mapping of logical Address to a physical address

Example

Calculate the physical address for each of logical address given below in the form of <segment number, offset>

Segment table

a) <0,400>

the base address of segment number 0 is 200. The vale of limit is 500. Thus, the address space of segment 0 is lies between 200 to 700. Hence, the physical address will be 200+400= 600.

b) <1,21>

the base address of segment number 1 is 2300. The value of limit is 20. Thus, the address space of segment 1 lies between 2300 to 2320. Hence, the physical address after the calculation is 2300+21= 2321. But, this will generate a trap because the address is going beyond the limit.

Practice Question

For the given segment table, calculate the physical address if the logical addresses are

  1. <0,430>
  2. <1,15>
  3. <2,400>
  4. <3,95>
Segment table

Share your answers in the comments section

PPT on Segmentation

Note: Clicking on the “next” slide button will not display any animation. Hence, Click within the slide area for animations.

Video on Segmentation

Previous                             Next
Paging                          Virtual Memory

13 thoughts on “Segmentation

  1. Segment 0 ->649
    Segment 1 -> 2315 , trap because it’s beyond limit which is 2314
    Segment 2 -> 1727
    Segment 3 -> 2047

  2. 1. 649 in range of 219 to 819
    2. 2315 out of range in 2300 to 2314 which will generate a trap
    3. 1727 in range of 1327 to 1907
    4. 2047 in range of 1952 to 2048

  3. 1. 0-649
    2. It will generate a trap because the adddress is going beyond the limit.
    3. 1727
    4. 1952

Leave a Reply

Your email address will not be published. Required fields are marked *