Download presentation
Presentation is loading. Please wait.
1
Virtual memory
2
Virtual memory What is virtual memory?
Virtual memory loosely describes a hierarchical storage system of at least two levels, which is managed by an operating system to appear to a user like a single large directly addressable main memory.
3
Virtual memory Reasons
To free users from the need to carry out storage allocation. To make programs independent of the configuration and capacity of the memory systems used during their execution. To permit efficient sharing of memory space among different users (processes) and achieve the high access rates and low cost per bit that is possible with a memory hierarchy.
4
Virtual memory Design Most virtual memory systems employ a two-level hierarchy M1 - main memory of relatively small capacity S1 M2 - much larger secondary memory of capacity S2 Ordinary user views the system as a single virtual or logical memory of unlimited capacity (unlimited!?)
5
Virtual memory Design The virtual memory is addressed by the set of logical addresses or identifiers explicitly or implicitly specified in the user’s program L – set of logical adresses The fixed physical storage locations in the memory units are identified by a set of physical addresses P – set of physical addresses
6
Virtual memory Design The virtual memory systems are implemented by providing an automatic mechanism for the address mapping f:L->P
7
Virtual memory Memory hierarchy
CPU and other processors communicate directly with the first member of the hierarchy M1 During the execution the CPU generates a continuous stream of logical memory addresses If an address is generated, which is currently assigned to Mi where i1 the address must be reasigned to M1 M1 CPU M2 Mn
8
Virtual memory Memory hierarchy
This relocation of addresses generally requires the transfer of information between levels Mi and M1, which is in most cases a relatively slow process In order for a memory hierarchy to work efficiently, the address generated by the CPU should be found in M1 as often as possible This requires that future addresses should be to some extent predictable
9
Virtual memory Memory hierarchy
Which characteristic of computer programs is essentail to successful operation of memory hierarchy? The predictability of logical memory addresses is based on a common characteristic of computer programs called locality of reference.
10
Virtual memory Locality of reference
Items of information whose addresses are referenced during the time interval t-T to t, constitute the working set W(t,T) It has been found that W(t,T) tends to change rather slowly By maintaining all of W(t,T) in the fastest level memory M1, the number of references to M1 can be considerably greater than the number of references to other levels
11
Virtual memory Implementation
Three solutions Paging Segmentation Segmentation with paging
12
Virtual memory Paging Paging systems use fixed-length blocks called pages and assign them to fixed regions of physical memory called page frames
13
Virtual memory Paging - Overview
14
Virtual memory Paging – Page table
15
Virtual memory Paging – Address translation
16
Virtual memory Paging – Page table
The entire page table may take up too much main memory Page tables are also stored in virtual memory When a process is running, part of its page table is in main memory
17
Virtual memory Paging – Translation Lookaside Buffer
Each virtual memory reference can cause two physical memory accesses one to fetch the page table one to fetch data To overcome this problem a special cache is set up for page table entries Contains page table entries that have been most recently used Works similar to main memory cache (associative mapping)
18
Virtual memory Paging – Address translation with TLB
19
Virtual memory Paging – Replacement algorithms
Page replacement algorithms OPT – Optimal Policy (theoretical) LRU – Least Recently Used FIFO - First In, First Out (FIFO with 2nd chance) Clock
20
Virtual memory Paging - Summary
Advantages Simplicity Incoming page may be assigned to any available frame Disadvantages Pages have no logical significance Danger of page thrashing Internal fragmentation
21
Virtual memory Segmentation
A program and its data sets can be viewed as a collection of linked elements Since segments contain logically related data it seems reasonable to maintain complete segments in main memory When a segment not currently resident in main memory is required, the entire segment is transferred from secondary memory
22
Virtual memory Segmentation – Segment table
23
Virtual memory Segmentation – Address Translation
24
Virtual memory Segmentation – Space management algorithms
Best fit First fit Which one is better? First fit is believed to be a better choice Easier to implement Faster Better overall performance
25
Virtual memory Segmentation - Summary
Advantages Segment boundaries correspond to natural program boundaries Because of their logical independence, segments can be changed and recompiled without affecting other segments Certain properties of programs such as the scope (range of definition) of variables and the access rights to a program may be specified by segment Segmentation allows to create multiple linear address spaces
26
Virtual memory Segmentation - Summary
Disadvantages Complexity The fact that segments can be of different length requires a relatively complex main memory allocation method to avoid excessive fragmentation of main memory space. External fragmentation Can be eliminated by time-consuming process of memory compaction.
27
Virtual memory Paging vs Segmentation
Consideration Paging Segmentation Need the programer be aware of it? Can virtual address space exceed memory size? How many linear spaces are there? Difficulty of replacing a block? Memory use inefficiency? Why was this technique invented?
28
Virtual memory Paged segments
Paging and segmentation can be combined in an attempt to gain the advantages of both This is done by dividing each segment into pages. The memory map consists of a segment table and a set of page tables, one for each segment Segment table contains for each segment address a pointer to the base of corresponding page table
29
Virtual memory Paged segments
30
Virtual memory Paged segments – Address translation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.