Saturday, February 6, 2010

KSM Now Enabled in Ubuntu Lucid

I just uploaded a qemu-kvm package that enables KSM by default on Ubuntu Lucid.

KSM is a bacronym, for Kernel SamePage Merging. Previously KSM stood for Kernel Shared Memory. KSM is a new feature of KVM, which can provide more efficient memory utilization on virtualization hosts. Basically, the host kernel tracks identical pages in memory, and stores only one copy when possible. If you're running several basically identical virtual machines, then you will likely have some identical pages in memory.

Ubuntu inherited these features from upstream with the merge of the Linux 2.6.32 kernel and the qemu-kvm 0.12.2 package. Fedora 12 shipped with the KSM kernel pieces backported to their kernel.

You can disable KSM, if you like, by editing /etc/default/qemu-kvm and then restarting qemu-kvm with sudo restart qemu-kvm.

I did a bit of very rough testing of KSM in a test deployment of Ubuntu Enterprise Cloud. I had 1 Eucalyptus Node, a simple laptop, with a dual-core 2.4GHz and 4GB of memory. I registered a single Ubuntu 9.10 64-bit server image, and started instances with 256MB of memory apiece.

With KSM disabled:
  • Running 0 VMs, the Node's memory utilization was steady around 12%
  • Running 1 VM, the Node's memory utilization was steady around 18%
  • Running 14VMs, the Node's memory utilization spiked and stabilized at 88%
With KSM enabled:
  • Running 0 VMs, the Node's memory utilization was steady around 12%
  • Running 1 VM, the Node's memory utilization was steady around 18%
  • Running 14VMs, the Node's memory utilization was steady at 60%
    • with 18,000 - 20,000 pages shared
It looks to me that KSM "saved" me about 28% of my host's memory, which is a little over a gigabyte.

If you want to try out KSM on your Lucid host:
  1. Upgrade to the latest qemu-kvm package
  2. Make sure that /sys/kernel/mm/ksm/run is set to 1 (the qemu-kvm upstart job will do this for you now)
  3. Launch two Ubuntu LiveCD ISOs
    • testdrive -u ./lucid-desktop-amd64.iso
    • testdrive -u ./lucid-desktop-amd64.iso
  4. Once they're running, you can see how many pages are shared with
    • watch cat /sys/kernel/mm/ksm/pages_shared
Enjoy!
:-Dustin

No comments:

Post a Comment

Please do not use blog comments for support requests! Blog comments do not scale well to this effect.

Instead, please use Launchpad for Bugs and StackExchange for Questions.
* bugs.launchpad.net
* stackexchange.com

Thanks,
:-Dustin