KSM allows identical pages of memory in VMs to be merged, particularly including common OS / application files cached in RAM.
Can KSM be used to similarly reduce the memory requirements of containers?
KSM allows identical pages of memory in VMs to be merged, particularly including common OS / application files cached in RAM.
Can KSM be used to similarly reduce the memory requirements of containers?
No.
KSM only merges anonymous (private) pages, never pagecache (file) pages.
It only works so well for VMs, because all the memory of a VM is stored as private pages in the host process. E.g. qemu's process on the host machine.
(Instead, for example, users of Docker can share pages between identical images, or images with a common ancestor and which use an overlayfs-based storage driver).
Additionally, the current KSM interface requires madvise(... MADV_MERGEABLE)
for each potentially shareable range. This call would have to be performed by every process in the container when it created a mapping. Obviously this interface is much easier to adapt individual special-purpose processes, including but not limited to qemu
, to use.