Kernel same-page merging explained

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 memory pages that have identical contents 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.

Deduplication

KSM performs memory deduplication by scanning through main memory for physical pages that have identical content, and identifies the virtual pages that are mapped to those physical pages. It leaves one page unchanged, and re-maps each duplicate page to point to the same physical page, after which it releases the extra physical pages for re-use. It also marks both virtual pages as "copy-on-write" (COW), so that kernel will automatically remap a virtual page back to having its own separate physical page as soon as any process begins to write to it.

KSM was originally intended to run more virtual machines on one host by sharing memory between processes as well as virtual machines. 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.[1] Upon its implementation, users found KSM to also be useful for non-virtualized environments in which memory is at a premium.[2] [3]

KSM was merged into the Linux kernel mainline in version 2.6.32, which was released on December 3, 2009.[2] [1] 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.[4]

Security risks

Security is also a concern:

See also

External links

Notes and References

  1. Web site: Linux kernel 2.6.32, Section 1.3. Kernel Samepage Merging (memory deduplication). 2009-12-03 . 2015-08-12. KernelNewbies.org.
  2. Web site: Anatomy of Linux Kernel Shared Memory. IBM . 2010-08-21 . IBM Developer . unfit . https://web.archive.org/web/20160709062356/http://www.ibm.com/developerworks/linux/library/l-kernel-shared-memory/ . 2016-07-09 .
  3. Web site: Increasing memory density by using KSM . 2010-08-21 . Kernel.org .
  4. Web site: KSM tries again. kernel.org . 2010-08-21 . lwn.net.
  5. Web site: Memory Deduplication as a Threat to the Guest OS. Kuniyasu Suzaki. Kengo Iijima. Toshiki Yagi. Cyrille Artho. September 16, 2013. January 5, 2013. https://web.archive.org/web/20130105174201/http://staff.aist.go.jp/k.suzaki/EuroSec2011-suzaki.pdf. dead.
  6. Web site: Barresi. Antonio. Razavi. Kaveh. Payer. Mathias. Mathias Payer. Gross. Thomas R.. August 2015. CAIN: Silently Breaking ASLR in the Cloud. 2015-08-12. USENIX.
  7. Web site: Red Hat. Polyakov. Andy. It's all a question of time - AES timing attacks on OpenSSL. access.redhat.com. Red Hat. 4 August 2016.
  8. Web site: Martin. Schwarzl. Erik. Kraft. Moritz. Lipp. Daniel. Gruss. Remote Memory-Deduplication Attacks. 2021. Network and Distributed System Security Symposium. 2 April 2022.
  9. Web site: New FFS Rowhammer Attack Hijacks Linux VMs. August 14, 2016 . 17 August 2016.