mm/page_owner.c: remove unnecessary stack_trace field
authorSergei Rogachev <rogachevsergei@gmail.com>
Wed, 11 Feb 2015 23:28:34 +0000 (15:28 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 12 Feb 2015 01:06:07 +0000 (17:06 -0800)
Page owner uses the page_ext structure to keep meta-information for every
page in the system.  The structure also contains a field of type 'struct
stack_trace', page owner uses this field during invocation of the function
save_stack_trace.  It is easy to notice that keeping a copy of this
structure for every page in the system is very inefficiently in terms of
memory.

The patch removes this unnecessary field of page_ext and forces page owner
to use a stack_trace structure allocated on the stack.

[akpm@linux-foundation.org: use struct initializers]
Signed-off-by: Sergei Rogachev <rogachevsergei@gmail.com>
Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/page_ext.h
mm/page_owner.c

index d2a2c84c72d04aa7a7b993be3c40df100015790e..c42981cd99aae91b33d21a0deb4bc9f925a7fbd1 100644 (file)
@@ -40,7 +40,7 @@ struct page_ext {
 #ifdef CONFIG_PAGE_OWNER
        unsigned int order;
        gfp_t gfp_mask;
-       struct stack_trace trace;
+       unsigned int nr_entries;
        unsigned long trace_entries[8];
 #endif
 };
index 9ab4a9b5bc091b80915850038d4d3f04eb331ee1..0993f5f36b011ec567e3b559f50bb4dafde90479 100644 (file)
@@ -59,20 +59,19 @@ void __reset_page_owner(struct page *page, unsigned int order)
 
 void __set_page_owner(struct page *page, unsigned int order, gfp_t gfp_mask)
 {
-       struct page_ext *page_ext;
-       struct stack_trace *trace;
-
-       page_ext = lookup_page_ext(page);
+       struct page_ext *page_ext = lookup_page_ext(page);
+       struct stack_trace trace = {
+               .nr_entries = 0,
+               .max_entries = ARRAY_SIZE(page_ext->trace_entries),
+               .entries = &page_ext->trace_entries[0],
+               .skip = 3,
+       };
 
-       trace = &page_ext->trace;
-       trace->nr_entries = 0;
-       trace->max_entries = ARRAY_SIZE(page_ext->trace_entries);
-       trace->entries = &page_ext->trace_entries[0];
-       trace->skip = 3;
-       save_stack_trace(&page_ext->trace);
+       save_stack_trace(&trace);
 
        page_ext->order = order;
        page_ext->gfp_mask = gfp_mask;
+       page_ext->nr_entries = trace.nr_entries;
 
        __set_bit(PAGE_EXT_OWNER, &page_ext->flags);
 }
@@ -84,6 +83,10 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
        int ret;
        int pageblock_mt, page_mt;
        char *kbuf;
+       struct stack_trace trace = {
+               .nr_entries = page_ext->nr_entries,
+               .entries = &page_ext->trace_entries[0],
+       };
 
        kbuf = kmalloc(count, GFP_KERNEL);
        if (!kbuf)
@@ -121,8 +124,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
        if (ret >= count)
                goto err;
 
-       ret += snprint_stack_trace(kbuf + ret, count - ret,
-                                       &page_ext->trace, 0);
+       ret += snprint_stack_trace(kbuf + ret, count - ret, &trace, 0);
        if (ret >= count)
                goto err;