×

Paging and Segmentation in OS

What is Paging in OS?

Paging is a storage technique used for memory management. In paging, the (OS) Operating System retrieves the processes from the secondary memory into the main memory, and the memory is in the form of the pages. In this technique, we split the main memory into the small blocks of physical memory which are called frames. The size of the frames is fixed. In paging, for the maximum usage of the main memory and to prevent external fragmentation, the frame size must be the same as the page size. Paging is a logical concept, and it helps us to access the data faster.

Benefits of Paging

The benefits of Paging are:

  1. In Paging, there is no need of external fragmentation.
  2. In Paging, the swapping between the equal-size pages and page frames is easy.
  3. Paging is a simple technique that we use for memory management.

Drawbacks of Paging

The Drawbacks of Paging are:

  1. In Paging, there may be a chance of Internal Fragmentation.
  2. In Paging, the Page table consumes extra memory.
  3. Due to Multi-level Paging, there may be a chance of memory reference overhead.

What is Paging Protection?

Paging Protection means to protect the paging process by inserting an extra bit, known as valid/Invalid bit.

In paging, memory protection is done by adding the protection bits with each page. With each page table entry, these bits are linked. It also helps to specify the protection on the corresponding page.

Example of Paging

Suppose we have main memory, and the size of the main memory is 16 KB, and the size of the frame is 1 KB. In this, the main memory is split into 16 frames, and each frame is of 1 KB.

In the system, we have four distinct processes, and the processes are A1, A2, A3, and A4, and the size of each process is 4 KB. In this, we split or divide all the pages into the pages of size 1KB so that the OS can store 1page in 1 frame.

What is Paging?

When the process started its execution, all the frames were vacant to store process pages in a contiguous manner.

The below figure shows the frames, pages, and the mapping between the frames and the pages.

We can see in the following example that after some time, the process A2 and the process A4 are moved into the waiting state. So, the eight frames will become vacant, and we need to load or put other pages in those vacant blocks. The process A5 is having a size of eight pages (8 KB), which are waiting in the ready queue.

What is Paging?

We can see in the following example that we have eight non-contiguous frames that are existing in the memory, with the help of paging, we can store the processes at different places. Due to this, we can load the pages of the A5 process instead of process A2 and Process A4.

What is Segmentation?

Segmentation is a technique of memory management. It is just like the Paging technique except the fact that in segmentation, the segments are of variable length but, in Paging, the pages are of fixed size. In segmentation, the memory is split into variable-length parts. Each part is known as segments. The information which is related to the segment is stored in a table which is called a segment table.

There are two types of information stored in the segment table:

  1. Limit
  2. Base

Limit: - The limit is the length or size of the segment

Base: - The base is the base address of the segment.

A segment of the program comprises of the utility function, data structure, and the main function of the program for each process. The operating system preserves a segment map table for mapping. The table consists of segment number, list of the memory blocks which are free along with its size, and its memory location in the virtual memory or the main memory.

What is Paging?

Types of Segmentation:

There are two types of Segmentation:

1. Simple Memory Segmentation

2. Virtual Memory Segmentation

Simple Memory Segmentation: - In simple memory segmentation, each process is split into different segments, and at the run time, all the processes are loaded. Also, not all the processes need to be loaded into a contiguous way.

Virtual Memory Segmentation: - As simple memory segmentation, in virtual memory segmentation, each process is split into different segments, but not all of them are residents at any point of time.

Benefits of Segmentation

The benefits of Segmentation are:

  1. Internal fragmentation is not present in the segmentation.
  2. Less overhead.
  3. In segmentation, the segment table size is less than the page table size.
  4. In segmentation, the relocation of the segment is easier than the whole address space.

Drawbacks of Segmentation

The drawbacks of segmentation are:

  1. In segmentation, there may be a chance of external fragmentation.
  2. The segmentation technique is expensive.
  3. In Segmentation, it is tough to allocate memory in a contiguous manner to a variable-sized partition.

Why Segmentation is needed?

Initially, we used the Paging technique for memory management. But instead of the user, it is closer to the operating system more probably. In paging, all the processes are split into the pages. Sometimes there may be a situation where a process having some relevant sections of the function requires being loaded on the same page.

The operating system does not mind the process from the user’s point of view. The operating system split the same function into the number of pages, and at the same time, the pages may be loaded or not loaded into the memory. Due to this reason, system efficiency could be decreased.

So, it is better to use the segmentation technique for memory management. In segmentation, the process is split into the segments. In this, every segment consists of a similar kind of function as a library function contained in one segment, and the main function contained in the other segment.

Translation of Logical Address into Physical Address by Segment Table

The CPU generates a logical address that comprises of two parts:

  1. Segment Number
  2. Segment Offset

Segment Number: - Segment Number is defined as the number of bits that are needed to represent the segment.

Segment Offset: - Segment Offset is defined as the number of bits which are needed to represent the size of the segment.

What is Paging?

We map the segment number to the segment table, and after mapping, a comparison is done between the limit of the segment to the offset. If the offset bit is less than the limit, then we can say that the address is valid. Otherwise, the address is invalid.

If the address is valid then we add the base address of the segment to the offset so that we can get the physical address of the actual word in the main memory.

Difference between Paging and Segmentation

            Paging          Segmentation
Paging is a memory management technique. In paging, memory is partitioned into fixed-size pages. Segmentation is also a memory management technique. In segmentation memory is partitioned into the variable size segments.
In paging, with the help of hardware page size is determine. In segmentation, the user gives the size of the segments.
In paging the OS is accountable for paging. There is a compiler which is accountable for the segmentation.
Paging is faster than the segmentation. Segmentation is slower than the paging.
In paging, there may be a chance of internal fragmentation. In segmentation, there may be a chance of external fragmentation.
In this technique, the logical address is partitioned into the page number and the page offset. In this technique, the logical address is partitioned into the section number and the section offset.
In paging, to calculate the absolute address requires page number and the offset. In segmentation, to calculate the value of absolute address require Segment number and the offset.
The user cannot see the Paging. The user can see the segmentation.
In this technique, the list of free frames is maintained by the operating system. In this technique, the list of holes is maintained by the operating system.
The page table is created to maintain page data. Section table is created to maintain the section data.
In paging, a page table encloses the base address of each page. In Segmentation, a segment table encompasses the segment number and the offset.

Related Topics

Need of Operating System

There are various needs of operating system: Managing Input-Output UnitThe Operating system as a platform for application programsMultitaskingConsistent user interface Managing Input-Output Unit: - With the help of the operating system, the...

2 minutes read.

Semaphore in Operating System

What is Semaphore in Operating System Semaphore is defined as an integer variable which is used to solve the problem of the critical section in process synchronization. In semaphore, we use...

3 minutes read.

Dining Philosophers Problem in Operating System

Edsger Wybe Dijkstra was a well-known Dutch scientist. He was the first person ever to present the Dining Philosophers Problem in the stream of Computer Science. The dining philosophers problem...

5 minutes read.

Components of Operating System

Components of Operating System: An operating system is a complex and vast system. We can only create the operating system by dividing it into small parts. Each part must be...

5 minutes read.

Strategies for Handling Deadlock

Strategies for Handling Deadlock The Strategies for handling Deadlock are: Deadlock IgnoranceDeadlock PreventionDeadlock AvoidanceDeadlock Detection and Recovery Deadlock Ignorance Deadlock Ignorance is the most popular deadlock handling strategy. We can use this in the various operating systems for...

2 minutes read.

Thrashing in Operating System

A virtual memory system's poor performance when the same pages are loaded repeatedly due to a lack of main memory to store them in secondary memory is referred to as...

3 minutes read.

Starvation in Operating System

Starvation is one of the major problems occurring when resource management is not done properly. This problem arises in the operating system when the resources are not being allocated for...

4 minutes read.

Test Set Lock Mechanism | Operating System

Modification in the Assembly Code The problem in the lock variable is that, in some cases, the process reads the previous or old value of the lock variable and enters into the critical...

4 minutes read.

Round-Robin Scheduling Algorithm in OS

Round-Robin is a Preemptive Scheduling Algorithm and is the most commonly used algorithm in CPU Scheduling.In this, each Process is assigned with a fix time interval to execute, which is...

5 minutes read.

Trap vs Interrupt in Operating System

What is Trap in Operating System? A trap is a synchronous interrupt used to perform functionality when an error occurs in a user process. A trap in an operating system can...

4 minutes read.

Functions of Operating System

The functions of Operating System are: Process Management Memory Management File Management Device Management Secondary storage Management Security Coordination between other software and users Networking Job Accounting Error detecting aids 1. Process Management Process Management support operating system to create and delete...

3 minutes read.

Linux Operating System

What is Linux? The Linux operating system is used on various devices, including cellphones, automobiles, supercomputers, household gadgets, personal computers, and business servers. You can find Linux on your phones, thermostats, vehicles,...

8 minutes read.

Difference between SCAN and FCFS Disk Scheduling Algorithm

SCAN / Elevator Algorithm A different form of disc scheduling method is the SCAN disc scheduling algorithm. We move the disc arm in a certain direction in this process (the direction...

3 minutes read.

Resource Allocation Graph in Operating System

Resource Allocation Graph in OS We use the resource allocation graph for the pictographic representation of the state of a system. The resource allocation graph contains all the information related to the processes that...

5 minutes read.

How to implement Monitors using Semaphores

Monitors Monitor is a type of synchronization device designed to solve difficulties caused by semaphores, such as timing errors. Monitors are the type of data types that are abstract by nature...

2 minutes read.

Types of Operating System

There are various types of operating system: Simple Batch Operating SystemMultiprogramming batch Operating SystemTime-sharing Operating SystemMultiprocessor Operating SystemDistributed Operating SystemNetwork Operating SystemReal-time Operating SystemMobile Operating System Simple Batch operating system In the simple batch operating system, there is no direct communication between...

6 minutes read.

Difference between SSTF and LOOK Disk Scheduling Algorithm

Shortest Seek Time First / SSTF Shortest Seek Time First (SSTF) is an acronym for "shortest seek time first." The task request that is closest to the present position of the...

4 minutes read.

Virtual Memory in Operating System

What is Virtual Memory Virtual Memory is a storage scheme in which the users have an illusion that users have a significant amount of Main Memory. We can perform this by taking a...

3 minutes read.

Kernel in OS

What is Kernel in OS? The kernel is the core component in the operating system. The job of the kernel is to handle the communication between the hardware and the software. ...

2 minutes read.

Bit Vector in Operating System

What is Bit vector? Bit vector is one of the most important methods used in the free space management of operating system. Free space management which is used by the operating...

3 minutes read.