Table of Contents
ToggleMethod of managing and coordinating computer memory, distributing blocks of memory to different running programs in order to enhance the performance of the entire system is called memory management. Paging and Segmentation in OS are the one of the schemes for memory management in OS. Segmentation came into existence because of the limitations in the paging technique.
In this article we will look into segmentation in OS in detail along with examples and how it is implemented in OS.
What is Segmentation in OS?
Segmentation in os is memory management technique in OS which divides memory into different segments which may or may not be of same size.Segmentation provides user’s view of memory which is mapped to physical memory using segment table. We will discuss its implantation further in article.
What is User’s View of Memory?
User’s view of memory is view of memory as collection of different size segments without any relative ordering between segments.
Types of Segmentation In OS
Different types of Segmentation are:
- Virtual Memory Segmentation: This type of segmentation divide process into n segments but division of these don’t happen at single point of time. This type of segmentation in os don’t happen at run time.
- Simple Segmentation: This type of segmentation also divides process into n segments but contrary to virtual memory segmentation the segmentation is done all together at once and it takes place at run time.
Mapping Logical Address Into Physical Address By Segment Table
Logical Address space is divided into different segments of different size. Each segment has a name and length. Thus to access particular address location user specifies two things segment name and offset( the memory address within that segment).
Thus logical address can be seen as combination of two things: segment name/number + offset
Segment Table
To map the logical address to physical address segment table is used.Table consists of two columns.
- Base Address: Containing the starting physical address of the segments in the memory.
- Limit: It specifies the maximum length of the segment.
Translation Of Two dimensional Logical Address To One Dimensional Physical Address
- When a program gets loaded into memory, the system looks for space enough to hold first segment which is obtained from memory manager.
- Once this is done, it looks for space for other segments. Once all segments are assigned the space, each is loaded into these allocated space, correspondingly maintaining the segment table for each.
- Logical address generated by CPU consists of two parts segment name/number + offset as discussed above.
- Using the segment number, Physical Base address and limit is determined from segment table.
- If the segment offset is less than limit obtained from segment table, 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 In OS
- Since segments are of variable sizes there is no internal fragmentation in case of segmentation.
- There is less overhead as compared to paging.
- Since process is divided into segments this it becomes easier to relocate segments than entire address space.
- The segment table is of lesser size as compare to the page table in paging.
Disadvantages of Segmentation
- Segmentation in OS can cause external fragmentation.
- Memory management algorithms for segmentation are costlier.
- Allocating contiguous memory to variable sized segments is difficult.
Difference Between segmentation and Paging
Parameters | Paging | Segmentation |
---|---|---|
Memory Size | Address space is partitioned into fixed sized blocks called pages. | Address space is partitioned into varying sized blocks called segments. |
Size | Page size is determined by available memory. | Section size is determined by the user. |
Data Storage | Page table is used to store paging data and mapping. | Segmentation table is used to segmentation data and mapping. |
Fragmentation | It cause internal fragmentation as some pages can go un utilised. | It can cause external fragmentation as some memory block may not be used at all. |
Logical Address | In paging logical address is combination of page number and page offset. | During segmentation, a logical address is divided into section number and section offset. |
Table | A logical address in paging is combination of page number and page offset. | A logical address in segmentation is combination of segment number and segment offset. |
Speed | Paging is faster in terms of memory access. | Segmentation is slower than paging. |
Conclusion
Paging and Segmentation in OS are two schemes for memory management is OS. Segmentation provides user view of memory with less overhead than paging.In this article we discussed segmentation in OS in detail along with its working underneath and looked upon some differences between paging and segmentation.
Got a question or just want to chat? Comment below or drop by our forums, where a bunch of the friendliest people you’ll ever run into will be happy to help you out!