L-5.19: Virtual Memory | Page fault | Significance of virtual memory | Operating System
Summary
TLDRThis video script delves into the concept of virtual memory, explaining its significance in modern computing. It provides an illusion of limitless process size and multiprogramming capacity, despite finite main memory. The script covers how virtual memory allows larger processes to run by swapping pages in and out of RAM, utilizing the principle of locality of reference. It also touches on the potential downsides, such as page faults leading to performance issues like thrashing, and the importance of effective memory access time. The explanation aims to clarify the advantages and challenges of virtual memory in operating systems.
Takeaways
- π‘ Virtual memory is a concept that provides the illusion of an unlimited memory space to programmers, allowing processes larger than the physical memory to be executed.
- π₯οΈ The main memory, such as RAM in a laptop, is finite, but virtual memory allows for the execution of processes that exceed the size of the main memory.
- π Virtual memory operates on the principle of paging, dividing processes into pages that are loaded into the main memory as needed, based on the locality of reference principle.
- π The process of loading pages into the main memory and replacing them is known as swap-in and swap-out, or roll-in and roll-out, which is managed by the operating system.
- π The operating system uses a page table to keep track of which pages of a process are currently in the main memory and which are stored in secondary storage.
- π« A page fault occurs when the CPU requests a page that is not currently in the main memory, triggering a page fault service process.
- π When a page fault happens, control is transferred from the user process to the operating system, which then handles the page replacement or loading from secondary storage.
- π The operating system checks for user authentication before servicing a page fault to ensure security.
- β± The effective memory access time is calculated considering the probability of page faults and the time taken for page fault service versus direct memory access.
- π The time taken to service a page fault is significantly higher than accessing the main memory, which can lead to performance degradation if there are too many page faults.
- β οΈ Excessive page faults can lead to a phenomenon called thrashing, where the system spends too much time swapping pages rather than executing processes, severely impacting performance.
Q & A
What is virtual memory?
-Virtual memory is a concept that provides the illusion to programmers that a process, even larger than the physical main memory, can be executed. It allows systems with limited RAM to handle larger processes by using hard disk space as an extension of the main memory.
How does virtual memory enable the execution of processes larger than the main memory?
-Virtual memory allows the execution of large processes by dividing them into smaller units called pages and only loading the necessary pages into the main memory as required, while the rest reside on the hard disk.
What is the significance of virtual memory in terms of process size?
-Virtual memory eliminates the limitation on the size of processes that can be executed. Regardless of the main memory size, any process can be executed as long as the necessary pages are loaded into the main memory when needed.
How does virtual memory affect the degree of multiprogramming?
-Virtual memory allows for a higher degree of multiprogramming by enabling the main memory to hold parts of multiple processes simultaneously, rather than whole processes, thus maximizing the use of limited main memory.
What is the concept of locality of reference in the context of virtual memory?
-Locality of reference is the principle that a process tends to access a small subset of its address space frequently. When a page is loaded into the main memory, pages that are likely to be accessed next are also loaded to optimize performance.
What is a page fault in the context of virtual memory?
-A page fault occurs when the CPU requests a page that is not currently in the main memory. This triggers a page fault service, where the operating system loads the required page from the hard disk into the main memory.
How is a page fault serviced in a system using virtual memory?
-When a page fault occurs, control is transferred from the user process to the operating system, which then locates the required page in the hard disk, loads it into an available frame in the main memory, and updates the page table before returning control to the user process.
What is the impact of page faults on system performance?
-Frequent page faults can significantly degrade system performance due to the time-consuming process of loading pages from the hard disk into the main memory. This can lead to a phenomenon known as thrashing, where the CPU spends most of its time servicing page faults rather than executing processes.
What is the effective memory access time and how is it calculated?
-The effective memory access time is the average time taken to access a memory location, considering both page hits (when the page is already in the main memory) and page faults. It is calculated as the product of the probability of a page fault and the page fault service time, plus the product of the probability of a page hit and the main memory access time.
What are some common page replacement algorithms mentioned in the script?
-The script mentions First In First Out (FIFO), Least Recently Used (LRU), and Most Recently Used (MRU) as examples of page replacement algorithms that determine which pages to replace when the main memory is full.
How does the script explain the difference in time between accessing main memory and servicing a page fault?
-The script explains that accessing the main memory is very fast, typically in nanoseconds, whereas servicing a page fault is much slower, usually taking milliseconds, due to the slower speed of the hard disk compared to the main memory.
Outlines
π‘ Virtual Memory Concept and Its Benefits
Virtual memory is introduced as a concept that extends the capabilities of physical memory (RAM). It provides programmers with the illusion that processes larger than the available RAM can be executed. This is possible because processes are divided into pages, and only the necessary pages are loaded into the main memory, thanks to the principle of locality of reference. This allows for a greater degree of multiprogramming, as the main memory can hold parts of multiple processes simultaneously. The concept is crucial as it overcomes the limitations of physical memory size, enabling the execution of larger processes and increasing the number of processes that can be active at one time.
π Swap Operations and Page Replacement
This paragraph delves into the mechanics of virtual memory management, focusing on swap-in and swap-out operations, also known as roll-in and roll-out. These operations are essential for handling the limited main memory by replacing pages that are not currently needed with those that are. The paragraph introduces the concept of page replacement algorithms, such as FIFO, LRU, and MRU, which determine which pages to swap out when the main memory is full. The advantages of virtual memory are highlighted, including the ability to handle processes of any size and any number of processes, despite the physical limitations of the main memory.
π¨ Understanding Page Faults and Their Impact
The third paragraph explains the process that occurs when a CPU demands a page not present in the main memory, an event known as a page fault. It describes the role of the page table and the memory management unit in handling page faults. The operating system's response to a page fault includes authentication checks, searching for the required page in the logical address space (hard disk), and updating the page table once the page is loaded into the main memory. The paragraph also introduces the concept of effective memory access time, which is influenced by the probability of page faults and the time taken for page fault service versus direct memory access.
β±οΈ Effective Memory Access Time and Threshing
The final paragraph discusses the calculation of effective memory access time, taking into account the probability of page faults (P) and the time taken for page fault service versus main memory access. It emphasizes the significant difference in access times between main memory (nanoseconds) and hard disk (milliseconds), and how frequent page faults can lead to performance degradation, a phenomenon known as threshing. The importance of reducing page faults and increasing page hits to improve effective memory access time is highlighted, concluding the significance and operation of virtual memory.
Mindmap
Keywords
π‘Virtual Memory
π‘Main Memory
π‘Process
π‘Paging
π‘Locality of Reference
π‘Page Table
π‘Page Fault
π‘Trap
π‘Context Switching
π‘Effective Memory Access Time
π‘Threshing
Highlights
Virtual memory provides the illusion that a process larger than the main memory can be executed.
Main memory is finite, but processes can still be executed even if they exceed the size of the main memory.
Virtual memory allows for an increased degree of multiprogramming by maximizing the number of processes in the main memory.
Processes are divided into pages, with the page size equal to the frame size, to manage memory efficiently.
The concept of locality of reference is used to bring related pages into the main memory for efficient processing.
Virtual memory enables parts of multiple processes to be kept in the main memory, giving the user the illusion of their presence.
Swap-in and swap-out operations, also known as roll-in and roll-out, are used to manage page replacement in the main memory.
Page replacement algorithms such as FIFO, LRU, and MRU are used to efficiently manage memory.
Virtual memory provides two main advantages: no limitation on process size and the number of processes.
Virtual memory is used in all modern operating systems, including laptops and PCs.
A page fault occurs when the CPU demands a page not present in the main memory, triggering a trap and context switching.
Operating systems check user authentication before servicing a page fault for security purposes.
Page faults are serviced by fetching the required page from the hard disk and updating the page table.
Effective memory access time is calculated considering the probability of page faults and main memory access time.
Excessive page faults can lead to thrashing, significantly degrading system performance.
The time difference between page fault service time in milliseconds and main memory access time in nanoseconds is significant.
Reducing page faults and increasing page hits can greatly improve effective memory access time.
Transcripts
- Virtual memory. Virtual memory is actually a concept.
- Till now we've discussed a lot about the main memory that is a physical memory
- in this video we will see about how the virtual memory actually works
- and what is the significance of the virtual memory
- now, the first significance of the virtual memory is that it provides the illusion to the programmer
- that a process whose size is larger than the size of main memory
- can also be execute
- means, if I have a process whose size is even more than the size of main memory
- we can execute that process also
- How is that possible? Actually, our main memory is finite
- Means, if I talk about my laptop, so in our laptop we get RAM upto 8gb or 16gb
- so if the main memory is of 18gb or 16gb but there is no limitations for the size of processes.
- the size of processes are increasing day by day. So if a process whose size is more than the size of the main memory.
- So if we see normally, so when a process won't fit in the main memory then how we will provide it's pages or data to the CPU
- if we see normally, when a process won't fit in this main memory then how we will provide the data to CPU and how will CPU execute that data
- but no. Even if the main memory here is finite but the concept of virtual memory is providing the first illusion
- that the process whose size is much larger than the size of main memory, we can execute that process also.
- second point here is, In degree of multi programming we talk about that more and more no. processes must come in the main memory
- So here I'm saying that main memory is limited. So we have to bring maximum no. of processes in the main memory
- so for that we should have more main memory
- but we've limited the size of the main memory that the size of main memory is, let say, 16gb
- so how we will bring maximum processes in main memory and how we will execute that, this is also a illusion which is provided by the virtual memory - so how virtual memory actually works here, that we will see now
- so what we're doing here basically, it's a logical address space, logical address space means we are talking about the hard disk
- where there are multiple processes, we have divided that processes into pages.
- we've already seen the concept of paging where we divide processes into pages. Page size is equal to size of frame.
- so I already divided multiple processes into pages. Now, one whole process
- means, instead of bringing one full process in main memory we are bringing only required processes/pages of required process in the main memory.
- means, the processes/pages that are required now we will bring only that in main memory
- means, there's a simple concept, locality of reference
- what we do in locality of reference is that when we bring a page in the main memory
- we don't bring that page only, we bring the related pages along with that. Let say, in school class teacher is telling to call roll no.10,
- then we call roll no.10 but we call roll no.8,9,11,12, the nearby roll no. students, along with it,
- so that, actually we are thinking that it may be possible that he have called roll no.10 now, next time it may call roll no.9 or 11.
- this is one of the example that we follow in this that we bring pages in the main memory but
- rather than entire process into the main memory, we keep some of the pages in the main memory.
- The advantage we get from that is, like in this main memory, some page of P1, some pages of P2, some pages of P3, some pages of P4
- this is how we can keep the main memory, that means we don't bring the whole process in main memory
- we will keep the process that are required in the main memory
- so what will happen, rather than entire process comes into the main memory only some part of it is coming in the main memory
- so it only some parts come in, so we can keep some parts of many processes in the main memory
- so what is the advantage of this, the advantage is that parts of maximum processes can be kept in main memory
- so by this user thinks, whenever I call process 1 it is there, 2, it is also there, 3, it is also there, 4,5, 6, 7, so many processes are there in main memory
- but these processes are not full, only there some pages are kept in the main memory
- and how we do this, by using the swap-in and swap-out operation that we also call roll-in and roll-out.
- Roll-in
- Roll-out
- Roll-in, Roll-out means, the meaning of swap-in is that we will bring page in the main memory and after some time we
- because we've limited main memory, so where we will have limitation, so I can't keep that page in permanent main memory
- I'll have to take out that page after some time and I'll have to bring some new process page.
- so we call this page replacement.
- that how we replace pages and we bring in new pages. So there are many algorithms of page replacement
- like first in first out, LRU, MRU, that we will see in further videos
- here we are just talking about what is the advantage of virtual memory. So what is the advantage here, there are 2 advantage, means it is providing illusion
- the size of process is as much wanted and 2nd, the no. of processes is also as much wanted. Means, there's no limitation of no. of processes
- there's no limitation of size of process but the main memory here is already limited.
- so the main memory is limited, let it be, but whatever the size of process is, we can bring it into the main memory
- and no matter how many are the number of processes, we can bring it into main memory
- so this is a very big advantage, the virtual memory, all the laptops and PCs and operating systems we are using nowadays
- actually the concept of virtual memory is used in all these
- So it is providing this big advantage. So is there any problem in this?
- Can there be a problem? Let's analyse this.
- Let say, CPU is executing a process P1. If CPU is executing a process P1
- then first thing CPU will do, it will demand for any page or it will demand for any data. Let say,
- CPU made a demand that it wants page no.1, the data of page no.1, means CPU generated a logical address.
- from that logical address I get to know that the data that CPU is demanding of is on page no.1 of process P1
- so where is page no.1 of process P1 in main memory
- how do we do that, by using the page table, we check that through memory management unit, what does memory management unit do
- it loads the page table, we loaded the page table from the main memory and checked which pages are lying in which frames
- So here we're talking about P1 page
- So as soon as CPU demands the data it wants, the logical address told that page is P1 page
- but if you look here carefully, P1 page is not present.
- Means, I looked here in page table entry, we've already discussed page table entry.
- So in page table entry, there are valid and invalid bits
- we also call them present or absent. That tells actually that page is present or absent in the main memory.
- So if a page that CPU wants now, if that page is absent in the main memory
- we call this page fault. If the page is present, that is the best case means the page that CPU is demanding of is already in main memory, then you'll pick that page from main memory and provide data to the CPU
- but if that page is not in main memory, it is absent is main memory then it will actually generate a page fault
- page fault
- so how we service page fault, means how we remove page fault or if page fault occurs what we will do after that, this is the concept
- so if the CPU generated the first step that, CPU demanded that it wants page 1 of some P1 process
- before checking in main memory, I checked in page table that actually the page is lying in which frame
- then I didn't found any entry here because my valid bit is stating that it's 0. That means that page is absent.
- so in this case, what will happen here, trap will generate here. Trap. Trap means, it is a kind of interrupt
- Now as soon as trap is generated, before this the control was in the hands of user
- means, because we are executing the process of user but as soon as trap generates here, control came from user to operating system
- means, you can call this context switching. Like we do context switching in round robin that means one process that is going on
- we send that into ready state. And we load another process in running state
- so this is called context switching. So here also context switching is happening.
- because user had the control, some P1 process of user was executing but as soon as its page wasn't found here
- so the control that user had was lost because trap is generated here.
- Trap means, it is a kind of interrupt. So interrupt occurred, so operating system took the control in it's hands.
- Now, what operating system will do here, first of all operating system will check that the user who is demanding of this page,
- that user is authenticate in actual or not. First of all, operating system will activate here, operating system will check authentication.
- authentication, authorization, kind of. That is just for a security purpose that the person/the user who is demanding of the particular process/page through CPU
- is a validate user or invalidate. So if that user is validate, then CPU will say ok, I'll now provide the page here
- but where's that page lying actually, that page is actually lying in the hard disk, if all the data isn't in main memory, then where that data will be
- in hard disk. Means, in logical address space. So operating system will first go in logical address space
- After getting in logical address space, it will search where that process is actually. So we're talking about page 1 of P1 process.
- So page 1 of P1 process is kept here. So here what operating system will do is that, we have to take out this page from here and enter it in some empty slot of main memory.
- So this process, I took out P1 page of this process and here I, Page 1 of process P1,
- this is the meaning of page 1 of process P1. We kept the page of that process here.
- And the address here, what it is, frame no.7. So I updated frame no.7 here.
- what it meant to say, that the first step was that what CPU generated, second step here is, trap generated, third step
- CPU, sorry, operating system first searched for the page in logical address space, when it was found there picked it up from there
- and the fourth step is that we placed that page in main memory. After that, the process of that page, where's that page, in main memory
- but you also have to update it in page table because the address that CPU generated, we've to first find it from here
- it may be possible that CPU again demands for that page. So for that I've to update address in the page table.
- So I updated the address here, means, page no.1 is present at frame no.7
- and then I'll give control back to the user. Means, after this
- after this step, this is your 4th, 5th, 6th step, sorry, this is the 6th step. So after 6th step,
- control will again be returned to user level from operating system. Means, here user mode to operating system, and the control from operating system again retuned back to
- the user. But here if we talk about time. What is the time actually we've used?
- So we can calculate the effective memory access time. This is called the effective memory access time.
- so what is the effective memory access time? Let say, there is a probability P
- that, P is a probability which tells that page fault occurs, P is the probability of page fault occurring
- so how we will calculate effective memory access time, if there's P probability of page table occurring, so as soon as page table occurs, so what I did in that case, we did page fault service
- the time used in page fault service is page fault service time
- that we can call page fault service time. Means, if P times, I've, P times or P is a probability that
- that how much page faults will occur. So as often page fault occurs, you have to do page service that much times.
- And, 1-P. What is 1-P? That is a best case, means there is no page fault.
- if page fault isn't occurring 1-P times, if page fault isn't occurring so you know in that case as soon as CPU demands of some page
- we will pick reference of that page from here, let say, it is kept in frame no.1, we will directly get to frame no.1
- So the time that is taken in accessing main memory, that time will be used here. So that means, 1-P times we are using
- main memory access
- main memory access time that we can call MA
- means the access time of main memory. So P time is taken in servicing page fault. 1-P into the time taken in accessing main memory
- and the important point here is that the time of accessing the main memory, in most of the cases, it is in nanoseconds.
- because main memory is very fast. So when we will find page in main memory,
- and I know that page is in main memory, then it will, we will access that data within nanoseconds.
- But as soon as page fault occurs, what we do in page fault is that first control is given to operating system
- when operating system have, when context switching will happen from user to operating system, first time will be wasted there.
- Because the control is transferred from user to operating system. Now, where the operating system is searching?
- In hard disk. Hard disk is very slow as compared to the main memory.
- so if hard disk is slow, So obviously it takes so much time to pick data from there and keep it in main memory
- and yes, this time is generally in milliseconds.
- This page fault service time is generally in milliseconds. So we wasted milliseconds of time to bring that page
- in main memory. And if that page fault haven't occurred, in that case we will access data in nanoseconds.
- One more point is here that when we are servicing page fault, in that case time taken is in milliseconds
- but sometimes it can happen that main memory time is also added in that, the time taken to access main memory
- why do we generally add that? When we've serviced page fault, means the page that was missing, we, from back end,
- means from hard disk, we kept that in main memory. But CPU didn't get it yet. CPU have to search again, and now it will get to know that, Ok, that page is in frame no.7
- main memory access time is in nanoseconds, so that's why this time, is very less as compared to this time. So that's why we don't consider this time here.
- so here I can say, effective memory access time actually is, P into page fault service time plus 1-P into main memory access time
- here you can get many numericals based on this that if this much percent page fault is occurring, main memory access time is this, then find what is the effective memory access time.
- and a very big problem here is that if there are too many page faults. If in case there are too many page faults
- so there can be the problem of threshing. You are using CPU utilisation too much.
- If page fault becomes too much, so the threshing and performance in that case will suddenly degrade.
- so generally, service time of page fault is in milliseconds and access time of main memory is in nanoseconds. And I, you all already know that 1 millisecond = 10 lakh
- or 1 million nanoseconds. Means there are 10 lakh nanoseconds in a millisecond
- so obviously, time gap will increase here so much just because of the page fault
- but there are advantages too here, it is providing illusion, there's no limitation of page size
- there's no limitation of no. of processes. So If I lessen the no. of the page faults and if we increase no. of page hits
- so in that case my effective memory access time will perform very well.
- so this is how actually the virtual memory works and this is the significance of the virtual memory
- so thanks a lot, if you liked my video please share it with your friends. Thank you.
Browse More Related Video
L-5.22: Page Replacement Introduction | FIFO Page Replacement algorithm | Operating System
Sistemas Computacionais - Técnica de memória virtual: paginação e segmentação
But, what is Virtual Memory?
L-5.1: Memory Management and Degree of Multiprogramming | Operating System
Operating System Interview Questions and Answers - Part I
What is Virtual Memory? What Does it Do?
5.0 / 5 (0 votes)