2

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?

  • I am not sure, what is the case if the container is created on this way. Logic dictates, it should help, at least a little bit. – peterh Sep 24 '17 at 14:16
2

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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.