Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Can any one explain to me why KSM is not working does that mean that currently my kernel is not utilizing KSM for less ram utilization.

 grep KSM /boot/config-3.2.0-23-generic 

 cat /sys/kernel/mm/ksm/pages_shared 
 cat /sys/kernel/mm/ksm/pages_sharing
 cat /sys/kernel/mm/ksm/pages_unshared


Ubuntu 12.04 LTS 64 bit Desktop

free -m

         total       used       free     shared    buffers     cached
Mem:      1964       1883         81          0         11        228
-/+ buffers/cache:       1644        320
Swap:         2008        485       1523

ipcs -m

 ------ Shared Memory Segments --------
 key        shmid      owner      perms      bytes      nattch     status      
0x00000000 0          myexperiments   600        393216     2          dest         
0x00000000 2490369    myexperiments   600        393216     2          dest         
0x00000000 98306      myexperiments   600        393216     2          dest         
0x00000000 2523139    myexperiments   600        393216     2          dest         
0x00000000 13008900   myexperiments   666        262080     1          dest         
0x00000000 1245189    myexperiments   666        4          2          dest         
0x00000000 1277958    myexperiments   666        4          1          dest         
0x00000000 6520839    myexperiments   600        393216     2          dest         
0x00000000 14811144   myexperiments   666        1277760    3          dest         
0x00000000 12648458   myexperiments   666        300000     1          dest         
0x00000000 8060939    myexperiments   666        300000     1          dest         
0x00000000 12943373   myexperiments   666        300000     2          dest         
0x00000000 12976142   myexperiments   666        262080     2          dest         
0x00000000 13271055   myexperiments   666        300000     2          dest
share|improve this question
Do you have virtual machines running? – Heis Spiter Jan 17 '13 at 18:01
no,i think KSM can be utilized by process also. – Kevin Parker Jan 17 '13 at 18:02
Then, no common page between processes were found. This can be easily done with virtual machines or for processes running several instances. Otherwise, it is unlikely to find pages that can be shared. – Heis Spiter Jan 17 '13 at 18:06
Your shared memory is working properly, no doubt about it. Only thing is that as David mentions KSMD won't do anything unless it's specific requirement is met. As far as I can see, there is no problem really. – Soham Chakraborty Jan 18 '13 at 10:24
ipcs shows the sysv shm shared memory segments. Areas of memory that are shared by multiple process or threads. like in database environments, oracle has a requirement to have a particular amount of shared memory which is satisfied by that. – Soham Chakraborty Jan 18 '13 at 18:47

2 Answers 2

up vote 5 down vote accepted

KSMD won't do anything unless application software tells it to by calling madvise(MADV_MERGEABLE). Most likely, you aren't using any application software that uses KSMD's services.

MADV_MERGEABLE (since Linux 2.6.32):

Enable Kernel Samepage Merging (KSM) for the pages in the range specified by addr and length. The kernel regularly scans those areas of user memory that have been marked as mergeable, looking for pages with identical content. These are replaced by a single write-protected page (which is automatically copied if a process later wants to update the content of the page). KSM only merges private anonymous pages (see mmap(2)).

The KSM feature is intended for applications that generate many instances of the same data (e.g., virtualization systems such as KVM). It can consume a lot of processing power; use with care. See the kernel source file Documentation/vm/ksm.txt for more details. The MADV_MERGEABLE and MADV_UNMERGEABLE operations are only available if the kernel was configured with CONFIG_KSM.

share|improve this answer

On top of what David Schwartz said about the need that applications defined via madvise which page could be authorised for merging, there is one more settings to activate on Ubuntu to allow ksm to do its work:

sudo bash -c "echo 1 > /sys/kernel/mm/ksm/run"

You can check before what the current value is: cat /sys/kernel/mm/ksm/run on my Ubuntu 14.04.3 LTS and Ubuntu 15.04 boxes, it's value is 0. Here are the different values according the Kernel Samepage Merging kernel documentation:

How to use the Kernel Samepage Merging feature

run         - set 0 to stop ksmd from running but keep merged pages,
              set 1 to run ksmd e.g. "echo 1 > /sys/kernel/mm/ksm/run",
              set 2 to stop ksmd and unmerge all pages currently merged,
                    but leave mergeable areas registered for next run
              Default: 0 (must be changed to 1 to activate KSM,
                          except if CONFIG_SYSFS is disabled)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.