Kernel same-page merging
In computing, kernel same-page merging (KSM), also known as kernel shared memory, memory merging, memory deduplication, and page deduplication is a kernel feature that makes it possible for a hypervisor system to share identical memory pages between multiple processes or virtualized guests. While not directly linked, Kernel-based Virtual Machine (KVM) can use KSM to merge memory pages occupied by virtual machines.
KSM performs the memory sharing by scanning through the main memory and finding duplicate pages. Each detected duplicate pair is then merged into a single page, and mapped into both original locations. The page is also marked as "copy-on-write" (COW), so the kernel will automatically separate them again should one process modify its data.[1]
KSM was originally intended to run more virtual machines on one host by shared memory between processes as well as virtual machines. Upon its implementation, different users found KSM to also be useful for non-virtualized environments in which memory is at a premium.[2][3] An experimental implementation of KSM by Red Hat found that 52 virtual instances of Windows XP with 1 GB of memory, could run on a host computer that had only 16 GB of RAM.[4]
KSM was merged into the Linux kernel mainline in version 2.6.32, which was released on December 3, 2009.[2][4] To be effective, the operating system kernel must find identical memory pages held by different processes. The kernel also needs to predict whether the pages are likely to update infrequently enough that the merging would be an efficient use of processor resources.[3] A concern is that although memory usage is reduced, CPU usage is increased, thus negating potential increases in performance.[1]
Security risks
Security is also a concern:
- Allows circumvention of address space layout randomization (ASLR)[5][6]
- Exposes information via timing attacks[7]
- Allows contamination of cryptographic resources in other virtualized guests via the memory row hammer attack[8]
References
- ^ a b "KSM tries again". lwn.net. kernel.org. Retrieved August 21, 2010.
- ^ a b "Anatomy of Linux Kernel Shared Memory". IBM Developer. IBM. Archived from the original on July 9, 2016. Retrieved August 21, 2010.
- ^ a b "Increasing memory density by using KSM" (PDF). kernel.org. Retrieved August 21, 2010.
- ^ a b "Linux kernel 2.6.32, Section 1.3. Kernel Samepage Merging (memory deduplication)". kernelnewbies.org. December 3, 2009. Retrieved August 12, 2015.
- ^ Kuniyasu Suzaki; Kengo Iijima; Toshiki Yagi; Cyrille Artho. "Memory Deduplication as a Threat to the Guest OS" (PDF).
- ^ Antonio Barresi; Kaveh Razavi; Mathias Payer; Thomas R. Gross (August 2015). "CAIN: Silently Breaking ASLR in the Cloud" (PDF). USENIX. Retrieved August 12, 2015.
- ^ Red Hat; Polyakov, Andy. "It's all a question of time - AES timing attacks on OpenSSL". access.redhat.com. Red Hat. Retrieved August 4, 2016.
- ^ "New FFS Rowhammer Attack Hijacks Linux VMs". Retrieved August 17, 2016.
External links
- Linux kernel documentation
- Using KSM (archived from the original on July 2, 2014)
- Fedora KSM page
- Kernel-based virtual machine site - KSM