Princess Nora University Faculty of Computer Information Systems
- Slides: 40
Princess Nora University Faculty of Computer & Information Systems Computer science Department Operating Systems (CS 340 D) Dr. Abeer Mahmoud
(Chapter-9) Virtual Memory
Chapter 9: Virtual Memory 1. Background 2. Virtual Memory Implementation 3 Dr. Abeer Mahmoud
OBJECTIVES: Ø To describe the benefits of a virtual memory system Ø To explain the concepts of demand paging Ø To explain the concepts of page-replacement algorithms 4 Dr. Abeer Mahmoud
Background 5 Dr. Abeer Mahmoud
Background In chapter of memory management , � various memory-management strategies used in computer systems were discussed and all of these strategies have the same goal: to keep many processes in memory simultaneously to allow multiprogramming. � However, they tend to require that an entire process be in memory before it can execute. Virtual memory is a technique that allows the execution of processes that are not completely in memory.
Background Advantages 1. programs can be larger than physical memory. 2. Map main memory into an extremely large, uniform array of storage, 3. separating logical memory as viewed by the user from physical memory. 4. This technique frees programmers from the concerns of memory. Virtual Memory That is Larger Than Physical Memory storage limitations.
Background � Advantages o (cont) Virtual memory also allows processes to share files easily and to implement shared memory. Shared Library Using Virtual Memory
Background �Disadvantage � Virtual memory is not easy to implement, however, and may substantially decrease performance if it is used carelessly
Virtual Memory Implementation Demand Paging 10 Dr. Abeer Mahmoud
Virtual memory can be implemented via: 1. 2. Demand paging Demand segmentation
1 -Demand Paging Consider how an executable program might be loaded from disk into memory. � One option is to load the entire program in physical memory at program execution time. However, a problem with this approach is that we may not initially need the entire program in memory. Ex: Suppose a program starts with a list of available options from which the user is to select. Loading the entire program into memory results in loading the executable code for all options, regardless of whether an option is ultimately selected by the user or not. � An alternative strategy is to load pages only as they are needed during program excution. This technique is known as demand paging and is commonly used in virtual memory systems.
1 -Demand Paging �A demand-paging system is similar to a paging system with swapping But rather than swapping the entire process into memory, we use a lazy swapper. � lazy swapper never swaps a page into memory unless that page will be needed. � Since we are now viewing a process as a sequence of pages, rather than as one large contiguous address space, use of the term swapper is technically incorrect. �A swapper manipulates entire processes, whereas a pager is concerned with the individual pages of a process. We thus use pager, rather than swapper, in connection with demand paging.
1 -Demand Paging � Bring a page into memory only when it is needed � Less I/O needed � Less memory needed � Faster response � More users is needed reference to it � invalid reference abort � not-in-memory bring to memory � Page
Transfer of a Paged Memory to Contiguous Disk Space
1 -Demand Paging (cont. . ) n With this scheme, we need some form of hardware support to distinguish between 1. the pages that are in memory 2. the pages that are on the disk. n The valid–invalid bit scheme can be used for this purpose. Ø “valid, ” : the associated page is both legal and in memory. Ø “invalid, ” the page either is not valid (that is, not in the logical address space of the process) or is valid but is currently on the disk.
1 -Demand Paging(cont. . ) Valid-Invalid Bit � With each page table entry a valid– invalid bit is associated (v in-memory, i not-in-memory) � Initially valid–invalid bit is set to i on all entries page table
Page Table When Some Pages Are Not in Main Memory
Page Fault � If there is a reference to a page, first reference to that page will trap to operating system: page fault 1. Operating system looks at another table to decide: � Invalid reference abort � Just not in memory 2. Get empty frame 3. Swap page into frame 4. Reset tables 5. Set validation bit = v 6. Restart the instruction that caused the page fault
Steps in Handling a Page Fault
Performance of Demand Paging n Demand paging can significantly affect the performance of a computer system. why ? • if no page faults, the effective access time is equal to the memory access time. • If, however, a page fault occurs, we must first read the relevant page from disk and then access the desired word. n Let p be the probability of a page fault (0 ≤ p ≤ 1). expect p to be close to only a few page faults. effective access time = (1 − p) × ma + p × page fault time.
Demand Paging Example � Memory access time = 200 nanoseconds � Average page-fault service time = 8 milliseconds � EAT � If = (1 – p) x 200 + p (8 milliseconds) = (1 – p x 200 + p x 8, 000 = 200 + p x 7, 999, 800 one access out of 1, 000 causes a page fault, then EAT = 8. 2 microseconds. This is a slowdown by a factor of 40!!
Page Replacement Algorithms 23 Dr. Abeer Mahmoud
Page Replacement � If we increase our degree of multiprogramming, we are overallocating memory. � Ex: If we run six processes, each of which is ten pages in size but actually uses only five pages, we have higher CPU utilization and throughput, with ten frames to spare. � It is possible, however, that each of these processes, for a particular data set, may suddenly try to use all ten of its pages, resulting in a need for sixty frames when only forty are available. � Further, consider that system memory is not used only for holding program pages. Buffers for I/O also consume a considerable amount of memory. This use can increase the strain on memory-placement algorithms.
Need For Page Replacement
Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame 3. Bring the desired page into the (newly) free frame; update the page and frame tables 4. Restart the process
Page Replacement
Page Replacement Algorithms 1. 2. 3. 28 FIFO Page Replacement Optimal Page Replacement Least Recently Used (LRU) Algorithm Dr. Abeer Mahmoud
FIFO Page Replacement 29 Dr. Abeer Mahmoud
FIFO Page Replacement algorithm n The simplest page-replacement algorithm is a first-in, first-out (FIFO) n FIFO each page has memory load start time or create FIFO queue to hold all pages in memory n When a page must be replaced, the oldest page is chosen.
FIFO Page Replacement
Optimal Page Replacement 32 Dr. Abeer Mahmoud
Optimal Algorithm Replace page that will not be used for longest period of time � 4 frames example � 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 4 2 3 4 5 How do you know this? � Used for measuring how well your algorithm performs �
Optimal Page Replacement
Least Recently Used (LRU) Page Replacement 35 Dr. Abeer Mahmoud
Least Recently Used (LRU) Algorithm � Reference � Counter o o string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1 1 5 2 2 2 3 5 5 4 4 3 3 3 implementation Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter When a page needs to be changed, look at the counters to determine which are to change
LRU Page Replacement
LRU Algorithm (Cont. ) � Stack implementation – keep a stack of page numbers in a double link form: � Page referenced: �move it to the top �requires 6 pointers to be changed � No search for replacement
Use Of A Stack to Record The Most Recent Page References
Thank you End of Chapter 9 40 Dr. Abeer Mahmoud
- Princes nourah university
- Princess nora university
- University of bridgeport computer science
- Bridgeport university computer science
- Fsu cybersecurity major
- Brown university computer science faculty
- University of split faculty of maritime studies
- Hubert kairuki memorial university faculty of medicine
- Hyperparathyreosis
- Applied medical sciences
- Faculty of business and economics mendel university in brno
- Singularity executive program
- Agnes csaki semmelweis
- Ascaris lumbricoides ova
- Feup university of porto
- Charles university faculty of humanities
- Faculty of veterinary medicine cairo university logo
- Faculty of law of the university of zagreb
- University of montenegro faculty of law
- University of kragujevac faculty of technical sciences
- University of cologne faculty of management
- Leading university faculty
- Hacettepe university faculty of medicine
- Auricle of heart vs atrium
- Semmelweis university faculty of medicine
- Lebanese university faculty of engineering
- York u my file
- Elearningunideb
- Clemson ece lab manual
- Faculty of veterinary medicine cairo university
- Faculty of mechanical engineering thammasat university
- Mendel university faculty of business and economics
- Masaryk university medical faculty
- Slidetodoc.com
- University of pecs faculty of health sciences
- Faculty of education khon kaen university
- นิเทศ จุฬา
- Cairo university faculty of veterinary medicine
- The protection of information in computer systems
- Ucl computer science department
- Faculty information system unt