Memory Management
Memory Management
• Here process of size 426k will not get any partition for allocation.
First fit
• Here process of size 426k will not get any partition for allocation.
Next Fit
• Search time is smaller
• Memory manager must have to keep track of last allotted hole to
process.
• It gives slightly worse performance than first fit.
Best fit
• Entire memory is searched here
• The smallest hole, which is large enough to hold the process, is selected for
allocation
• Processes of 212k, 417k,112k and 426k arrives in order.
• Here process of size 426k will not get any partition for allocation
• Search time is high, as it searches entire memory every time.
• This algorithm can be used only with dynamic partitioning
Virtual Memory
Our computer has a finite(fix) amount of RAM
when too many programs are running at once at that time it is possible
to run out of memory
• Each page can be labeled with the number of instructions that will be
executed before that page is first referenced.
• The optimal page algorithm simply says that the page with the
highest label should be removed.
• The only problem with this algorithms is that it is unrealizable.
• At the time of the page fault, the operating system has no way of
knowing when each of the pages will be referenced next.
FIFO Page Replacement Algorithm
• The first in first out page replacement algorithm is the simplest page
replacement algorithm
• The operating system maintains a list of all pages currently in memory, with
the most recently arrived page at the tail and least recent at the head.
• On a page fault, the page at head is removed and the new page is added to
the tail.
• When a page replacement is required the oldest page in memory needs to
be replaced.
• The performance of the FIFO algorithm is not always good because it may
happen that the page which is the oldest is frequently referred by OS.
• Hence removing the oldest page may create page fault again.
FIFO Page Replacement Algorithm
Page Reference String:
• 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1
Three frames
Second Chance Page Replacement Algorithm
• It is modified form of the FIFO page replacement algorithm.
• It looks at the front of the queue as FIFO does, but instead of
immediately paging out that page, it checks to see if its referenced bit
is set.
• If it is set(zero) the page is swapped out.
• Otherwise the referenced bit is cleared, the page is inserted at the
back of the queue(as if it were a new page) and this process is
repeated.
Second Chance Page Replacement Algorithm
• If all the pages have their referenced bit set, on the second encounter
of the first page in the list, that page will be swapped out, as it now
has its referenced bit cleared.
• If all the pages have their reference bit cleared, then second chance
algorithm degenerates into pure FIFO.
Clock Page Replacement Algorithm
• In second chance algorithm pages are constantly moving around on
its list. So it is not working efficiently.
• A better approach is to keep all the page frames on a circular list in
the form of a clock.
Clock Page Replacement Algorithm
• When a page fault occurs, the page being pointed to by the hand is
inspected.
• If its R is 0, the page is evicted, the new page is inserted into the clock
in its place, and the hand is advanced one position.
• If R is 1, it is cleared and the hand is advanced to the next page
LRU(Least Recently Used) Page Replacement Algorithm
• A good approximation to the optimal algorithm is based on the observation
that pages that have been heavily used in last few instructions will
probably be heavily used again in next few instructions.
• When page fault occurs, throw out the page that has been used for the
longest time. This strategy is called LRU(Least Recently Used) paging.
• To fully implement LRU, it is necessary to maintain a linked list of all pages
in memory, with the most recently used page at the front and the least
recently used page at the rear.
• The list much be updated on every memory reference.
• Finding a page in the list, deleting it, and then moving it to the front is a
very time consuming operations.
LRU(Least Recently Used) Page Replacement
Algorithm
• For example, if
• 1. Page-0 is of class-2(referenced, not modified)
• 2. Page-1 is of class-1 (not referenced, modified)
• 3. page-2 is of class-0(not referenced, not modified)
• 4. Page-3 is of class-3 (referenced, modified)
• So lowest class page-2 needs to be replaced by NRU.
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 a contiguous block of available memory.
• Segmentation memory management works very similar to paging but
there segments are of variable-length where as in paging pages are of
fixed size.
Segmentation
Paging was invented to get large address space without Segmentation was invented to allow programs and data to be
having to buy more physical memory broken up into logically independent address space and to
add sharing and protection
The programmer does not aware that paging is used The programmer is aware that segmentation is used
Procedure and data cannot be distinguished and protected Procedure and data be distinguished and protected
separately separately
Change in data or procedure requires compiling entire Change in data or procedure requires compiling only affected
program segment not entire program