3

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?

sourcejedi
  • 50,249

1 Answers1

3

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.

sourcejedi
  • 50,249
  • 2
    This doesn’t quite answer “Can KSM be used to reduce the memory requirements of containers?” KSM can reduce the memory requirements of containers, just not by sharing pagecache pages. (Additionally, it needs help since it only considers memory which has been flagged as mergeable.) – Stephen Kitt Sep 24 '17 at 14:22
  • @StephenKitt question minimally fixed to reflect author intent. – sourcejedi Sep 24 '17 at 14:40