×

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

Difference between Rotational Latency and Disk Assess Time in Disk Scheduling

Disk scheduling is used by operating systems to arrange the arrival of I/O requests to the disc. Disk scheduling is necessary because several I/O requests may occur from various processes,...

4 minutes read.

Producer-Consumer Problem in OS

What is Producer-Consumer Problem? The Producer-Consumer problem is a classical problem. The Producer-Consumer problem is used for multi-process synchronization, which means synchronization between more than one processes. In this problem, we have one producer...

4 minutes read.

DOS Operating System

What is DOS Operating System? An operating system that runs from a hard disk drive is known as the DOS (Disk Operating System).In other words, DOS (Disk Operating System) is defined...

7 minutes read.

Non-Contiguous Memory Allocation in Operating System

Memory is nothing but a storage space where various data are stored. We can store data in temporary and permanent memory as per our future requirements for data. We can...

9 minutes read.

Operating System Services

The Operating System provides various types of services:   I/O operationProgram executionFile system manipulationCommunicationError HandlingResource allocationAccountingProtection 1. I/O Operation: - To execute a program, needs I/O, which consists of a file, or I/O device. Due to the protection...

3 minutes read.

Multi-user Operating Systems

Introduction Since only one user may interact with the computer at any given time, the operating system we use on our personal computers, laptops, tablets, and phones is sometimes referred to...

8 minutes read.

Feedback Queue in Operating System

In a computer or a laptop, there is a processor which do all the tasks. The processor cannot do all the tasks at a time. So, the tasks will be...

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

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.

Disk Scheduling Algorithms

Disk Scheduling Algorithms Disk scheduling algorithms are the algorithms that are used for scheduling a disk. Generally, the scheduling refers to a time-table for completing any task or a job. With the help...

2 minutes read.

Page Table in Operating System

What is a Page Table? A page table is a data structure used by an operating system (OS) to store information about the physical location of the pages in a computer's...

6 minutes read.

Inter Process Communication in Operating System

Inter-Process Communication or IPC refers to the methods and techniques that allow processes (programs or tasks) to communicate with each other within a computer system. This is typically done through...

3 minutes read.

SJF Scheduling in OS

Shortest Job First (SJF) Scheduling in OS Shortest Job First is a Preemptive or Non-Preemptive algorithm. In the shortest job first algorithm, the job having shortest or less burst time will...

4 minutes read.

Partitioning Algorithms

Partitioning Algorithms There are various types of Partitioning Algorithm: First-Fit AlgorithmNext-Fit AlgorithmBest-Fit AlgorithmWorst-Fit AlgorithmQuick-Fit Algorithm 1. First-Fit Algorithm: - In the First-Fit Partitioning algorithm, first, the linked list is scan, and when it...

3 minutes read.

Simple Structure in Operating System

An operating system is a piece of software that lets the user applications talk to the hardware of the system. Because it is such a complicated structure, the operating system...

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.

Can a Computer Run Without the Operating System

Computers may function right out of the box, mostly due to operating systems. Nowadays, there are probably already some pre-installed apps in a new computer when you buy one. Have...

9 minutes read.

What is Deadlock in OS?

Deadlock in Operating System In an Operating System, a process uses various resources, and the resources are used in the following manner: Request the ResourceUse the ResourceRelease the Resource In the Operating System, Deadlock is a condition...

4 minutes read.

Android Operating System

What is Android Operating System? Android is a Linux-based and open-source operating system mainly established for mobile devices like tablet computers and Smartphones. The Android operating system was established by the...

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.