Professional Documents
Culture Documents
Paging
Important Formulas
Main Memory Related
• Physical Address Space = Size of main memory
• Size of main memory = Total number of frames x Page size
• Frame size = Page size
• If number of frames in main memory = 2 X, then
o number of bits in frame number = X bits
• If Page size = 2X Bytes, then number of bits in page offset = X bits
• If size of main memory = 2X Bytes, then number of bits in physical address = X bits.
Process Related
• Virtual Address Space = Size of process
• Number of pages the process is divided = Process size / Page size
• If process size = 2X bytes, then number of bits in virtual address space = X bits
General Formulas:
• If the given address consists of ‘n’ bits, then using ‘n’ bits, 2 n locations are possible.
• Then, size of memory = 2n x Size of one location.
• If the memory is byte-addressable, then size of one location = 1 byte.
• Thus, size of memory = 2n bytes.
• If the memory is word-addressable where 1 word = m bytes, then size of one
location = m bytes.
• Thus, size of memory = 2n x m bytes.
Module 5
Operating System
Problem 1.
Given the Logical Address Space: 128 KB, Physical Address Space: 512KB and Page size:
16 KB. Calculate the Following:
a) Number of bits for logical address
b) Number of bits for Physical Address
c) Number of pages in logical address space
d) Number of frames in main memory
e) Page table size.
Solution:
a) Using the Formula, size of memory = 2n bytes.
128 KB = 2n
Since, 1 KB = 1024 bytes, 128 KB = 1024 x 128 = 131072 bytes.
Rewrite the equation as
131072 = 2n
Take log on both sides (base 2)
Log (131072) = log (2n)
Log (131072) = 2n
= 217
= No. of bits required for logical address is 17 bits.
Module 5
Operating System
d) Number of frames:
Physical address space is 512 KB which is 2 19.
Page size = Frame Size = 16 KB = 2 14
No. of frames = 219 / 214 = 25.
Problem 2.
The page size is 4 KB and page table entry size is 4 bytes. The size of page table is 4 KB.
Give the division of virtual address space.
Solution:
Let the number of bits in virtual address = n bits
No. of bits in Page Offset:
Page Size = 4 KB = 212 V
Number of bits in page offset: 12 bits
Page Table Size:
Using the formula-
page table size = Number of entries in page table x Page table entry size
Number of entries in page table = Number of pages the process is divided
Number of pages the process is divided = Process size / Page size
Assume process size = 2n bytes
Number of pages the process is divided = 2n / 4 KB = 2n / 212 B
= 2n-12 pages.
Thus, calculating (page table size is given 4 KB)
4 KB = 2n-12 x 4 bytes
Module 5
Operating System
4 KB = 2n-12+2 bytes
4 KB = 2n-10 bytes
212 = 2n-10 bytes
12 = n – 10
12 + 10 = n = 22
Thus, number of bits in virtual address = 22 bits
Problem 3.
Consider a user program of logical address of size 6 pages and page size is 4 bytes. The
physical address contains 300 frames. The user program consists of 22 instructions a, b,
c, . . . u, v . Each instruction takes 1 byte. Assume at that time the free frames are 7, 26, 52,
20, 55, 6, 18, 21, 70, and 90.
Find the following:
I. Draw the logical and physical maps and page tables?
II. Allocate each page in the corresponding frame?
III. Find the physical addresses for the instructions m, d, v, r?
IV. Calculate the fragmentation if exist?
Module 5
Operating System
Solution:
Problem 4.
Consider a process with 4 logical pages, numbered 0–3. The page table of the process
consists of the following logical page number to physical frame number mappings: (0, 11),
(1, 35), (2, 3), (3, 1). The process runs on a system with 16-bit virtual addresses and a
Module 5
Operating System
page size of 256 bytes. You are given that this process accesses virtual address 770.
Answer the following questions, showing suitable calculations.
a) Which logical page number does this virtual address correspond to?
b) Which physical address does this virtual address translate to?
Solution.
(a) 770 = 512 + 256 + 2 = 00000011 00000010 = page 3, offset 2
(b) page 3 maps to frame 1. physical address = 0000001 00000010 = 256 + 2 = 258
Module 5