Thrashing and Frame Allocation
Thrashing and Frame Allocation
1
To understand Thrashing we must first understand the following concepts
Degree of multiprogramming
Maximum number of process that can be moved from New state to Ready state is
called degree of multiprogramming.
(Basically, number of programs in the RAM)
● now often times, there are programs which will demand input/output operations
while being executed and in that case, CPU goes to idle state but we don’t want it to
sit free!
● We want max CPU utilization so we try to stuff as many programs in the RAM as
possible so that even if some programs are busy in performing input output
operations, the CPU wont sit free and will start executing next program in the
ready state
2
●
Its not like the whole program for a certain process is brought inside the RAM
●
Instead, we bring some pages of Processes inside the RAM.
This is done to achieve the maximum level of multiprogramming.
●
What is a Page?
The program is divided into smaller units ( i.e. its broke down into smaller
pieces). The smallest unit which is then imported from secondary memory to
RAM is called a page.
You can define a page as fixed length contiguous block of virtual memory
Virtual memory- A computer can address more memory than the amount physically installed on the system. This extra memory is
actually called virtual memory and it is a section of a hard disk that's set up to emulate the computer's RAM.
3
●
Page Hit- when the page required to execute an instruction is inside the RAM.
●
Page fault- When the required page is not inside the RAM. Can happen maybe because the
RAM deleted that certain page thinking that its work had been done or maybe because that
page was never mapped in the memory.
●
Pager fault service time- as the name suggests, it fixes the page fault.
The CPU asks the controller to bring the required page from secondary
memory into Primary memory i.e. RAM. It consumes a lot of time
*A controller, in a computing context, is a hardware device or a software program that manages or
directs the flow of data between two entities. In computing, controllers may be cards, microchips or
separate hardware devices for the control of a peripheral device.
4
FRAMES
5
●
So basically, a FRAME is the smallest fixed length block of physical
memory into which memory pages are mapped by the operating system
●
Paging- Transfer of memory pages from secondary to primary memory.
●
Swapping- process can be temporarily swapped from main memory to
secondary memory so that the main memory can be made available for
other processes.
(swapping happens when the the RAM becomes full)
6
7
Thrashing
8
How to handle Thrashing?
9
●
So the most recent page references are examined
●
If page is in active use, it will be in the working set otherwise it will be dropped.
●
Working set is just an approximation of the locality
●
Decreases thrashing while keeping a maximum degree of multi programming
●
OS has to monitor the working set as it keeps changing. This is a disadvantage.
●
If Demand>available, system will choose few processes and shut them down.
They will be restarted again later when there will be enough frames available.
●
If demand<=available, there will be no thrashing and system will continue to
run smoothly.
10
2. Page fault frequency
A direct approach to prevent thrashing.
●
We declare an upper bound and a lower bound.
●
Thrashing must remain between this domain.
●
If thrashing>upper bound, means process needs more frames. So frame allocation to that
process will be increased
●
If thrashing< lower bound, means the process has ample frames so we can snatch away
those frames and provide them to another process, hence decreasing the frame allocation.
11
12
Frame Allocation
1. Equal Allocation
All processes get equal frames.
Disadvantage-Both low and high priority processes get equal frames, so the
system suffers.
2. Proportional Allocation
Distribution is done on the basis of size
3. Priority Allocation
As the name suggests, this allocation method allocate frames on basis of the
priority of the process.
13
Global and Local page replacement algorithms
These aren’t exactly frame allocation algorithms but dynamically effect the
allocation. These come into action when the frames are full and swapping is
required.
1. Global page replacement - When a process needs a page which is
not in the memory, it can bring in the new page and allocate it a frame from
the set of all frames, even if that frame is currently allocated to some other
process; that is, one process can take a frame from another.
●
Higher priority process can increase its allocation on expense of a lower
priority process.
●
Allows more efficient use of frames and gives a better throughput.
14
●
2. Local Page Replacement - When a process needs a page
which is not in the memory, it can bring in the new page and allocate
it a frame from its own set of allocated frames only.
●
Number of frames belonging to the process wont change.
●
Processes can control their own page fault rate. ( In case of global page
replacement, its not the same.)
15