After some time the RAM usage (cache) is very high. I read somewhere that this might be the Kernel caching disk I/O or other Application’s caches but if that’s the case, shouldn’t it be freed if it’s needed?
I also ran this command: sudo lsof -s | sort -rnk 7 | numfmt --field=7 --to=iec | less but nothing obvious showed up. Htop doesn’t show anything interesting. Also, none of the tmpfs listed in df -h is filled up.
Example:
I closed every app except terminal, disabled the swap, dropped the caches (sync; echo 3 > /proc/sys/vm/drop_caches), ran the memory allocation program (from Experiments and fun with the Linux disk cache) which was killed at 5800MB and took this screenshot.
Now i opened by browser back to write this post, and the cache usage is even higher:
$ free -h
total used free shared buff/cache available
Mem: 15Gi 4,7Gi 560Mi 6,9Gi 10Gi 3,6Gi
Swap: 15Gi 30Mi 15Gi
Another example:
I have browser, file manager and couple of terminal emulators opened and htop shows 10GB (for some reason) used. Then I open a VM (with 4 GB ram) and the system becomes unresponsive because the ram is ~98% full. When I close the VM, the cache usage stays where it was before I ran the VM. Shouldn’t the cache be freed when it’s needed?? My PC should handle this workflow pretty easily but it doesn’t.
One observation: When I close every app and make my PC go to sleep, after waking it up, the (free -h) used grows by about 2GB. If I don’t close every app, not only used grows but also shared and buff/cache. Every time RAM usage (used or shared or buff) grows after sleep, it doesn’t get significantly freed by any of the methods I described before.
Ok, at this point I have no Idea what causes what. Once only used column is growing, and other times the used+shared+buff/cache is growing. I’m sure there is a issue somewhere because I have the same setup (Manjaro+KDE+Most of the apps) on my laptop and procedure like this: open a bunch of apps, close them, clear caches, brings the memory usage very close to fresh boot, and sleeping doesn’t affects memory usage.
The title doesn’t fully describe the issue, but after merging the posts I can not change it. Can any moderator (maybe @Yochanan?) change the title to something like: RAM usage grows significantly after waking up PC from sleep. (this additional RAM is not easily reclaimable)
I have similar problem. It is reproducing in different distributive, like Manjaro and NixOs. I have different environment gnome 3, mate and sway and different hardware - amd. Do have you installed lxd? Isn’t enough to send number to drop_caches or close program for my situation. You need to first close program and second send to drop_caches. Maybe echo 2 > /proc/sys/vm/drop_caches be enough. I don’t find patterns for this case but I close only Firefox and it allow to free almost all leaked ram. I see that in case that you run program from linuxatemyram you have disabled swap. If I try to allocate free memory, then It move it to swap(I use zram, but it may cause significant slowing if swap located in slow storage like hdd). After closing program I got something like that.
free -hw
total used free shared buffers cache available
Mem: 13Gi 7,7Gi 3,7Gi 575Mi 0,0Ki 2,2Gi 5,2Gi
Swap: 10Gi 3,0Gi 7,3Gi
I have different root filesystem ext4 and btrfs.
Can you describe it characteristics? Maybe it has less ram? Or maybe it haven’t virtual machine or containers?
That’s exactly what I did when I was taking those screenshots.
Yes indeed, my laptop has less ram - 8GB - but that shouldn’t affect the ram management, right? Also, I didn’t had any virtual machines nor containers running when I was taking the screenshots/describing the issue.
I haven’t any times when memory usage exceeds half of all memory, so it may be reason of this. It can be easy checked: see current usage with all closed programs and usage after reboot. I see absence of leak in some cases, but I doesn’t noticed yet condition, because I try to change some buffer size and values like vfs_cache_pressure.
Update: Until I get this fixed, my workaround is to not use sleep but setup swapfile and just hibernate my system instead. It’s a bit slower to boot but it doesn’t have this weird RAM issue.
I wrote simple script to analyze which component is leaking. If you have any suggestions, I be grateful.
First of all, you need save memory usage before sleep. This command require root privileges, maybe you prefer use sudo. We save usage to file. Be sure, that file “1” doesn’t exist, otherwise it be rewritten.
cat /proc/slabinfo > 1
After that we going to sleep, and after sleep also save usage to another file and we using this script on ruby.
#!/usr/bin/env ruby
def read_f name
File.read(name).gsub!(/ +/, ' ').split("\n").map { |i| i.split ' ' }[2..-1]
end
before = read_f ARGV[0]
after = read_f ARGV[1]
before.map.with_index do |v, i|
puts v.join("\t"), after[i].join("\t"), "---" if v[2].to_i * v[3].to_i < after[i][2].to_i * after[i][3].to_i
end
Now I went to sleep two times and got this result. There is same category on both times, so I think that this item is reason of leak. Now I need more proof, that my suggestions are correct. I continue watching, but I need help in other cases on other machine.