Product SiteDocumentation Site

Chapter 22. KSM

The concept of shared memory is common in modern operating systems. For example, when a program is first started it shares all of its memory with the parent program. When either the child or parent program tries to modify this memory, the kernel allocates a new memory region, copies the original contents and allows the program to modify this new region. This is known as copy on write.
KSM is a new Linux feature which uses this concept in reverse. KSM enables the kernel to examine two or more already running programs and compare their memory. If any memory regions are exactly identical, the kernel can combine the two regions into one and mark those regions for copy on write as above.
This is useful for virtualization with KVM. When a virtualized guest virtual is started, it only inherits the memory from the parent qemu-kvm process. Once the guest is running the contents of the guest operating system image can be shared when guests are running the same operating system or applications. KSM identifies these identical blocks in an anonymous way which does not interfere with the guest or impact the secturity. KSM allows KVM to request that these identical guest memory regions be shared.
The benefits of KSM are speed and utilization. With KSM, common data is kept in cache or in main memory. This reduces cache misses for the KVM guests which can improve performace for some applications and operating systems. Secondly, sharing memory reduces the overall memory usage of guests which allows for higher densities and greater utilization of resources.
Activating KSM
To be done
Deactivating KSM
To be done
Tuning KSM
To be done