WhatIsMemoryUsage written at 01:48:06; Add Comment
What do we mean when we talk about something's memory usage?
One of the problems is that the question being asked here is not well defined. There are several things that this question could mean (talking only about a single process in order to simplify life):
(Each of these questions is useful and interesting in certain situations.)
What makes most of these questions difficult and complicated is memory that's shared between processes. If there was no memory sharing (or only negligible memory sharing) then several of the questions would collapse together and it would be easy for the operating system to give useful answers to most of them. Unfortunately for Robert Haas, modern Unix systems and modern applications share significant amounts of memory in many circumstances.
(To be fair, properly accounting for shared memory usage has bedeviled
Unix from the moment people implemented copy on write for
There are theoretically straightforward extensions of all of these questions to groups of processes. For things like 'how much RAM would be freed up if they all exited', you have to work out what RAM or virtual memory is shared only between all of the processes versus what RAM is also (partially) shared with outside processes. RAM used only within the group gets entirely charged to the group; RAM also shared outside the group may need to be handled in various ways depending on the specific question you're asking.
(Correctly and usefully grouping processes together is also often not a completely trivial issue. What processes should be considered to be 'your web server' or 'your database server' is often something that's obvious to an experienced human but not necessarily something that's clear to a computer in any useful way. Even when you can come up with an acceptable mechanical definition of a group, groups can easily overlap or be supersets of each other; consider the groups of 'all processes executing this binary' and 'all processes descending from pid <X>'.)
By the way: you may need very low-level access to page table information in order to get correct answers to these questions for groups of processes. If the system provides information on who has what memory areas mapped it's relatively easy to detect entire memory areas that are only shared within a group (eg, all of the database server processes are the only users of a common shared memory segment). But to detect the case where some area of a broadly-shared object is only used by your group of processes, you need detailed per-page information.
(For instance, your database server processes might be the only users of a set of functions and data tables in the base C++ support library, although lots of other processes also have the library mapped.)
* * *
Atom feeds are available; see the bottom of most pages.