Today I found my server only have few free memory. and I executed free -h, it shows there are 60G memory used by cache. So I execute command to release cache, the result like this:

$ free -h; sudo sync; echo 3 > sudo /proc/sys/vm/drop_caches; free -h
             total       used       free     shared    buffers     cached
Mem:          126G       114G        11G       5.6M       465M        60G
-/+ buffers/cache:        53G        72G
Swap:          75G       607M        74G
             total       used       free     shared    buffers     cached
Mem:          126G       114G        11G       5.6M       465M        60G
-/+ buffers/cache:        53G        72G
Swap:          75G       607M        74G

It seemes didm't release any cache at all, and this server doesn't have virtual machine on it. Why? What should I do to release cache except reboot server(My OS is Debian 8)?
Thank you!

  • Don't try to do this at all. There is no need to do it and it will dramatically harm your server's performance. – Michael Hampton May 20 '19 at 2:42
  • Errrrrr, but I do need load some huge file to memory. – fajin yu May 20 '19 at 3:15
  • Indirectly mean there is no dirty cache or memory in your system which can be released. Is it giving memory error for new process? – asktyagi May 20 '19 at 4:25
  • I will let my mate try it and confirm if there is any error tomorrow. Maybe reboot server tonight. – fajin yu May 20 '19 at 5:55
  • 1
    So just load the file. You don't need to do anything special with dropping caches. That is a myth. – Michael Hampton May 20 '19 at 6:02

/proc/sys/vm/drop_caches serves no operational purpose. Don't try it, you would only hurt performance. The only practical use case is cold caches for benchmarks.

Cached is available to applications, but Linux calls it used. Obligatory: https://www.linuxatemyram.com/

Why would you spend money and power on fast memory and not use it for a performance boost?

  • After my program use over 66GB memory (load an array), it can still acquire new memory from cached, but the speed is very slooooow, about 10MB/s. After reboot, the cached is cleared, my program can acquire memory in flash. Now, I upgrade memory to 768G... – fajin yu Sep 15 '20 at 3:12
  • Reboot clears all memory not just cached. Memory reclaim on Linux is a complex topic. Ask a new question about how you could tune memory to your workload. Include lots of detail: the size of the allocation (how huge of an array?), how the program allocates memory and how long its taking, kernel version, kernel tuning (tuned-adm active, sysctl -a | grep vm), hardware specs including any NUMA, /proc/meminfo and kernel.org/doc/html/latest/accounting/psi.html metrics when under load. – John Mahowald Sep 29 '20 at 23:48

One of the reasons why drop_caches won't release memory is because some caches are still in use, for instance by tmpfs (in-memory) file systems. In order to find out how much memory is allocated for this kind of stuff, you can use df utility:

df -t tmpfs --total -h

This command will print out usage for all tmpfs currently in use. -t tmpfs limits list to tmpfs systems only, --total produces grand total for all file systems listed and -h formats all sizes in human-readable format.

The problem is, some applications customary create temporary files, open them and then delete, without closing. As a result, tmpfs can't release memory since files are still in use. In order to find applications like this, you can use this command:

lsof -nP +L1 /dev/shm | grep DEL

This would list all opened deleted files in /dev/shm (commonly used system tmpfs), as well as applications that opened these. -nP are optimizations for faster execution, +L1 limits links counting and /dev/shm specifies directory to scan for opened files. Then, | grep DEL selects only deleted files from the list.

Chromium is one of most popular software that abuses /dev/shm for its purposes, so, you might get several GB of deleted files created by chromium- or electron-based applications. And this cache won't be removed with drop_caches and it won't get freed up in low-memory situations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.