pages_sharing and pages_shared difference in ksm

Kevin Parker asked:

Can some one please help me understand this.

i am running kvm hosts with 5 vms on it.

These are ksm driver statistics

each page is 4KB

cat /sys/kernel/mm/ksm/pages_shared     162221
cat /sys/kernel/mm/ksm/pages_sharing    264281
cat /sys/kernel/mm/ksm/pages_unshared   241483

Is “pages_sharing” total no of pages created by vms. and “pages_shared” is the number of pages that is found similar and merged together.

if that is true then why is  pages_sharing-pages_shared != pages_unshared

 264281-162221 != 241483

My answer:

pages_unshared means just what it says: the pages could not be shared because they’re unique.

pages_shared indicates how many pages are actually in use and being shared.

pages_sharing indicates how many pages the VMs think there are. If you didn’t have KSM running, this is how many pages would actually be in use.

So, in your example, 264281 pages have been found to be shareable, and so they were merged into 162221 pages, while 241483 pages were not shareable. KSM saved you about 398 MB of memory.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.