From Fedora Project Wiki

Revision as of 12:54, 25 January 2010 by Lewis41 (talk | contribs)



Consentire alle macchine virtuali KVM guest, di condividere identiche pagine di memoria. Ciò è particolarmente utile quando multipli guest sono in esecuzione dalla medesima o similare immagine del S.O. base. Poichè la memoria è condivisa, la memoria combinata usata dai guest risulta ridotta.


Stato corrente

Descrizione dettagliata

Il concetto di memoria condivisa è molto comune nell'architettura dei S.O. Per esempio, quando si avvia un processo per la prima volta, esso condivide tutta la memoria con il processo genitore. Quando il processo genitore o figlio modificano una parte della memoria, il kernel alloca una nuova regione della memoria, copia i contenuti originali e permette al processo interessato di modificare la nuova regione di memoria. Questa operazione è denominata copy on write (o copia in caso di scrittura).

KSM è una nuova caratteristica di Linux che riprende questo concetto. Esso abilita il kernel a bloccare i due processi (genitore&figlio) in esecuzione per confrontare la loro memoria. Se le zone di memoria sono esattamente identiche, il kernel combina le due regioni in una e le segna per la copy on write.

This is especially useful in the case of KVM. When guest virtual machines are started, they can only inherit the memory of the parent qemu-kvm process. However, it is the contents of the guest operating system image which has the data which is most likely to be shareable. KSM allows KVM to request that these identical guest memory regions be shared.

Vantaggi per Fedora

With this feature Fedora will be able to run guest virtual machines in a potentially much more memory efficient manner. This will mean that Fedora host machines will be capable of hosting more guests than before.


The main effort here is the kernel support. Since it is not going to make 2.6.31, we need to consider backporting it once the userspace API has been declared stable. KSM is a pretty well self-contained memory management feature, so backporting should be straightforward.

Once the kernel support is available, a minor patch for qemu-kvm is required to enable the memory sharing.

An open question is whether KSM will be enabled for all guests by default. If not, support for enabling it will need to be added to libvirt, virtinst, virt-manager etc.

How To Test

  • Ensure you are using kernel >= 2.6.31-0.94.rc4.fc12 and qemu-kvm >=0.10.92-4.fc12
  • Install two or more virtual machines and run them
  • KSM is enabled by default, but limited to 2000 kernel pages. It is recommended that this be set to a more sane value with the ksm service chkconfig ksm on
  • Check whether pages were merged using /sys/kernel/mm/ksm/pages_shared
  • Optionally turn on the ksmtuned service which dynamically controls ksm in response to what is happening on the host at any given time with chkconfig ksmtuned on

User Experience

Users running multiple, but similar, KVM guests should experience a reduction in memory usage when KSM is enabled.

Fedora's kvm comes with 2 services controlling the behavior of ksm. One, simply called ksm, is just a nice means to start and stop ksm's kernel thread. The other, called ksmtuned, controls the first service and tunes its parameters according to the memory stress that is generated by KVM virtual machines. ksmtuned may stop ksm service alltogether, if memory is not in need. Later, if ksmtuned senses that memory stress has risen, it will fire up ksm again.


Getting KSM accepted for 2.6.32 and the API declared stable.

Contingency Plan

None needed, if KSM is not implemented guests will still work as they do now, without the advantage of a reduced memory footprint.


Release Notes

Fedora 12 adds KSM (Kernel SamePage Merging) which allows identical memory pages to be merged by the kernel into a single page. This is initially used by KVM to allow multiple, but similar, guest virtual machines to have a reduced memory footprint. To enable KSM, it is recommended that you turn on the ksm service with 'sudo chkconfig ksm on' to set up limits appropriate for your system. For additional tuning with a large number of guests, the ksmtuned service can be enabled with 'sudo chkconfig ksmtuned on'.

Comments and Discussion