how to clear cache memory inside docker container

11,311

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.

Share:
11,311
Anandkumar Lakshmanan
Author by

Anandkumar Lakshmanan

Updated on June 04, 2022

Comments

  • Anandkumar Lakshmanan
    Anandkumar Lakshmanan almost 2 years

    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 ?