0

I use a laptop for work and therefore I only do a suspend to RAM rather than shutdown everyday. so I do not have to start each application again every day.

after some days of "run time" I see that Cache gets filled up, but I'm unable to clear it completely. this leads to swap usage and later to OOM.

# echo 3 > /proc/sys/vm/drop_caches; free -wht
              total        used        free      shared     buffers       cache   available
Mem:           23Gi       2.2Gi        15Gi       4.7Gi       0.0Ki       5.2Gi        15Gi
Swap:         2.0Gi          0B       2.0Gi
Total:         25Gi       2.2Gi        17Gi
# free -wht
              total        used        free      shared     buffers       cache   available
Mem:           23Gi       4.4Gi       457Mi       9.1Gi       3.5Gi        14Gi       9.2Gi
Swap:         2.0Gi       0.0Ki       2.0Gi
Total:         25Gi       4.4Gi       2.4Gi
# echo 3 > /proc/sys/vm/drop_caches; free -wht
              total        used        free      shared     buffers       cache   available
Mem:           23Gi       4.3Gi       9.0Gi       9.0Gi       0.0Ki       9.8Gi       9.4Gi
Swap:         2.0Gi       0.0Ki       2.0Gi
Total:         25Gi       4.3Gi        11Gi
# echo 3 > /proc/sys/vm/drop_caches; free -wht
              total        used        free      shared     buffers       cache   available
Mem:           23Gi       4.3Gi       9.0Gi       9.0Gi       0.0Ki       9.8Gi       9.4Gi
Swap:         2.0Gi       0.0Ki       2.0Gi
Total:         25Gi       4.3Gi        11Gi
# uptime
 10:57:09  up 3 days 19:26,  5 users,  load average: 0.89, 1.94, 1.69
# uname -a
Linux xxxxx-00164 5.3.18-150300.59.76-preempt #1 SMP PREEMPT Thu Jun 16 04:23:47 UTC 2022 (2cc2ade) x86_64 x86_64 x86_64 GNU/Linux
# 

I could not yet figure out how to check what application or files are stuck in the cache. I assumed that 3 > drop_caches removes all entries of the file cache. but as my laptop runs some hours more, the drop cache action will free less every time. the output above spans accross ~8h hours. what remains in Cache is missing from Available, although I tried to clear the Cache twice within 1s (the last two echo commands)

how to analyse such a behavior? what remains in Cache??

Many Thanks! Stefan K.

  • Are you sure it is cache that is causing your oom issues? Cache will use all memory available as more disk is accessed on any system, but it is replaced when required for new data. Never seen an instance of oom caused by cache. – Zip Jul 26 '22 at 12:39
  • Run top and hit 'M' to sort on physical memory used, Watch the process occupying the top slot. If it is continuously increasing, you likely have a memory leak going on. – stark Jul 26 '22 at 13:04

1 Answers1

1

after some days of "run time" I see that Cache gets filled up, but I'm unable to clear it completely. this leads to swap usage and later to OOM.

I think you're chasing the wrong problem. The drop_caches command can't drop anything that's in use — that's why it doesn't go to zero. But it's normally not a problem. You can probably find a dozen answers on this site (like How do you empty the buffers and cache on a Linux system?) telling you that this normally pointless.

But that said, I don't think any of these explain why echo 3 > /proc/sys/vm/drop_caches isn't making the cached number go right to zero. I know of at least two things that can have impact: files in tmpfs (including ones which are still open but may be deleted (see this answer on Serverfault) and zram (see zramctl command). There may be some others.

The basic problem isn't the cache — something is using your memory for real.

mattdm
  • 40,245
  • why is Available decreasing all the time then?

    `#closed all applications

    echo 3 > /proc/sys/vm/drop_caches; free -wht; uptime

              total        used        free      shared     buffers       cache   available
    

    Mem: 23Gi 2.2Gi 11Gi 8.7Gi 0.0Ki 9.3Gi 11Gi Swap: 2.0Gi 0B 2.0Gi Total: 25Gi 2.2Gi 13Gi 17:05:30 up 3 days 2:38, 4 users, load average: 0.40, 0.95, 1.47

    echo $((23-2-10))

    11 #`

    – StefanKaerst Jul 28 '22 at 15:06
  • Because something is using it. – mattdm Jul 28 '22 at 16:32
  • That's a separate question from "why can't I drop everything from the caches". – mattdm Jul 28 '22 at 16:32
  • ok .. one more time. Cache increases all the time and Available decreases all the time..... only in that direction!!! even if I close all applications!! so the question/problem remains. How do I (really) drop the cache content and free this memory? I know the os should do that automatically because Cache is expandable in favor of Available .. but this does not work for me here. maybe you guys try to run Xorg server for serveral days to see with your own eyes. (if I logout, the Cache drops to .5G because Xorg server will be restarted) looks like an Xorg bug, AFAIK – StefanKaerst Jul 29 '22 at 06:44
  • ^^ drop or query the Cache? (editiing my own comments is made terrible complicated, sry) – StefanKaerst Jul 29 '22 at 07:47
  • I try another window manager besides KDE Plasma, maybe this helps... I'll update this post as I have more information – StefanKaerst Jul 29 '22 at 11:00