Answers: <p>This question is discussed in some detail in <a href="https://github.com/moby/moby/issues/7950" rel="nofollow noreferrer">issue 7950</a>  The conclusion seems to be that:</p>
  
  <ul>
  <li><p>Depending on your storage configuration, the kernel page cache may be used if multiple containers are accessing the same file (e.g., see <a href="https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/#overlayfs-and-docker-performance" rel="nofollow noreferrer">OverlayFS and Docker Performance</a>).</p></li>
  <li><p>You may be able to enable <a href="https://openvz.org/KSM_(kernel_same-page_merging)#Enabling_memory_deduplication_libraries_in_containers" rel="nofollow noreferrer">Kernel same-page merging</a> through use of of the <a href="https://vleu.net/ksm_preload/" rel="nofollow noreferrer">ksm_preload</a> tool.</p></li>
  </ul>
  
Answers: CC BY-SA 3.0
Answers: 2017-12-04T17:22:11.993Z
Answers: 2017-12-04T17:22:11.993Z
Answers: larsks
Body: <p>Imagine you would run a bunch of services say based on the same Tomcat image.</p>
  
  <p>Would Docker optimize memory usage for identical memory segments and reuse these patterns?</p>
  
Tags: <docker><performance>
Title: Docker and shared memory optimization?
UserDisplayName: Ta Mu
ThreadText: # Docker and shared memory optimization?
  
  (Asked by: username_0 on 2017-12-04)
  
  Imagine you would run a bunch of services say based on the same Tomcat image.
  
  Would Docker optimize memory usage for identical memory segments and reuse these patterns?
  
  **Tags:** docker, performance
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-12-04. Score: 2 | Accepted answer
  
  This question is discussed in some detail in [issue 7950](https://github.com/moby/moby/issues/7950) The conclusion seems to be that:
  
  * Depending on your storage configuration, the kernel page cache may be used if multiple containers are accessing the same file (e.g., see [OverlayFS and Docker Performance](https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/#overlayfs-and-docker-performance)).
  * You may be able to enable [Kernel same-page merging](https://openvz.org/KSM_(kernel_same-page_merging)#Enabling_memory_deduplication_libraries_in_containers) through use of of the [ksm\_preload](https://vleu.net/ksm_preload/) tool.
  
  
  ---
  
  