Skip to content

Commit eefa864

Browse files
JoonsooKimtorvalds
authored andcommitted
mm/page_ext: resurrect struct page extending code for debugging
When we debug something, we'd like to insert some information to every page. For this purpose, we sometimes modify struct page itself. But, this has drawbacks. First, it requires re-compile. This makes us hesitate to use the powerful debug feature so development process is slowed down. And, second, sometimes it is impossible to rebuild the kernel due to third party module dependency. At third, system behaviour would be largely different after re-compile, because it changes size of struct page greatly and this structure is accessed by every part of kernel. Keeping this as it is would be better to reproduce errornous situation. This feature is intended to overcome above mentioned problems. This feature allocates memory for extended data per page in certain place rather than the struct page itself. This memory can be accessed by the accessor functions provided by this code. During the boot process, it checks whether allocation of huge chunk of memory is needed or not. If not, it avoids allocating memory at all. With this advantage, we can include this feature into the kernel in default and can avoid rebuild and solve related problems. Until now, memcg uses this technique. But, now, memcg decides to embed their variable to struct page itself and it's code to extend struct page has been removed. I'd like to use this code to develop debug feature, so this patch resurrect it. To help these things to work well, this patch introduces two callbacks for clients. One is the need callback which is mandatory if user wants to avoid useless memory allocation at boot-time. The other is optional, init callback, which is used to do proper initialization after memory is allocated. Detailed explanation about purpose of these functions is in code comment. Please refer it. Others are completely same with previous extension code in memcg. 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>
1 parent 2d48366 commit eefa864

7 files changed

Lines changed: 485 additions & 0 deletions

File tree

‎include/linux/mmzone.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ typedef struct pglist_data {
722722
int nr_zones;
723723
#ifdef CONFIG_FLAT_NODE_MEM_MAP /* means !SPARSEMEM */
724724
struct page *node_mem_map;
725+
#ifdef CONFIG_PAGE_EXTENSION
726+
struct page_ext *node_page_ext;
727+
#endif
725728
#endif
726729
#ifndef CONFIG_NO_BOOTMEM
727730
struct bootmem_data *bdata;
@@ -1075,6 +1078,7 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
10751078
#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)
10761079

10771080
struct page;
1081+
struct page_ext;
10781082
struct mem_section {
10791083
/*
10801084
* This is, logically, a pointer to an array of struct
@@ -1092,6 +1096,14 @@ struct mem_section {
10921096

10931097
/* See declaration of similar field in struct zone */
10941098
unsigned long *pageblock_flags;
1099+
#ifdef CONFIG_PAGE_EXTENSION
1100+
/*
1101+
* If !SPARSEMEM, pgdat doesn't have page_ext pointer. We use
1102+
* section. (see page_ext.h about this.)
1103+
*/
1104+
struct page_ext *page_ext;
1105+
unsigned long pad;
1106+
#endif
10951107
/*
10961108
* WARNING: mem_section must be a power-of-2 in size for the
10971109
* calculation and use of SECTION_ROOT_MASK to make sense.

‎include/linux/page_ext.h‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef __LINUX_PAGE_EXT_H
2+
#define __LINUX_PAGE_EXT_H
3+
4+
struct pglist_data;
5+
struct page_ext_operations {
6+
bool (*need)(void);
7+
void (*init)(void);
8+
};
9+
10+
#ifdef CONFIG_PAGE_EXTENSION
11+
12+
/*
13+
* Page Extension can be considered as an extended mem_map.
14+
* A page_ext page is associated with every page descriptor. The
15+
* page_ext helps us add more information about the page.
16+
* All page_ext are allocated at boot or memory hotplug event,
17+
* then the page_ext for pfn always exists.
18+
*/
19+
struct page_ext {
20+
unsigned long flags;
21+
};
22+
23+
extern void pgdat_page_ext_init(struct pglist_data *pgdat);
24+
25+
#ifdef CONFIG_SPARSEMEM
26+
static inline void page_ext_init_flatmem(void)
27+
{
28+
}
29+
extern void page_ext_init(void);
30+
#else
31+
extern void page_ext_init_flatmem(void);
32+
static inline void page_ext_init(void)
33+
{
34+
}
35+
#endif
36+
37+
struct page_ext *lookup_page_ext(struct page *page);
38+
39+
#else /* !CONFIG_PAGE_EXTENSION */
40+
struct page_ext;
41+
42+
static inline void pgdat_page_ext_init(struct pglist_data *pgdat)
43+
{
44+
}
45+
46+
static inline struct page_ext *lookup_page_ext(struct page *page)
47+
{
48+
return NULL;
49+
}
50+
51+
static inline void page_ext_init(void)
52+
{
53+
}
54+
55+
static inline void page_ext_init_flatmem(void)
56+
{
57+
}
58+
#endif /* CONFIG_PAGE_EXTENSION */
59+
#endif /* __LINUX_PAGE_EXT_H */

‎init/main.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <linux/mempolicy.h>
5252
#include <linux/key.h>
5353
#include <linux/buffer_head.h>
54+
#include <linux/page_ext.h>
5455
#include <linux/debug_locks.h>
5556
#include <linux/debugobjects.h>
5657
#include <linux/lockdep.h>
@@ -484,6 +485,11 @@ void __init __weak thread_info_cache_init(void)
484485
*/
485486
static void __init mm_init(void)
486487
{
488+
/*
489+
* page_ext requires contiguous pages,
490+
* bigger than MAX_ORDER unless SPARSEMEM.
491+
*/
492+
page_ext_init_flatmem();
487493
mem_init();
488494
kmem_cache_init();
489495
percpu_init_late();
@@ -621,6 +627,7 @@ asmlinkage __visible void __init start_kernel(void)
621627
initrd_start = 0;
622628
}
623629
#endif
630+
page_ext_init();
624631
debug_objects_mem_init();
625632
kmemleak_init();
626633
setup_per_cpu_pageset();

‎mm/Kconfig.debug‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
config PAGE_EXTENSION
2+
bool "Extend memmap on extra space for more information on page"
3+
---help---
4+
Extend memmap on extra space for more information on page. This
5+
could be used for debugging features that need to insert extra
6+
field for every page. This extension enables us to save memory
7+
by not allocating this extra memory according to boottime
8+
configuration.
9+
110
config DEBUG_PAGEALLOC
211
bool "Debug page memory allocations"
312
depends on DEBUG_KERNEL

‎mm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ obj-$(CONFIG_ZSMALLOC) += zsmalloc.o
7171
obj-$(CONFIG_GENERIC_EARLY_IOREMAP) += early_ioremap.o
7272
obj-$(CONFIG_CMA) += cma.o
7373
obj-$(CONFIG_MEMORY_BALLOON) += balloon_compaction.o
74+
obj-$(CONFIG_PAGE_EXTENSION) += page_ext.o

‎mm/page_alloc.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <linux/backing-dev.h>
4949
#include <linux/fault-inject.h>
5050
#include <linux/page-isolation.h>
51+
#include <linux/page_ext.h>
5152
#include <linux/debugobjects.h>
5253
#include <linux/kmemleak.h>
5354
#include <linux/compaction.h>
@@ -4856,6 +4857,7 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat,
48564857
#endif
48574858
init_waitqueue_head(&pgdat->kswapd_wait);
48584859
init_waitqueue_head(&pgdat->pfmemalloc_wait);
4860+
pgdat_page_ext_init(pgdat);
48594861

48604862
for (j = 0; j < MAX_NR_ZONES; j++) {
48614863
struct zone *zone = pgdat->node_zones + j;

0 commit comments

Comments
 (0)