As we discussed before that the main memroy or the physical memory in a system is limited and is divided into small fixed-size blocks called frames. Simillarly the logical memroy is also divided into the same small size blocks called pages. A single process may require many number of pages in the memory. When a process is ready for execution its pages are loaded into the main memory frames from the backing store. All of this is called memory paging.
What is Paging?
In paging the OS retrives the data form the secondary storage in the form of blocks which are the same size as the memroy frames and loads these block in the main memory. Paging is a part of virtual memroy that allows the OS to use secondary storage like HDD and SSD to excede the size of the physical memory.
The backing store is also divided into small blocks. These blocks are also the same size as the frame size in the memory. Paging requires additional hardware support in the form of paging table. Every logical address generated by the CPU consists of the following two parts.
- A page number (p)
- A page displacement (d)
The page number is used as an index in the paging table. The paging table contains the base address of the process in the physical memory. The base address is added to the paging displacement to determine the physical address of the process in memory. It is then sent to the memory management unit which completes its translation from logical address to physical address.
The page size and frame size are hardware dependent. It is common that the page size is of the power of 2. like 512 bytes or 16 megabytes etc. as these are easy to work with when translating addresses.
Suppose the logical address space consists of 2^m
bytes and the page/frame size is 2^n
bytes. The high-order m-n bits of logical address will designate the page number. THe low order n bits will designate the page displacement as show below.
Page number p | Page displacement d |
---|---|
m-n bits | n bits |