0% found this document useful (0 votes)
7 views30 pages

Chapter 6 Memory Managment and Virtual Memory New 2023

Uploaded by

Henok Zeleke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views30 pages

Chapter 6 Memory Managment and Virtual Memory New 2023

Uploaded by

Henok Zeleke
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Chapter 6

MEMORY MANAGEMENT VIRTUAL MEMORY


Introduction to Memory management
•Requirements
•Partitioning
•Swapping
•Virtual Memory
•Paging
•Page Replacement Policies.
2
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?
3
Introduction

 Memory management is the functionality of an operating system


which handles or manages primary memory and moves processes
back and forth between main memory and disk during execution.
 Memory management keeps track of each and every memory
location, regardless of either it is allocated to some process or it is free.
 It checks how much memory is to be allocated to processes. It
decides which process will get memory at what time.
 It tracks whenever some memory gets freed or unallocated and
correspondingly it updates the status.
4
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
100 sec
Magnetic Tape
◦ Hence the MM has a responsibility to
 Keeps track of which is in use or not.
 Allocate and De-allocate
 Manage Swapping and etc.
5
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.
6
Memory Management: Partitioning

 Partition: divide memory to partitions, and dynamically assign to


different processes.

 Fixed Partitioning

 Dynamic Partitioning
7
Memory Management: Partitioning

 Fixed Partitioning

 Any process whose size is less than or equal to the


partition size can be loaded into an available partition.

 The operating system can swap a process out of a


partition.

 A program may not fit in a partition. – The programmer


must design the program with overlays.
8
Memory Management: Partitioning

 Dynamic Partitioning

 Unequal-size partitioning.

 Smaller programs can be placed in


smaller partitions.

 Programs larger than 16M cannot be


accommodated without overlay.
9
Swapping

 Swapping is a memory management technique used in


multi-programming to increase the number of processes
sharing the CPU.
 It is a technique of removing a process from the main
memory and storing it into secondary memory, and then
bringing it back into the main memory for continued
execution.
10
Swapping

 Memory allocation changes as processes come into memory and


leave it.
 The shaded regions are unused memory.
11
Swapping…

 Allocating space for a growing data segment.


12
Swapping…

 Allocating space for a growing stack


and a growing data segment.
13
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.


14
MM using Bitmaps

 The Size of the bitmap


depends on the size of
memory and size of
the allocation unit.
 Divide memory into
allocation units.

 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.
15
MM using Linked List

 Hole – block of available memory.


 When a process arrives, it is allocated memory from a hole large enough to
accommodate it.
 Four neighbor combinations for the terminating process, X.
16
Virtual Memory

 Formerly Overlays were used as a virtual memory.


It is a technique to run a program that is bigger than the

size of the physical memory by keeping only those
instructions and data that are needed at any given time.
◦ 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.
17
Virtual Memory

 Hence in 1961 a method of doing everything 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 Y MB machine where X>Y.
18
Paging

 Paging is a function of memory management where a computer will


store and retrieve data from a device's secondary storage to the
primary storage.
 VM uses a technique called paging.
19
Paging…

 Pages and page frames are always


equal. Here 4KB
 Virtual address
 Divided into pages

 Physical memory
 Divided into frames

 Page vs. Frame


 Same size block
20
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
21
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.
22
Page Replacement
23
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 are:
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
24

• In this algorithm, operating system keeps track of all


pages in the memory in a queue, oldest page is in
the front of the queue.
• When a page needs to be replaced page in the
front of the queue is selected for removal.
25

What happens when we have 4 frames?


26

 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!
27
28

 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.
29
30

End of Chapter 6

You might also like