LoginSignup
4
3

More than 5 years have passed since last update.

コンテナにおけるmemory deduplication

Last updated at Posted at 2016-02-03

DLLのページ共有

一般に,複数のプロセスが同じDLLを呼び出す場合,DLLのページは共有される: http://unix.stackexchange.com/questions/116327/loading-of-shared-libraries-and-ram-usage

Dockerなどのコンテナでも,問題なくページが共有される.

ただし,aufsやoverlayfsではページ共有がなされるが,devicemapperやbtrfsでは(コンテナ毎にデバイスのmajor/minor番号が異なるため)ページ共有がなされない.
https://github.com/docker/docker/issues/7950

KSM

KVMではゲストメモリ領域に対してmadvise(addr, length, MADV_MERGEABLE)を呼び出すことで,KSM(Kernel SamePage Merging)を用いたMemory Deduplicationが行われる.

コンテナでもLD_PRELOADを用いてmmap(2)などをフックし,madvise(2)を呼び出させてやることでKSMが可能 https://openvz.org/KSM_(kernel_same-page_merging)#Enabling_memory_deduplication_libraries_in_containers

ただし,LD_PRELOADはstatic linkedなバイナリには適用できないので,Goで書かれたプログラムなどには適用できない.
SystemTapのguruモードを使えばstatic linkedなバイナリにも適用できそう.
そもそもGoでKSMしてどの程度の効果があるのかは不明.

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3