After writing "A preliminary discussion of the memory mechanism of VMware", it was planned to write a "VMware memory mechanism re-explore", talking about several other important aspects of the VMware Memory mechanism, such as transparent memory sharing (TPS, Transparent Page sharing), Relaim Memory, ballooning, swapping and so on. But there are netizens reflect that the previous article is still not understand. So I thought, if the official documents are listed as such, it might as well go to the original manual, so we have a piece of this stuff.
First of all, remember that in the case of memory overcommitment, the memory scheduling mechanism does not start at all, and there is no reclaim memory. Obviously, when the total physical memory of the host physical is larger than the total amount of all virtual machine configuration memory, how much memory each VM wants, it can be satisfied, of course, no scheduling is required.
Therefore, the following discussion of the memory mechanism of VMware, in the case of excessive memory configuration occurs.
My story happens in an intelligent pool (Host), the pool has a lot of water (4GB of physical memory), there are 2 tanks (configured 2 VMS), the water tank has a certain capacity (configuration memory is 4GB), originally was empty (no boot).
But now the tank 1 to raise fish, must put some water in so that the fish can survive (boot up). Minimum 1GB of memory is required. So the Tank 1 (VM1) to the pool (Host) to water (physical memory), there is enough water in the pool, to meet the requirements of the water tank 1. Now the water Tank 1 has a 1GB of living water, and the pool is only 3GB. Now we to the water tank 1 more lost some fish (start a new application), the original 1GB water is not enough, so the tank 1 continue to water to the pool, there is enough water in the pool, and meet the requirements of the water tank 1. Now the Tank 1 contains 3GB of water, and the pool is only 1GB of water left.
Explanation: Be aware that at this point the application in VM1 is active (active), so the memory is active, called active memory. After a period of time, the tank 1 inside the fish was arrested, now the tank 1 does not need so much water is enough to feed the remaining fish. But the pool didn't know the condition of the tank 1. So the tank 1 still has so much water.
Explanation:Some of VM1 's applications ended, releasing some of the memory, but the memory release action was released at the guest OS level of the VM, so the host was unaware of the memory being released and the memory was not returned to the host, still occupied by VM1. Some of the memory in VM1 is idle, and some of the memory being used is active. Of course, VM1 own Gos looks like, there is 3GB free memory (idle memories), 1GB of active memory, and at this point in the host, only see 3GB memory is assigned to the VM1. Host is driven through VMware tools, at a certain time (default is 60 seconds in ESX4, 30 seconds by default in ESX3) to scan the memory usage status of VM1 to see how much active memory it has
At this point, we began to fish in the tank 2 (VM2 boot), water Tank 2 also began to pump from the pool. But the water inside the pool can not be exhausted, so the pool has a warning water level, the first warning water level is 6%, when down to the first alert below the water level and still continue to decline, it is necessary to activate other mechanisms from other water tanks to pump back.
Explanation:The VM2 also requires 1GB of memory at boot time, and it constantly requests memory from host. The host allocates its own memory to the VM2 until it drops to the first warning bit 6%. There are 4 states of host memory, namely high, Soft, hard and low, with the dividing line between 6%, 4%, 2% and 1% respectively. When the available memory is above 6%, the balloon or swap mechanism is not started. When it is below 6% and approaching 4% (soft state), the balloon mechanism starts. (For more explanations of the 4 states of memory, please refer to the Official document "Understanding Memory Resource Management in VMware ESX Server". How do I see these 4 statuses? can be used esxtop or resxtop)
Which water tank is it going to pump? Whoever has the richest water will smoke.
Explanation:How to judge it? As we said, host scans the guest OS memory usage at a certain time, and host calculates the share memory of each VM with the free memory tax of
ρ,
ρ , and VM (IMT, Idel memory ) closely related to the
ρ minimum of that virtual machine start balloon Drive (balloon driver), the balloon starts to swell (inflating). For an algorithm of
ρ and IMT, please see my blogalgorithm for free memory tax".
As a result, the balloon begins to swell and the excess water is squeezed out of the tank.
Explanation: The balloon drive, like the normal driver, constantly requests memory from the guest OS, and the guest OS does its best to satisfy the balloon driver and prioritize the free portion of memory to it, noting that the guest OS may be running out of physical memory at this point and causing the guest The paging mechanism of the OS, a part of the memory page out into its own swap. In this example, VM1 has a lot of free memory, so it's enough for the host to reclaim and meet the needs of VM2.
The host will compare the address of this part of the memory that the balloon expands to, if it was originally assigned to VM1 (i.e. no TPS share), then it can be retracted. The host will continue to recover memory through the balloon drive, and the target is to keep at least 6% of the memory. This process of recovering memory is called reclaim.
Note: There is no contention in memory at this time, so shares still does not work, but overcommitment is there, so there will be reclaim, there will be ballooning. ballooning recovering memory is slow and usually takes a few minutes.
If the memory of the host free memory pool is reduced faster than the balloon drive to return the memory of the host, then the available memory will be further reduced, when the 2nd cordon through 4%, into the hard state, the host will enable the 2nd reclaim mechanism--swapping, Swap a portion of the physical memory of the VM1 into a swap file to speed up the recovery of memory. The goal is to keep the available memory above the 4% cordon.
If the available memory continues to fall below 2%, the ESX will not only continue to accelerate swapping, but will also block memory requests from all VMS on it when it enters the low state.
Now, the situation has changed, the water tank 2 more and more fish, it constantly to the pool to water, and the pool also through the balloon drive, keep the tank 1 free memory extrusion, until the tank 1 and 2 of the total demand is greater than the amount of water the pool can supply. The pool can no longer provide more water, only partially meet the requirements of 2 water tanks. What about the not enough parts? Use some dirty water (swap) to satisfy. Although dirty water (swap memory speed is very slow), fish in the sewage inside the survival of very difficult, but after all, there is still a good, not because there is not enough water to cause the fish to die.
At this point, the active memory of VM1 and VM2 is composed of 2 parts, 1 is the host physical RAM obtained, and the other part is swap. Please note that the Guest OS is not aware that a portion of its physical memory is a swap file on the hard disk.
When the machine is running out of memory, the shares starts to work. However, note that if IMT is 0, there is no tax on free memory, since 4GB of VM1 and 4GB of VM2 share are 40960, they will eventually get the same physical memory 2GB. But if IMT is the default, then the cost of free memory is greater, and the 2 VMs will get a different amount of physical memory depending on the amount of active memory. "Review of the knowledge points of this article"
(1) Reclaim memory is not required in the case of memory overcommitment without excessive configuration
(2) When does reclaim memory start? When you break the 6% cordon, the memory state changes from high to soft .
(3) Reclaim priority with ballooning, only ballooning enough to use the time, will use swapping
(4) When does swapping start? When the host's available memory falls below the 4% cordon, the memory state becomes hard.
(5) host cannot know which memory blocks within the VM are already idle (idle). You must use ballooning to recover free memory.
(6) As far as possible to avoid resource contention, or the resulting chasing-the-tail effect, will lead to more serious performance negative impact.
"Reference Document"
(1) Carl, A. Waldspurger, 2002,
Memory Resource Management in VMware ESX Server 
Http://waldspurger.org/carl/papers/esx-mem-osdi02.pdf 
(2) VMware inc.  
Understanding Memory Resource Management in VMware ESX Server  
http ://www.vmware.com/files/pdf/perf-vsphere-memory_management.pdf 
(3 ) VMware inc.  
understanding Host & Guest Memory Usage (  
http://mylearn.vmware.com/courseware/12400/PS_ Ta21_288707_166-1_fin_v3.pdf 
(4) Idel memory Tax 
http://www.boche.net/blog/index.php/2009/01/29/idle-memory-tax/
This article is from the "technical notebook of the Triangle Balcony" blog, please be sure to keep this source http://delxu.blog.51cto.com/975660/288682
Diagram of the VMware memory mechanism