I do face the same hangs like this post: https://askubuntu.com/questions/41778/computer-freezing-on-almost-full-ram-possibly-disk-cache-problem

To sums up: looks like prefetched/cached/paged RAM reclaiming takes too long, so I live in constant fear that the disk makes insane disk readings to the point that the PC hangs and forces me to reboot.

So I've digged more into this problem and got that useful command :

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

Which do drop the prefetched RAM... up to a point since there's still some left, which seems to be a "static" part.

I've noticed that adding this to the prefetchless RAM usage matches top's used RAM.

However, this doesn't tell me how much "static" prefetched RAM I'm using. And knowing this will let me give enough time to Linux's paged cache offloading to do its job when I'll be about to reach the total RAM count.

E.g: Cache was ~1000 MiB, then got to ~700 MiB after doing "echo 3 | sudo tee /proc/sys/vm/drop_caches"; the ~700 MiB are the "static" part of the prefetched RAM that I need to know.

So my question is: How do you get the -real- "static" part of the Prefetched/Cached/Paged RAM usage ?


On the other hand, is there a way to only output the total RAM used by every processes -even root's ones- (like htop's mem value) ?


You can find the RAM used by every process for all users with the following command:

ps -eo pid,command,rss,user

That gives, in order, the process id, command, the memory used, and the user of the process.

If you want the total amount of RAM being used by all of the processes, the the following command will work


If you want a SUM of the memory being used by every process, use the following code:

ps -eo rss | awk '{sum+=$1} END {print sum}'

That will give you a value which is the total amount of memory being used by all of the processes.

  • Doh, sorry if I wasn't clear. By "all the RAM", I meant the total RAM used by every processes. – X.LINK Jan 12 '18 at 17:58
  • 1
    See my edit above – Nasir Riley Jan 12 '18 at 19:25
  • It did showed the total amount, but there's other outputs too. I could grep that, but I need a single -and only- output so I can do some repeating math without using too much resources. What's more apriopriate would be how free get that value internally, but I unfortunately don't know how to code. So there must be another way to get such numbers. – X.LINK Jan 12 '18 at 21:10
  • 1
    I have added another edit. – Nasir Riley Jan 12 '18 at 21:39
  • I'll be damned, by replacing "%mem" by "rss" you've got me on the right path for the whole answer. What the RSS total shows is the real memory usage without the "dynamic" part of prefetched RAM, and neither top's "used" or neither htop's RAM nonsense values ! Thanks ! – X.LINK Jan 13 '18 at 5:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.