Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I found from command 'top' that 8GB memory are used. However, using command 'ps' with some options to grep the running processes and then summing up the memory used by the running processes are less than 2 GB. Where has the used memory gone ? what command to check this? Thks.
The "used" memory reported by top includes "buffers" and "cached", which are categories of memory use that are not included in any individual process in ps.
The whole topic is more complex than you might expect. But if you want a nearly correct greatly simplified view, you should consider "buffers" and "cached" to be free memory.
So the actual free memory is the sum of what top reports as "free", "buffers" and "cached". The actual used memory is what top reports as "used" minus both "buffers" and "cached"
The free command gives you used and free values both before and after that adjustment. top only gives you the unadjusted values.
Quote:
Originally Posted by a6speedo
using command 'ps' with some options to grep the running processes and then summing up the memory used by the running processes are less than 2 GB.
I expect even that value is more than the actual memory used by your running processes.
If you enable the RSS column in ps and sum that, you will get a value that is at least the total memory use of the processes, but may be significantly more than the total memory use. I don't know anything else you might have summed that wouldn't be even further from correct.
You have the best understanding of Linux memory than anyone I've worked with!
I wonder if you know about the Active memory metric reported from /proc/meminfo
and also vmstat -a. The metrics from top and free line up perfectly - you can see how used - cache - buffers = [actual] used and that number subtracted from Total = the [real] free amount.
I can see that the Inactive number from /proc/meminfo and vmstat -a map to Buffer amount, but I have tried every combination I can think of and still do not see what the Active number is derived from. Does it include cache ? How is it used ? I've been told that one can use free, top, /proc/meminfo, or vmstat and get the same results, but that does not appear to be quite true.
What am I missing ?????????
Really appreciate your time and expertise!
Thanks.
Active and inactive are merely classifications the memory manager code uses to determine suitability of pages for reclaim. Recently referenced pages stay on the "active" queue. After a (essentially indeterminate) period of non-reference, they migrate to the inactive q, where they are amongst the first considered for reclaim.
Trying to be exact with memory allocation is a waste of time - too many unknown variables. I would expect active pus inactive (including anon a+i) plus slab should approximate the total non page-cache in use on a "quiet" system.
It is possible for pages no longer allocated to remain on any of those queues even after the owning process has terminated. There is no way to account for those that I know of (in userspace).
Thank you both for responding so quickly, especially considering it's a weekend!
I've been on other Q&A sites where questions never get a response - so thanks again.
I did a top, free, cat /proc/meminfo, and vmstat -a on a relatively quiet(right now) Linux machine right before my post. Here's pertinent output:
--------------------------------------------------------------------------------
bl460-5:$ top
-----------------------------------------------------------------------------------
bl460-5:$ vmstat 1 2 -a
r b swpd free inact active si so bi bo in cs us sy id wa st
0 0 0 10887316 646908 4941476 0 0 0 1 0 0 0 0 100 0 0
0 0 0 10887316 646904 4941480 0 0 0 20 1012 43 0 0 100 0 0
johnsfine, the top and /proc/meminfo Buffers number looked so close to the vmstat
inact number, that I was thinking it reflected the same thing. Not so ?
sysg00, thanks for admonition about a B-A-C-K-U-P. I ALWAYS take a backup before
ANY changes, and test changes on a machine that's not being used. It only takes one time of being burned to teach you that lesson (I was indeed once burned).
What we're really trying to determine is which number to report for the amount of
memory that was used during the benchmark of an application ? As I mentioned, several people have said that ALL the measurement tools (top, free, etc)
source the information they report from the same "place", and that /proc/meminfo
is the most reliable. Since the Active number from /proc/meminfo and vmstat
are a little different, it's not clear what the most accurate, "best" number
is to report.
Sorry this is so long, guys. Appreciate your help and interest.
Hope I can return the favor down the line.
...the top and /proc/meminfo Buffers number looked so close to the vmstat inact number, that I was thinking it reflected the same thing. Not so ?
coincidence.
Quote:
What we're really trying to determine is which number to report for the amount of memory that was used during the benchmark of an application ?
Using system-wide metrics to infer the usage by a single process (and children ?) would seem especially unpredictable - and unrepeatable.
Quote:
As I mentioned, several people have said that ALL the measurement tools (top, free, etc) source the information they report from the same "place", and that /proc/meminfo is the most reliable. Since the Active number from /proc/meminfo and vmstat are a little different, it's not clear what the most accurate, "best" number is to report.
All these numbers are sampled from /proc/xxx
That means they are read at different times - each are as "correct" as any other. For that instant in time.
I would be inclined to use /proc/meminfo for the system-wide numbers, and /proc/<pid>/{stat,statm,status,smaps} for the process depending on what data format you need. You'll have to sample these yourself, or use something like sysstat or collectl.
Again these are only samples, so are not necessarily reproducable, or applicable to different environments.
Edit: if getrusage was fully implemented in Linux, the GNU time command would fit this requirement beautifully.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.