When you use virtualization, you run many OS instances on one physical piece of hardware. Often, the VMs run similar versions of OS. For example, you might have 50 instances of Windows 7 running on a single physical server in a VDI environment. Because these are the same OS, a large part of their memory contents will be the same. Page sharing is the idea of only storing a page that is duplicated across VMs once in memory—basically Single Instance Storage for VM memory.
A process in the hypervisor looks at every page of memory for every VM and creates a hash value for them. It compares the hash values and if a duplicate hash is found, the process does a bit by bit comparison of the memory pages to make sure they really are identical. The content is then stored only once in memory and the duplicate VM page addresses just point to the page.
A number of factors make this technique less effective with modern OSs than older ones. One factor (but not a huge one) is that Windows Vista and above use Address Space Load Randomization, a security technology that loads key components of the Windows kernel into 1 of 256 possible locations. The feature makes it harder for malware to attack the kernel based on the component's location in memory because the locations will vary on different instances of the OS and at each reboot. As a side effect, though, duplicate instances of the same OS won't have the same content in the same locations. For this specific content, Address Space Load Randomization hurts the effectiveness of page sharing, but this is only for a small part of the OS content.
Another factor is that page sharing works best on empty pages, but as I mentioned in the previous sections, modern OSs rarely leave memory empty. But the biggest blow to page sharing is large memory pages. In the past, memory pages were 4KB, and the chances of finding 4KB pages with the same content across OSs is pretty high, so physical memory space will be saved. Modern windows and Linux OSs use 2MB memory pages by default, however, and the chances of finding duplicate 2MB memory pages are very slim.
Why do you even want larger memory pages? OSs work with virtual address spaces for memory, and these spaces have to be mapped to physical memory through page tables. Lookups in the page table can take time, so processors have the Translation Lookaside Buffer (TLB), a very fast memory cache on the processor that stores recently accessed physical-to-virtual address space mappings. This gives you faster lookups for commonly used memory areas, but the TLB has a finite size, so using 2MB memory pages instead of 4KB pages enables the TLB to cover far more memory—512 times more memory is addressable using the TLB with large memory pages than with small.
Swapping to disk
Swapping memory to disk by the hypervisor is never recommended by any virtualization platform. But it's present in some as a last resort for when the hypervisor badly needs memory and can't reclaim it through page sharing or quickly enough through ballooning. In this case, the hypervisor will randomly pick pages of the guests' memory and write them out to a hypervisor-level disk swap file. At this point, there will likely be a performance impact on the guest OSs. You never want this type of swapping to occur because the hypervisor could be writing key areas of memory to disk, crippling performance.
Microsoft's solution for VM memory doesn't use page sharing because most OSs will use large memory pages going forward. It doesn't allocate memory on first write in the overcommit style of allocation because of the inherent dangers of overcommitting any resource. It also doesn't perform hypervisor swapping out to disk.