# Will KVM support KSM?

## sipingal

The kernel 2.6.32 has already supported kernel Samepage Merging(KSM). Will kvm(qemu-kvm) support KSM soon?

Details please see: http://www.linux-kvm.com/content/using-ksm-kernel-samepage-merging-kvm

Thank you in advance,

Sipingal

----------

## Mad Merlin

It's not in qemu-kvm-0.11.0, but is in the git version. It should be in the next released version of qemu-kvm.

----------

## Kev111

It should be inside now in the qemu-kvm-0.12.X.

But my guests won't start after an upgrade to qemu-kvm-0.12.1.1 and libvirt 0.7.5 anymore...

(error: unknown OS type hvm)

edit: ok, you need the qemu use flag to use kvm in >=libvirt 0.7.5

----------

## ferringb

Note that you still need linux-headers carrying MADV_MERGEABLE...

----------

## Mad Merlin

 *ferringb wrote:*   

> Note that you still need linux-headers carrying MADV_MERGEABLE...

 

Would this be >=2.6.32 headers only? I grepped the 2.6.30 linux-headers (the newest in portage at the time) and didn't see MADV_MERGEABLE.

----------

## ferringb

 *Mad Merlin wrote:*   

>  *ferringb wrote:*   Note that you still need linux-headers carrying MADV_MERGEABLE... 
> 
> Would this be >=2.6.32 headers only? I grepped the 2.6.30 linux-headers (the newest in portage at the time) and didn't see MADV_MERGEABLE.

 

Yep, and Yep.

Either you can build your own headers (I tried it... then reverted down to 2.6.30) or (and you're completely, utterly freaking responsible for any mistakes made) you can tweak the headers yourself backporting the defines.

Tweaking the headers is actually pretty straightforward, just need to dig through and do some testing to ensure that sys/mman.h picks up the change (mostly via tweaking asm-generic/ headers).

Among other things, I've got a python2.4, 2.5, 2.6, 2.7, and 3.1 KVM buildslaves I run for pkgcore/portage- the end result from KSM was actually pretty nice, around 100k redundant pages merged into ~24k pages (75k * 4096, you do the math).  Only thing I'd caution about for KSM- the default settings are a bit whacky, you'll want to tune them.

At least for my setup, the slaves don't change much... nor does the VM landscape really, thus scanning every 20 millisec is a bit of overkill.  Instead, tuned it down to scan every 5 minutes doing a scan of a couple hundred thousand pages.  Reasoning for this approach is that the box is setup to be as low power as possible... having KSM running and waking it up frequently isn't grand, and is a waste of CPU cycles to boot (as said, VM setup doesn't change that rapidly).

----------

## cassiol

helloo

please read that

http://bud-it.blogspot.com/2010/01/enabling-ksm-on-gentoo.html

----------

## Truzzone

News about ksm in the official portage?

I see now in the portage the linux-headers-2.6.33 and gentoo-sources-2.6.33-r2

glibc-2.11.1 in portage include the KSM patch?   :Question: 

Truzzone   :Smile: 

----------

## ero

And after all, how can we use KSM? I mean how can I tell the kernel to enable it at boot? I am with 2.6.38 kernel.

----------

## Truzzone

 *ero wrote:*   

> And after all, how can we use KSM? I mean how can I tell the kernel to enable it at boot? I am with 2.6.38 kernel.

 

Only need to load module or build-in after you need to enable it, read docs  :Wink: 

I add this line in /etc/conf.d/local.start :

```
echo 1 > /sys/kernel/mm/ksm/run
```

I enable and use fine with the packages from portage: gentoo-sources-2.6.37-r3 + glibc-2.11.3 + qemu-kvm-0.13.0-r2

Best regards,

Truzzone   :Smile: 

----------

