Paging & segmentation; advantages and disadvantage

1,500 views 19 slides Mar 17, 2024
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19

About This Presentation

Paging and segmentation


Slide Content

Paging & Segmentation Paging: It permits programs memory to be non-contiguous & allowing the process to be allocated to physical memory, when it is available.

Cont… CPU p d f d P f Physical Memory Logical address Physical address Page table

p = Page Number ( is used to specify the specific page of the process from which the CPU wants to read the data & it is also used an index to the page table) f = Frame Number (Base Address of the frame, where that page is stored in physical memory) d= Page offset (Displacement within page, it is used to specify the specific word(instruction) on the page that CPU wants to read) Cont…

1) It is important to note that Logical Memory(Secondary Memory) which is divided into region or partition is known as Pages . 2) While, Physical Memory(Main Memory) which is divided into region or partition is known as Frames. Cont…

Example: ( Source : Galvin)

Example: 32-byte memory and 4-byte pages (Source: Galvin )

Suppose we want to map instruction ‘a’ into physical memory. 1) We first check where instruction ‘a’ exist in page table and finds that ‘a’ is in page 0. 2) Then corresponding frame number for instruction ‘a’ is 5 which exist in page table. 3) Then we will calculate: (Frame no. x total no. of instructions in logical memory+ no. of displacement of that instruction in particular block of logical memory). i.e , 5x 4 + 0 = 20. So instruction ‘a’ will map into physical memory at Frame Number 20. Cont…

It allows to store parts of a single process in a non-contiguous fashion. It solves the problem of external fragmentation. Advantages of Paging

It suffers from internal fragmentation. Problem to maintain page table for each process. Time taken to fetch instruction increases since now two memory accesses are required. Disadvantage of Paging

1)Like paging, segmentation is another non-contiguous memory allocation technique. 2) In Segmentation, process is not divided into fixed size pages, rather is divided into modules for better visualization. 3) Segmentation is variable size partitioning scheme 4) In segmentation, logical memory & physical memory are divide into partitions of unequal size. 5) Size of partitions depend on length of modules. Segmentation

6) In segmentation, the memory is divided into the variable size parts. Each part is known as segment which can be allocated to a process. 7) Memory-management scheme that supports user view of memory. 8) A program is a collection of segments A segment is a logical unit such as: main program, procedure, function, method, object, local variables, global variables, stack, arrays etc. The details about each segment are stored in a table called as segment table . Cont…

User ’ s View of a Program Source: Galvin

Cont… CPU s d Physical Memory Logical address < + Trap, Error Seg no. Limit Base Segment table No Yes Segment No. Segment Offset Length of Segment

Example: Seg No. Base Length 1 02 6 2 24 7 3 14 4 c 02 07 14 17 24 30 PM Library Stack Program LM Segment Table a b c d m n u v w

Consider the following segment table: What are the physical address for the following logical address? i ) <0,435> ii) <2,500> iii) <1,10> Cont… Segment No. Base Length 219 600 1 2300 14 2 90 100 3 1327 586 4 1952 96

Solve problem of internal fragmentation. It divides program into module provides better visualization. Segment table consumes less space as compare to page table in paging. Advantage of Segmentation

Problem to maintain a segment table for each process. Time taken to fetch instruction increases since now two memory accesses are required. Segments of unequal size are not suited for swapping. Suffers from external fragmentation. Disadvantages of Segmentation

System using a paging and segmentation, the virtual address space consists of up to 8 segments where each segment can be up to 2 29  byte long. The hardware pages each segment into 256 bytes pages. How many bits in the virtual address specify the 1)     Segment number? 2)      Page number   ? 3)     Offset within page? 4)     Entire virtual address? Example:( University Exam 2022)

Ans :    1) segment number:   virtual address space consists up to 8 segments . So         8 = 2 3 Since 3 bits are needed to specify segment number. 2) Page number:   Hardware pages each segment into 256 byte pages. So              256 = 2 8  byte page Size of segment is 229 bytes. Since 2 29  / 2 8     = 2 29-8  = 2 21  = 21 pages Since 21 bits are required to specify the page number.     3) Offset within the page:   for 28 byte page, 8 bits are needed. 4) Entire virtual address:                 = segment number + page number + offset    = 3 + 21 + 8 = 32. Cont …