0% found this document useful (0 votes)
2 views26 pages

Lecture 12 Memory Mangement Week14

Memory management in operating systems involves handling memory operations and resources for multiple processes, tracking memory status, and allocating resources efficiently. Various methods such as partition allocation, paging, and different allocation algorithms (first fit, best fit, worst fit, next fit) are used to manage memory effectively. The document details these methods, their advantages, and examples of how processes are allocated memory in a partitioned system.

Uploaded by

nzangi824
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)
2 views26 pages

Lecture 12 Memory Mangement Week14

Memory management in operating systems involves handling memory operations and resources for multiple processes, tracking memory status, and allocating resources efficiently. Various methods such as partition allocation, paging, and different allocation algorithms (first fit, best fit, worst fit, next fit) are used to manage memory effectively. The document details these methods, their advantages, and examples of how processes are allocated memory in a partitioned system.

Uploaded by

nzangi824
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/ 26

MEMORY

MANAGEMENT IN
OPERATING SYSTEM
CHAPTER 8: MAIN MEMORY
MEMORY MANAGEMENT IN OS

• Memory management is the process of intelligently handling all the memory related
operations and resources in the primary memory or storage disk when there are multiple
processes that are using memory and resources. It keeps track of all the memory, it may be
idle in the system or can be allocated to different processes at a given time.

• It decides which processes will get memory resources and when


• It keeps track of all memory status, when allocated or when idle
MEMORY MANAGEMENT IN OS
MEMORY MANAGEMENT METHODS

• There are various methods through which the memory


management system in OS intelligently manage the
system:
3. Paging
1. Partition Allocation Method
4. Segmentation
• Create page
• First Fit 5. Buddy-System Allocator
• Best fit 6. Page Replacement Algorithms
• Worst fit • LRU
• Next fit • FIFO

2. Fragmentation • Optimal Page Replacement algorithm

• Internal 7. Thrashing
• External 8. Translation lookaside buffer
PARTITION ALLOCATION METHOD
• The memory systems developed in early 1990 had a contiguous(continuous) memory
available for storing different files one example of such traditional OSes is MS-Dos.
• But, new systems that have been developed do not have a contiguous memory space
available for files. In fact they are divided into blocks of different sizes.
• This was done to avoid complete memory
corruption if a file is infected. If memory is
divided into blocks corrupted file will only
infect that memory block in which its stored.
PARTITION ALLOCATION METHOD
• Example of Memory Partitioning
• For example, a 500Mb memory may be (equally or unequally) divided to blocks 5 blocks of 100Mb each.
• Or unequally as in 5 blocks of 125mb, 75mb, 125mb, 75mb, 125mb respectively.
• The main memory must accommodate –
1. Operating system
2. User processes
3. Operating System Processes
• For a partitioned memory available in modern systems, we need different algorithms to decide most which
processes must use which memory block while maintaining the most efficient use of these memory block.
• We therefore need to allocate different parts of the main memory in the most efficient way possible
PARTITION ALLOCATION METHOD

• Static Partitioning-
Static partitioning is a fixed size partitioning scheme.
In this technique, main memory is pre-divided into fixed size partitions.
The size of each partition is fixed and can not be changed.
Each partition is allowed to store only one process.
• Example-
Under fixed size partitioning scheme, a memory of size 10 KB may be divided into
fixed size partitions as-
These partitions are allocated to the processes as they arrive.
The partition allocated to the arrived process depends on the algorithm followed
MEMORY MANAGEMENT IN OS
MEMORY MANAGEMENT IN OS
• There are two major divisions one for operating system residing and other for allocating processes.
• OS memory can’t be altered in a direct by way by user.
• Process memory is managed by OS to perform processes.

• One of the simplest methods for memory allocation


• Divide memory into several fixed-sized partitions.
• Each partition may contain exactly one process.
• When a partition is free, a process is selected from the input queue and is loaded into the free partition.
• When the process terminates, the partition becomes available for another process.
• The operating system keeps a table indicating which parts of memory are available and which are occupied
using a table.
• Finally, when a process arrives and needs memory, a memory section large enough for this process is
provided.
FIRST FIT
• This algorithm starts scanning the partitions serially from the starting.
• When an empty partition that is big enough to store the process is found, it is allocated to the
process.
• Obviously, the partition size has to be greater than or at least equal to the process size.
• For a process P1, whichever first partition (starting from the top) is large enough to fit the current
process, gets the process allocated to itself.
FIRST FIT

• Job 1 (size – 100k)


• Can’t fit in block 1 as 50k(block size) <100k (job size)
• Goes to block 2 as can fit in block 2 as 200K > 100K (Size of block more than size of process)
• 100K remains empty in this block now.

• Job 2 (size 10K)


FIRST FIT

• Job 3 (size 35 K)
• Can fit Block 1 but block 1 is not
• mpty(used by job2)
• Can’t fit and also Block 2 not empty
• Can fit in block 3 Goes to block 3

• Job 4
• Goes to block 4

• Job 5
• All blocks 1 to 4 are occupied
• Can’t fit in block 5 as size is more than
block
• So block 5 remains unused. and Job5 has
to wait until other processes finish.
FIRST FIT

Facts:
First-fit memory allocation is faster in making allocation but leads to memory waste.
If the chosen block is significantly larger than that requested, then it is usually split, and the
remainder added to the list as another free block.
The first fit algorithm performs reasonably well, as it ensures that allocations are quick.
When recycling free blocks, there is a choice as to where to add the blocks to the free list—
effectively in what order the free list is kept.
BEST FIT

• This algorithm first scans all the empty partitions.


• It then allocates the smallest size partition to the process.
• Best-fit memory allocation makes the best use of memory space but slower in making the
allocation.
• Thus, in short words – Allocate the process to the partition which is first smallest sufficient
partition among the free available partition.
BEST FIT

• Example
• Job 1 (size – 100k)
• Block 1 size(50k) – 100k = Negative value
• Block 2 size(200k) – 100k = 100k
• Block 3 size(70k) – 100k = Negative value
• Block 4 size(115k) – 100k = 15k
• Block 5 size(15k) – 100k = Negative value
• Goes to block 4 as 15K is best case
BEST FIT

• Job 2 (size – 10k) • Block 4 occupied by job 1


• Block 1 size(50k) – 10k = 40k • Block 5 occupied by job 2
• Block 2 size(200k) – 10k = 190k • Goes to block 1 as 15K is best case
• Block 3 size(70k) – 10k = 60k • Job 4 (size – 15k)
• Block 4 occupied by job 1 • Block 1 occupied by job 3
• Block 5 size(15k) – 10k = 5K • Block 2 size(200k) – 15k = 185k
• Goes to block 5 as 5K is best case • Block 3 size(70k) – 15k = 55k
• Job 3 (size – 35k) • Block 4 occupied by job 1
• Block 1 size(50k) – 35k = 15k • Block 5 occupied by job 2
• Block 2 size(200k) – 35k = 165k • Goes to block 3 as 55k is best case
• Block 3 size(70k) – 35k = 35k
BEST FIT

• Job 5 (size – 23k)


• Block 1 occupied by job 3
• Only option. size of block (200k) > size of job(23k)
• Block 3 occupied by job 4
• Block 4 occupied by job 1
• Block 5 occupied by job 2
• Goes to block 2 as 100K is worst case
BEST FIT
WORST FIT

• This algorithm first scans all the empty partitions.


• It then allocates the largest size partition to the process.
• Worst-fit memory allocation is opposite to best-fit. It allocates free available block to the
new job and it is not the best choice for an actual system It selects the largest available hole
in memory that can fit a needed segment, so as to leave a large hole for other segments.
• Basically look for the largest value –
• Size of block – size of job
• Whichever, gives the highest value job goes to that block.
WORST FIT EXAMPLE
• Job 1 (size – 100k) • Block 3 size(70k) – 10k = 60k
• Block 1 size(50k) – 100k = negative value => • Block 4 size(115k) – 10k = 105k
Can’t fit • Block 5 size(15k) – 10k = 5k
• Block 2 size(200k) – 100k = 100k • goes to block 4 as 105k is worst case.
• Block 3 size(70k) – 100k =negative value => • Job 3(size – 35k)
Can’t fit
• Block 1 size(50k) – 35k = 15k
• Block 4 size(115k) – 100k = 15k
• Block 2 already used by job 1. So not possible
• Block 5 size(15k) – 100k = negative value =>
• Block 3 size(70k) – 35k = 35k
Can’t fit
• Block 4 already used by job 2. So not possible
• Goes to block 2 as 100K is worst case
• Block 5 size(15k) – 35k = negative value =>
• Job 2 (size – 10k) Can’t fit
• Block 1 size(50k) – 10k = 40k • goes to block 3 as 35k is worst case.
• Block 2 already used by job 1. So not possible
WORST FIT EXAMPLE
• Job 4(size -15k)
• Block 1 size(50k) – 15k = 35k
• Block 2 already used by job 1. So not possible
• Block 3 already used by job 3. So not possible
• Block 4 already used by job 2. So not possible
• Block 5 size(15k) – 15k = 0
• Goes to block 1 as 35k is the worst

• Job 5(size – 23k)


• Block 1 already used by job 4. So not possible
• Block 2 already used by job 1. So not possible
• Block 3 already used by job 3. So not possible
• Block 4 already used by job 2. So not possible
• Block 5 size(15k) – 23k = negative value
• Goes no where has to wait indefinitely for other blocks free up.
WORST FIT EXAMPLE TABLE
NEXT FIT
• Next fit is a modified version of ‘first fit’. It begins as first fit to find a free partition but when called next
time it starts searching from where it left off, not from the beginning next fit is a very fast searching
algorithm and is also comparatively faster than First Fit and Best Fit Memory Management Algorithms.
• Example:
NEXT FIT
• Example:
Job 1 (size – 100k)
Can’t fit in block 1 as 50k(block size) <100k(job size)
Can fit in block 2 as 200K > 100K (Size of block more than size of process)
100K remains empty in this block now.
Job 2 (size 10k)
Last job entered in block 2 so will start from block 3 now
Goes to block 3 as block size(70k) > job size(10k)
Job 3(size 35K)
Last job entered in block 3 so will start from block 4 now
Goes to block 4 as block size(115k) > job size(10k)
NEXT FIT
• Job 4(size 15k)
• Last job entered in block 4 so will start from block 5 now
• Goes to block 5 as block size(10k) = job size(10k)

• Job 5(23k)
• Last job entered in block 5 and there no further blocks, so goes back to block 1
• Goes to block 1 as block size(50k) > job size(23k).
Any Question?

You might also like