T3 - Memory Management-Virtual Memory
T3 - Memory Management-Virtual Memory
memory
• Only part of the program needs to be in memory for execution
• Logical address space can therefore be much larger than physical
address space
• Allows address spaces to be shared by several processes
• Allows for more efficient process creation
• More programs running concurrently
• Less I/O needed to load or swap processes
Virtual Memory That is Larger Than Physical Memory
disk
• Virtual address space – logical view of how process is stored
in memory
• Usually start at address 0, contiguous addresses until end
of space
• Meanwhile, physical memory organized in page frames
• MMU must map logical to physical
• Virtual memory can be implemented via:
• Demand paging
• Demand segmentation
Paged Memory Allocation
The simplified example for the image above shows how the Memory
Manager keeps track of a program that is four pages long. To simplify the
arithmetic, we’ve arbitrarily set the page size at 100 bytes. Job 1 is 350 bytes
long and is being readied for execution.
Paged Memory Allocation (cont.)
First-in first-out (FIFO): Removes page that has been in memory for the
longest.
FIFO 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. Consider page reference string 1, 3, 0, 3, 5, 6 with 3 page frames. Find number
of page faults.
Least-recently-used (LRU): Removes page that has been least and this algorithm
replaces the page which has not been referred for a long time. This algorithm is
just opposite to the optimal page replacement algorithm. In this, we look at the past
instead of staring at future.
in memory.
Limit: It specifies the length of the segment.
Translation of Two-dimensional Logical Address to one dimensional Physical Address.
Address generated by the CPU is divided into:
Segment number (s): Number of bits required to represent the
segment.
Segment offset (d): Number of bits required to represent the size
of the segment.
Advantages of Segmentation –
No Internal fragmentation.
Segment Table consumes less space in comparison to Page table
in paging.
Disadvantage of Segmentation –
As processes are loaded and removed from the memory, the free
memory space is broken into little pieces, causing External
fragmentation.
Segmented/Demand Page Memory Allocation