Up to now, what I've said is, if I'm experiencing memory pressure in a particular VM, I can go and get more memory from the hypervisor, but there are also other things that you can do. You can share memory across Virtual Machines. When you're using a vanilla operating system, when you create processes. If you're running a Firefox browser and there's another instance of the Firefox browser, there's not dual commitment of memory that is being done for these different processes, right? All of these processes are using the same instance. So even though they have separate address spaces, they're sharing physically, the memory that hosts the core pages for the application that you're running. That's the same thing that is happening with memory sharing across VMs. The idea is, you may have two different VMs, but they both may be running the same instance of the Linux operating system, and there are two processes that are running inside each one of these, and they're Firefox processes. Even though they are distinct processes and distinct VMs, the codebase for that is exactly the same, and therefore, there's an opportunity to map the virtual memory of these processes to point to the same machine memory, and that way, oblivious to the virtual machines, you can actually do the sharing. The way that I've shown this picture is a little bit misleading because, how does the hypervisor go and make these changes in the page table of these VMs? That's not something that is going to be possible, whether it is paravirtualized or fully virtualized setup. Because these page table data structures, are internal to the virtual machines. So there is a method to the madness of how you can do this sharing across Virtual Machines, and that is what is called VM oblivious page sharing. The idea is, I have no idea what the VMs are doing. I don't know whether they are running Firefox application or anything like that. All I know is that each of these virtual machines have pages that point to machine memory that is managed by the hypervisor, and so if a particular VM, let's say this guy, has a page fault, then what is going to happen is it's going to go to the disk and pull that page. So when you do that, what we're going to do is we're going to look at the page that is coming from the desk, and hash the contents of that page and generate a unique signature for that page, right? Take the contents of the page, create a unique signature for the page and there is a data structure that the hypervisor maintains, which is called a hint table or a hint hash table, and the contents of this hint hash table, is for each of the machine memory pages, which is the VM that is using that particular machine memory page. What is the physical page number of that VM that corresponds to that machine page, and what is the machine page number? So this is what is contained in this data structure, and the entry is the hash value of that particular machine page. So when I pull in this page, and I see that this is a signature that I generated, and let's say that the signature matches with this signature. If it identically matches with the signature, then there's a good chance that these two pages are the same. I say it's a good chance because it's a hash. So we need to know whether they really are exactly the same contents or not. But at least the first order we know that there is a good chance that they may actually be the contents of the page maybe exactly the same, and if that is the case, so here is a particular physical page of VM3 that maps to a particular machine page. Now, this is the page that has been brought in on behalf of the page fault that we had in VM2. That is a particular machine page and that has been host in a particular machine memory. That's what happens, at the time that you have the page fault, you allocate a machine page, and you bring this page in, and now, we find that there is a match between the hash value that is generated for the contents of the page that you brought in and an existing entry in this hash table. So when you have that, then you're going to say, "Well, there is a match. See, even though there is a match, I don't know whether they're exactly the same." I'm going to do a full comparison once you have this match between these two machine pages, to see if they really are exactly the same. Once I determined that they're exactly the same, then I can say that," Well, I don't have to have two copies of it." Get rid of it, and make both of these guys point to the same machine page. This is why it's called VM oblivious page sharing, because I didn't have to do anything with respect to the VMs themselves. This is being done by data structures that are completely managed by the hypervisor. Like I told you, that there is an illusion every operating system has in terms of the physical memory, right? But the physical memory maps to a particular physical page, maps to a particular machine page, and that mapping is known to the hypervisor, and therefore, it can use that knowledge to do this trick of sharing oblivious to the Virtual Machines, and so it will modify the MPN mapping for VM2, so that it points now to this guy, and I can get rid of the original machine page that this guy was pointing to. Also, the other thing that we want to do is, you want to mark the page entry in the virtual machines as copy-on-write, and the reason is because I know that they're exactly the same, but I don't know the semantics of usage of this particular bit. I don't even know whether this is a text page or data page or anything like that. All I know is that at this point of time, they match exactly. So we make it copy-on-write so that, if one of these guys decides to modify that page at that point, I'll recognize that, and then decide that there's no longer a possibility to share the page across these VMs. So that's the technique that's used. But one thing that you notice is that, this comparison of two pages to see if they're equal or not, it's not a trivial thing, it's going to take some cycles, right? So you don't want to do that when the machines are busy. So usually, the scanning of pages to find out when there is content hash match, whether there is a full match of the pages themselves, is something that is done in the background. Similar to in any operating system that is paging demon, that wakes up every once in a while, and then sees how many free page frames that are available. If it has fallen below a threshold, then it might start freeing up some pages. In a similar manner, there's a background activity that the server can do when there are space cycles to deal with.