aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoonsoo Kim <iamjoonsoo.kim@lge.com>2014-12-12 19:56:01 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-13 15:42:48 -0500
commit48c96a3685795e52903e60c7ee115e5e22e7d640 (patch)
tree49940b1971c9b487a52b2c91b2423eee9278ced5
parent9a92a6ce6f842713ccd0025c5228fe8bea61234c (diff)
mm/page_owner: keep track of page owners
This is the page owner tracking code which is introduced so far ago. It is resident on Andrew's tree, though, nobody tried to upstream so it remain as is. Our company uses this feature actively to debug memory leak or to find a memory hogger so I decide to upstream this feature. This functionality help us to know who allocates the page. When allocating a page, we store some information about allocation in extra memory. Later, if we need to know status of all pages, we can get and analyze it from this stored information. In previous version of this feature, extra memory is statically defined in struct page, but, in this version, extra memory is allocated outside of struct page. It enables us to turn on/off this feature at boottime without considerable memory waste. Although we already have tracepoint for tracing page allocation/free, using it to analyze page owner is rather complex. We need to enlarge the trace buffer for preventing overlapping until userspace program launched. And, launched program continually dump out the trace buffer for later analysis and it would change system behaviour with more possibility rather than just keeping it in memory, so bad for debug. Moreover, we can use page_owner feature further for various purposes. For example, we can use it for fragmentation statistics implemented in this patch. And, I also plan to implement some CMA failure debugging feature using this interface. I'd like to give the credit for all developers contributed this feature, but, it's not easy because I don't know exact history. Sorry about that. Below is people who has "Signed-off-by" in the patches in Andrew's tree. Contributor: Alexander Nyberg <alexn@dsv.su.se> Mel Gorman <mgorman@suse.de> Dave Hansen <dave@linux.vnet.ibm.com> Minchan Kim <minchan@kernel.org> Michal Nazarewicz <mina86@mina86.com> Andrew Morton <akpm@linux-foundation.org> Jungsoo Son <jungsoo.son@lge.com> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Dave Hansen <dave@sr71.net> Cc: Michal Nazarewicz <mina86@mina86.com> Cc: Jungsoo Son <jungsoo.son@lge.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--Documentation/kernel-parameters.txt6
-rw-r--r--include/linux/page_ext.h10
-rw-r--r--include/linux/page_owner.h38
-rw-r--r--lib/Kconfig.debug16
-rw-r--r--mm/Makefile1
-rw-r--r--mm/page_alloc.c11
-rw-r--r--mm/page_ext.c4
-rw-r--r--mm/page_owner.c222
-rw-r--r--mm/vmstat.c101
-rw-r--r--tools/vm/Makefile4
-rw-r--r--tools/vm/page_owner_sort.c144
11 files changed, 554 insertions, 3 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 6f067954675b..68153642c44e 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2513,6 +2513,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
2513 OSS [HW,OSS] 2513 OSS [HW,OSS]
2514 See Documentation/sound/oss/oss-parameters.txt 2514 See Documentation/sound/oss/oss-parameters.txt
2515 2515
2516 page_owner= [KNL] Boot-time page_owner enabling option.
2517 Storage of the information about who allocated
2518 each page is disabled in default. With this switch,
2519 we can turn it on.
2520 on: enable the feature
2521
2516 panic= [KNL] Kernel behaviour on panic: delay <timeout> 2522 panic= [KNL] Kernel behaviour on panic: delay <timeout>
2517 timeout > 0: seconds before rebooting 2523 timeout > 0: seconds before rebooting
2518 timeout = 0: wait forever 2524 timeout = 0: wait forever
diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h
index 61c0f05f9069..d2a2c84c72d0 100644
--- a/include/linux/page_ext.h
+++ b/include/linux/page_ext.h
@@ -1,6 +1,9 @@
1#ifndef __LINUX_PAGE_EXT_H 1#ifndef __LINUX_PAGE_EXT_H
2#define __LINUX_PAGE_EXT_H 2#define __LINUX_PAGE_EXT_H
3 3
4#include <linux/types.h>
5#include <linux/stacktrace.h>
6
4struct pglist_data; 7struct pglist_data;
5struct page_ext_operations { 8struct page_ext_operations {
6 bool (*need)(void); 9 bool (*need)(void);
@@ -22,6 +25,7 @@ struct page_ext_operations {
22enum page_ext_flags { 25enum page_ext_flags {
23 PAGE_EXT_DEBUG_POISON, /* Page is poisoned */ 26 PAGE_EXT_DEBUG_POISON, /* Page is poisoned */
24 PAGE_EXT_DEBUG_GUARD, 27 PAGE_EXT_DEBUG_GUARD,
28 PAGE_EXT_OWNER,
25}; 29};
26 30
27/* 31/*
@@ -33,6 +37,12 @@ enum page_ext_flags {
33 */ 37 */
34struct page_ext { 38struct page_ext {
35 unsigned long flags; 39 unsigned long flags;
40#ifdef CONFIG_PAGE_OWNER
41 unsigned int order;
42 gfp_t gfp_mask;
43 struct stack_trace trace;
44 unsigned long trace_entries[8];
45#endif
36}; 46};
37 47
38extern void pgdat_page_ext_init(struct pglist_data *pgdat); 48extern void pgdat_page_ext_init(struct pglist_data *pgdat);
diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h
new file mode 100644
index 000000000000..b48c3471c254
--- /dev/null
+++ b/include/linux/page_owner.h
@@ -0,0 +1,38 @@
1#ifndef __LINUX_PAGE_OWNER_H
2#define __LINUX_PAGE_OWNER_H
3
4#ifdef CONFIG_PAGE_OWNER
5extern bool page_owner_inited;
6extern struct page_ext_operations page_owner_ops;
7
8extern void __reset_page_owner(struct page *page, unsigned int order);
9extern void __set_page_owner(struct page *page,
10 unsigned int order, gfp_t gfp_mask);
11
12static inline void reset_page_owner(struct page *page, unsigned int order)
13{
14 if (likely(!page_owner_inited))
15 return;
16
17 __reset_page_owner(page, order);
18}
19
20static inline void set_page_owner(struct page *page,
21 unsigned int order, gfp_t gfp_mask)
22{
23 if (likely(!page_owner_inited))
24 return;
25
26 __set_page_owner(page, order, gfp_mask);
27}
28#else
29static inline void reset_page_owner(struct page *page, unsigned int order)
30{
31}
32static inline void set_page_owner(struct page *page,
33 unsigned int order, gfp_t gfp_mask)
34{
35}
36
37#endif /* CONFIG_PAGE_OWNER */
38#endif /* __LINUX_PAGE_OWNER_H */
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index d780351835e9..5f2ce616c046 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -227,6 +227,22 @@ config UNUSED_SYMBOLS
227 you really need it, and what the merge plan to the mainline kernel for 227 you really need it, and what the merge plan to the mainline kernel for
228 your module is. 228 your module is.
229 229
230config PAGE_OWNER
231 bool "Track page owner"
232 depends on DEBUG_KERNEL && STACKTRACE_SUPPORT
233 select DEBUG_FS
234 select STACKTRACE
235 select PAGE_EXTENSION
236 help
237 This keeps track of what call chain is the owner of a page, may
238 help to find bare alloc_page(s) leaks. Even if you include this
239 feature on your build, it is disabled in default. You should pass
240 "page_owner=on" to boot parameter in order to enable it. Eats
241 a fair amount of memory if enabled. See tools/vm/page_owner_sort.c
242 for user-space helper.
243
244 If unsure, say N.
245
230config DEBUG_FS 246config DEBUG_FS
231 bool "Debug Filesystem" 247 bool "Debug Filesystem"
232 help 248 help
diff --git a/mm/Makefile b/mm/Makefile
index 580cd3f392af..4bf586e66378 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o
63obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o 63obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o
64obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o 64obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o
65obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o 65obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
66obj-$(CONFIG_PAGE_OWNER) += page_owner.o
66obj-$(CONFIG_CLEANCACHE) += cleancache.o 67obj-$(CONFIG_CLEANCACHE) += cleancache.o
67obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o 68obj-$(CONFIG_MEMORY_ISOLATION) += page_isolation.o
68obj-$(CONFIG_ZPOOL) += zpool.o 69obj-$(CONFIG_ZPOOL) += zpool.o
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 303d38516807..c13b6b29add2 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -59,6 +59,7 @@
59#include <linux/page_ext.h> 59#include <linux/page_ext.h>
60#include <linux/hugetlb.h> 60#include <linux/hugetlb.h>
61#include <linux/sched/rt.h> 61#include <linux/sched/rt.h>
62#include <linux/page_owner.h>
62 63
63#include <asm/sections.h> 64#include <asm/sections.h>
64#include <asm/tlbflush.h> 65#include <asm/tlbflush.h>
@@ -813,6 +814,8 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
813 if (bad) 814 if (bad)
814 return false; 815 return false;
815 816
817 reset_page_owner(page, order);
818
816 if (!PageHighMem(page)) { 819 if (!PageHighMem(page)) {
817 debug_check_no_locks_freed(page_address(page), 820 debug_check_no_locks_freed(page_address(page),
818 PAGE_SIZE << order); 821 PAGE_SIZE << order);
@@ -988,6 +991,8 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
988 if (order && (gfp_flags & __GFP_COMP)) 991 if (order && (gfp_flags & __GFP_COMP))
989 prep_compound_page(page, order); 992 prep_compound_page(page, order);
990 993
994 set_page_owner(page, order, gfp_flags);
995
991 return 0; 996 return 0;
992} 997}
993 998
@@ -1560,8 +1565,11 @@ void split_page(struct page *page, unsigned int order)
1560 split_page(virt_to_page(page[0].shadow), order); 1565 split_page(virt_to_page(page[0].shadow), order);
1561#endif 1566#endif
1562