Score:1

Unexpectedly high memory usage in Ubuntu 22.04.3 LTS

wf flag

I have noticed for a while now that my system seems to be using up my memory much more quickly than I would expect. When it gets like this, I do notice it slowing down a bit at time, and my fan starts to spin aggressively (though maybe this latter thing is a separate issue?). I have tried googling around to understand what is going on (for example, I came across High memory usage that cannot be traced to a service or application and https://www.linuxatemyram.com/), but I haven't yet found a satisfying answer. What are reasons that my computer would be using much more memory (close to 100% of RAM and swap) than is reported by the running applications?

Currently, free -m outputs

               total        used        free      shared  buff/cache   available
Mem:           15337       14538         386          14         411         454
Swap:          20480       15442        5038

A rough estimate of the amount of memory my running applications are using (computed with ps -o %mem ax | tail -n +2 | paste -sd+ | bc) is 47.6%. Also, if I open up System Monitor and try manually adding up the amounts in the Memory column, then I again don't get a value close to the total reported amount of used memory.

Running arcstat -a outputs

    time  hits  miss  read  hit%  miss%  dhit  dmis  dh%  dm%  phit  pmis  ph%  pm%  mhit  mmis  mread  mh%  mm%  arcsz  size     c   mfu   mru  mfug  mrug  eskip  el2skip  el2cach  el2el  el2mfu  el2mru  el2inel  mtxmis  dread  pread  grow  need  free  avail  waste
13:14:22     0     0     0     0      0     0     0    0    0     0     0    0    0     0     0      0    0    0   5.0K  5.0K  479M     0     0     0     0      0        0        0      0       0       0        0       0      0      0     1     0  830M   235M      0

The output of running arc_summary can be found here. I put it in pastebin since askubuntu limits the number of characters in this question.

I can't say I know how to parse all this output, but to my naive eyes, this doesn't seem to indicate much memory is being used by ARC caches (at least, the ARC size (current) row reports a small number). Also, zfs get comprresion produces no output.

Similarly, running df -hl -t"tmpfs" outputs the following, which again doesn't seem to account for much of my "missing" memory usage.

Filesystem      Size  Used Avail Use% Mounted on
tmpfs           1.5G  4.0M  1.5G   1% /run
tmpfs           7.5G  260K  7.5G   1% /dev/shm
tmpfs           5.0M  8.0K  5.0M   1% /run/lock
tmpfs           7.5G     0  7.5G   0% /run/qemu
tmpfs           1.5G  228K  1.5G   1% /run/user/1000

If it helps, cat /proc/meminfo outputs

MemTotal:       15705548 kB
MemFree:          672004 kB
MemAvailable:     838776 kB
Buffers:            2060 kB
Cached:           329484 kB
SwapCached:       258588 kB
Active:          3268524 kB
Inactive:        3574140 kB
Active(anon):    3095044 kB
Inactive(anon):  3439264 kB
Active(file):     173480 kB
Inactive(file):   134876 kB
Unevictable:         340 kB
Mlocked:             340 kB
SwapTotal:      20972540 kB
SwapFree:        4630972 kB
Zswap:                 0 kB
Zswapped:              0 kB
Dirty:               452 kB
Writeback:             0 kB
AnonPages:       6253600 kB
Mapped:           191184 kB
Shmem:             22852 kB
KReclaimable:     194792 kB
Slab:             588360 kB
SReclaimable:     194792 kB
SUnreclaim:       393568 kB
KernelStack:       75888 kB
PageTables:       194976 kB
SecPageTables:         0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    28825312 kB
Committed_AS:   46712256 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      231560 kB
VmallocChunk:          0 kB
Percpu:            19776 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:    11380384 kB
DirectMap2M:     4728832 kB
DirectMap1G:           0 kB

The only other thing I can think to add is a screenshot of the resources tab of System Monitor. enter image description here

Let me know if there is anything else I can do to help figure out what's going on.

us flag
Open the processes tab, and check out which which all processes are consuming so much memory.
Niven avatar
wf flag
There's no single process using up near the amount of memory reported. I have many firefox tabs open (and no other processes using close to as much memory as them), but even these collectively only count for something like 5 gb of memory.
us flag
Alright, check the output of the command `htop` (you may have to install it with `sudo apt install htop`), then, click on Memory, and check if some process is consuming a lot of memory.
Niven avatar
wf flag
The most I'm seeing is an instance of firefox using about 4% of memory (also, the RES column shows 533M and the VIRT column shows 18.6G. I don't know what these mean or if they are relevant). `htop` seems to be duplicating many of its table entries for me (unless I'm totaling over 200% of memory usage), so it's hard to say exactly how much memory is being used by all the processes it explicitly lists.
waltinator avatar
it flag
The system uses memory not allocated to processes as easily releasable buffers for disk metadata, I/O optimization, buffering at several levels. When memory is requested by a process, the kernel frees the memory. One uses swap space to control what happens when programs allocate all the RAM and want more. In the Out-Of-Memory condition, with swap, some task's memory is written to disk, freed for reuse, and automatically returned to memory when the task runs. Without swap, the dreaded OOM-Killer (a fake process, hard-coded in the kernel) runs, and picks a process to KILL, in order to free RAM.
Niven avatar
wf flag
I can't say I followed all of your comment. Just to clarify, does the system use both regular RAM and swap for the disk and I/O buffers you mentioned, or does it just use RAM? If it's the latter, I'm still confused about why my computer is using so much swap. The amount of processes I have running don't seem to come close to using up all my RAM.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.