Commit b40d4f84 authored by Nikanth Karthikesan's avatar Nikanth Karthikesan Committed by Linus Torvalds

/proc/pid/smaps: export amount of anonymous memory in a mapping

Export the number of anonymous pages in a mapping via smaps.

Even the private pages in a mapping backed by a file, would be marked as
anonymous, when they are modified. Export this information to user-space via
smaps.

Exporting this count will help gdb to make a better decision on which
areas need to be dumped in its coredump; and should be useful to others
studying the memory usage of a process.
Signed-off-by: default avatarNikanth Karthikesan <knikanth@suse.de>
Acked-by: default avatarHugh Dickins <hughd@google.com>
Reviewed-by: default avatarKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Matt Mackall <mpm@selenic.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d16e15f5
...@@ -370,6 +370,7 @@ Shared_Dirty: 0 kB ...@@ -370,6 +370,7 @@ Shared_Dirty: 0 kB
Private_Clean: 0 kB Private_Clean: 0 kB
Private_Dirty: 0 kB Private_Dirty: 0 kB
Referenced: 892 kB Referenced: 892 kB
Anonymous: 0 kB
Swap: 0 kB Swap: 0 kB
KernelPageSize: 4 kB KernelPageSize: 4 kB
MMUPageSize: 4 kB MMUPageSize: 4 kB
...@@ -378,9 +379,15 @@ The first of these lines shows the same information as is displayed for the ...@@ -378,9 +379,15 @@ The first of these lines shows the same information as is displayed for the
mapping in /proc/PID/maps. The remaining lines show the size of the mapping mapping in /proc/PID/maps. The remaining lines show the size of the mapping
(size), the amount of the mapping that is currently resident in RAM (RSS), the (size), the amount of the mapping that is currently resident in RAM (RSS), the
process' proportional share of this mapping (PSS), the number of clean and process' proportional share of this mapping (PSS), the number of clean and
dirty shared pages in the mapping, and the number of clean and dirty private dirty private pages in the mapping. Note that even a page which is part of a
pages in the mapping. The "Referenced" indicates the amount of memory MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used
currently marked as referenced or accessed. by only one process, is accounted as private and not as shared. "Referenced"
indicates the amount of memory currently marked as referenced or accessed.
"Anonymous" shows the amount of memory that does not belong to any file. Even
a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE
and a page is modified, the file page is replaced by a private anonymous copy.
"Swap" shows how much would-be-anonymous memory is also used, but out on
swap.
This file is only present if the CONFIG_MMU kernel configuration option is This file is only present if the CONFIG_MMU kernel configuration option is
enabled. enabled.
......
...@@ -327,6 +327,7 @@ struct mem_size_stats { ...@@ -327,6 +327,7 @@ struct mem_size_stats {
unsigned long private_clean; unsigned long private_clean;
unsigned long private_dirty; unsigned long private_dirty;
unsigned long referenced; unsigned long referenced;
unsigned long anonymous;
unsigned long swap; unsigned long swap;
u64 pss; u64 pss;
}; };
...@@ -357,6 +358,9 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, ...@@ -357,6 +358,9 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
if (!page) if (!page)
continue; continue;
if (PageAnon(page))
mss->anonymous += PAGE_SIZE;
mss->resident += PAGE_SIZE; mss->resident += PAGE_SIZE;
/* Accumulate the size in pages that have been accessed. */ /* Accumulate the size in pages that have been accessed. */
if (pte_young(ptent) || PageReferenced(page)) if (pte_young(ptent) || PageReferenced(page))
...@@ -410,6 +414,7 @@ static int show_smap(struct seq_file *m, void *v) ...@@ -410,6 +414,7 @@ static int show_smap(struct seq_file *m, void *v)
"Private_Clean: %8lu kB\n" "Private_Clean: %8lu kB\n"
"Private_Dirty: %8lu kB\n" "Private_Dirty: %8lu kB\n"
"Referenced: %8lu kB\n" "Referenced: %8lu kB\n"
"Anonymous: %8lu kB\n"
"Swap: %8lu kB\n" "Swap: %8lu kB\n"
"KernelPageSize: %8lu kB\n" "KernelPageSize: %8lu kB\n"
"MMUPageSize: %8lu kB\n", "MMUPageSize: %8lu kB\n",
...@@ -421,6 +426,7 @@ static int show_smap(struct seq_file *m, void *v) ...@@ -421,6 +426,7 @@ static int show_smap(struct seq_file *m, void *v)
mss.private_clean >> 10, mss.private_clean >> 10,
mss.private_dirty >> 10, mss.private_dirty >> 10,
mss.referenced >> 10, mss.referenced >> 10,
mss.anonymous >> 10,
mss.swap >> 10, mss.swap >> 10,
vma_kernel_pagesize(vma) >> 10, vma_kernel_pagesize(vma) >> 10,
vma_mmu_pagesize(vma) >> 10); vma_mmu_pagesize(vma) >> 10);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment