The Wayback Machine - https://web.archive.org/web/20240925222535/https://www.geeksforgeeks.org/paging-in-operating-system/
Open In App

Paging in Operating System

Last Updated : 04 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Paging is a memory management scheme that eliminates the need for a contiguous allocation of physical memory. The process of retrieving processes in the form of pages from the secondary storage into the main memory is known as paging. The basic purpose of paging is to separate each procedure into pages. Additionally, frames will be used to split the main memory. This scheme permits the physical address space of a process to be non – contiguous.

In paging, the physical memory is divided into fixed-size blocks called page frames, which are the same size as the pages used by the process. The process’s logical address space is also divided into fixed-size blocks called pages, which are the same size as the page frames. When a process requests memory, the operating system allocates one or more page frames to the process and maps the process’s logical pages to the physical page frames.

The mapping between logical pages and physical page frames is maintained by the page table, which is used by the memory management unit to translate logical addresses into physical addresses. The page table maps each logical page number to a physical page frame number.

Terminologies Associated with Memory Control

  • Logical Address or Virtual Address: This is a deal that is generated through the CPU and used by a technique to get the right of entry to reminiscence. It is known as a logical or digital deal because it isn’t always a physical vicinity in memory but an opportunity for a connection with a place inside the device’s logical address location.
  • Logical Address Space or Virtual Address Space: This is the set of all logical addresses generated via a software program. It is normally represented in phrases or bytes and is split into regular-duration pages in a paging scheme.
  • Physical Address: This is a cope that corresponds to a bodily place in reminiscence. It is the actual cope with this that is available on the memory unit and is used by the memory controller to get admission to the reminiscence.
  • Physical Address Space: This is the set of all bodily addresses that correspond to the logical addresses inside the way’s logical deal with place. It is usually represented in words or bytes and is cut up into fixed-size frames in a paging scheme.

In a paging scheme, the logical deal with the region is cut up into steady-duration pages, and every internet web page is mapped to a corresponding body within the physical deal with the vicinity. The going for walks tool keeps a web internet web page desk for every method, which maps the system’s logical addresses to its corresponding bodily addresses. When a method accesses memory, the CPU generates a logical address, that is translated to a bodily address using the net page table. The reminiscence controller then uses the physical cope to get the right of entry to the reminiscence.

Important Features of Paging in PC Reminiscence Management

  • Logical to bodily address mapping: In paging, the logical address area of a technique is divided into constant-sized pages, and each web page is mapped to a corresponding physical body within the main reminiscence. This permits the working gadget to manipulate the memory in an extra flexible way, as it is able to allocate and deallocate frames as needed.
  • Fixed web page and frame length: Paging makes use of a set web page length, which is usually identical to the size of a frame within the most important memory. This facilitates simplifying the reminiscence control technique and improves device performance.
  • Page desk entries: Each page within the logical address area of a method is represented through a page table entry (PTE), which contains facts approximately the corresponding bodily body in the predominant memory. This consists of the frame range, in addition to other manipulate bits which can be used by the running machine to manage the reminiscence.
  • A number of page desk entries: The range of page desk entries in a manner’s page desk is identical to the wide variety of pages inside the logical deal with the area of the technique.
  • Page table stored in important memory: The web page desk for each system is typically saved in important reminiscence, to allow for green get right of entry to and change by the operating device. However, this could additionally introduce overhead, because the web page table must be updated on every occasion a system is swapped in or out of the main memory.

How Paging Works?

Paging is a method used by operating systems to manage memory efficiently. It breaks physical memory into fixed-size blocks called “frames” and logical memory into blocks of the same size called “pages.” When a program runs, its pages are loaded into any available frames in the physical memory.

This approach prevents fragmentation issues by keeping memory allocation uniform. Each program has a page table, which the operating system uses to keep track of where each page is stored in physical memory. When a program accesses data, the system uses this table to convert the program’s address into a physical memory address.

Paging allows for better memory use and makes it easier to manage. It also supports virtual memory, letting parts of programs be stored on disk and loaded into memory only when needed. This way, even large programs can run without fitting entirely into main memory.

  • If Logical Address = 31 bit, then Logical Address Space = 231 words = 2 G words (1 G = 230)
  • If Logical Address Space = 128 M words = 27 * 220 words, then Logical Address = log2 227 = 27 bits
  • If Physical Address = 22 bit, then Physical Address Space = 222 words = 4 M words (1 M = 220)
  • If Physical Address Space = 16 M words = 24 * 220 words, then Physical Address = log2 224 = 24 bits

The mapping from virtual to physical address is done by the Memory Management Unit (MMU) which is a hardware device and this mapping is known as the paging technique.

  • The Physical Address Space is conceptually divided into a number of fixed-size blocks, called frames.
  • The Logical Address Space is also split into fixed-size blocks, called pages.
  • Page Size = Frame Size

Example

  • Physical Address = 12 bits, then Physical Address Space = 4 K words
  • Logical Address = 13 bits, then Logical Address Space = 8 K words
  • Page size = frame size = 1 K words (assumption)
paging

Paging

The address generated by the CPU is divided into

  • Page number(p): Number of bits required to represent the pages in Logical Address Space or Page number
  • Page offset(d): Number of bits required to represent a particular word in a page or page size of Logical Address Space or word number of a page or page offset.

In a paging scheme, the physical cope with the area is divided into fixed-length frames, each of which contains some bytes or words. When a manner is running, its logical address space is split into constant-size pages, which might be mapped to corresponding frames within the physical address space.

Physical Address is divided into:

To represent a physical address in this scheme, parts are commonly used:

Frame Range: This is the variety of the frame within the physical cope with the area that consists of the byte or phrase being addressed. The wide variety of bits required to represent the body range relies upon the scale of the physical cope with the area and the size of each frame. For instance, if the physical cope with area carries 2^20 frames and each frame is 4KB (2^12 bytes) in size, then the frame range could require 20-12 = 8 bits.

Frame Offset: This is the wide variety of the byte or word within the body this is being addressed. The number of bits required to represent the frame offset relies upon the size of every frame. For instance, if everybody is 4KB in size, then the frame offset could require 12 bits. So, a physical address in this scheme may be represented as follows:

Physical Address = (Frame Number << Number of Bits in Frame Offset) + Frame Offset, where “<<” represents a bitwise left shift operation.

  • The TLB is associative, high-speed memory.
  • Each entry in TLB consists of two parts: a tag and a value.
  • When this memory is used, then an item is compared with all tags simultaneously. If the item is found, then the corresponding value is returned.

Paging is a memory management technique used in operating systems to manage memory and allocate memory to processes. In paging, memory is divided into fixed-size blocks called pages, and processes are allocated memory in terms of these pages. Each page is of the same size, and the size is typically a power of 2, such as 4KB or 8 KB.

Important Points About Paging in Operating Systems

  • Reduces internal fragmentation: Paging facilitates lessening internal fragmentation by using allocating memory in fixed-size blocks (pages), which might be usually a whole lot smaller than the size of the process’s facts segments. This lets in for greater efficient use of memory in view that there are fewer unused bytes in each block.
  • Enables reminiscence to be allotted on call for: Paging enables memory to be allocated on call for, this means that memory is most effectively allocated when it’s far needed. This allows for extra efficient use of memory in view that only the pages that are absolutely used by the manner want to be allocated inside the physical memory.
  • Protection and sharing of memory: Paging allows for the protection and sharing of reminiscence between methods, as each procedure has its own web page table that maps its logical deal with area to its physical address space. This permits techniques to proportion facts at the same time as preventing unauthorized get right of entry to every other’s memory.
  • External fragmentation: Paging can result in outside fragmentation, wherein memory turns fragmented into small, non-contiguous blocks. This can make it difficult to allocate massive blocks of reminiscence to a method seeing that there may not be enough contiguous free memory to be had.
  • Overhead: Paging involves overhead because of the renovation of the web page table and the translation of logical addresses to physical addresses. The working device must maintain the page table for each manner and perform a deal with translation whenever a procedure accesses memory, which can slow down the machine.

What is Memory Management Unit (MMU)?

A memory management unit (MMU) is a technique used to convert logical address to physical address. Logical address is the address generated by CPU for each page and physical address is the real address of the frame where page is going to be stored.

Whenever a page has to be accessed by CPU using the logical address, it requires physical address for accessing the page. Logical address comprises of two parts: Page Number and Offset.

Conclusion

In conclusion, paging is a memory management technique that helps computers in storing data efficiently and it also helps in retrieve data as it breaks the memory into small, fixed size chunks called pages. It helps in handling larger amount of data without the issue of fragmentation that improves the performance and usability.

Frequently Asked Questions on Paging – FAQs

What is the use of Paging in an Operating System?

Paging is a memory management technique that is used to retrieve processes from secondary storage to main memory.

What is the basic advantage of Paging?

Paging reduces internal fragmentation and in paging there is a possibility of external fragmentation.

What is the effect of Paging?

Paging helps in improving the performance of the system by improving the utilization of the memory and accessing the available memory present there.



Previous Article
Next Article

Similar Reads

Two Level Paging and Multi Level Paging in OS
Paging is the process in which we convert the entire process into equal-sized pages. Each page further consists of a fixed number of words (if it is word addressable). The Pages are represented by the Virtual Address generated by the CPU. These Pages are mapped to the Physical Address by the MMU. So, to help in this mapping we use the concept of Pa
3 min read
Multilevel Paging in Operating System
Multilevel paging is a memory management technique used in modern computer systems to efficiently handle large amounts of memory. It breaks down the virtual address space into smaller, more manageable pieces, organized into multiple levels of page tables. Multilevel Paging consists of two or more levels of page tables in a hierarchical manner. It i
6 min read
What is Demand Paging in Operating System?
Demand paging is a memory management scheme used in operating systems to improve memory usage and system performance. Let's understand demand paging with real life example Imagine you are reading a very thick book, but you don’t want to carry the entire book around because it’s too heavy. Instead, you decide to only bring the pages you need as you
10 min read
Paged Segmentation and Segmented Paging
INTRODUCTION: Paged Segmentation and Segmented Paging are two different memory management techniques that combine the benefits of paging and segmentation. Paged Segmentation is a memory management technique that divides a process's address space into segments and then divides each segment into pages. This allows for a flexible allocation of memory,
6 min read
Performance of paging
Introduction: Paging is a memory management technique used in operating systems to divide a process's virtual memory into fixed-sized pages. The performance of paging depends on various factors, such as: Page size: The larger the page size, the less the number of page tables required, which can result in faster memory access times. However, larger
4 min read
Performance of 2-level Paging
INTRODUCTION: Two-level paging is a hierarchical paging technique that divides the virtual address space into two levels of page tables: the top-level page table and the second-level page table. The top-level page table maps virtual memory addresses to second-level page tables, while the second-level page tables map virtual memory addresses to phys
5 min read
Design Issues for Paging
Paging is an important concept in memory management. In Paging, the operating system divides each incoming program into pages of equal sizes of blocks. The section of disks is called blocks. The section of main memory is called page frames. Fixed-size blocks are called frames and the breaking of logical memory into blocks of the same size is called
7 min read
Working Set in Paging
When pages are exchanged in and out of main memory too frequently for a process, slowing down its execution, it is called Thrashing. A process generally requires a lot of pages. But in a certain span of time, only a certain subset of these pages is used repeatedly. This is called the locality model of execution and has been widely observed. The req
4 min read
Algorithms For Demand Paging in OS
The operating system is necessary for managing computer resources and using hardware efficiently. Memory management involves allocating and releasing memory for various programs and files and is one of the most important aspects of modern working. Operating systems use a variety of methods to provide efficient memory management; one of them is requ
8 min read
Translation Lookaside Buffer (TLB) in Paging
In Operating System (Memory Management Technique: Paging), for each process page table will be created, which will contain a Page Table Entry (PTE). This PTE will contain information like frame number (The address of the main memory where we want to refer), and some other useful bits (e.g., valid/invalid bit, dirty bit, protection bit, etc). This p
6 min read
Difference between Paging and Swapping in OS
Swapping: Swapping is a process of swapping a process temporarily to a secondary memory from the main memory which is fast than compared to secondary memory. But as RAM is of less size so the process that is inactive is transferred to secondary memory. The main part of swapping is transferred time and the total time is directly proportional to the
2 min read
Difference Between Paging and Segmentation
In computer operating systems, memory management is crucial for efficient use of resources. Paging and segmentation are two fundamental techniques used to organize and allocate memory. Paging divides memory into fixed-size blocks called pages, simplifying management by treating memory as a uniform structure. Segmentation, in contrast, divides memor
5 min read
Difference between Demand Paging and Segmentation
Demand Paging is another segmentation technique which is used in operating system to manage system resources. It is therefore important for those who would understand various aspects of operating systems to have a clear distinction between them. This article shall provide a description of what each technique entails, Their pros and cons as well as
5 min read
System Protection in Operating System
Introduction: System protection in an operating system refers to the mechanisms implemented by the operating system to ensure the security and integrity of the system. System protection involves various techniques to prevent unauthorized access, misuse, or modification of the operating system and its resources. There are several ways in which an op
3 min read
User View Vs Hardware View Vs System View of Operating System
User View of Operating System: The Operating System is an interface, hides the details which must be performed and present a virtual machine to the user that makes it easier to use. Operating System provides the following services to the user. Execution of a programAccess to I/O devicesControlled access to filesError detection (Hardware failures, a
1 min read
Xv6 Operating System -adding a new system call
Prerequisite - Xv6 Operating System -add a user program In last post we got to know how to add user program in Xv6 Operating System. Now here you will see how to add new system call in Xv6 Operating System. A dding new system call to xv6: A system call is way for programs to interact with operating system. A computer program makes system call when
6 min read
Traps and System Calls in Operating System (OS)
Traps and system calls are two mechanisms used by an operating system (OS) to perform privileged operations and interact with user-level programs. Here is an overview of each mechanism: Traps: A trap is an interrupt generated by the CPU when a user-level program attempts to execute a privileged instruction or encounters an error. When a trap occurs
3 min read
Difference between System Software and Operating System
1. System Software: System software is a type of computer program that is designed to run a computer's hardware and application programs it controls a computer's internal functioning, chiefly through an operating system. It also controls peripherals devices such as monitors, printers, and storage devices. 2. Operating System: An operating system or
3 min read
Fork System Call in Operating System
In many operating systems, the fork system call is an essential operation. The fork system call allows the creation of a new process. When a process calls the fork(), it duplicates itself, resulting in two processes running at the same time. The new process that is created is called a child process. It is a copy of the parent process. The fork syst
5 min read
System Programs in Operating System
System Programming can be defined as the act of building Systems Software using System Programming Languages. According to Computer Hierarchy, Hardware comes first then is Operating System, System Programs, and finally Application Programs. Program Development and Execution can be done conveniently in System Programs. Some of the System Programs ar
3 min read
File System Implementation in Operating System
A file is a collection of related information. The file system resides on secondary storage and provides efficient and convenient access to the disk by allowing data to be stored, located, and retrieved. File system implementation in an operating system refers to how the file system manages the storage and retrieval of data on a physical storage de
11 min read
Banker's Algorithm in Operating System
Prerequisite - Resource Allocation Graph (RAG), Banker’s Algorithm, Program for Banker’s Algorithm Banker's Algorithm is a resource allocation and deadlock avoidance algorithm. This algorithm test for safety simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-state” check to test for possible acti
15 min read
Swap Space in Operating System
A computer has a sufficient amount of physical memory but most of the time we need more so we swap some memory on disk. Swap space is a space on a hard disk that is a substitute for physical memory. It is used as virtual memory which contains process memory images. Whenever our computer runs short of physical memory it uses its virtual memory and s
6 min read
Thread Models in Operating System
A thread is a light weight process which is similar to a process where every process can have one or more threads. Each thread contains a Stack and a Thread Control Block. There are four basic thread models : 1. User Level Single Thread Model : Each process contains a single thread.Single process is itself a single thread.process table contains an
2 min read
The Tempo Operating System
Operating system : An Operating system is an interface between the computer user and computer hardware. An Operating system is a software which performs all the basic task like file handling, file management, memory management, handling input and output, controlling peripherals devices such as disk drive and printer, mouse...etc Tempo operating sys
5 min read
Boot Block in Operating System
Basically for a computer to start running to get an instance when it is powered up or rebooted it need to have an initial program to run. And this initial program which is known as bootstrap needs to be simple. It must initialize all aspects of the system, from CPU registers to device controllers and the contents of the main memory, and then starts
5 min read
Comparison on using Java for an Operating System instead of C
Java is a managed language which offers memory safety. In Java, pointers do not exist, so we cannot do pointer arithmetic on a function pointer. An application can invoke a method defined in a class through the class object. In Java, we cannot do unsafe typecast of an object to overwrite the method pointer with something else. An out of bound array
2 min read
Difference between Loading and Linking in Operating System
An operating system acts as an intermediary between the user of a computer and computer hardware. The purpose of an operating system is to provide an environment in which a user can execute programs conveniently and efficiently. Linking and Loading are utility programs that play an important role in the execution of a program. Linking intakes the o
4 min read
Stack Implementation in Operating System uses by Processor
A stack is an associate ordered a set of components, only one of that (last added) are often accessed at a time. The point of access is named the highest of the stack. The number of components within the stack, or length of the stack, is variable. Items could solely be side to or deleted from the highest of the stack. For this reason, a stack is ad
4 min read
Best-Fit Allocation in Operating System
INTRODUCTION: Best-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In Best-Fit, the operating system searches through the list of free blocks of memory to find the block that is closest in size to the memory request from the process. Once a suitable block is found, the operating system spli
4 min read