Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Maharashtra State Board of Technical Education Mumbai

Government Polytechnic Yavatmal

Course Name
Operating System(OSY-22516)

Unit-5
Memory Management

Sub-Topic 5.2
Virtual Memory

B P Bhagat
Lecturer in Computer Engineering
Course Outcomes

a. Install operating system and configure it.


b. Use operating system tools to perform various Functions.
c. Execute process commands for performing process management
operations.
d. Apply scheduling algorithm to calculate turnaround time and
average waiting Time.
e. Calculate efficiency of different memory management
techniques.
f. Apply File management techniques.
Learning Outcome(LO 4a):
Identify the need of memory management
Unit-V Memory Management

5.1 Basics Memory Management


 Partitioning
 Fixed and Variable
 Free space management Techniques- Bitmap, Linked List.

5.2 Virtual Memory


 Introduction to Paging
 Segmentation
 Fragmentation
 Page Fault
5.3 Page Replacement Algorithms.
 FIFO
 LRU
 Optimal
Paging
 Paging is a memory management scheme that permits the Physical address
space of a process to be noncontiguous; process is allocated physical memory
whenever the latter is available
 Avoids external fragmentation
 Avoids problem of varying sized memory chunks
 Paging handled by hardware.
 Divides logical address space into blocks of same size called pages
 Divides physical address space into fixed-sized blocks called frames
 Size is power of 2, between 512 bytes and 16 Mbytes
 Keeps track of all free frames.
 To run a program of size N pages, need to find N free frames and load
program.
 Set up a page table to translate logical to physical addresses
 Backing store likewise split into pages
 Still have Internal fragmentation
Address Translation Scheme

 Address generated by CPU is divided into:


 Page number (p) – used as an index into a page table which contains
base address of each page in physical memory
 Page offset (d) – combined with base address to define the physical
memory address that is sent to the memory unit

page number page offset


p d
m -n n

 For given logical address space 2m and page size 2n


Paging Hardware
Paging Model of Logical and Physical Memory

n=2 and 2n =4bytes Page size


m=4 and 2m =32-byte memory
and 4-byte pages
Page Physical
Number Page address
Paging Example Offset

Using a page size of 4 byte and physical memory of 32


bytes(8 pages)
We shows how the user's view of memory mapped into 0
0
physical memory.
Logical address 0 is page 0,offset 0. 1 1
Indexing into the page table ,we find that page 0 is in
frame 5. 2 2
Thus, logical address 0 maps to physical address 20
3 3
(=(5X4+0) ) page a available.
Logical address 3 is page 0,offset 3. 4
Indexing into the page table ,we find that page 0 is in
frame 5. 5
Thus, logical address 0 maps to physical address 23
(=(5X4+3) ) page d available 6
Logical address 4 is page 1,offset 0.
Indexing into the page table ,we find that page 0 is in 7
frame 6.
Thus, logical address 0 maps to physical address 24 Frame
Number
(=(6X4+0) ) page e available
Paging (Cont.)

 Calculating internal fragmentation


 Page size = 2,048 bytes
 Process size = 72,766 bytes
 35 pages + 1,086 bytes
 Internal fragmentation of 2,048 - 1,086 = 962 bytes
 Worst case fragmentation = 1 frame – 1 byte
 On average fragmentation = 1/ 2 frame size
 So small frame sizes desirable?
 But each page table entry takes memory to track
 Page sizes growing over time
 Solaris supports two page sizes – 8 KB and 4 MB
 Process view and physical memory now very different
 By implementation process can only access its own memory
Segmentation
 It is a memory-management scheme that supports user view of memory.
 A logical address space is a collection of segments.
 Each segment has a name and a length.
 The addresses specify both the segment name and the offset.
 The user specifies each address by two quantities: segment name and an offset.
 For simplicity segments are numbered and are referred as segment number.
 Logical address consists of a two tuple:
<segment-number, offset>,
 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, common block, stack, symbol table, arrays etc.
User’s View of a Program
Logical View of Segmentation

4
1 2

3 4
2

user space physical memory space


Segmentation Hardware

 Segment table – maps two-dimensional


physical addresses; each table entry has:
 base – contains the starting physical
address where the segments reside in
memory
 limit – specifies the length of the segment
 A logical address consists of two parts:
segment-number, offset
 The segment number is used as an index to
page table..
 The offset d of the logical address must be
between 0 and segment limit.
 If it is not than trap to operating system.
 When an offset is legal ,it is added to the
segment base to produce physical address
Segmentation Architecture (Cont.)

 Segment-table base register (STBR) points to the segment table’s location in memory
 Segment-table length register (STLR) indicates number of segments used by a
program;
segment number s is legal if s < STLR
 Protection
 With each entry in segment table associate:

 validation bit = 0  illegal segment


 read/write/execute privileges

 Protection bits associated with segments; code sharing occurs at segment level
 Since segments vary in length, memory allocation is a dynamic storage-allocation
problem
 A segmentation example is shown in the following diagram
Example of Segmentation
Fragmentation:(Loss of memory)

 External Fragmentation – total memory space exists to


satisfy a request, but it is not contiguous
 Internal Fragmentation – allocated memory may be
slightly larger than requested memory; this size
difference is memory internal to a partition, but not
being used
 First fit analysis reveals that given N blocks allocated,
0.5 N blocks lost to fragmentation
 1/3 may be unusable -> 50-percent rule
Example of Fragmentation
Fragmentation (Cont.)

 Reduce external fragmentation by compaction


 Shuffle memory contents to place all free memory together in one
large block
 Compaction is possible only if relocation is dynamic, and is done
at execution time
 I/O problem

 Latch job in memory while it is involved in I/O


 Do I/O only into OS buffers
 Page Fault: It is a type of interrupt ,raised when a running process
accesses a memory page ,that is mapped into virtual memory but
not loaded in main memory.
Summary

5.2 Virtual Memory


Introduction to Paging
Segmentation
Fragmentation-Internal and External
Page Fault

Reference:
Operating System Concept
By Abraham Silberchanz, Peter Galvin, Greg Gagne

Thank You …!!!

You might also like