0% found this document useful (0 votes)
9 views

Chapter 3- Memory Managment and Virtual Memory

Chapter 3 discusses memory management and virtual memory, highlighting the importance of efficient memory allocation and the role of the operating system in managing memory resources. It covers techniques such as paging, page replacement policies, and the differences between simpler memory management systems and multiprogramming with fixed partitions. The chapter also explains the challenges of page replacement and various algorithms used to optimize memory usage.

Uploaded by

btbonsa
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Chapter 3- Memory Managment and Virtual Memory

Chapter 3 discusses memory management and virtual memory, highlighting the importance of efficient memory allocation and the role of the operating system in managing memory resources. It covers techniques such as paging, page replacement policies, and the differences between simpler memory management systems and multiprogramming with fixed partitions. The chapter also explains the challenges of page replacement and various algorithms used to optimize memory usage.

Uploaded by

btbonsa
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

Chapter 3

Memory management and Virtual Memory


Outline
Introduction to Memory management
• Requirements
• Partitioning

Introduction to Virtual Memory


• Paging
• Page Replacement Policies.
What is in this chapter?
• Just as processes share the CPU, they also
share physical memory.
– This chapter overviews mechanisms and facts for
doing that sharing.
Introduction
Memory is an important resource that needs to be
managed properly.
◦ Why?-
 they are limited in nature!
◦ What is programmers/expert users need?
 Infinitely …
 less of this and less of that… more of this and more of that…
◦ Can the technology provide that?
◦ NO
Hence the operating system owes to manage the
memory.
◦ How?
Introduction…
 The OS has a part called Memory manager that manipulates
and perform an operation on memory hierarchy.

Registers <1
nsec
2 nsec
Cache Memory
10 nsec
Main Memory
10 msec
Magnetic Disk
Magnetic Tape 100 sec

◦ Hence the MM has a responsibility to


 Keeps track of which is in use or not.
 Allocate and De allocate
 Manage Swapping and etc.
Memory Management
Memory management systems are divided in
to two classes.
◦ Those that move processes back and forth b/n main
memory and disk (paging and swapping) b/c of
memory insufficiency
◦ Those that do not (simpler)
Also the realm of software tech. persuade the
creation of efficient memory.
Simpler ones… monoprogramming

0X FFF Devices drivers in


OS in ROM ROM

User Program
User Program

User program

OS in RAM OS in RAM
0
Palm tops, Early PC w/r
Formerly in main portion of a
embedded
frames and system is called
systems and
minicomputers BIOS
Smart cards
In all cases only one process can run at a time
◦ No Swapping and Paging (ex. Three level scheduling in batch
system)
Multiprogramming with Fixed Partitions
• An easy way to achieve MP is to
divide Memory in to Unequal
partitions.
• For efficient CPU utilization
• Partitioning can be done
manually.
• Fixed memory partitions
• Some space may not be used by a
job hence will be lost
– Multiple input queue
• Dis advantageous in the case of
P3 and P1
– Single input queue
• Small Jobs can be unworthy of
having the whole partitions.
• Another approach is implemented
– Always reserve a small partition
• Modeling multiprogramming
• Analysis of multiprogramming system
performance
• Relocation and protection
Swapping

• Memory allocation changes as processes come


into memory and leave it.
• The shaded regions are unused memory.
Swapping…
• Allocating space for a growing data segment.
Swapping…
• Allocating space for a growing stack
and a growing data segment.
MM with BM and LL
• As memory is assigned dynamically OS must
manage it.
• There are two ways of keep track of memory
usage
– Bitmaps
– Linked list/free list.
MM using Bitmaps
 The Size of the
bitmap depends
on the size of
memory and
size of the
allocation unit.

 a) A part of memory with five processes and three holes. The tick marks show the
memory allocation units. The shaded regions (0 in the bitmap) are free.
 (b) The corresponding bitmap.
 (c) The same information as a list.
MM using Linked List
• Four neighbor combinations for the
terminating process, X.
Virtual Memory
 Formerly Overlays were used as a virtual memory.
◦ Splitting done manually by the programmer
◦ Swapping done by the system
But some overlay systems were so complex and
expensive to work with. And the first task, by nature, is
time consuming and boring.
 Hence in 1961 a method of doing every thing using
system is advised.
◦ i.e. Virtual Memory.
 The main idea is to put currently used data, program
and stack in the main memory and the rest in the disk.
◦ i.e. X MB Program can run on YMB machine where X>>Y
and X and Y are size of power of 2
Paging
• VM uses a technique called paging.
– For instance- the instruction MOV REG,1000 –
copy the content of memory address 1000 in to
REG
Paging…
 Pages and page frames are always
equal. Here 4KB
◦ How much pages and
page frames can we get
from 64 KB of Virtual
address space and 32 KB
of physical memory?
 Lets do the following instruction.
 MOV REG 0
 MOV REG 8192
will be transformed in to ___,
and ____, output will be
moved to bus
What happens if the program
tries to use MOV REG,
32780
Paging … page tables
 Purpose : map virtual pages
onto page Frames.
 Major issues to be faced
1. The page table can be
extremely large
2. The mapping must be fast.
Paging … page tables
Page table Entry Structure
What happens if there is no free frame?
• Page replacement – find some page in memory,
but not really in use, swap it out.
– Algorithm- want an algorithm which will result in
minimum number of page faults.
– performance – reduce overhead
• Same page may be brought into memory several
times.
• Same with cache memory cleaning and removing
heavily used web pages from the server
Page Replacement
• Prevent over-allocation of memory by modifying page-
fault service routine to include page replacement.
– A process may have 10 pages but only 5 are in use. Demand
paging only brings in those 5. This allows us to bring more
programs into memory – increase degree of multiprogramming
or over-allocating memory. If have 40 frames, run 8 processes
using 5 pages each instead of 4 processes using 10 pages. What
happens when a process suddenly needs all 10 pages? All
memory is in use.
– Terminate process – why, it is running normally
– Swap out a process – will be considered later
– Page replacement
Need For Page Replacement
Basic Page Replacement
1. Find the location of the desired page on disk.
2. Find a free frame:
- If there is a free frame, use it.
- If there is no free frame, use a page replacement
algorithm to select a victim frame.
3. Read the desired page into the (newly) free frame.
Update the page and frame tables.
4. Restart the process.
 Use modify (dirty) bit to reduce overhead of page
transfers – only modified pages are written to disk.
 Page replacement completes separation between logical
memory and physical memory – large virtual memory
can be provided on a smaller physical memory.
Page Replacement
Page Replacement Algorithms
• Want lowest page-fault rate.
• Evaluate algorithm by running it on a
particular string of memory references
(reference string) and computing the number
of page faults on that string.
• In all our examples, the reference string is
What happens when we have 4 frames?
 Replace page that will not be used for longest period of time.

 Each page will be labeled the number of instruction that will be


executed before that page is needed/ first referenced.

 The only problem with this algorithm is unrealizable… THE ONLY


PROBLEM?

 How do you know this? Requires future knowledge!

 Used as yardstick to evaluate how well other algorithms perform.


 The optimal algorithm uses the time when a page is to be used
next
 FIFO uses the time when a page was brought into memory
 LRU – use the recent past as an approximation of the near future.
 Replace the page that has not been used for the longest period of
time.
 Counter implementation
◦ Every page entry has a counter; every time page is referenced through
this entry, copy the clock into the counter.
◦ When a page needs to be changed, look at the counters to determine
which one is the smallest value and use that frame.
 Global replacement – process selects a replacement frame
from the set of all frames; one process can take a frame
from another.
◦ A process is no longer in control of its page-fault rate
◦ Usually results in greater system throughput and its therefore more
commonly used
 Local replacement – each process selects from only its own
set of allocated frames.
◦ Does not take advantage of less used pages in other processes
which could improve overall system throughput

You might also like