4

I have a docker swarm CE setup in EC2. I have two nodes. 1 manager and 1 worker. The host instance type is Alpine Linux.

In the Manager host the Memory usage is:

~ $ free -m
                    total       used       free     shared    buffers     cached
Mem:                 7972       4996       2975        715        178       2857
-/+ buffers/cache:   1960       6011
Swap:                 0          0          0

~ $

Now when i login the container,

~ $ docker exec -it c7cc255aca1f /bin/bash
 [root@c7cc255aca1f /]# 

And see the memory utilization:

[root@c7cc255aca1f /]# free -m
              total        used        free      shared  buff/cache   available
Mem:           7972        1654        2970         715        3347        5269
Swap:             0           0           0
[root@c7cc255aca1f /]#

Kindly help me how to clear the buff/cache or cached ?

2 Answers2

2

To clear the cache please see https://unix.stackexchange.com/questions/17936/setting-proc-sys-vm-drop-caches-to-clear-cache.

By the way why do you want to drop the cache? I am certain you do not want to drop the cache (unless you are doing some read benchmark, like with dd).

Your cache will be freed up as soon as a process needs memory. It is designed to use all available memory. Under Linux it is completely OK to run with no "free" memory (the one free refers to as "free") as long as you have enough available (or total-- buffers/cache is enough).

It is also highly recommended to add SWAP (even if you do not want to swap) to prevent OOM situations. Just create a swapfile somewhere, and set the vm.swappiness sysctl parameter to 0 so it won't be used if there is still RAM memory available.

scream314
  • 41
  • 6
  • 2
    @tamerlaha: Many people, including me (if you want I can link some articles, but you can easily Google it yourself). _Usually_ it is better to avoid the OOM killer and sacrifice some performance, but as always YMMW (I've seen some systems breaking because of the lack of SWAP). But please elaborate your comment, maybe you have a point I'm missing. Anyways, the original question was about buffer/cache, if you want to ask another question, please post one, or if you have a counterargument, please post it in a more detailed and constructive comment. – scream314 Sep 20 '19 at 22:13
  • 1
    I have Active(file) memory growing inside container A. What happens if container B runs out of memory? Can the cache in container A be freed to provide memory to container B? – MrR Aug 05 '21 at 21:35
  • @MrR did you get any answer for this question? Please share. – Ashish Shinde Oct 19 '22 at 14:37
  • @MrR I think you should post a separate question. – scream314 Oct 29 '22 at 20:28
  • @AshishShinde no I didn't - we just increased capacity. scream314 sorry this was a while ago and not a pressing requirement anymore. – MrR Nov 03 '22 at 12:30
1

While the kernel may evict buffers/cache for containers as needed, it cannot evict tmpfs.

LXCFS reports tmpfs as buffers/cache.

Systemd-journald writing logfiles in /run (a tmpfs), will be charged to the buffers/cache - and no amount of dumping buffers will free ram up once journald eats all ram. When OOMkiller strikes, it might take out a process or the entire container due to tmpfs eating all ram.

You can clear your journal files to reduce the size:

journalctl --vacuum-time=2days

Or you can clear based on size:

journalctl --vacuum-size=100M

Note that older versions of journalctl do NOT offer --vacuum functions. I am not aware how to cleanly clear the logfiles (other than deleting them by hand?)

math
  • 151
  • 3