KSM or Kernel Same-Page Merging in linux or in KVM

What is KSM or Kernel Same-Page Merging ?

Each and every process will have some pages accessed in memory. KSM is a feature which allows you to share identical memory pages between processes.

KSM scans for identical memory pages and consolidate these into one COW ( Copy on write ) shared page .. when a process writes into this shared page , it ( process) gets its own new copy with the changes . The original COW shared page can be accessed by other processes. The advantage KSM brings here is it reduces physical memory consumption.

At first the processes which participate in this will “register” memory pages for use with KSM..

There is a user space process called “ksmctl” to activate and control KSM..

Below is an illustration on this utility ..

[root@humble-node ~]# lsmod |grep ksm =========>Here I verified that “ksm.ko” is loaded in my system
ksm 51808 2
kvm 223264 2 ksm,kvm_intel

[root@humble-node ~]# ksmctl start 1000 50 =======>The command ksmctl start npages sleep starts KSM, scans npages pages, and sleeps for sleep ms before scanning that many pages again.
created scanner

[root@humble-node ~]# ksmctl info ====> prints out information about KSM activity
flags 1, pages_to_scan 1000, sleep_time 50
[root@humble-node ~]#

 

KSM is used by “KVM” ( Kernel-based Virtual Machine) to implement memory Over commit feature..

Also refer #http://www.linux-kvm.org/page/KSM

Let us meet in next blog..