Paging and Segmentation in Operating System

In this tutorial, we are going to learn about virtual memory, paged virtual memory system, segmented virtual memory system. Further we will see how combined segmentation and paging system works.

Before reading this, I will suggest all to go through this first. Now, without delay let’s dive into the topic.

What is Virtual Memory :

Virtual memory creates an illusion that more memory exists than the actual available in system. There are two types of addresses in virtual memory, virtual address and physical address. Memory management unit (MMU) is responsible for translating virtual address to physical address.

Paging in Operating System :

It is a virtual memory management technique that allows the physical address space to be non-contiguous. In paging the physical address space is divided into fixed size blocks (i.e. frames). The virtual address space is also divided into fixed size blocks (i.e. pages). Here, page size and frame size are equal.

Physical address:

It is divided into two parts. They are

A. Frame no.(number of bits for representing the frames) and

B. Frame offset(number of bits to indicate a particular word in a frame).

Virtual address:

It is divided into two parts,

A. Page no.(number of bits for representing the pages) and

B. Page offset(number of bits to indicate a particular word in a page).

In this scheme, we use a page table to get the frame number for a particular page number. Page table is a data structure. We store it in main memory. In general, page table contains certain information. They are frame number, present/absent bit, protection bit, reference bit, caching bit and dirty bit.

Paging is simple to implement and it surely reduces the external fragmentation. But it suffers from internal fragmentation. Not to mention, maintaining page table for each of the process is also difficult.

Segmentation in Operating System:

Segmentation is basically dividing a process into segments. It is not necessary that the segment should be in same size. In Segmentation, the relation between virtual address and physical address is not very simple. So there is a segment table responsible for storing all necessary information.

Segment Table

It helps to map virtual address into physical address. Segment table consists of base address and limit. Base address has the starting of the physical address of segments. Whereas limit represents the length of the segment.

Here, the virtual address is consists of two parts ,

A. Segment no.(number of bits for representing the segments) and

B. Segment offset(number of bits to indicate the size of the segment).

In Segmentation, though there is no internal fragmentation but external fragmentation is present.

Segmented Paging in Operating System:

Segmented paging is the implementation of segmentation and paging combined. Firstly, processes are divided into segments. After that, we divide each segment into multiple pages. For each segment there is a page table that stores information about frames. Virtual address contains three parts. They are Segment Number (indicates the segment), Page Number (specifies the page) and most important, Page Offset (indicates to a specific words).

Segmented paging undoubtedly solves the problem of external fragmentation. Though it suffers from internal fragmentation.