5.memory Management

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

SUBJECT : OPERATING SYSTEM (22516)

Unit-5

MEMORY MANAGEMENT
Marks-14

By: Mr.A.D.Cholke
MEMORY MANAGEMENT
Memory Management

• Introduction-
• Memory management is the important function 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..
Memory Management

• Memory Partitioning-
• Memory partitioning is the system by which the memory of a computer system is
divided into sections for use by the resident programs.
• These memory divisions are known as partitions.
• There are different ways in which memory can be partitioned:
1. Static partitioning (fixed)-
2. Dynamic partitioning (variable)-
Memory Management

• Memory Partitioning-
1. Static Partitioning (fixed)-
• This is the oldest and simplest technique used to put more than one processes in
the main memory.
• In this partitioning, number of partitions
(non-overlapping) in RAM are fixed but
size of each partition may or may not be same.
• As it is contiguous allocation, hence no
spanning is allowed.
• Here partition are made before execution or
during system configure.
Memory Management

• Memory Partitioning-
2. Dynamic Partitioning (Variable)-
• Initially RAM is empty and partitions are made
during the run-time according to process’s need
instead of partitioning during system configure.
• The size of partition will be equal to incoming
process.
• The partition size varies according to the need of
• the process so that the internal fragmentation can
be avoided to ensure efficient utilization of RAM.
• Number of partitions in RAM is not fixed and depends
on the number of incoming process and Main Memory’s size.
Memory Management

• Free Space Management -


• The system keeps tracks of the free disk blocks for allocating space to files
when they are created.
• Also, to reuse the space released from deleting the files, free space
management becomes crucial.
• The system maintains a free space list which keeps track of the disk blocks
that are not allocated to some file or directory.
• The free space list can be implemented mainly as:
1. Bitmap or Bit vector
2. Linked List
Memory Management
• Free space management
1. Bitmap or Bit vector-
• A Bitmap or Bit Vector is series or collection of bits where each bit
corresponds to a disk block.
• The bit can take two values: 0 and 1: 0 indicates that the block is
allocated and 1 indicates a free block.
• The given instance of disk blocks on the disk in Figure 1 (where
green blocks are allocated) can be represented by a bitmap of 16 bits
as: 0000111000000110.
• Advantages –
1. Simple to understand.
2. Finding the first free block is efficient. It requires scanning the words (a
group of 8 bits) in a bitmap for a non-zero word. (A 0-valued word has all
bits 0). The first free block is then found by scanning for the first 1 bit in the
non-zero word.
Memory Management
• Free space management
2. 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 Figure-2, the free space list head points to Block 5
which points to Block 6, the next free block and so on.
The last free block would contain a null pointer
indicating the end of free list.
• A drawback of this method is the I/O required for free
space list traversal.
Memory Management
• Virtual Memory-
• Virtual Memory is the memory
generated from physical memory
devices like disk when less amount
of main memory is available.
• It is a separation of the user logical
memory to physical memory and it is
commonly used in demand paging.
• Due to this programming task is
become easy.
• In case of multiprogramming virtual
memory is applicable.
Memory Management
• Introduction to Paging-
• Dynamic memory partitioning suffer from external fragmentation.
• This problem can be overcome by paging or compaction.
• This method allows a program to be allocate physical memory whenever it is available.
• In paging primary memory is broken in to fixed size block called as pages
• When process executed pages are loaded in to back store (Large capacity disk).
Memory Management
• Paging Hardware-
• Address generated by CPU is divided into
1. Page number(p): Number of bits required to
represent the pages in Logical Address Space or
Page number.
2. Page offset(d): Number of bits required to represent
particular word in a page or page size of Logical
Address Space or word number of a page or page
offset.
• Physical Address is divided into
1. Frame number(f): Number of bits required to
represent the frame of Physical Address Space or
Frame number.
2. Frame offset(d): Number of bits required to
represent particular word in a frame or frame size of
Physical Address Space or word number of a frame
or frame offset.
Memory Management
• Demand Paging-
• A demand paging system is quite similar to a
paging system with swapping where
processes reside in secondary memory and
pages are loaded only on demand, not in
advance.
• When a context switch occurs, the operating
system does not copy any of the old
program’s pages out to the disk or any of the
new program’s pages into the main memory
Instead, it just begins executing the new
program after loading the first page and
fetches that program’s pages as they are
referenced.
• Demand Paging- Memory Management
• While executing a program, if the program
references a page which is not available in the main
memory because it was swapped out a little ago, the
processor treats this invalid memory reference as
a page fault and transfers control from the program
to the operating system to demand the page back into
the memory.
• Advantages
Following are the advantages of Demand Paging −
1. Large virtual memory.
2. More efficient use of memory.
3. There is no limit on degree of multiprogramming.
• Disadvantages
1. Number of tables and the amount of processor
overhead for handling page interrupts are greater
than in the case of the simple paged management
techniques
Memory Management
Segmentation
• Segmentation is a memory management technique in which each job is divided into
several segments of different sizes, one for each module that contains pieces that
perform related functions.
• Each segment is actually a different logical address space of the program.
• When a process is to be executed, its corresponding segmentation are loaded into
non-contiguous memory though every segment is loaded into a contiguous block of
available memory.
• Segmentation memory management works very similar to paging but here segments
are of variable-length where as in paging pages are of fixed size.
Difference Between Paging & Segmentation
Memory Management
• Page Fault – A page fault happens when a running program accesses a memory
page that is mapped into the virtual address space, but not loaded in physical memory.
• Since actual physical memory is much smaller than virtual memory, page faults happen.
• In case of page fault, Operating System might have to replace one of the existing pages
with the newly needed page.
• Different page replacement algorithms suggest different ways to decide which page to
replace.

• Page Replacement Algorithms :


1. First In First Out (FIFO)
2. Least Recently Used (LRU) –
3. Optimal Page replacement –
Page Replacement Algorithms
First In First Out (FIFO) –
• This is the simplest page replacement algorithm.
• In this algorithm, the operating system keeps track of all pages in the memory in a queue,
the 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.
• Example-1
Consider page reference string 1, 3, 0, 3, 5, 6
with 3 page frames.
Find number of page faults.
Page Replacement Algorithms
Least Recently Used –
• In this algorithm page will be replaced which is least recently used.
• Example-1
Consider the page reference string
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2
with 4 page frames.
Find number of page faults.
Page Replacement Algorithms
Optimal Page Replacement –
• In this algorithm page will be replaced which would not be used in the future for
longest duration of time.
• Example-1
Consider the page reference string
7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2,3
with 4 page frames.
Find number of page faults.

You might also like