Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Segmentation in Operating System

Operating systems use a number of memory management strategies to keep your computer operating efficiently. Segmentation in OS, which divides memory into controllable parts, is one of these. We’ll go through the operating system’s segmentation mechanism and its workings in this article. We’ll also talk about how it can improve the overall performance of your computer.

Data objects are stored on the storage device in segments using the memory management method known as segmentation in OS. It creates segments, or fixed-sized chunks, from the process or user-accessible area.

The process of assigning and managing a computer’s virtual address space is known as memory management. In plain English, it is the method through which computers maintain track of the projects they are working on at any one time. Various kernel components might operate in different address regions thanks to the memory management method known as segmentation in OS.

What is Segmentation in OS?

A memory management strategy called segmentation divides an application’s virtual address space into sections.
The operating system may keep track of which memory space is being used and which is free by dividing the memory up into manageable pieces. As a result, the operating system can allocate and deallocate memory considerably more quickly and easily. The segments are not arranged in a continuous manner and are of different sizes. Internal fragmentation doesn’t happen since it uses a non-contiguous memory allocation mechanism. In a user program, the segment’s purpose is used to determine the segment’s length.

Why Segmentation is Required?

The issues with the paging method led to the creation of segmentation. When using the paging approach, a function or piece of code is divided into pages without taking into account the possibility of further division of the related sections of the code. So that the entire associated code is available for execution, the CPU must load more than one page into the frames for the process that is now in use. For a process to be loaded into the main memory, paging required extra pages. Thus, segmentation—the division of code into modules—was created so that similar code might be merged into a single block.

The fact that the user’s perspective of physical memory is different from the real view of physical memory is a significant shortcoming of other memory management strategies. By breaking the user’s software into parts based on the particular need, segmentation aids in issue solving.

Segment Table and its Uses

The data for each segment of the process is kept in a segment table. As is well known, a segment table is used to translate a logical address created by the CPU into a physical address. The segment table is used to translate a two-dimensional logical address into a one-dimensional physical address.

There are two parts to the segment table:

  1. Segment Base: The base address of a segment is another name for the segment base. The memory segments’ initial physical addresses are contained in the segment base.
  2. Segment Limit: Segment offset is another name for the segment limit. The segment’s precise length is contained inside it.

Below is a basic illustration of the segment table.

  • STBR: Segment Table Base Register is referred to as STBR. The segment table’s base address is kept in the STBR.
  • STLR: Segment Table Length Register is referred to as STLR. The amount of segments a program uses is stored in STLR.

NOTE: The segment table itself is kept in the main memory as a distinct segment. If there are many segments, the segment table may occasionally use a lot of memory.

Types of Segmentation

Segmentation can be divided into two types:

1. Virtual Memory Segmentation:

Processes are divided into n parts using virtual memory segmentation. Not all of the segments are separated at once. A program’s execution time may or may not involve virtual memory segmentation.

2. Simple Segmentation:

Although the segmentation is completed all at once, Simple Segmentation also splits the operations into n parts. Simple segmentation happens during a program’s execution time. One part of the process could be located in a different position than another due to simple segmentation that scatters the segments into the memory (in a noncontinuous manner).

Characteristics of Segmentation

Some of the characteristics of segmentation are discussed below:

  • The program is divided into chunks with varying lengths by segmentation.
  • Partition size is influenced by the kind and size of modules.
  • The idea behind segmentation is that the related data should fit into a single segment.
  • Depending on the segmentation approach selected, memory segments may or may not be stored continuously.
  • For each process, the operating system keeps a segment table.

Advantages of using Segmentation Technique

Some of the Advantages of segmentation technique are as follows:

  • By enabling various kernel components to execute on multiple processor cores, it can increase the system’s effectiveness.
  • By letting many threads operate simultaneously, it can also increase the system’s responsiveness.
  • improved CPU usage
  • Offer a remedy for internal fragmentation.
  • The segment table is used to keep track of segment records. The RAM needed to hold this segment table is also used.
  • Data and security protocols can be kept separate.
  • The user’s perception of physical memory is quite similar to segmentation. Users can divide user programmes into modules via segmentation. These modules are nothing more than the separate processes’ codes.
  • In contrast to paging, where the hardware determines the page size, the user selects the segment size.

Disadvantages of using Segmentation Technique

  • The price of system performance may go up. This is necessary so that the kernel may allocate fresh memory for a segment while it is in use.
  • When compared to using a simpler memory management strategy, the system may need more resources to manage segmentation.
  • It is fragmented on the outside.
  • costs associated with keeping a segment table for each process.
  • Since two memory visits are now necessary—one for the segment table and the other for main memory—access time to retrieve the instruction rises.
  • Segments of different sizes are not suitable for switching.

How Does Segmentation Work?

Data is divided into manageable parts using the memory management method known as segmentation. The system initially looks for the segment that holds the data when you wish to store or read it.

The paging idea is the same as this one. However, unlike paging, segmentation divides the process into larger units known as segments or modules rather than pages. This logical address is produced by the CPU. The supplementary memory is accessible at this logical address. However, the CPU must use the main memory. What should we do now? Address translation is necessary in this situation to translate a logical address into a physical one.

An address for locating data in the main memory is known as a physical address. The segment table will now be used by the CPU. A data structure for keeping track of all process segments is known as a segment table. The logical address is translated into a physical address by the CPU using a segment table. There are two different sorts of information in the segment table.

  1. Limit: Actual size of a segment.
  2. Base Address: the address of the segment in the main memory.

If the value of the offset(d) equals the Limit, then. Only the CPU will then be able to read that section otherwise, an error will occur. The size of the segment that the CPU wishes to read is shown by offset(d).

Segmentation Example

Let’s say the CPU desires access to section 3. The segment number and size of the segment it wishes to read are specified in a logical address that is generated by the program (as illustrated below). The intended section size is 300. This indicates that segment 3’s 300 instructions will be read by the CPU. The CPU learns that the base address is 2500 after reading the segment table. However, the portion is 200 instructions long. Offset(d)>Limit in this case. So an error will result from this.

An operating system’s performance can be increased by using the memory management approach of segmentation. The operating system can better control its memory utilisation by segmenting physical memory, which boosts productivity and speed. Please spread the word about this article to your friends if you enjoyed it.

FAQs related to Segmentation in OS

1. What is segmentation and paging in the OS?
In paging, a process address space is divided into units called pages. When segmenting, we divide the address space of a process into units called sections. The pages come in fixed-size chunks. Different-sized bricks make up the parts.

2. What is an example of segmentation in OS?
Now imagine that the CPU requests segment number 2, which is 400 bytes long and is located at address 4300 in the memory. The 53rd byte of segment 2 is what the CPU wants to refer to. Therefore, segment number 2 and offset 53 are the inputs the CPU provides in this case.

3. What is paging give an example?
Paging is a storage method used in operating systems to recover processes as pages from secondary storage and place them in main memory. The basic purpose of pagination is to separate each procedure into pages. Frames will also be used to divide up the main memory.

4. What is the importance of segmentation in OS?
An effective memory management method is segmentation. Users can divide their applications into modules that run separately from one another. In paging, the segment table is smaller than the page table in size. Segments make it simple for two processes to exchange data.

Leave a Reply

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