TeachingBee

The Ultimate Guide to Segmentation in OS

segmentation in os

Method 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.

segmentation
User’s View Of Memory

Types of Segmentation In OS

Different types of Segmentation are:

  1. 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.
  2. 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.
Screenshot 2022 05 03 at 4.58.44 PM

Translation Of Two dimensional Logical Address To One Dimensional Physical Address

segementationImpl
Translation Of Two dimensional Logical Address To One Dimensional Physical Address
  1. When a program gets loaded into memory, the system looks for space enough to hold first segment which is obtained from memory manager.
  2. 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.
  3. Logical address generated by CPU consists of two parts segment name/number + offset as discussed above.
  4. Using the segment number, Physical Base address and limit is determined from segment table.
  5. 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

ParametersPagingSegmentation
Memory SizeAddress space is partitioned into fixed sized blocks called pages.Address space is partitioned into varying sized blocks called segments.
SizePage size is determined by available memory.Section size is determined by the user.
Data StoragePage table is used to store paging data and mapping.Segmentation table is used to segmentation data and mapping.
FragmentationIt 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 AddressIn paging logical address is combination of page number and page offset.During segmentation, a logical address is divided into section number and section offset.
TableA 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.
SpeedPaging is faster in terms of memory access.Segmentation is slower than paging.
Difference Between segmentation and 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!

90% of Tech Recruiters Judge This In Seconds! 👩‍💻🔍

Don’t let your resume be the weak link. Discover how to make a strong first impression with our free technical resume review!

Related Articles

Types of Memory and Storage in system design thumbnail

Types of Computer Memory and Storage

In this article we will look into different types of computer memory, distinguishing between primary memory and secondary memory. We will also see their characteristics, major kinds, usage, and key

latency in system design thumbnail

What is Latency In System Design?

In this article we will look into Latency In System Design, we will see how is latency introduced into the systems and what are various ways to reduce the latency

Why Aren’t You Getting Interview Calls? 📞❌

It might just be your resume. Let us pinpoint the problem for free and supercharge your job search. 

Newsletter

Don’t miss out! Subscribe now

Log In