Today you will learn Segmentation in OS: Hardware Architecture, Need, Advantages, Disadvantages with example and a short assignment that you have to submit via email to [email protected] Segmentation gives a memory-management scheme that increases the support of the user’s perspective on memory. A user program can be subdivided using a segmentation scheme, in which the program and the information related to it are separated into different segments. In this manner, a logical address space is the collection of segments. In other words segmentation is a memory management technique, where the memory is divided into variable-size chunks. Each chunk is known as a segment that can be attached in a process.
The insights related to each segment are stored in a table named segment table. The segment table is put into one (or a large number) of chunks. The segment table mainly contains two types of data about the segment:
- Segment base address: Addresses specify both the name of the segment and the offset inside the segment. The user, thus, determines each address by two amounts: a segment name and an offset.
- Segment Limit: This indicates the length of the segment.
Need of Segmentation
An important part of memory management that has become unavoidable with paging is the partitioning of the user perspective on memory from actual physical memory. As we have just seen, perspective on user memory is not equal to actual physical memory. The user view is mapped to physical memory. Before segmenting, operating system users were using paging as the primary memory of the management method. Unlike users, the operating system has more paging. This divides all the processes into types of pages that pay little attention to the way that the process may have some common capacity fragments that must be stacked on a similar page.
The operating system could not care less about the customer’s perspective on the process. It can split a similar capacity into different pages and those pages can be compiled together in memory. This reduces the productivity of the system.
It is more suited to have a segmentation that divides the process into segments. Each segment contains the same type of functions such as the main function that can be included in one segment and the library functions can be included in the other segment.
Hardware Architecture of Segmentation
The hardware architecture of segmentation and the use of a segment table is illustrated in Figure. A logical address consists of two parts:
- A segment number: The segment number is used as an index to the segment table. It is represented by s.
- An offset into that segment: It is represented by d. The offset d of the logical address must be between 0 and the segment limit. If it is not, we trap to the operating system (logical addressing attempt beyond the end of the segment). When an offset is legal, it is added to the segment base to produce the address in the physical memory of the desired byte. The segment table is thus essentially an array of base–limit register pairs.
Figure: Hardware Architecture of Segmentation
Translation of Logical address into a physical address by segment table
The CPU generates a logical address that contains two parts: Segment Number and Offset. The Segment number is mapped to the segment table. The limit of the respective segment is compared with the offset. If the offset is less than the limit then the address is valid otherwise it throws an error as the address is invalid.
In the case of a valid address, the base address of the segment is added to the offset to get the physical address of the actual word in the main memory.
Advantages of Segmentation
- Segmentation provides a powerful memory management mechanism.
- It allows user to partition their programs into modules that operate independently of one another.
- The segment table is of lesser size as compare to the page table in paging.
- Segments allow two processes to easily share data.
- Average Segment Size is larger than the actual page size.
- It is easier to relocate segments than the entire address space.
- There is no internal fragmentation
- Less overhead
- It can have external fragmentation.
- It is difficult to allocate contiguous memory to variable-sized partition.
- Costly memory management algorithms.
- Segmentation: find free memory area big enough.
- Paging: keep a list of free pages, any page is ok.
- Segments of inconsistent sizes are also not fit for swapping.
Briefly, describe the segmentation memory management scheme. How does it differ from the paging memory management scheme in terms of the user’s view of memory?
- Briefly, describe the segmentation memory management mechanism.
- Explain and justify your answer how does it differ from the paging memory management scheme in terms of the user’s view of memory?