Reduce memory waste by page extension user
Subsystems (3)
v2 cover Reduce memory waste by page extension user
From: Joonsoo Kim <[email protected]>
v2:
Fix rebase mistake (per Vlastimil)
Rename some variable/function to prevent confusion (per Vlastimil) Fix header dependency (per Sergey)
This patchset tries to reduce memory waste by page extension user.
First case is architecture supported debug_pagealloc. It doesn't requires additional memory if guard page isn't used. 8 bytes per page will be saved in this case.
Second case is related to page owner feature. Until now, if page_ext users want to use it's own fields on page_ext, fields should be defined in struct page_ext by hard-coding. It has a following problem.
struct page_ext {
#ifdef CONFIG_A int a; #endif #ifdef CONFIG_B int b;
#endif
};
Assume that kernel is built with both CONFIG_A and CONFIG_B. Even if we enable feature A and doesn't enable feature B at runtime, each entry of struct page_ext takes two int rather than one int. It's undesirable waste so this patch tries to reduce it. By this patchset, we can save 20 bytes per page dedicated for page owner feature in some configurations.
Thanks.
Joonsoo Kim (6):
mm/debug_pagealloc: clean-up guard page handling code mm/debug_pagealloc: don't allocate page_ext if we don't use guard page mm/page_owner: move page_owner specific function to page_owner.c mm/page_ext: rename offset to index
mm/page_ext: support extra space allocation by page_ext user mm/page_owner: don't define fields on struct page_ext by hard-coding
include/linux/page_ext.h | 8 +-- include/linux/page_owner.h | 2 + mm/page_alloc.c | 44 +++++++------ mm/page_ext.c | 45 +++++++++---- mm/page_owner.c | 156 ++++++++++++++++++++++++++++++++++++++------- mm/vmstat.c | 79 ----------------------- 6 files changed, 196 insertions(+), 138 deletions(-)
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 1/6 mm/debug_pagealloc: clean-up guard page handling code
From: Joonsoo Kim <[email protected]>
We can make code clean by moving decision condition for set_page_guard() into set_page_guard() itself. It will help code readability. There is no functional change.
--- mm/page_alloc.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
mm/page_alloc.c +18 -16
@@ -638,17 +638,20 @@ static int __init debug_guardpage_minorder_setup(char *buf) }__setup ("debug_guardpage_minorder=" , debug_guardpage_minorder_setup); -static inline void set_page_guard (struct zone *zone,struct page *page, +static inline bool set_page_guard (struct zone *zone,struct page *page,unsigned int order,int migratetype) {struct page_ext *page_ext;if (!debug_guardpage_enabled ()) -return ; +return false; + +if (order >=debug_guardpage_minorder ()) +return false; page_ext =lookup_page_ext (page);if (unlikely (!page_ext)) -return ; +return false;__set_bit (PAGE_EXT_DEBUG_GUARD , &page_ext->flags);
@@ -656,6 +659,8 @@ static inline void set_page_guard(struct zone *zone, struct page *page,set_page_private (page, order);/* Guard pages are not available for any usage */ __mod_zone_freepage_state (zone, -(1 << order), migratetype); + +return true; } static inline void clear_page_guard(struct zone *zone, struct page *page,
@@ -678,8 +683,8 @@ static inline void clear_page_guard(struct zone *zone, struct page *page, }#else struct page_ext_operations debug_guardpage_ops = {NULL , }; -static inline void set_page_guard (struct zone *zone,struct page *page, -unsigned int order,int migratetype) {} +static inline bool set_page_guard (struct zone *zone,struct page *page, +unsigned int order,int migratetype) {return false; }static inline void clear_page_guard (struct zone *zone,struct page *page,unsigned int order,int migratetype) {}#endif
@@ -1650,18 +1655,15 @@ static inline void expand(struct zone *zone, struct page *page, size >>=1 ;VM_BUG_ON_PAGE (bad_range (zone, &page[size]), &page[size]); -if (IS_ENABLED (CONFIG_DEBUG_PAGEALLOC ) && -debug_guardpage_enabled () && - high <debug_guardpage_minorder ()) { -/* -* Mark as guard pages (or page), that will allow to -* merge back to allocator when buddy will be freed. -* Corresponding page table entries will not be touched, -* pages will stay not present in virtual address space -*/ -set_page_guard (zone, &page[size], high, migratetype); +/* +* Mark as guard pages (or page), that will allow to +* merge back to allocator when buddy will be freed. +* Corresponding page table entries will not be touched, +* pages will stay not present in virtual address space +*/ +if (set_page_guard (zone, &page[size], high, migratetype))continue ; - } +list_add (&page[size].lru, &area->free_list[migratetype]); area->nr_free++;set_page_order (&page[size], high);
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 2/6 mm/debug_pagealloc: don't allocate page_ext if we don't use guard page
In reply to [email protected]From: Joonsoo Kim <[email protected]>
What debug_pagealloc does is just mapping/unmapping page table. Basically, it doesn't need additional memory space to memorize something. But, with guard page feature, it requires additional memory to distinguish if the page is for guard or not. Guard page is only used when debug_guardpage_minorder is non-zero so this patch removes additional memory allocation (page_ext) if debug_guardpage_minorder is zero.
It saves memory if we just use debug_pagealloc and not guard page.
--- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
mm/page_alloc.c +7 -1
@@ -608,6 +608,9 @@ static bool need_debug_guardpage(void)if (!debug_pagealloc_enabled ())return false; +if (!debug_guardpage_minorder ()) +return false; +return true; }
@@ -616,6 +619,9 @@ static void init_debug_guardpage(void)if (!debug_pagealloc_enabled ())return ; +if (!debug_guardpage_minorder ()) +return ; + _debug_guardpage_enabled = true; }
@@ -636,7 +642,7 @@ static int __init debug_guardpage_minorder_setup(char *buf)pr_info ("Setting debug_guardpage_minorder to %lu\n" , res);return 0 ; } -__setup ("debug_guardpage_minorder=" , debug_guardpage_minorder_setup); +early_param ("debug_guardpage_minorder" , debug_guardpage_minorder_setup);static inline bool set_page_guard (struct zone *zone,struct page *page,unsigned int order,int migratetype)
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 3/6 mm/page_owner: move page_owner specific function to page_owner.c
In reply to [email protected]From: Joonsoo Kim <[email protected]>
There is no reason that page_owner specific function resides on vmstat.c.
--- include/linux/page_owner.h | 2 ++ mm/page_owner.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ mm/vmstat.c | 79 ---------------------------------------------- 3 files changed, 79 insertions(+), 79 deletions(-)
include/linux/page_owner.h +2 -0
@@ -14,6 +14,8 @@ extern void __split_page_owner(struct page *page, unsigned int order);extern void __copy_page_owner (struct page *oldpage,struct page *newpage);extern void __set_page_owner_migrate_reason (struct page *page,int reason);extern void __dump_page_owner (struct page *page); +extern void pagetypeinfo_showmixedcount_print (struct seq_file *m, +pg_data_t *pgdat,struct zone *zone);static inline void reset_page_owner (struct page *page,unsigned int order) {
mm/page_owner.c +77 -0
89 lines not on this page · raw message
mm/vmstat.c +0 -79
85 lines not on this page · raw message
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 3/6] mm/page_owner: move page_owner specific function to page_owner.c
Quoted 6 lines · On 08/16/2016 04:51 AM, [email protected] wrote:
From: Joonsoo Kim <[email protected]>
There is no reason that
page_ownerspecific function resides onvmstat.c.Reviewed-by Sergey Senozhatsky <[email protected]>Signed-off-by Joonsoo Kim <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 4/6 mm/page_ext: rename offset to index
In reply to [email protected]From: Joonsoo Kim <[email protected]>
Here, 'offset' means entry index in page_ext array. Following patch will use 'offset' for field offset in each entry so rename current 'offset' to prevent confusion.
--- mm/page_ext.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/page_ext.c +3 -3
@@ -102,7 +102,7 @@ void __meminit pgdat_page_ext_init(struct pglist_data *pgdat)struct page_ext *lookup_page_ext (struct page *page) {unsigned long pfn =page_to_pfn (page); -unsigned long offset; +unsigned long index;struct page_ext *base; base =NODE_DATA (page_to_nid (page))->node_page_ext;
@@ -119,9 +119,9 @@ struct page_ext *lookup_page_ext(struct page *page)if (unlikely (!base))return NULL ;#endif - offset = pfn -round_down (node_start_pfn (page_to_nid (page)), + index = pfn -round_down (node_start_pfn (page_to_nid (page)),MAX_ORDER_NR_PAGES ); -return base + offset; +return base + index; }static int __init alloc_node_page_ext (int nid)
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 4/6] mm/page_ext: rename offset to index
Quoted 7 lines · On 08/16/2016 04:51 AM, [email protected] wrote:
From: Joonsoo Kim <[email protected]>
Here, 'offset' means entry index in
page_extarray. Following patch will use 'offset' for field offset in each entry so rename current 'offset' to prevent confusion.Signed-off-by Joonsoo Kim <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 5/6 mm/page_ext: support extra space allocation by page_ext user
In reply to [email protected]From: Joonsoo Kim <[email protected]>
Until now, if some page_ext users want to use it's own field on page_ext, it should be defined in struct page_ext by hard-coding. It has a problem that wastes memory in following situation.
struct page_ext {
#ifdef CONFIG_A int a; #endif #ifdef CONFIG_B int b;
#endif
};
Assume that kernel is built with both CONFIG_A and CONFIG_B. Even if we enable feature A and doesn't enable feature B at runtime, each entry of struct page_ext takes two int rather than one int. It's undesirable result so this patch tries to fix it.
To solve above problem, this patch implements to support extra space allocation at runtime. When need() callback returns true, it's extra memory requirement is summed to entry size of page_ext. Also, offset for each user's extra memory space is returned. With this offset, user can use this extra space and there is no need to define needed field on page_ext by hard-coding.
This patch only implements an infrastructure. Following patch will use it for page_owner which is only user having it's own fields on page_ext.
--- include/linux/page_ext.h | 2 ++ mm/page_alloc.c | 2 +- mm/page_ext.c | 41 +++++++++++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 11 deletions(-)
include/linux/page_ext.h +2 -0
@@ -7,6 +7,8 @@struct pglist_data ;struct page_ext_operations { +size_t offset; +size_t size;bool (*need)(void );void (*init)(void ); };
mm/page_alloc.c +1 -1
@@ -688,7 +688,7 @@ static inline void clear_page_guard(struct zone *zone, struct page *page,__mod_zone_freepage_state (zone, (1 << order), migratetype); }#else -struct page_ext_operations debug_guardpage_ops = {NULL , }; +struct page_ext_operations debug_guardpage_ops;static inline bool set_page_guard (struct zone *zone,struct page *page,unsigned int order,int migratetype) {return false; } static inline void clear_page_guard(struct zone *zone, struct page *page,
mm/page_ext.c +31 -10
110 lines not on this page · raw message
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v2 5/6] mm/page_ext: support extra space allocation by page_ext user
Quoted 27 lines · On 08/16/2016 04:51 AM, [email protected] wrote:
From: Joonsoo Kim <[email protected]>
Until now, if some
page_extusers want to use it's own field onpage_ext, it should be defined in structpage_extby hard-coding. It has a problem that wastes memory in following situation.struct
page_ext{#ifdef CONFIG_A int a; #endif #ifdef CONFIG_B int b;#endif
};Assume that kernel is built with both
CONFIG_AandCONFIG_B. Even if we enable feature A and doesn't enable feature B at runtime, each entry of structpage_exttakes two int rather than one int. It's undesirable result so this patch tries to fix it.To solve above problem, this patch implements to support extra space allocation at runtime. When
need()callback returns true, it's extra memory requirement is summed to entry size ofpage_ext. Also, offset for each user's extra memory space is returned. With this offset, user can use this extra space and there is no need to define needed field onpage_extby hard-coding.
Quoted 4 lines
This patch only implements an infrastructure. Following patch will use it for
page_ownerwhich is only user having it's own fields onpage_ext.Signed-off-by Joonsoo Kim <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 6/6 mm/page_owner: don't define fields on struct page_ext by hard-coding
In reply to [email protected]From: Joonsoo Kim <[email protected]>
There is a memory waste problem if we define field on struct page_ext by hard-coding. Entry size of struct page_ext includes the size of those fields even if it is disabled at runtime. Now, extra memory request at runtime is possible so page_owner don't need to define it's own fields by hard-coding.
This patch removes hard-coded define and uses extra memory for storing page_owner information in page_owner. Most of code are just mechanical changes.
--- include/linux/page_ext.h | 6 ---- mm/page_owner.c | 83 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 31 deletions(-)
include/linux/page_ext.h +0 -6
@@ -44,12 +44,6 @@ enum page_ext_flags {*/ struct page_ext {unsigned long flags; -#ifdef CONFIG_PAGE_OWNER -unsigned int order; -gfp_t gfp_mask; -int last_migrate_reason; -depot_stack_handle_t handle; -#endif };extern void pgdat_page_ext_init (struct pglist_data *pgdat);
mm/page_owner.c +58 -25
231 lines not on this page · raw message
Signature · 7 lines
1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 26 lines · Joonsoo Kim
From: Joonsoo Kim <[email protected]>
v2:
Fix rebase mistake (per Vlastimil)
Rename some variable/function to prevent confusion (per Vlastimil) Fix header dependency (per Sergey)This patchset tries to reduce memory waste by page extension user.
First case is architecture supported
debug_pagealloc. It doesn't requires additional memory if guard page isn't used. 8 bytes per page will be saved in this case.Second case is related to page owner feature. Until now, if
page_extusers want to use it's own fields onpage_ext, fields should be defined in structpage_extby hard-coding. It has a following problem.struct
page_ext{#ifdef CONFIG_A int a; #endif #ifdef CONFIG_B int b;#endif
};
Quoted 6 lines
Assume that kernel is built with both
CONFIG_AandCONFIG_B. Even if we enable feature A and doesn't enable feature B at runtime, each entry of structpage_exttakes two int rather than one int. It's undesirable waste so this patch tries to reduce it. By this patchset, we can save 20 bytes per page dedicated for page owner feature in some configurations.
FWIW I like this. I have only glanced over those patches so I do not feel comfortable to give my a-b but the approach is sensible and the memory savings are really attractive. Page owner is a really great debugging feauture so enabling it makes a lot of sense on production servers where the memory wasting is a no-go.
Thanks!
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 34 lines · Michal Hocko
Quoted 26 lines · Joonsoo Kim
From: Joonsoo Kim <[email protected]>
v2:
Fix rebase mistake (per Vlastimil)
Rename some variable/function to prevent confusion (per Vlastimil) Fix header dependency (per Sergey)This patchset tries to reduce memory waste by page extension user.
First case is architecture supported
debug_pagealloc. It doesn't requires additional memory if guard page isn't used. 8 bytes per page will be saved in this case.Second case is related to page owner feature. Until now, if
page_extusers want to use it's own fields onpage_ext, fields should be defined in structpage_extby hard-coding. It has a following problem.struct
page_ext{#ifdef CONFIG_A int a; #endif #ifdef CONFIG_B int b;#endif
};Quoted 6 lines
Assume that kernel is built with both
CONFIG_AandCONFIG_B. Even if we enable feature A and doesn't enable feature B at runtime, each entry of structpage_exttakes two int rather than one int. It's undesirable waste so this patch tries to reduce it. By this patchset, we can save 20 bytes per page dedicated for page owner feature in some configurations.
Quoted 5 lines
FWIW I like this. I have only glanced over those patches so I do not feel comfortable to give my a-b but the approach is sensible and the memory savings are really attractive. Page owner is a really great debugging feauture so enabling it makes a lot of sense on production servers where the memory wasting is a no-go.
OK, I have missed that page_ext is only allocated if there is at least one feature which requires it enabled. So normally there shouldn't be too much of wasted memory. Anyway allocating per feature makes a lot of sense regardless.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>