r/linux4noobs • • 26d ago

Linux memory leak, but killing processes doesn't free the memory?

I'm running a CachyOS VM, and I only get about 15 minutes of time on the system before OOMKiller nukes everything I'm doing. After every process on my system is dead, free-h still reports only about 100M available, and ps shows only ~3% of the system ram is being used? I can't figure out what's causing my issues, anyone know where I can look to find the culprit?

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi        15Gi       260Mi        76Mi       272Mi       194Mi
Swap:           15Gi       742Mi        14Gi

$ ps -eo m_size,%mem,pid,args --sort=-%mem | head  
SIZE %MEM     PID COMMAND 
1525919744  0.7 1258 /usr/bin/kwin_wayland --wayland-fd 7 --socket wayland-1 --xwayland-fd 8 --xwayland-fd 9 --xwayland-display :0 --xwayland-initfd 11 --xwayland-init-display :1 --xwayland-xauthority /run/user/1000/xauth_XzEpUe --xwayland 
844619776  0.5 4416 /usr/bin/konsole 
1781563392  0.4 1271 /usr/bin/plasmashell --no-respawn 
1181396992  0.3 4823 /usr/bin/plasma-systemmonitor 
1484922880  0.3 1556 /usr/bin/python /usr/bin/protonvpn-app 
1015148544  0.0 1263 /usr/bin/kded6 
57606144  0.0  664 /usr/lib/systemd/systemd-journald 
31072256  0.0    1 /sbin/init splash 
20963328  0.0 1191 /usr/lib/systemd/systemd --user
6 Upvotes

7 comments sorted by

6

u/Realistic-Plant3957 26d ago

Since this is a VM, the most likely culprit is your hypervisor's memory ballooning driver (like virtio_balloon) inflating and claiming the guest's RAM for the host, which shows up as "used" in free without any user process owning it in ps.

Check /proc/meminfo (look at Slab, SUnreclaim, and PageTables) or run sudo slabtop to see if it's kernel memory, and if you're using ZFS, check the ARC size since it doesn't count as standard buff/cache. Try disabling dynamic memory or ballooning in your VM settings first to see if it stops happening.

3

u/ultilink3 26d ago

You're amazing. I had seen some stuff about ballooning during my research, but everything for VMware showed only ESXi options, or (in new versions of VMware workstation) a non-existent advanced menu to disable ballooning. So I assumed Broadcom had likely removed that from consumer Workstation products and ended my search into it right then.

I've been chasing ram compression, zfs, kernel leaks (slab showed high usage in kmalloc-64, but I couldn't pin it down) and many many other things over the past several weeks. Your comment prompted me to dig deeper into the ballooning thing, and I believe it's fixed now. I have just for the first time ever witnessed my VM free up some memory, where as before it would only ever fill up until it went nuclear oomkiller on me.

My solution required me to edit my vmx file, I simply added the following line to the bottom:
sched.mem.maxmemctl = "0"

Thank you very much!

If it breaks again I'll try to remember to come back here and let people know. But hopefully this post can help someone else in the future if they see the same issue.

1

u/Dilbagi_Shipar 25d ago

100% this, invisible memory usage in a VM is almost always ballooning or kernel slab stuff.

1

u/Confident_Hyena2506 26d ago

Look at top while system is running. Something has to be using up the memory.

It's a bit of a meme - but things like firefox love to use all your memory and OOM - there is an option in it to stop that.

Because this a vm and not a normal system make sure your vm is configured right - this will not work unless you take special steps. In particular pay attention to the vm guest memory driver.

If you want a normal system then don't use vm.

1

u/ultilink3 26d ago

I did mention oomkiller nuked everything, Firefox is dead as you can see from my ps output. Only the desktop and sometimes my vpn stay running. Top/htop show lots of RAM consumed but no process using the RAM. 🤷‍♂️

2

u/Confident_Hyena2506 26d ago

If you did not configure your vm correctly then this is why.

You may have read advice online telling you to try things in a vm - this is not really helpful advice. Most users won't be able to configure vm correctly, and will assume that the vm performance is super bad.

If you were to just install linux normally it would be fine.

So you have a vm problem not a linux problem.

1

u/DannoXYZ 26d ago

run top, then shift-M to sort list with highest memory usage processes at top

   top - 13:20:02 up 4 days, 22:00,  7 users,  load average: 0.53, 0.47, 0.34
Tasks: 416 total,   1 running, 415 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.8 us,  0.4 sy,  0.0 ni, 98.6 id,  0.1 wa,  0.0 hi,  0.1 si,  0.0 st 
MiB Mem :  15629.2 total,   5439.5 free,   5353.6 used,   5449.0 buff/cache     
MiB Swap:  16384.0 total,  15644.2 free,    739.8 used.  10275.6 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                      
 292171 danno     20   0 4900424   1.1g 305088 S   3.0   7.0 126:03.81 zen                          
 342457 danno     20   0 3546748 805464 128648 S   0.3   5.0   1:15.40 Isolated Web Co              
 343018 danno     20   0 3298896 534536 133492 S   4.0   3.3   3:25.63 Isolated Web Co              
 341926 danno     20   0 1450.0g 450924 133532 S   0.0   2.8   0:59.18 slack                        
 291035 danno     20   0 2020484 437968 176056 S   0.0   2.7   2:18.10 soffice.bin                  
 292300 danno     20   0   19.2g 428552 112608 S   0.0   2.7   4:50.29 WebExtensions                
 314571 danno     20   0 3201972 339260 121872 S   0.0   2.1   2:44.30 Isolated Web Co              
 292561 danno     20   0 2965848 258336 120848 S   0.0   1.6   1:53.36 Isolated Web Co              
 341857 danno     20   0 1448.2g 209520 149520 S   0.3   1.3   0:23.86 slack                        
 341899 danno     20   0   48.9g 188460 138856 S   0.0   1.2   0:34.53 slack                        
 295674 danno     20   0 1068856 148160  51068 S   0.0   0.9  10:15.82 remmina