Both sides previous revisionPrevious revisionNext revision | Previous revision |
proc:pagemap_file [2017/04/06 10:27] – peter | proc:pagemap_file [2020/07/15 09:30] (current) – external edit 127.0.0.1 |
---|
The general procedure for using pagemap to find out about a process' memory usage goes like this: | The general procedure for using pagemap to find out about a process' memory usage goes like this: |
| |
1. Read /proc/pid/maps to determine which parts of the memory space are mapped to what. | - Read /proc/pid/maps to determine which parts of the memory space are mapped to what. |
2. Select the maps you are interested in -- all of them, or a particular library, or the stack or the heap, etc. | - Select the maps you are interested in -- all of them, or a particular library, or the stack or the heap, etc. |
3. Open /proc/pid/pagemap and seek to the pages you would like to examine. | - Open /proc/pid/pagemap and seek to the pages you would like to examine. |
4. Read a u64 for each page from pagemap. | - Read a u64 for each page from pagemap. |
5. Open /proc/kpagecount and/or /proc/kpageflags. For each PFN you just read, seek to that entry in the file, and read the data you want. | - Open /proc/kpagecount and/or /proc/kpageflags. For each PFN you just read, seek to that entry in the file, and read the data you want. |
| |
For example, to find the "unique set size" (USS), which is the amount of memory that a process is using that is not shared with any other process, you can go through every map in the process, find the PFNs, look those up in kpagecount, and tally up the number of pages that are only referenced once. | For example, to find the "unique set size" (USS), which is the amount of memory that a process is using that is not shared with any other process, you can go through every map in the process, find the PFNs, look those up in kpagecount, and tally up the number of pages that are only referenced once. |