<p>I'm running my rethinkdb container in Kubernetes cluster. Below is what I notice:</p>

<p>Running <code>top</code> in the host which is CoreOS, rethinkdb process takes about 3Gb: </p>

<pre><code>$ top
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  981 root      20   0   53.9m  34.5m  20.9m S  15.6  0.4   1153:34 hyperkube
51139 root      20   0 4109.3m 3.179g  22.5m S  15.0 41.8 217:43.56 rethinkdb
  579 root      20   0  707.5m  76.1m  19.3m S   2.3  1.0 268:33.55 kubelet
</code></pre>

<p>But running <code>docker stats</code> to check the rethinkdb container, it takes about 7Gb!</p>

<pre><code>$ docker ps | grep rethinkdb
eb9e6b83d6b8        rethinkdb:2.1.5                             "rethinkdb --bind al   3 days ago          Up 3 days                               k8s_rethinkdb-3.746aa_rethinkdb-rc-3-eiyt7_default_560121bb-82af-11e5-9c05-00155d070266_661dfae4

$ docker stats eb9e6b83d6b8
CONTAINER           CPU %               MEM USAGE/LIMIT     MEM %               NET I/O
eb9e6b83d6b8        4.96%               6.992 GB/8.169 GB   85.59%              0 B/0 B

$ free -m
         total       used       free     shared    buffers     cached
Mem:          7790       7709         81          0         71       3505
-/+ buffers/cache:       4132       3657
Swap:            0          0          0
</code></pre>

<p>Can someone explain why the container is taking a lot more memory than the rethinkdb process itself? </p>

<p>I'm running docker v1.7.1, CoreOS v773.1.0, kernel 4.1.5</p>

<p>In <code>top</code> command, your are looking at physical memory amount. in stats command, this also include the disk cached ram, so it's always bigger than the physical amount of ram. When you really need more RAM, the disk cached will be released for the application to use.</p>

<p>In deed, the memmory usage is pulled via cgroup <code>memory.usage_in_bytes</code>, you can access it in <code>/sys/fs/cgroup/memory/docker/long_container_id/memory.usage_in_bytes</code>. And acording to linux doc <code>https://www.kernel.org/doc/Documentation/cgroups/memory.txt</code> section 5.5:</p>

<blockquote>
  <p>5.5 usage_in_bytes</p>
  
  <p>For efficiency, as other kernel components, memory cgroup uses some
  optimization to avoid unnecessary cacheline false sharing.
  usage_in_bytes is affected by the method and doesn't show 'exact'
  value of memory (and swap) usage, it's a fuzz value for efficient
  access. (Of course, when necessary, it's synchronized.) If you want to
  know more exact memory usage, you should use RSS+CACHE(+SWAP) value in
  memory.stat(see 5.2).</p>
</blockquote>
