linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>, Michal Hocko <mhocko@suse.com>,
	Mel Gorman <mgorman@techsingularity.net>,
	Johannes Weiner <hannes@cmpxchg.org>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Hugh Dickins <hughd@google.com>,
	David Rientjes <rientjes@google.com>
Subject: [RFC] fs/proc/meminfo: introduce Unaccounted statistic
Date: Thu, 20 Oct 2016 14:11:49 +0200	[thread overview]
Message-ID: <20161020121149.9935-1-vbabka@suse.cz> (raw)

The /proc/meminfo virtual file is a collection of various system-wide memory
usage statistics. One of the use cases for looking at the output is to see
whether the kernel might be leaking memory by direct allocations that are not
counted among any of the statistics. This is hovewer not immediately obvious,
because some fields are meant to add up to the MemTotal value, and others not.
Subtle changes also happen over time, e.g. the AnonPages field started
including THP's since commit 3cd14fcd3f12 ("thp: account anon transparent
huge pages into NR_ANON_PAGES") and the Cached field used to include hugetlb
until commit 4165b9b46181 ("hugetlb: do not account hugetlb pages as
NR_FILE_PAGES").

To make kernel memory leaks more obvious, this patch adds an Unaccounted field
whose value is calculated by subtracting a sum of fields that are supposed to
add up to MemTotal without overlap, from the MeTotal value. This should also
help anyone looking at the code to determine these fields easily.

Not-yet-signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: David Rientjes <rientjes@google.com>
---
Hi, I'm wondering if people would find this useful. If you think it is, and
to not make performance worse, I could also make sure in proper submission
that values are not read via global_page_state() multiple times etc...

 fs/proc/meminfo.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 8a428498d6b2..3fcd71d4d805 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -48,6 +48,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 	unsigned long committed;
 	long cached;
 	long available;
+	long unaccounted;
 	unsigned long pages[NR_LRU_LISTS];
 	int lru;
 
@@ -65,6 +66,18 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 
 	available = si_mem_available();
 
+	unaccounted = i.totalram - i.freeram
+			- global_node_page_state(NR_ANON_MAPPED)
+			- global_node_page_state(NR_FILE_PAGES)
+			- global_page_state(NR_PAGETABLE)
+			- global_page_state(NR_SLAB_RECLAIMABLE)
+			- global_page_state(NR_SLAB_UNRECLAIMABLE)
+			- (global_page_state(NR_KERNEL_STACK_KB)
+							>> (PAGE_SHIFT - 10))
+			- global_page_state(NR_BOUNCE)
+			- global_node_page_state(NR_WRITEBACK_TEMP)
+			- hugetlb_total_pages();
+
 	show_val_kb(m, "MemTotal:       ", i.totalram);
 	show_val_kb(m, "MemFree:        ", i.freeram);
 	show_val_kb(m, "MemAvailable:   ", available);
@@ -119,6 +132,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 		    global_page_state(NR_PAGETABLE));
 #ifdef CONFIG_QUICKLIST
 	show_val_kb(m, "Quicklists:     ", quicklist_total_size());
+	unaccounted -= quicklist_total_size();
 #endif
 
 	show_val_kb(m, "NFS_Unstable:   ",
@@ -156,6 +170,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 
 	hugetlb_report_meminfo(m);
 
+	if (unaccounted < 0)
+		unaccounted = 0;
+	show_val_kb(m, "Unaccounted:    ", unaccounted);
+
 	arch_report_meminfo(m);
 
 	return 0;
-- 
2.10.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2016-10-20 12:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-20 12:11 Vlastimil Babka [this message]
2016-10-20 13:33 ` [RFC] fs/proc/meminfo: introduce Unaccounted statistic Michal Hocko
2016-10-20 22:59   ` Dave Chinner
2016-10-21  7:25     ` Vlastimil Babka
2016-10-21 11:17       ` Dave Chinner
2016-10-21  7:36     ` Michal Hocko
2016-10-21  7:31   ` Vlastimil Babka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161020121149.9935-1-vbabka@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=rientjes@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).