Category: Virtualization

KSM – What is it??

Kernel Samepage Merging (KSM) allows de-depulication of memory in Linux and has been released with kernel version 2.6.32. KSM tries to find identical Memory Pages and merge those to free memory. It tries to find memory pages that are updated seldom, otherwise it could be inefficient.

Originally KSM was developed for virtual machines. If these virtual machines use the same programs or operating systems, the overall memory usage can be reduced dramatically and more virtual machines can be operated with the available physical RAM.

Some tests from Red Hat have shown, that 52 virtual machines with Windows XP and 1 GB RAM can be operated on one server with only 16 GB RAM.

The following command allows to check if KSM is integrated into the kernel:

$ grep KSM /boot/config-`uname -r`

Further information and configuration options can be found in sysfs file system:

$ ls -1  /sys/kernel/mm/ksm/

Going through source code of libvirt

Clone the source code:

git clone

The directory listing inside the repository is something like this.

libvirtd is based on C programming language. It has bindings in different languages – C,C++,C#,Java,PHP, Ruby, and so on.

docs, daemon, and src are the few important directories. It is an well documented project, which is found in

libvirtd starts connection or operates based on driver modes. On initialization, the drivers are registered with libvirtd.
Different types of drivers are a part of libvirtd. Each driver has a registration API, which loads up the driver specific function references for the libvirt APIs to call.

As we see in the above figure there is a Public API exposed to the client. When the client calls the Public API, depending on the connection uri, delegation is done to the specific driver implementation.

libvirt , qemu and kvm

libvirt talks to various hypervisors underlying it. It is an open source API and a domain management tool for managing different hypervisors.

Command-line clint of libvirt is virsh.

Goal of libvirt library is to provide a common and stable layer to manage Virtual Machines running on a hypervisor.
In order to manage VMs, libvirt provides APIs for VM provision, creation, modification, monitoring, control and migration.

The libvirt process is daemonized, and is known as libvirtd.

What happens when libvirt client, such as virsh, requests service from libvirtd?
Based on connection URI passed by the client, libvirtd opens a connection to the hypervisor. This is how the clients virsh or virt-manager asks libvirtd to start talking to the hypervisor. Like any other daemon, it also provides services to its client.

Most people think that libvirt is restricted to a single node or local node
where it is running; it’s not true. libvirt has remote support built into the
library. So, any libvirt tool (for example virt-manager) can remotely connect to a libvirt daemon over the network, just by passing an extra connect argument.

Connection sample URI:

1. qemu://xxxx/system
2. qemu://xxxx/session

[1] requests to connect locally as “root” to the daemon supervising qemu / kvm virtual machines.
[2] requests to connect locally as a normal user to its own set of qemu/kvm domains.

qemu also supports remote connections. To achieve remote connections, a small change need to be done in the connection URI.
The connection format is :
[driver+transport]://[username@hostname]:[port]/[path][?extra parameters]

Example command of a virsh process for a remote connection is :

$ virsh --connect qemu+ssh://root@remtelocation.server/system list --all

Recent Posts


GiottoPress by Enrique Chavez