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

UNIT 5 OSY Updated

Uploaded by

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

UNIT 5 OSY Updated

Uploaded by

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

Chapter 5:

Memory Management
What is Memory Management
Main-Memory Management:
Primary-Memory or Main-Memory is a large array of words or bytes.
Each word or byte has its own address. Main-memory provides storage
that can be access directly by the CPU.
That is to say for a program to be executed, it must in the main
memory.
The major activities of an operating in regard to memory-
management are:

1. Keep track of which part of memory are currently being used and
by whom.
2. Decide which process are loaded into memory when memory space
becomes available
3. Allocate and De-allocate memory space as needed.
BASIC MEMORY MANAGEMENT TECHNIQUES

 PARTITIONING : Dividing the memory into various


sections of different sizes is called partitioning.
 Once these partitions are decided then they cant
be changed.
 System generation is a process of specifying the
various requirements of the operating system.
 There are two types of Partitioning
 1. Fixed/Static Partitioning
 II. Variable/Dynamic Partitioning
1. Fixed/Static Partitioning
 Partition main memory
into a set of non-
overlapping memory
regions called partitions.
 Fixed partitions can be of
equal or unequal sizes.
 Leftover space in
partition, after program
assignment, is called
internal fragmentation.
 Equal-size partitions:
 If there is an available partition, a
process can be loaded into that partition

 because all partitions are of equal size,
it does not matter which partition is
used.
 If all partitions are occupied by blocked
processes, choose one process to swap
out to make room for the new process.
 Unequal-size partitions,
use of multiple queues:
 assign each process to
the smallest partition
within which it will fit.
 a queue exists for
each partition size.
 tries to minimize
internal fragmentation.
 problem: some queues
might be empty while
some might be loaded.
 Unequal-size partitions,
use of a single queue:
 when its time to load a
process into memory,
the smallest available
partition that will hold
the process is
selected.
 increases the level of
multiprogramming at
the expense of internal
fragmentation.
II. Variable/Dynamic Partitioning
1. Dynamic partitioning tries to overcome the problems caused by fixed
partitioning. In this technique, the partition size is not declared initially.

2. It is declared at the time of process loading.

3. The first partition is reserved for the operating system.

4. The remaining space is divided into parts.

5. The size of each partition will be equal to the size of the process.
6. The partition size varies according to the need of the process so that the
internal fragmentation can be avoided.

Advantages of Dynamic Partitioning

7. No Internal Fragmentation
8. No Limitation on the size of the process
9. Degree of multiprogramming is dynamic
Variable Partitioning: example
Internal Fragmentation

There are two types of fragmentation in OS


which are given as: Internal fragmentation, and
External fragmentation.

Internal Fragmentation:
Internal fragmentation happens when the
memory is split into mounted sized blocks.
Whenever a method request for the memory,
the mounted sized block is allotted to the
method. just in case the memory allotted to the
method is somewhat larger than the memory
requested, then the distinction between allotted
and requested memory is that the Internal
fragmentation.
External Fragmentation

External Fragmentation:

External fragmentation happens when there’s a


sufficient quantity of area within the memory to
satisfy the memory request of a method. however
the process’s memory request cannot be fulfilled
because the memory offered is during a non-
contiguous manner. Either you apply first-fit or
best-fit memory allocation strategy it’ll cause
external fragmentation.
WHAT IS COMPACTION
1. Compaction is a process in which the free space is collected in a large
memory chunk to make some space available for processes.
2. In memory management, swapping creates multiple fragments in the
memory because of the processes moving in and out.
3. Compaction refers to combining all the empty spaces together and
processes.
4. Compaction helps to solve the problem of fragmentation, but it requires too
much of CPU time.
5. It moves all the occupied areas of store to one end and leaves one large
free space for incoming jobs, instead of numerous small ones.
6. In compaction, the system also maintains relocation information and it
must be performed on each new allocation of job to the memory or
completion of job from memory.
WHAT IS FREE SPACE MANAGEMENT TECHNIQUE
A file system is responsible to allocate the free blocks to the file therefore it has to keep track of all
the free blocks present in the disk.
There are mainly four approaches by using which, the free blocks in the disk are
managed.
 Bit Vector
 Linked List
 Grouping
 Counting
Bit Vector:
 The free-space list is implemented as a bit map or bit vector.
 Each block is represented by 1 bit. If the block is free, the bit is 1; if the block is
allocated, the bit is 0.
For example, consider a disk where blocks 2, 3, 4, 5, 8, 9, 10, 11, 12, 13 are free
and the rest of the blocks are allocated.
The free-space bit map would be : 0011110011111100
0=Free block
1= Allocated block

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 0 1 1 1 1 0 0 1 1 1 1 1 1 0 0
WHAT IS FREE SPACE MANAGEMENT
TECHNIQUE
Linked List
 In this approach, the free disk blocks
are linked together i.e. a free block
contains a pointer to the next free
block.

 The block number of the very first


disk block is stored at a separate
location on disk and is also cached in
memory.

 In this approach, link all the disk


blocks together, keeping a pointer to
the first free block.

 This block contains a pointer to the


next free disk block, and so on.
WHAT IS FREE SPACE MANAGEMENT
TECHNIQUE
Grouping –

This approach stores the address of the free blocks in the first free block. The first
free block stores the address of some, say n free blocks. Out of these n blocks,
the first n-1 blocks are actually free and the last block contains the address of
next free n blocks.

An advantage of this approach is that the addresses of a group of free disk blocks
can be found easily.

Counting :
This approach stores the address of the first free disk block and a number n of
free contiguous disk blocks that follow the first block.
Every entry in the list would contain: Address of first free disk block A number n
Virtual Memory

 Virtual memory is the separation of user logical


memory from physical memory. This separation
allows an extremely large virtual memory to be
provided for programmers when only a smaller
physical memory is available.
 Virtual memory makes the task of programming
much easier, because the programmer no longer
needs to worry about the amount of physical
memory available, or about what code can be
placed in overlays, but can concentrate instead
on the problem to be programmed.
Virtual Memory
Virtual Memory

Example:

Consider, an e-mail program, a web browser and a word processor


is loaded into RAM simultaneously; the 64 MB space is not enough
to store all these programs. Without a virtual memory, a message
“You cannot load any more applications. Please close an application
to load a new one.” would be displayed. By using a virtual memory,
a computer can look for empty areas of RAM which is not being
used currently and copies them on to the hard disk device. Thus
RAM is freed to load new applications. Actually it is done
automatically, the user do not even know that it is happening, and
the user feels like RAM has unlimited space even though the RAM
capacity is 32 MB. It is a process of increasing computer’s RAM by
using a section of the hard disk storage as an extension of RAM.
Virtual-address Space
Paging Vs. Segmentation
Paging Segmentation

It divides the physical memory into frames It divides the Computer’s physical memory and
and program’s address space into same size program’s address space into segments.
pages
Page is always of fixed block size. Segment is of variable size

The size of the page is specified by the The size of the segment is specified by the user
hardware.
It may lead to internal fragmentation as the It may lead to External fragmentation as the
page is of fixed block size. memory is filled with the variable sized blocks
Page table is used to map pages with frames Segment table is used to map segments with
from memory. physical memory.
Page table contains page number and frame Segment table contains segment number, length of
number. segment and base address of segment from
memory.
It does not support user’s view of memory It support user’s view of memory

Invisible to Programmer Visible to programmer

Paging consist of Static linking & dynamic Segment consist of Dynamic Linking & Dynamic
loading Loading
What is Page Fault & Page Table
 Page Fault : A page fault occurs when a program
accesses a page that has been mapped in the
address space, but has not been loaded in the
physical memory.
 A page fault occurs when the page requested by a
program is not available in the memory it is called
as a page fault.

 Page Table: A page table is the data structure


used by a virtual memory system in a computer
operating system to store the mapping between
virtual addresses and physical addresses
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
- Write victim frame to disk if dirty

3. Bring the desired page into the (newly) free frame; update the
page and frame tables

4. Continue the process by restarting the instruction that caused the


trap

Note now potentially 2 page transfers for page fault – increasing EAT
FIFO Page Replacement

Page fault: 9
Optimal Page Replacement
Least Recently Used (LRU)
Algorithm
Least Recently Used (LRU)
Algorithm
End of Chapter 5

You might also like