Professional Documents
Culture Documents
Memory Management
Outline
• Bounds register
– Ending location of the process
• However
– Virtual Memory has evolved from the
partitioning methods
Types of Partitioning
• Fixed Partitioning
• Dynamic Partitioning
• Paging
• Dynic Paging
• Segmentation
Fixed Partitioning
• Equal-size partitions
– Any process whose size is less
than or equal to the partition size
can be loaded into an available
partition
• The operating system can swap a
process out of a partition
– If none are in a ready or running
state
Fixed Partition Selection
• First fit
– Program is allocated to the first partition big enough to hold it
• Next fit
– works the same way as first fit, except that it keeps track of
where it is whenever it finds a suitable partition
• Best fit
– Program is allocated to the smallest partition big enough to
hold it
• Worst fit
– Program is allocated to the largest partition big enough to
hold it
Fixed Partitioning Problems
• Equal-size
– Placement is trivial (no options)
• Unequal-size
– Can assign each process to the smallest
partition within which it will fit
– Queue for each partition
– Processes are assigned in such a way as to
minimize wasted memory within a partition
Fixed Partitioning
• First-fit algorithm
– Scans memory from the beginning and
chooses the first available block that is
large enough
– Fastest
– May have many process loaded in the front
end of memory that must be searched over
when trying to find a free block
Dynamic Partitioning
• Next-fit
– Scans memory from the location of the last
placement
– More often allocate a block of memory at the
end of memory where the largest block is found
– The largest block of memory is broken up
into smaller blocks
– Compaction is required to obtain a large block
at the end of memory
Allocation Schemes
Solutions:
•Break memory into fixed-sized blocks and allocate in units of block
sizes. Since the allocation will always be slightly larger than the
process, some Internal Fragmentation still results.
•Compaction: move all processes to one end of memory and holes to the
other end. Expensive and can only be done when relocation is done at
execution time, not at load time.
Paging
• Once a bit has been set to 1, it will stay until the operating system resets it to 0.
• When a process is started up, both page bits for all its pages are set to 0 by
OS.
• When a page fault occurs, OS inspects all the pages and divides them into four
categories based on the current values of the R and M bits.
– Class 0: not referenced, not modified.
– Class 1: not referenced, modified
– Class 2: referenced, not modified
– Class 3: referenced, modified
• NRU algorithm removes a page at random from the lowest numbered non-
empty class.
First In First Out (FIFO)
Algorithm
• The operating system maintains a list of all
pages currently in memory, with the page at the
head of the list the oldest one and the page
at the tail the most recent arrival.
• On a page fault, the page at the head is
removed and the new page added to the tail
of the list.
• Not a good algorithm because there are
chances of removing a heavily used page
Second Chance Algorithm
• Simple modification to FIFO that avoids the problem of throwing out a
heavily used page
• Inspect the R bit of the oldest page
– If it is 0, the page is both old and unused, so it is replaced.
– If the R bit is 1, the bit is cleared and the page is put at the end of the list of pages,
and its load time is updated as though it has just arrived in memory.
• The search continues.
• The second chance looks for an old page that has not been referenced in the
previous clock interval.
• If all have been referenced then second chance degenerates into a pure FIFO.
• Suppose that all the pages have their R bits set.
– One by one the OS moves the pages to the end of the list and clears their R bit.
– Eventually, it comes back to page A, which now has its R bit cleared.
– At this point A is evicted. Thus the algorithm always terminates.
Least Recently Used (LRU) Algorithm
• Pages that have been heavily used in the last few instructions will
probably be heavily used again in the next few instructions.
• Conversely, pages that have not been used for ages will probably
remain unused for a longer time.
• When page fault occurs, OS throws out the pages that have been
unused for the longest time.
• 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 problem is that the list must be updated on every memory
reference.
• Finding a page in the list, deleting and then moving it from to the front is
a very time consuming operation.
Segmentation