I'm trying to save some disk space between multiple systems and re-using the same swap partition (which seems to be fine).I'm now getting into multiple virtual machines and am thinking of a pass-through file system to another drive to be used as a linux swap.  It would be possible (I assume) to mount both systems to the same swap partition, but would it cause problems.  Since the application are mapped and don't conflict are OS identifiers also mapped or part of the application mapping?The stressed scenario would be multiple VMs running (possibly paused, so not actively running conncurrently).To be explicit:Start VM 1Pause VM 1Start VM 2Both share the same swap file.  No hibernationIf have seen this: FreeBSD and Linux shared partitions but the answer states it is unconfirmed.  Also I need to know if it breaks down for different OSes/Kernel versions.
Can linux systems on multiple virtual machines share the same swap partition?
filesystems;partition;swap
I think what you're going to find is that it's possible but probably not advisable to do this. In looking at 3 virtualization technologies:VirtualBoxVMWareKVMIt would appear to be possible in the first 2 (VirtualBox and VMWare):VirtualBoxHow to share [ swap | home ] disk files between boxes?VMWareStoring a virtual machine swap file in a location other than the default (1004082)For KVM it seems possible as well but with several caveats. For one with newer versions of RHEL a new technology called KSM - Kernel Samepage Merging has been deployed which allows identical pages across VM guests to be shared, however they are pinned in memory and cannot be swapped out. excerpt - Kernel Virtual Machine (KVM) Best practices for KVMThe system cannot swap memory pages that are shared by KSM because  they are pinned.So it becomes unclear what happens if the VM has it's own swap, and one of these guest's pages needs to be swapped by the VM. So it would do so, but the physical memory wouldn't become freed (would be my guess) thus wasting now disk within the VM's swap and still continuing to use the physical RAM.Additionally it seems dangerous to have all the VMs using the same swap for this reason: What happens when the swap becomes full, all the VMs are at risk since the resource has been essentially exhausted.excerpt Overcommitting with KVMAs KVM virtual machines are Linux processes, memory used by  virtualized guests can be put into swap if the guest is idle or not in  heavy use. Memory can be committed over the total size of the swap and  physical RAM. This can cause issues if virtualized guests use their  total RAM. Without sufficient swap space for the virtual machine  processes to be swapped to the pdflush process, the cleanup process,  starts. pdflush kills processes to free memory so the system does not  crash. pdflush may destroy virtualized guests or other system  processes which may cause file system errors and may leave virtualized  guests unbootable.Anatomy of a swap out on KVMThere is an excellent write up on the KVM website that discusses how a VM provisions memory as well as how it eventually will make use of swap. It was written for qemu-kvm v0.12, so I don't know how much has changed since that version.excerpt from above pageSwap-out pathNow, let's say the host is under memory pressure. The page from above  has gone through the Linux LRU and has found itself on the inactive  list. The kernel decides that it wants the page back:The host kernel uses rmap structures to find out in which VMA (vm_area_struct) the page is mapped.The host kernel looks up the mm_struct associated with that VMA, and walks down the Linux page tables to find the host hardware page  table entry (pte_t) for the page.The host kernel swaps out the page and clears out the pte_t (let's assume that this page was only used in a single place). But, before  freeing the page.The host kernel calls the mmu_notifier invalidate_page(). This looks up the page's entry in the NPT/EPT structures and removes it.Now, any subsequent access to the page will trap into the host ((2) in the fault-in path above)So what the above is trying to say is that when a page of the guest VM's memory needs to be swapped out, it's done so by the host. But realize this is when the entire host has exhausted it's RAM, not when a guest VM has.Should you use swap in KVM?I do and as long as you understand that if you have a lot of VMs on a system they may all be hitting the disk if they're over provisioned, and so you'll be creating a ton of I/O on your disk. See this ServerFault question for more details.