Kernel Samepage Merging – linux

KSM is a memory-saving de-duplication feature, that merges anonymous (private) pages (not pagecache ones). Although it started this way, KSM is currently not suitable only for Virtual Machine use, but rather, it can be useful to any application which generates many instances of the same data.

KSM enables the kernel to examine two or more already running programs and compare their memory. If any memory regions or pages are identical, KSM reduces multiple identical memory pages to a single page. This page is then marked copy on write. If the contents of the page is modified by a guest, a new page is created for that guest.

You can verify KSM is in action, by checking for the existence of some of its /sys files, under /sys/kernel/mm/ksm/

pages_shared how many shared pages are being used
pages_sharing how many more sites are sharing them i.e. how much saved
pages_unshared how many pages unique but repeatedly checked for merging
pages_volatile how many pages changing too fast to be placed in a tree
full_scans how many times all mergeable areas have been scanned

Check if your kernel supports this:

grep KSM /boot/config-`uname -r`
CONFIG_KSM=y

More info there:

https://www.kernel.org/doc/Documentation/vm/ksm.txt

Leave a Reply

Your email address will not be published. Required fields are marked *