r/linuxquestions • u/superSmitty9999 • Sep 29 '26
Support Why is finding memory usage on Linux so impossible and confusing?
Currently using DGX OS (Ubuntu) on unified memory DGX Spark and I cannot for the life of me figure out how much memory is used on my machine!
I run htop and get these three memory numbers: VIRT(ual) RES(ident) and SHR(shared) memory usage but have no idea how to interpret them. On Windows and Mac the task managers show easy to interpret numbers.
In a practical sense what I care about how much memory will be freed if I kill a process? I can't seem to get a sorted list of the biggest offenders like I could with by listing largest files/folders.
Additionally, htop doesn't show RAM usage from virtual machines!!
Ideally there is a CLI utility which shows a sorted list of the worst offenders. Does anyone know of something like this?
I don't feel I should need to do math or run multiple commands to figure out how much RAM my machine is using.
23
u/JaKrispy72 Sep 29 '26
What do you think these “other OS’” are showing that Linux isn’t?
Look at “Mission Center” and install that maybe.
Htop and btop and all these other things (along with core utilities) are giving you the numbers, but you can’t be bothered to understand them? A number is a number. Because it’s on Windows you trust it for some reason?
-3
u/superSmitty9999 Sep 29 '26
Okay. I installed mission center. I look at my memory, it tells me 20GB in use 60GB including cache.
I go to the apps and services tab, add everything up, it's nowhere close to the 20GB number. Like none of these numbers add up.
but you can’t be bothered to understand them?
I really can't figure it out. I've spent 3 hours today looking at this and I still can't figure out a clean way to represent it. Depending on what numbers I look at I'm getting wildly different numbers.
10
u/JaKrispy72 Sep 29 '26
And you are saying the numbers add up in Windows? With what monitoring system would that be?
-10
u/superSmitty9999 Sep 29 '26
Im not saying they match perfectly but Task Manager is close enough that I never noticed or felt the need to spend 6 hours deepdiving into memory management.
For example, if you add up all the values in the VIRT column it could be 2x or more the total memory on your system.
I despise Windows lol but yeah on this one thing it seems like they did good. Task Manager is a good program.
17
u/ipsirc Sep 29 '26 edited Sep 29 '26 •
![]()
I really can't figure it out. I've spent 3 hours today looking at this and I still can't figure out a clean way to represent it. Depending on what numbers I look at I'm getting wildly different numbers.
Man, I've spent 20 years with Linux, it's my job for 18 years and I still don't understand fully the memory management in Linux, it's too complex. By the way, memory management in other operating systems is complex too; it’s just that they afford themselves the luxury of lying to the user. But it’s not really a lie - just a rough estimate so as not to confuse the user. Linux, on the other hand, strives for greater precision, which is why it doesn't provide a single number like an OS designed for fools.
If you wanna learn about the detailed memory management, you should read https://www.kernel.org/doc/html/latest/admin-guide/mm/index.html and https://docs.kernel.org/mm/index.html and http://kos.enix.org/pub/linux-vmm.html , but I can assure you that even a lifetime is not enough to fully learn the whole thing.
What I’ve come to realize over the years is that even the Linux kernel itself doesn't know exactly how much memory a given process has allocated—given the existence of kernelspace memory, userspace memory, cache, slab, swap and not to mention compressed swap in ram... The kernel doesn't track them, and every single little memory monitoring utility uses a different estimation method.
There are indeed auditing tools that provide a fairly accurate estimate when run in a virtual environment—but there is a price to pay. The cost is that 60–70% of the CPU is consumed by this monitoring, meaning everything runs at a third of the speed; in exchange, you get more precise data. Well, precisely for the sake of performance, this is not a task performed on a daily basis.
The point is, you have to accept getting absolute values for a process is impossible - much like with an OS designed for "babies," where they’d rather feed the user a made-up estimate than have them learn about the OS's highly complex memory management. By the way, have you ever actually verified whether the figure shown in the task manager on other operating systems is accurate? I’m guessing not; you just believed it blindly. Now you’ve learned that those aren't real values.
8
u/JaKrispy72 Sep 29 '26
He admitted to me, Task Manager doesn’t add up either.
Just let the system do what it needs to do. That’s why we use computers, because it can do calculations faster and more reliable than a human. At some point you just have to let it do what it was designed to do.
It’s not like there was some problem or issue, they just could not understand what the computer was telling them.
31
u/aioeu Sep 29 '26 edited Sep 29 '26
In a practical sense what I care about is how much more memory will be consumed if I launch a service and how much will be freed if I close one?
I'm not sure how anything could know how much RAM a service might use before you start running it...
As for how much will be made available when you stop a process, what you are probably most interested in is something called the "unique set size".
Very few tools actually display the USS. One utility I know of that does provide it is smem.
(Resident set size minus shared memory size, as shown in utilities like top, might be close to the unique set size, but will always underestimate it. The shared memory measurement in these utilities is really "shareable" memory; it might be shareable but still unique to the process.)
Edit: I've just discovered that top does have USS now. I probably should have double-checked that before writing this comment... :-p
-6
u/superSmitty9999 Sep 29 '26
I'm not sure how anything could know how much RAM a service might use before you start running it...
Yeah obviously haha I mean if I kill a process or open it there will be a measurable difference in RAM consumption and that is the value I am after.
I guess really what I don't understand is why are the other OS's completely cable of showing a single number when on here all the other answers require hours of research to even begin to understand.
Very few tools actually display the USD
Yes and I dont understand why not. Seems like a huge UX oversight
24
u/dkopgerpgdolfg Sep 29 '26 edited Sep 29 '26
I guess really what I don't understand is why are the other OS's completely cable of showing a single number
As the other answers already told you, you have the same complexity in Windows. What you see in the default taskmanager is a dumbed-down value that can't be relied on.
If that Windows taskmanager shows 500MB or something, it doesn't mean that exactly 500MB will be "free" (for any kind of free) when you close that process. It might be that, it might be ten times as much, or anything else.
3
u/Conscious-Ball8373 Sep 29 '26
The USS / USD is not the amount of RAM that will be recovered when you close the process. It's the amount of RAM+swap that will be recovered when you close the process if all the shared objects it uses are not used by other processes.
That "simple" number that task manager shows you is also not the amount of RAM that will be recovered when you close the process. You might not have understood that when you looked at it; that just means the lie fooled you.
5
u/ptoki Sep 29 '26
I guess really what I don't understand is why are the other OS's completely cable of showing a single number
Because they lie.
Linux is more honest and shows you the complexity of memory allocation while taskmanager is just telling you "chill bro, its 200MB, go away now" while it is not 200MB.
-16
u/aioeu Sep 29 '26
I guess really what I don't understand is why are the other OS's completely cable of showing a single number when on here all the other answers require hours of research to even begin to understand.
This...
Yes and I dont understand why not. Seems like a huge UX oversight
... and this have the same answer.
Windows provides the information in a way that makes it easy for applications to use, Linux does not, and application developers will usually take the easiest option when given a choice.
6
u/superSmitty9999 Sep 29 '26
Windows provides the information in a way that makes it easy for applications to use, Linux does not
Would you mind elaborating on this? Thank you!
6
u/aioeu Sep 29 '26 edited Sep 29 '26
Well, I might be overstating things a bit.
The Windows API has a direct way to get a process's working set size. I believe that is a USS measurement. I don't know if that's what you see in Task Manager though.
On Linux, this could be derived from
smapswith a bit of calculation, but that becomes rather heavyweight if you need to do it across multiple processes.smaps_rolluphas made things easier, but it's only been around for 9 years.The real problem is that the procfs interface is kind of a terrible way to get all this information. Opening, reading and parsing files is fast on Linux... but it's still a clunky roundabout way to get the data. But this is "the Unix way" apparently...
One thing you've got to remember is that different numbers are useful in different situations. You asked specifically about the amount of memory freed when a process is terminated. I think the USS is the right measurement for that. But USS is not the right measurement when talking about the memory used by processes. You should probably go with PSS ("proportional set size") if you're interested in that, since it behaves correctly when you add it across processes.
So what "one true number" should one of these utilities show?
3
u/silversurger Sep 29 '26
The Windows API has a direct way to get a process's working set size. I believe that is a USS measurement.
The working set size under Windows includes any shared memory. You're looking for the private working set, which you can make visible in task manager. It doesn't show the column by default, but it's available. You still can get that number from an API call (GetProcessMemoryInfo afaik includes "private usage" which is the USS).
The real problem is that the procfs interface is kind of a terrible way to get all this information. Opening, reading and parsing files is fast on Linux... but it's still a clunky roundabout way to get the data. But this is "the Unix way" apparently...
Why is parsing the info from a file more "terrible" or "roundabout" than parsing the info you get from an API call? Isn't it kinda the same thing? I guess I would agree if the API call actually just gave you back the value you're looking for, but that would hold true for file based calls too. And yes, "everything is a file" is one of the core concepts of Unix und Linux.
2
u/aioeu Sep 29 '26 edited Sep 29 '26
Why is parsing the info from a file more "terrible" or "roundabout" than parsing the info you get from an API call?
A lot of CPU cycles to turn numbers calculated by or stored within the kernel into text form, and to have them all parsed back into the original numbers again in the application.
There have been a number of proposals to get process stats out of the kernel in a simpler fashion. Unfortunately the general consensus is usually "yes, that would be good, but that would mean we would have to maintain two different ways to get the data, and we'd prefer to only maintain one". Totally understandable, but rather disappointing.
The one saving grace in all this is that Linux is exceptionally fast at pathname lookup and basic procfs file operations (
getdentsto get PIDs, andopen,read,closeover and over again to get their stats). Nevertheless, on a busy system when you runtopyou might seetopitself using a lot of CPU. In fact, the whole reasonsmaps_rollupwas added was because the Android devs were finding there was too much time spent in parsingsmaps.Personally, I would like to see some
PIDFD_GET_*_STATSioctls on pidfds. We already havePIDFD_GET_INFOto get a variety of ID-related information. In this ioctl, the caller specifies what information in the structure they would like populated, and the kernel only needs to fill those fields out. More ioctls of a similar kind (PIDFD_GET_CPU_STATSandPIDFD_GET_MEM_STATSperhaps?) could be useful.1
u/silversurger Sep 29 '26
A lot of CPU cycles to turn numbers calculated by or stored within the kernel into text form, and to have them all parsed back into the original numbers again in the application.
True. And I just checked, GetProcessMemoryInformation actually returns the pointers to the values for each info block, so you don't have to render it out and parse it again the application, you get direct access to the values by pointers.
Fair enough - thanks for the expanded explanation!
2
u/aioeu Sep 29 '26
And don't get me wrong, I think text interfaces are just fine most of the time.
For instance, I am totally glad Linux dropped the
sysctlsyscall. The only interface to sysctls on Linux is now/proc/sys/. (Compare OpenBSD, for instance, which still uses a syscall.)But that's OK because there aren't too many applications that would want to read sysctls frequently and in bulk.
1
u/ask_compu Sep 29 '26
9 years is ages in the linux world
5
u/aioeu Sep 29 '26 edited Sep 29 '26
Exactly. That was my point.
What could be easier than making use of a nine-year-old feature? How about... not making use of it?
What's weird is that a lot of these tools are already reading
smaps(orsmaps_rollup) to get other stats. If something has the ability to show PSS, then it should also have the ability to show USS, since the data comes from the same file. Even if USS isn't particularly useful most of the time, it would be nice to have it available inhtop.htophas M_PRIV, but that does the RES - SHR approximation I was talking about before.Edit: Ooh, I just noticed that
topdoes have USS now. Well, huzzuh!
8
u/rsgbc Sep 29 '26
Why is finding memory usage on Linux so impossible and confusing?
It isn't. You just need to learn some new things.
0
14
u/Dolapevich Please properly document your questions :) Sep 29 '26
On Windows and Mac the task managers show easy to interpret numbers.
Yeah, but it is conforting somewhat useful and limiting lie. It doesn't discriminate a bunch of different ways in which the OS might have allocated ram.
Edit: Open process explorer to start seeing similar concepts as in linux
7
u/gordonmessmer Fedora Maintainer Sep 29 '26
I think it only seems more complex on Linux because you're being given more specific information.
The tool you're looking for is 'smem'
More info here:
https://gordonmessmer.codeberg.page/dev-blog/2026/08/24/what-ate-my-ram.html
7
u/Abducted_Llama Sep 29 '26 edited Sep 29 '26
TL;DR you bought a development/research box with unified memory (atypical from a normal Linux machine). You have to learn more than the average person on this subreddit will probably know.
Well you are using a system with unified memory, so it’s going to be different than most machines as it is. Plus adding VMs on top of it just complicates it more.
Without the VMs, free -h and Nvidia-smi would probably suffice for most things. Though Nvidia-smi will only show things taking “vram” even though it’s shared. vllm would show up here for trying to gauge loading models.
With loading things into memory like models, there’s not a good way to gauge without* using complex math to gauge kv cache, weights, Max concurrent sessions, etc.
As far as VMs I really don’t know.
And lastly, you bought a specialized development/research box. It isn’t targeted at people new to Linux or are not already fairly tech savvy. They are not designed to be easy, and either are most of the the things you use them for. So you are going to have to get your hands dirty and start learning this stuff.
This isn’t a Linux problem.
ETA: watch -n 1 free -h and watch -n 1 nvidia-smi will also help to watch live if you are loading models.
7
u/Conscious-Ball8373 Sep 29 '26
If other OSs give you a "simple" memory use number, they are lying to you. Memory use numbers are complex because memory use is complex. The three numbers you quote are interesting in different ways:
VIRT is the amount of storage a process has allocated. Some of this will be in RAM, some of it will be in swap. In most cases, most of it will be in swap. Lots of processes load lots of things they don't really need - a process might use one function out of a shared library, but the whole shared library still gets loaded into memory. If you run something in Python, the Python interpreter pre-loads a big pile of its standard libraries but the specific thing you're doing might not use them. So those things get put in swap and left there.
RES is the amount of actual RAM your process is doing - swap is not counted here. That RAM can be shared or it can be process-specific. When Linux loads an executable or a shared library, it first checks to see if it has already loaded that binary and if it has, it reuses to read-only pages from another process rather than duplicating them in memory. So if you add up all the RES memory for all the processes on your system, it will add up to more than the used RAM because there is double-counting going on; each process that uses a shared library will count it as part of that process's RES memory even though it's also used by another process.
SHR is the amount of a process's storage that is shared with other processes. That shared storage might be in RAM or it might be in swap.
That architecture is common to pretty much all desktop OSs today. If they give you a simpler view, they are lying to you about it. I'm not sure how you can give a simpler view without also producing perverse effects. How can you give a simple single number for the amount of memory a process is using?
If you use VIRT, you massively over-estimate a process's impact on RAM because that amount will never be loaded into RAM ever.
If you use RES, you still over-estimate a process's impact on RAM because some of that is shared with other processes; closing the process will only free some of the RES memory - unless it's the last process using the shared objects. Now you might think that you could take that into account - for each shared object, divide its memory use between the processes that are using it. But that would produce bizarre, perverse effects - every time you launch a bash shell, the memory use of all the other ones would reduce a bit. And then as you start closing them, the memory use of all the other ones goes up. The internet would be littered with people asking, "Why does closing one shell make all the other ones use more memory?"
If you use RES - SHR, you will underestimate a process's impact on RAM for the same reason - it might be the last object using a shared object and you won't count that. (This is what USS is.)
Memory is complex and you can't present a simple view of it without significantly distorting it.
1
u/Jawhshuwah Sep 29 '26
This is a really good explanation and has helped me to personally understand memory allocation, hopefully the OP finds it equally as useful
5
u/spider_life Sep 29 '26
free -h
2
u/-Sa-Kage- Sep 29 '26
And look for 'available' instead of 'free'
Because available also lists memory, that has things cached just in case, that could be used for other things though, if needed
4
u/BTC-brother2018 Sep 29 '26
Like the other commentor said type free -h in terminal. For the top 20 processes using most memory use:
ps aux --sort=-%mem | head -20
1
u/Lonely-Medium-2140 Sep 29 '26
Maybe im not understanding what you mean but my task manager app (kde default) shows exactly the ram amount, which for me is around 10gb outbm of 32 total, each program is listed with the ram that it used, what exactly do you want more than that? Its the same as windows
0
u/superSmitty9999 Sep 29 '26
For me the task manager app numbers aren't close to adding up
4
u/Lonely-Medium-2140 Sep 29 '26
Have you tried doing the same on windows? Im pretty sure they dont exactly line up with what the apps claim to use in there too
1
u/psyblade42 Sep 29 '26 edited Sep 29 '26
Could be the unified memory. That's rater unusual. I wouldn't assume all tools know how to deal with it.
EDIT: htop doesn't seem to be able to
3
u/Cyber_Faustao Sep 29 '26
You can do a simple online search, or open any operating systems design book to get the answer. But in short, resident memory is what matters most of the time as it is exclusive to that process
3
u/Original-Active-6982 Sep 29 '26
Windows has the same measurements as Linux (or any other virtual memory system.) You probably didn't see them since Task Manager doesn't show them by default - might confuse those Windows users.
An interesting new cross-platform "Task Manager" has been released by David Plummer (the original author of the Windows version) - TMOG - https://www.tmog.org/. It has a lot of information on your system performance. Enjoy - and learn about computers.
2
u/BranchLatter4294 Sep 29 '26
You can just open the Resources app to see your memory usage. Not impossible or confusing.
2
u/DanKegel Sep 29 '26
Doesn't ps show it? e.g.
# ps aux --sort=-%mem
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mysql 2519 0.2 2.0 2661720 425816 ? Sl Sep28 1:00 //opt/mysql/usr/sbin/mysqld --defaults-file=/opt/mysql/etc/mysql
root 2300 0.0 0.4 1368012 89392 ? Sl Sep28 0:02 mysqld --user root
...
2
u/agmatine Sep 29 '26 edited Sep 29 '26
Additionally, htop doesn't show RAM usage from virtual machines!!
? https://i.imgur.com/hj3lEZt.png
Also, try e.g. cat /proc/meminfo.
2
u/MycologistNeither470 Sep 29 '26
quick summary of memory usage:
>free -mh
if you want to view per process
htop. sort by memory by doing shift + M
you can also get btop to order processes by RAM usage.
regarding htop
virt is the amount of memory the program can potentially use.
res is the amount of memory the program is actually using
shr is the amount of memory that can be potentially be shared with other processes
in reality, you only care about res. That is the memory actually being used.
regarding virtual machines... these would usually appear as the qemu-kvm process. For linux, they are just that - another process. The virt memory is going to be gigantic-- the entire max memory allotted to that vm. Again, what you care about is the res.. what it is actually being used.
3
u/Billy_Twillig Sep 29 '26
Do the work, man. And stop whining.
https://deepwiki.com/NVIDIA/dgx-spark-playbooks/8.3-memory-management
1
1
1
1
1
1
1
u/psyblade42 Sep 29 '26
Additionally, htop doesn't show RAM usage from virtual machines!!
I haven't tested it on DXG-OS but it does show on plain debian. Unless Nvidia went out of their way to remove it it should show there too. Look for processes with qemu or kvm in their command.
1
u/ptoki Sep 29 '26
Windows and mac are lying to you.
They show it in very similar fashion but they call it wrong way so you think they are more understandable.
1
1
u/libben Sep 29 '26
Use BTOP in terminal. Is good.
If you want fancy new stuff that is made by a real autistic programmet that created the windows task manager. He just released tmog. Is free if you want and a paid pro version for some extra small fancy QOL stuff.
works on linux, windows and osv. Get it!
1
u/Thanatiel Sep 29 '26
TL/DR: you only care about resident memory.
In a nutshell ...
The physical memory of your computer is divided into "pages" (e.g. 4KB : let's not get into details here).
Resident is the physical memory usage of a program (the pages it's currently using for itself.)
Shared is the physical memory shared between processes (e.g. the memory containing the code of several libraries is written on pages that can be shared among programs).
Virtual is real-estate to put these pages in. You can ignore it.
There are several process managers showing the RSS/resident memory. e.g. "system monitor"
1
1
u/FedUp233 Sep 29 '26
The other thing here that may be implied in other responses but I didn’t see explicitly mentioned in a quick scan, is shared memory.
Resides all the other issues, real memory, swap space, assigned but not allocated and such, this messes everything up.
In Linux, as in windows and Mac, pretty much every program uses lots of shared libraries. The read only code kart of these only has one copy shared between the processes using that library - how do you want to cpu g this - it’s commonly much larger than the code space used by the actual program executable. And then there is the data part of the memory for these shared libraries. It starts out shared like the code part, but then any pages that are modified get copies made that are owned by the current process, but unmodified pages are still shared. And what pages are modified can be different for different processes Sharing the same library! And it can change over time as the program uses different library functions based on what it is asked to do!
Now include the fact that many programs, particularly daemons, may fork copies of themselves to handle requests as they come in. And that starts off all shared but then each forked process gets its own pages if it modifies them. Do you just count the memory used by one instance, or if not, how many? And since they destroy instances as well when done, the idle usage will be well below that when lots of requests are being processed.
Lots of these things happen in windows and Mac as well, but there no one tends to think about them much I guess - they aren’t as “in your face”.
So I’m not sure how you could really get a number for memory used by a program - that’s why you have swap space so if you need more ram than you have it will start swapping pages out at the cost of performance.
And we haven’t even though of disk caching - do you count the memory used to cache files as part of the I/o buffering? And that can be shared by several processes as well if they open the same file!


25
u/dkopgerpgdolfg Sep 29 '26
As you seem to notice yourself, it isn't just one number in reality, so it matters what exactly you want to look at.
If you start a new process, it can use eg. (not a complete list, and partially overlapping):
just fully own memory allocations in physical RAM (probably the most straightforward part to understand)
overcommit: allocated memory that wasn't yet written to, therefore the OS didn't actually assign any real memory to it
swap usage
allocations that are shared with other processes
mapped disk files (including binary and shared libraries, and any files that the software itself asks for)
tmpfs
mapped memory of hardware
increased pagecache usage because of things it used before (but not anymore), and/or readahead
various metadata inside of the kernel
...
You can run "free -m" and look at the free column. That's quick, easy, and mostly useless to know.