Skip to contentSkip to conversation

Support free page filtering looking up mem_map array

PATCH Superseded HATAYAMA Daisuke 2 participants 22 messages Nov 8, 2012 – Nov 15, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Support free page filtering looking up mem_map array

This patch set implements filtering free pages looking up mem_map array instead of free lists. This is compatible for cyclic mode because looking up mem_map can be divided into cycles. On the other hand, dividing free pages contaiend in free lists is difficult since they are not sorted in physical-address order.

Unlike RFC version, the logic used is automatically selected at runtime according to the current mode. On cyclic mode, mem_map array logic is used. On non-cyclic mode, free list logic is used.

The RFC version is:
http://lists.infradead.org/pipermail/kexec/2012-June/006441.html

* TODO

Add the following values in VMCOREINFO on the upstream kernel. These are used in the mem_map logic.

- OFFSET(page._mapcount)
- OFFSET(page.private)
- SIZE(pageflags)
- NUMBER(PG_buddy)
- NUMBER(PG_slab)
- NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)

* Test

I tested this patch set on the following kernel versions.

- 3.4
- 3.1
- 2.6.38
- 2.6.32
- 2.6.18

On the test, I manually specified VMCOREINFO while extending it with the following values according to the kernel versions.

- 3.1, 3.4
NUMBER(PG_slab)=7
SIZE(pageflags)=4
OFFSET(page._mapcount)=24
OFFSET(page.private)=48
NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)=-128

- 2.6.38
SIZE(pageflags)=4
OFFSET(page._mapcount)=12
OFFSET(page.private)=16
NUMBER(PG_slab)=7
NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)=-2

- 2.6.32
NUMBER(PG_slab)=7
NUMBER(PG_buddy)=19
OFFSET(page._mapcount)=12
OFFSET(page.private)=16
SIZE(pageflags)=4

- 2.6.18
NUMBER(PG_slab)=7
NUMBER(PG_buddy)=19
OFFSET(page._mapcount)=12
OFFSET(page.private)=16

---

HATAYAMA Daisuke (10):
Print warning about cyclic buffer overrun if it can happen Add page_is_buddy for old kernels
Add page_is_buddy for PG_buddy
Add page_is_buddy for recent kernels
Exclude free pages by looking up mem_map array
Add hardcoded page flag values
Add debuginfo-related processing for VMCOREINFO/VMLINUX Add new parameters to various tables
Add debuginfo interface for enum type size
Move page flags setup for old kernels after debuginfo initialization

 dwarf_info.c   |   18 ++++++
 dwarf_info.h   |    1 
 makedumpfile.c |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 makedumpfile.h |   29 +++++++++-
 4 files changed, 204 insertions(+), 14 deletions(-)
Signature · 7 lines
Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

PATCH 1/10 Move page flags setup for old kernels after debuginfo initialization

Page flags setup needs to be done after debuginfo initialization. We use hard coded values only when debugging information doesn't provide corresponding values.

---

 makedumpfile.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
makedumpfile.c +3 -2
index 1183330..6513059 100644
@@ -2723,8 +2723,6 @@ initial(void)
 		debug_info = TRUE;
 	}
 
-	if (!get_value_for_old_linux())
-		return FALSE;
 out:
 	if (!info->page_size) {
 		/*
@@ -2789,6 +2787,9 @@ out:
 	if (is_xen_memory() && !get_dom0_mapnr())
 		return FALSE;
 
+	if (!get_value_for_old_linux())
+		return FALSE;
+
 	return TRUE;
 }
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

PATCH 2/10 Add debuginfo interface for enum type size

In reply to HATAYAMA Daisuke

This is need to determine if a specified enumeration type is present in a given debug information.

In this patch set, I'll use this to check if enum pageflags is present.

The newly introduced interface is a simple extension from the existing one for enumeration value.

---

 dwarf_info.c   |   18 +++++++++++++++++-
 dwarf_info.h   |    1 +
 makedumpfile.h |   13 +++++++++++--
 3 files changed, 29 insertions(+), 3 deletions(-)
dwarf_info.c +17 -1
index 94b920a..09a8e1e 100644
@@ -607,7 +607,7 @@ search_structure(Dwarf_Die *die, int *found)
 static void
 search_number(Dwarf_Die *die, int *found)
 {
-	int tag;
+	int tag, bytesize;
 	Dwarf_Word const_value;
 	Dwarf_Attribute attr;
 	Dwarf_Die child, *walker;
@@ -618,6 +618,22 @@ search_number(Dwarf_Die *die, int *found)
 		if (tag != DW_TAG_enumeration_type)
 			continue;
 
+		if (dwarf_info.cmd == DWARF_INFO_GET_ENUMERATION_TYPE_SIZE) {
+		   		   name = dwarf_diename(die);
+
+			if (!name || strcmp(name, dwarf_info.struct_name))
+			   	     continue;
+
+			if ((bytesize = dwarf_bytesize(die)) <= 0)
+			   	      	continue;
+
+			*found = TRUE;
+
+			dwarf_info.struct_size = bytesize;
+
+			return;
+				}
+
 		if (dwarf_child(die, &child) != 0)
 			continue;
 
dwarf_info.h +1 -0
index 8d0084d..185cbb6 100644
@@ -46,6 +46,7 @@ enum {
 	DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE,
 	DWARF_INFO_GET_SYMBOL_TYPE,
 	DWARF_INFO_GET_MEMBER_TYPE,
+	DWARF_INFO_GET_ENUMERATION_TYPE_SIZE,
 };
 
 char *get_dwarf_module_name(void);
makedumpfile.h +11 -2
index 97aca2a..20f4d99 100644
@@ -256,14 +256,23 @@ do { \
 #define ARRAY_LENGTH(X)		(array_table.X)
 #define SIZE_INIT(X, Y) \
 do { \
-	if ((SIZE(X) = get_structure_size(Y, 0)) == FAILED_DWARFINFO) \
+	if ((SIZE(X) = get_structure_size(Y, DWARF_INFO_GET_STRUCT_SIZE))	\
+		== FAILED_DWARFINFO) \
 		return FALSE; \
 } while (0)
 #define TYPEDEF_SIZE_INIT(X, Y) \
 do { \
-	if ((SIZE(X) = get_structure_size(Y, 1)) == FAILED_DWARFINFO) \
+	if ((SIZE(X) = get_structure_size(Y, DWARF_INFO_GET_TYPEDEF_SIZE)) \
+		== FAILED_DWARFINFO) \
 		return FALSE; \
 } while (0)
+#define ENUM_TYPE_SIZE_INIT(X, Y) \
+do { \
+	if ((SIZE(X) = get_structure_size(Y,	\
+		DWARF_INFO_GET_ENUMERATION_TYPE_SIZE))	\
+			== FAILED_DWARFINFO)				\
+	return FALSE; \
+} while (0)
 #define OFFSET_INIT(X, Y, Z) \
 do { \
 	if ((OFFSET(X) = get_member_offset(Y, Z, DWARF_INFO_GET_MEMBER_OFFSET)) \

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

PATCH 3/10 Add new parameters to various tables

In reply to HATAYAMA Daisuke

Add new parameters required for mem_map-based freepages filtering, to various tables.

---

 makedumpfile.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
makedumpfile.h +8 -0
index 20f4d99..1304df0 100644
@@ -1163,6 +1163,8 @@ struct size_table {
 	long	cpumask_t;
 	long	kexec_segment;
 	long	elf64_hdr;
+
+	long	pageflags;
 };
 
 struct offset_table {
@@ -1171,6 +1173,8 @@ struct offset_table {
 		long	_count;
 		long	mapping;
 		long	lru;
+		long	_mapcount;
+		long	private;
 	} page;
 	struct mem_section {
 		long	section_mem_map;
@@ -1332,6 +1336,10 @@ struct number_table {
 	long	PG_lru;
 	long	PG_private;
 	long	PG_swapcache;
+	long	PG_buddy;
+	long	PG_slab;
+
+	long	PAGE_BUDDY_MAPCOUNT_VALUE;
 };
 
 struct srcfile_table {

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

PATCH 4/10 Add debuginfo-related processing for VMCOREINFO/VMLINUX

In reply to HATAYAMA Daisuke

---

 makedumpfile.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
makedumpfile.c +20 -1
index 6513059..0d03716 100644
@@ -914,6 +914,8 @@ get_structure_info(void)
 	OFFSET_INIT(page.flags, "page", "flags");
 	OFFSET_INIT(page._count, "page", "_count");
 	OFFSET_INIT(page.mapping, "page", "mapping");
+	OFFSET_INIT(page._mapcount, "page", "_mapcount");
+	OFFSET_INIT(page.private, "page", "private");
 
 	/*
 	 * Some vmlinux(s) don't have debugging information about
@@ -1005,6 +1007,10 @@ get_structure_info(void)
 	ENUM_NUMBER_INIT(PG_lru, "PG_lru");
 	ENUM_NUMBER_INIT(PG_private, "PG_private");
 	ENUM_NUMBER_INIT(PG_swapcache, "PG_swapcache");
+	ENUM_NUMBER_INIT(PG_buddy, "PG_buddy");
+	ENUM_NUMBER_INIT(PG_slab, "PG_slab");
+
+	ENUM_TYPE_SIZE_INIT(pageflags, "pageflags");
 
 	TYPEDEF_SIZE_INIT(nodemask_t, "nodemask_t");
 
@@ -1355,6 +1361,7 @@ write_vmcoreinfo_data(void)
 	WRITE_STRUCTURE_SIZE("list_head", list_head);
 	WRITE_STRUCTURE_SIZE("node_memblk_s", node_memblk_s);
 	WRITE_STRUCTURE_SIZE("nodemask_t", nodemask_t);
+	WRITE_STRUCTURE_SIZE("pageflags", pageflags);
 
 	/*
 	 * write the member offset of 1st kernel
@@ -1363,6 +1370,8 @@ write_vmcoreinfo_data(void)
 	WRITE_MEMBER_OFFSET("page._count", page._count);
 	WRITE_MEMBER_OFFSET("page.mapping", page.mapping);
 	WRITE_MEMBER_OFFSET("page.lru", page.lru);
+	WRITE_MEMBER_OFFSET("page._mapcount", page._mapcount);
+	WRITE_MEMBER_OFFSET("page.private", page.private);
 	WRITE_MEMBER_OFFSET("mem_section.section_mem_map",
 	    mem_section.section_mem_map);
 	WRITE_MEMBER_OFFSET("pglist_data.node_zones", pglist_data.node_zones);
@@ -1407,6 +1416,10 @@ write_vmcoreinfo_data(void)
 	WRITE_NUMBER("PG_lru", PG_lru);
 	WRITE_NUMBER("PG_private", PG_private);
 	WRITE_NUMBER("PG_swapcache", PG_swapcache);
+	WRITE_NUMBER("PG_buddy", PG_buddy);
+	WRITE_NUMBER("PG_slab", PG_slab);
+
+	WRITE_NUMBER("PAGE_BUDDY_MAPCOUNT_VALUE", PAGE_BUDDY_MAPCOUNT_VALUE);
 
 	/*
 	 * write the source file of 1st kernel
@@ -1654,11 +1667,14 @@ read_vmcoreinfo(void)
 	READ_STRUCTURE_SIZE("list_head", list_head);
 	READ_STRUCTURE_SIZE("node_memblk_s", node_memblk_s);
 	READ_STRUCTURE_SIZE("nodemask_t", nodemask_t);
+	READ_STRUCTURE_SIZE("pageflags", pageflags);
 
 	READ_MEMBER_OFFSET("page.flags", page.flags);
 	READ_MEMBER_OFFSET("page._count", page._count);
 	READ_MEMBER_OFFSET("page.mapping", page.mapping);
 	READ_MEMBER_OFFSET("page.lru", page.lru);
+	READ_MEMBER_OFFSET("page._mapcount", page._mapcount);
+	READ_MEMBER_OFFSET("page.private", page.private);
 	READ_MEMBER_OFFSET("mem_section.section_mem_map",
 	    mem_section.section_mem_map);
 	READ_MEMBER_OFFSET("pglist_data.node_zones", pglist_data.node_zones);
@@ -1695,9 +1711,12 @@ read_vmcoreinfo(void)
 	READ_NUMBER("PG_lru", PG_lru);
 	READ_NUMBER("PG_private", PG_private);
 	READ_NUMBER("PG_swapcache", PG_swapcache);
-
+	READ_NUMBER("PG_slab", PG_slab);
+	READ_NUMBER("PG_buddy", PG_buddy);
 	READ_SRCFILE("pud_t", pud_t);
 
+	READ_NUMBER("PAGE_BUDDY_MAPCOUNT_VALUE", PAGE_BUDDY_MAPCOUNT_VALUE);
+
 	return TRUE;
 }
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

PATCH 5/10 Add hardcoded page flag values

In reply to HATAYAMA Daisuke

Basically, these should be exported as VMCOREINFO from kernel. But we cannot modify old kernels. Luckily, page flag values had frequently changed in old kernels, so on old kernels, it's relatively easy to determine appropreate page flags on a given kernel version without any symbol and type information.

Specifically:

- PG_slab has had the same value 7 since v2.6.15, and

- PG_buddy had been defined as macro value from v2.6.17 to v2.6.26

On later kernel version, enum pageflags type was introduced and at the version, PG_buddy's value depends on CONFIG_PAGEFLAGS_EXTEND; luckily, this can be determined by looking at error_states array, for example, without any debugging information but I don't implement it in this patch because it's better to check if enum pageflags is present to simplify design.

---

 makedumpfile.c |    6 ++++++
 makedumpfile.h |    3 +++
 2 files changed, 9 insertions(+), 0 deletions(-)
makedumpfile.c +6 -0
index 0d03716..cb64902 100644
@@ -1210,6 +1210,12 @@ get_value_for_old_linux(void)
 		NUMBER(PG_private) = PG_private_ORIGINAL;
 	if (NUMBER(PG_swapcache) == NOT_FOUND_NUMBER)
 		NUMBER(PG_swapcache) = PG_swapcache_ORIGINAL;
+	if (NUMBER(PG_slab) == NOT_FOUND_NUMBER)
+		NUMBER(PG_slab) = PG_slab_ORIGINAL;
+	if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER
+	    && info->kernel_version >= KERNEL_VERSION(2, 6, 17)
+	    && info->kernel_version <= KERNEL_VERSION(2, 6, 26))
+		NUMBER(PG_buddy) = PG_buddy_v2_6_17_to_v2_6_26;
 	return TRUE;
 }
 
makedumpfile.h +3 -0
index 1304df0..fecb003 100644
@@ -71,9 +71,12 @@ int get_mem_type(void);
  * The following values are for linux-2.6.25 or former.
  */
 #define PG_lru_ORIGINAL	 	(5)
+#define PG_slab_ORIGINAL	(7)
 #define PG_private_ORIGINAL	(11)	/* Has something at ->private */
 #define PG_swapcache_ORIGINAL	(15)	/* Swap page: swp_entry_t in private */
 
+#define PG_buddy_v2_6_17_to_v2_6_26	(19)
+
 #define PAGE_MAPPING_ANON	(1)
 
 #define LSEEKED_BITMAP	(1)

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

PATCH 6/10 Exclude free pages by looking up mem_map array

In reply to HATAYAMA Daisuke

Add free page filtering logic in __exclude_unnecessary_pages.

Unlike other filtering levels, the number of free pages indicated by buddy page is multiple. So I put this logic in the first position to skip the pages corresponding to free pages.

This mem_map array logic is used in cyclic mode only. In non cyclic mode, existing freelist logic is used.

Newly introduced page_is_buddy handler abstracts condition of buddy page that varies depending on kernel versions. On the kernel versions supported by makedumpfile, there are three kinds of buddy conditions. Later patches will introduce them in order.

If failing to choose a correct page_is_buddy handler, then we give up free pages filtering.

---

 makedumpfile.c |   40 ++++++++++++++++++++++++++++++++--------
 makedumpfile.h |    5 +++++
 2 files changed, 37 insertions(+), 8 deletions(-)
makedumpfile.c +32 -8
index cb64902..6358fc0 100644
@@ -58,6 +58,8 @@ do { \
 		*ptr_long_table = value; \
 } while (0)
 
+static void setup_page_is_buddy(void);
+
 void
 initialize_tables(void)
 {
@@ -2815,6 +2817,9 @@ out:
 	if (!get_value_for_old_linux())
 		return FALSE;
 
+	if (info->flag_cyclic && (info->dump_level & DL_EXCLUDE_FREE))
+		setup_page_is_buddy();
+
 	return TRUE;
 }
 
@@ -3637,6 +3642,13 @@ exclude_free_page(void)
 	return TRUE;
 }
 
+static void
+setup_page_is_buddy(void)
+{
+	MSG("Can't select page_is_buddy handler; "
+	    "filtering free pages is disabled.\n");
+}
+
 /*
  * If using a dumpfile in kdump-compressed format as a source file
  * instead of /proc/vmcore, 1st-bitmap of a new dumpfile must be
@@ -3847,8 +3859,8 @@ __exclude_unnecessary_pages(unsigned long mem_map,
 	unsigned long long pfn_read_start, pfn_read_end, index_pg;
 	unsigned char page_cache[SIZE(page) * PGMM_CACHED];
 	unsigned char *pcache;
-	unsigned int _count;
-	unsigned long flags, mapping;
+	unsigned int _count, _mapcount;
+	unsigned long flags, mapping, private;
 
 	/*
 	 * Refresh the buffer of struct page, when changing mem_map.
@@ -3902,11 +3914,26 @@ __exclude_unnecessary_pages(unsigned long mem_map,
 		flags   = ULONG(pcache + OFFSET(page.flags));
 		_count  = UINT(pcache + OFFSET(page._count));
 		mapping = ULONG(pcache + OFFSET(page.mapping));
+		_mapcount = UINT(pcache + OFFSET(page._mapcount));
+		private = ULONG(pcache + OFFSET(page.private));
+
+		/*
+		 * Exclude the free page managed by a buddy
+		 */
+		if ((info->dump_level & DL_EXCLUDE_FREE)
+		    && info->flag_cyclic
+		    && info->page_is_buddy
+		    && info->page_is_buddy(flags, _mapcount, private, _count)) {
+			int i;
 
+			for (i = 0; i < (1 << private); ++i)
+				clear_bit_on_2nd_bitmap_for_kernel(pfn + i);
+			pfn_free += i;
+		}
 		/*
 		 * Exclude the cache page without the private page.
 		 */
-		if ((info->dump_level & DL_EXCLUDE_CACHE)
+		else if ((info->dump_level & DL_EXCLUDE_CACHE)
 		    && (isLRU(flags) || isSwapCache(flags))
 		    && !isPrivate(flags) && !isAnon(mapping)) {
 			if (clear_bit_on_2nd_bitmap_for_kernel(pfn))
@@ -3987,16 +4014,13 @@ exclude_unnecessary_pages_cyclic(void)
 	 */
 	copy_bitmap_cyclic();
 
-	if (info->dump_level & DL_EXCLUDE_FREE)
-		if (!exclude_free_page())
-			return FALSE;
-
 	/*
 	 * Exclude cache pages, cache private pages, user data pages, and free pages.
 	 */
 	if (info->dump_level & DL_EXCLUDE_CACHE ||
 	    info->dump_level & DL_EXCLUDE_CACHE_PRI ||
-	    info->dump_level & DL_EXCLUDE_USER_DATA) {
+	    info->dump_level & DL_EXCLUDE_USER_DATA ||
+	    info->dump_level & DL_EXCLUDE_FREE) {
 
 		gettimeofday(&tv_start, NULL);
 
makedumpfile.h +5 -0
index fecb003..3ccc750 100644
@@ -1031,6 +1031,11 @@ struct DumpInfo {
 	 */
 	int flag_sadump_diskset;
 	enum sadump_format_type flag_sadump;         /* sadump format type */
+	/*
+	 * for filtering free pages managed by buddy system:
+	 */
+	int (*page_is_buddy)(unsigned long flags, unsigned int _mapcount,
+			     unsigned long private, unsigned int _count);
 };
 extern struct DumpInfo		*info;
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw

PATCH 7/10 Add page_is_buddy for recent kernels

In reply to HATAYAMA Daisuke

On kernels from v2.6.38 and later kernels, buddy page is marked by _mapcount == PAGE_BUDDY_MAPCOUNT_VALUE, which varies once as follows:

kernel version | PAGE_BUDDY_MAPCOUNT_VALUE
------------------+--------------------------
v2.6.38 | -2
v2.6.39 and later | -128

One more notice is that _mapcount shares its memory with other fields for SLAB/SLUB when PG_slab is set. Before looking up _mapcount value, we need to check if PG_slab is set.

---

 makedumpfile.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
makedumpfile.c +23 -2
index 6358fc0..27ad3e6 100644
@@ -3642,11 +3642,32 @@ exclude_free_page(void)
 	return TRUE;
 }
 
+/*
+ * For v2.6.38 and later kernel versions.
+ */
+static int
+page_is_buddy_v3(unsigned long flags, unsigned int _mapcount,
+			unsigned long private, unsigned int _count)
+{
+	if (flags & (1UL << NUMBER(PG_slab)))
+		return FALSE;
+
+	if (_mapcount == (int)NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE))
+		return TRUE;
+
+	return FALSE;
+}
+
 static void
 setup_page_is_buddy(void)
 {
-	MSG("Can't select page_is_buddy handler; "
-	    "filtering free pages is disabled.\n");
+	if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER
+	    && SIZE(pageflags) != NOT_FOUND_STRUCTURE
+	    && NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
+		info->page_is_buddy = page_is_buddy_v3;
+	else
+		MSG("Can't select page_is_buddy handler; "
+		    "filtering free pages is disabled.\n");
 }
 
 /*

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#8 lore raw

PATCH 8/10 Add page_is_buddy for PG_buddy

In reply to HATAYAMA Daisuke

On kernels from v2.6.18 to v2.6.37, buddy page is marked by the PG_buddy flag.

kernel version | PG_buddy
------------------ +---------------------------------

  v2.6.17 to v2.6.26 | 19

v2.6.27 to v2.6.37 | 19 if CONFIG_PAGEFLAGS_EXTEND=y
| 18 otherwise

Note for hard coding: alghouth I don't do in this patch set, it's possible to determine whether CONFIG_PAGEFLAGS_EXTEND=yes or not by looking at error_status array defined in mm/memory-failure.c, for example.

---

 makedumpfile.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)
makedumpfile.c +23 -7
index 27ad3e6..838ef53 100644
@@ -3643,6 +3643,19 @@ exclude_free_page(void)
 }
 
 /*
+ * For the kernel versions from v2.6.17 to v2.6.37.
+ */
+static int
+page_is_buddy_v2(unsigned long flags, unsigned int _mapcount,
+			unsigned long private, unsigned int _count)
+{
+	if (flags & (1UL << NUMBER(PG_buddy)))
+		return TRUE;
+
+	return FALSE;
+}
+
+/*
  * For v2.6.38 and later kernel versions.
  */
 static int
@@ -3661,13 +3674,16 @@ page_is_buddy_v3(unsigned long flags, unsigned int _mapcount,
 static void
 setup_page_is_buddy(void)
 {
-	if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER
-	    && SIZE(pageflags) != NOT_FOUND_STRUCTURE
-	    && NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
-		info->page_is_buddy = page_is_buddy_v3;
-	else
-		MSG("Can't select page_is_buddy handler; "
-		    "filtering free pages is disabled.\n");
+	if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
+		if (SIZE(pageflags) != NOT_FOUND_STRUCTURE
+		    && NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
+			info->page_is_buddy = page_is_buddy_v3;
+		else {
+			MSG("Can't select page_is_buddy handler; "
+			    "filtering free pages is disabled.\n");
+		}
+	} else
+		info->page_is_buddy = page_is_buddy_v2;
 }
 
 /*

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#9 lore raw

PATCH 9/10 Add page_is_buddy for old kernels

In reply to HATAYAMA Daisuke

On kernels from v2.6.15 to v2.6.17 buddy page is marked by the condition that PG_private flag is set and _count == 0.

Unfortunately, I have yet to test this logic on these kernel versions simply because I've been failing to boot them on my box.

Note that on these kernels, free list can be corrupted due to the bug that the above two conditions are not checked atomically. The reason why PG_buddy was introduced is a fix for this bug.

---

 makedumpfile.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
makedumpfile.c +17 -2
index 838ef53..d1efc09 100644
@@ -3643,6 +3643,20 @@ exclude_free_page(void)
 }
 
 /*
+ * For the kernel versions from v2.6.15 to v2.6.17.
+ */
+static int
+page_is_buddy_v1(unsigned long flags, unsigned int _mapcount,
+			unsigned long private, unsigned int _count)
+{
+	if ((flags & (1UL << NUMBER(PG_private)))
+	    && _count == 0)
+		return TRUE;
+
+	return FALSE;
+}
+
+/*
  * For the kernel versions from v2.6.17 to v2.6.37.
  */
 static int
@@ -3675,8 +3689,9 @@ static void
 setup_page_is_buddy(void)
 {
 	if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
-		if (SIZE(pageflags) != NOT_FOUND_STRUCTURE
-		    && NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
+		if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
+			info->page_is_buddy = page_is_buddy_v1;
+		else if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
 			info->page_is_buddy = page_is_buddy_v3;
 		else {
 			MSG("Can't select page_is_buddy handler; "

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#10 lore raw

PATCH 10/10 Print warning about cyclic buffer overrun if it can happen

In reply to HATAYAMA Daisuke

Clearling bits on cyclic buffer can overrun the cyclic buffer according to some combination of MAX_ORDER and cyclic buffer size.

This patch warns this possibility but continues processing.

---

 makedumpfile.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 47 insertions(+), 1 deletions(-)
makedumpfile.c +47 -1
index d1efc09..98eb640 100644
@@ -58,6 +58,7 @@ do { \
 		*ptr_long_table = value; \
 } while (0)
 
+static void check_cyclic_buffer_overrun(void);
 static void setup_page_is_buddy(void);
 
 void
@@ -2806,6 +2807,9 @@ out:
 		    !sadump_generate_elf_note_from_dumpfile())
 			return FALSE;
 
+		if (info->flag_cyclic && info->dump_level & DL_EXCLUDE_FREE)
+			check_cyclic_buffer_overrun();
+
 	} else {
 		if (!get_mem_map_without_mm())
 			return FALSE;
@@ -3642,6 +3646,38 @@ exclude_free_page(void)
 	return TRUE;
 }
 
+static void
+check_cyclic_buffer_overrun(void)
+{
+	int max_order = ARRAY_LENGTH(zone.free_area);
+	int max_order_nr_pages = 1 << (max_order - 1);
+
+	/*
+	 * Let C be a cyclic buffer size and B a bitmap size used for
+	 * representing maximum block size managed by buddy
+	 * allocator. Then, if C mod B != 0, i.e., if there exists n >
+	 * 0, B > b > 0 such that C = n x B + b, then clearing
+	 * operation overruns cyclic buffer (B - b)-bytes.
+	 *
+	 * The bitmap size used for maximum block size B is calculated
+	 * from MAX_ORDER as:
+	 *
+	 *   B := ROUND_UP((1 << (MAX_ORDER - 1)), / BITS_PER_BYTE)
+	 *
+	 * Normally, MAX_ORDER is 11 at default. This is configurable
+	 * through CONFIG_FORCE_MAX_ZONEORDER.
+	 *
+	 * Note that If MAX_ORDER is default 11, this overrun issue
+	 * never happens. First, if MAX_ORDER is 11, B is 128
+	 * bytes. Cyclic buffer size is always specified in kilobytes,
+	 * i.e. C = 1024 x c for some c > 0. Hence, C mod B = 0
+	 * because 1024 mod 128 = 0.
+	 */
+	if (info->bufsize_cyclic %
+	    roundup(max_order_nr_pages, BITPERBYTE))
+		MSG("Some free pages are not filtered.\n");
+}
+
 /*
  * For the kernel versions from v2.6.15 to v2.6.17.
  */
@@ -3978,8 +4014,18 @@ __exclude_unnecessary_pages(unsigned long mem_map,
 		    && info->page_is_buddy(flags, _mapcount, private, _count)) {
 			int i;
 
-			for (i = 0; i < (1 << private); ++i)
+			for (i = 0; i < (1 << private); ++i) {
+				/*
+				 * According to combination of
+				 * MAX_ORDER and size of cyclic
+				 * buffer, this clearing bit operation
+				 * can overrun the cyclic buffer.
+				 *
+				 * See check_cyclic_buffer_overrun()
+				 * for the detail.
+				 */
 				clear_bit_on_2nd_bitmap_for_kernel(pfn + i);
+			}
 			pfn_free += i;
 		}
 		/*

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#11 lore raw

Re: [PATCH 10/10] Print warning about cyclic buffer overrun if it can happen

Hello HATAYAMA-san,

Quoted 7 lines · On Thu, 08 Nov 2012 18:49:00 +0900 HATAYAMA Daisuke…

Clearling bits on cyclic buffer can overrun the cyclic buffer according to some combination of MAX_ORDER and cyclic buffer size.

This patch warns this possibility but continues processing.

---

Thank you for pointing it out.

v1.5.1-rc will calculate the cyclic buffer size automatically and this issue can happen even if MAX_ORDER is 11, so this patch is useful.

I'll try to resolve this issue essentially in v1.5.2.

Thanks
Atsushi Kumagai

Quoted 87 lines
 makedumpfile.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 47 insertions(+), 1 deletions(-)
makedumpfile.c +47 -1
index d1efc09..98eb640 100644
@@ -58,6 +58,7 @@ do { \
 		*ptr_long_table = value; \
 } while (0)
 
+static void check_cyclic_buffer_overrun(void);
 static void setup_page_is_buddy(void);
 
 void
@@ -2806,6 +2807,9 @@ out:
 		    !sadump_generate_elf_note_from_dumpfile())
 			return FALSE;
 
+		if (info->flag_cyclic && info->dump_level & DL_EXCLUDE_FREE)
+			check_cyclic_buffer_overrun();
+
 	} else {
 		if (!get_mem_map_without_mm())
 			return FALSE;
@@ -3642,6 +3646,38 @@ exclude_free_page(void)
 	return TRUE;
 }
 
+static void
+check_cyclic_buffer_overrun(void)
+{
+	int max_order = ARRAY_LENGTH(zone.free_area);
+	int max_order_nr_pages = 1 << (max_order - 1);
+
+	/*
+	 * Let C be a cyclic buffer size and B a bitmap size used for
+	 * representing maximum block size managed by buddy
+	 * allocator. Then, if C mod B != 0, i.e., if there exists n >
+	 * 0, B > b > 0 such that C = n x B + b, then clearing
+	 * operation overruns cyclic buffer (B - b)-bytes.
+	 *
+	 * The bitmap size used for maximum block size B is calculated
+	 * from MAX_ORDER as:
+	 *
+	 *   B := ROUND_UP((1 << (MAX_ORDER - 1)), / BITS_PER_BYTE)
+	 *
+	 * Normally, MAX_ORDER is 11 at default. This is configurable
+	 * through CONFIG_FORCE_MAX_ZONEORDER.
+	 *
+	 * Note that If MAX_ORDER is default 11, this overrun issue
+	 * never happens. First, if MAX_ORDER is 11, B is 128
+	 * bytes. Cyclic buffer size is always specified in kilobytes,
+	 * i.e. C = 1024 x c for some c > 0. Hence, C mod B = 0
+	 * because 1024 mod 128 = 0.
+	 */
+	if (info->bufsize_cyclic %
+	    roundup(max_order_nr_pages, BITPERBYTE))
+		MSG("Some free pages are not filtered.\n");
+}
+
 /*
  * For the kernel versions from v2.6.15 to v2.6.17.
  */
@@ -3978,8 +4014,18 @@ __exclude_unnecessary_pages(unsigned long mem_map,
 		    && info->page_is_buddy(flags, _mapcount, private, _count)) {
 			int i;
 
-			for (i = 0; i < (1 << private); ++i)
+			for (i = 0; i < (1 << private); ++i) {
+				/*
+				 * According to combination of
+				 * MAX_ORDER and size of cyclic
+				 * buffer, this clearing bit operation
+				 * can overrun the cyclic buffer.
+				 *
+				 * See check_cyclic_buffer_overrun()
+				 * for the detail.
+				 */
 				clear_bit_on_2nd_bitmap_for_kernel(pfn + i);
+			}
 			pfn_free += i;
 		}
 		/*
Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#12 lore raw

RE: [PATCH 10/10] Print warning about cyclic buffer overrun if it can happen

Quoted 21 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Tuesday, November 13, 2012 4:56 PM
To: Hatayama, Daisuke/畑山 大輔
Cc: [email protected]
Subject: Re: [PATCH 10/10] Print warning about cyclic buffer overrun if it can happen

Hello HATAYAMA-san,

Quoted 7 lines · On Thu, 08 Nov 2012 18:49:00 +0900 HATAYAMA Daisuke…

Clearling bits on cyclic buffer can overrun the cyclic buffer according to some combination of MAX_ORDER and cyclic buffer size.

This patch warns this possibility but continues processing.

---

Quoted 7 lines

Thank you for pointing it out.

v1.5.1-rc will calculate the cyclic buffer size automatically and this issue can happen even if MAX_ORDER is 11, so this patch is useful.

I'll try to resolve this issue essentially in v1.5.2.

Instead of the check, how about the following?

info->bufsize_cyclic = round(info->bufsize_cyclic,

                               roundup(max_order_nr_pages,
                                       BITPERBYTE));

This chooses the largest buffer size from the sizes smaller than info->bufsize_cyclic fitting into max_order size.

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#13 lore raw

Re: [PATCH 10/10] Print warning about cyclic buffer overrun if it can happen

Hello HATAYAMA-san,

Quoted 29 lines · Daisuke
Quoted 21 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Tuesday, November 13, 2012 4:56 PM
To: Hatayama, Daisuke
Cc: [email protected]
Subject: Re: [PATCH 10/10] Print warning about cyclic buffer overrun if it can happen

Hello HATAYAMA-san,

Quoted 7 lines · On Thu, 08 Nov 2012 18:49:00 +0900 HATAYAMA Daisuke…

Clearling bits on cyclic buffer can overrun the cyclic buffer according to some combination of MAX_ORDER and cyclic buffer size.

This patch warns this possibility but continues processing.

---

Quoted 7 lines

Thank you for pointing it out.

v1.5.1-rc will calculate the cyclic buffer size automatically and this issue can happen even if MAX_ORDER is 11, so this patch is useful.

I'll try to resolve this issue essentially in v1.5.2.

Quoted 8 lines

Instead of the check, how about the following?

info->bufsize_cyclic = round(info->bufsize_cyclic,

                               roundup(max_order_nr_pages,
                                       BITPERBYTE));

This chooses the largest buffer size from the sizes smaller than info->bufsize_cyclic fitting into max_order size.

It looks good, please change this patch as the above in v2.

Thanks
Atsushi Kumagai

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#14 lore raw
In reply to HATAYAMA Daisuke

Hello HATAYAMA-san,

Quoted 6 lines · On Thu, 08 Nov 2012 18:48:07 +0900 HATAYAMA Daisuke…

This patch set implements filtering free pages looking up mem_map array instead of free lists. This is compatible for cyclic mode because looking up mem_map can be divided into cycles. On the other hand, dividing free pages contaiend in free lists is difficult since they are not sorted in physical-address order.

Quoted 6 lines

Unlike RFC version, the logic used is automatically selected at runtime according to the current mode. On cyclic mode, mem_map array logic is used. On non-cyclic mode, free list logic is used.

The RFC version is:
http://lists.infradead.org/pipermail/kexec/2012-June/006441.html

Thanks for re-sending the mem_map array patch set.

This function will work fine when VMCOREINFO is specified manually, so I think the basic logic is good.

Quoted 11 lines

* TODO

Add the following values in VMCOREINFO on the upstream kernel. These are used in the mem_map logic.

- OFFSET(page._mapcount)
- OFFSET(page.private)
- SIZE(pageflags)
- NUMBER(PG_buddy)
- NUMBER(PG_slab)
- NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)

And I will post the patch to add the values above to the upstream kernel, so there is no problem on the future kernel.

However, according to my tests, current makedumpfile can't get some of the values above from VMLINUX and can't exclude free pages with the mem_map array logic.
For example, page_is_buddy_v1() will be selected for kernel-3.4 with setup_page_is_buddy() due to not founding NUMBER(PG_buddy) and SIZE(pageflags), it's miss selection.

Therefore, I propose to change the policy for excluding free page as below in order to take care of current kernels:

1. If VMCORE (or specified VMCOREINFO) includes the values above, using the mem_map array logic.

2. In other cases, using the current logic which uses free_list even if running on cyclic mode.

Of course, page_is_buddy_v1() and page_is_buddy_v2() should be retain because there is valuable for the user who can prepare VMCOREINFO.

Thanks
Atsushi Kumagai

Quoted 55 lines

* Test

I tested this patch set on the following kernel versions.

- 3.4
- 3.1
- 2.6.38
- 2.6.32
- 2.6.18

On the test, I manually specified VMCOREINFO while extending it with the following values according to the kernel versions.

- 3.1, 3.4
NUMBER(PG_slab)=7
SIZE(pageflags)=4
OFFSET(page._mapcount)=24
OFFSET(page.private)=48
NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)=-128

- 2.6.38
SIZE(pageflags)=4
OFFSET(page._mapcount)=12
OFFSET(page.private)=16
NUMBER(PG_slab)=7
NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)=-2

- 2.6.32
NUMBER(PG_slab)=7
NUMBER(PG_buddy)=19
OFFSET(page._mapcount)=12
OFFSET(page.private)=16
SIZE(pageflags)=4

- 2.6.18
NUMBER(PG_slab)=7
NUMBER(PG_buddy)=19
OFFSET(page._mapcount)=12
OFFSET(page.private)=16

---

HATAYAMA Daisuke (10):
Print warning about cyclic buffer overrun if it can happen Add page_is_buddy for old kernels
Add page_is_buddy for PG_buddy
Add page_is_buddy for recent kernels
Exclude free pages by looking up mem_map array
Add hardcoded page flag values
Add debuginfo-related processing for VMCOREINFO/VMLINUX Add new parameters to various tables
Add debuginfo interface for enum type size
Move page flags setup for old kernels after debuginfo initialization

Quoted 10 lines
 dwarf_info.c   |   18 ++++++
 dwarf_info.h   |    1 
 makedumpfile.c |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 makedumpfile.h |   29 +++++++++-
 4 files changed, 204 insertions(+), 14 deletions(-)
Signature · 2 lines
Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#15 lore raw
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Tuesday, November 13, 2012 4:56 PM

[...]

Quoted 21 lines
Quoted 6 lines

- OFFSET(page._mapcount)
- OFFSET(page.private)
- SIZE(pageflags)
- NUMBER(PG_buddy)
- NUMBER(PG_slab)
- NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)

And I will post the patch to add the values above to the upstream kernel, so there is no problem on the future kernel.

However, according to my tests, current makedumpfile can't get some of the values above from VMLINUX and can't exclude free pages with the mem_map array logic.
For example, page_is_buddy_v1() will be selected for kernel-3.4 with setup_page_is_buddy() due to not founding NUMBER(PG_buddy) and SIZE(pageflags),
it's miss selection.

Therefore, I propose to change the policy for excluding free page as below in order to take care of current kernels:

Quoted 9 lines

1. If VMCORE (or specified VMCOREINFO) includes the values above, using the mem_map array logic.

2. In other cases, using the current logic which uses free_list even if running on cyclic mode.

Of course, page_is_buddy_v1() and page_is_buddy_v2() should be retain because there is valuable for the user who can prepare VMCOREINFO.

You are corrent. I'll repost the patch set soon. Rc1 or beta, which is better?

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#16 lore raw
Quoted 3 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hatayama, Daisuke

[..]>

Quoted 30 lines
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Tuesday, November 13, 2012 4:56 PM

[...]

Quoted 11 lines
Quoted 6 lines

- OFFSET(page._mapcount)
- OFFSET(page.private)
- SIZE(pageflags)
- NUMBER(PG_buddy)
- NUMBER(PG_slab)
- NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)

And I will post the patch to add the values above to the upstream kernel, so there is no problem on the future kernel.

However, according to my tests, current makedumpfile can't get some of

the

Quoted 7 lines

values above from VMLINUX and can't exclude free pages with the mem_map array logic.
For example, page_is_buddy_v1() will be selected for kernel-3.4 with setup_page_is_buddy() due to not founding NUMBER(PG_buddy) and SIZE(pageflags),
it's miss selection.

Quoted 7 lines

Therefore, I propose to change the policy for excluding free page as below in order to take care of current kernels:

1. If VMCORE (or specified VMCOREINFO) includes the values above, using the mem_map array logic.

2. In other cases, using the current logic which uses free_list even

Quoted 9 lines

if

Quoted 5 lines

running on cyclic mode.

Of course, page_is_buddy_v1() and page_is_buddy_v2() should be retain because there is valuable for the user who can prepare VMCOREINFO.

You are corrent. I'll repost the patch set soon. Rc1 or beta, which is better?

The patch I intend is like this, and this will be merged into the patch 06/10.

$ git diff
makedumpfile.c +10 -3
index 98eb640..f57612d 100644
@@ -3730,8 +3730,8 @@ setup_page_is_buddy(void)
                else if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
                        info->page_is_buddy = page_is_buddy_v3;
                else {
-                       MSG("Can't select page_is_buddy handler; "
-                           "filtering free pages is disabled.\n");
+                       DEBUG_MSG("Can't select page_is_buddy handler; "
+                                 "follow freelist instead of mem_map.\n");
                }
        } else
                info->page_is_buddy = page_is_buddy_v2;
@@ -4118,7 +4118,7 @@ exclude_unnecessary_pages_cyclic(void)
        if (info->dump_level & DL_EXCLUDE_CACHE ||
            info->dump_level & DL_EXCLUDE_CACHE_PRI ||
            info->dump_level & DL_EXCLUDE_USER_DATA ||
-           info->dump_level & DL_EXCLUDE_FREE) {
+           ((info->dump_level & DL_EXCLUDE_FREE) && info->page_is_buddy)) {
 
                gettimeofday(&tv_start, NULL);
 
@@ -4166,6 +4166,10 @@ update_cyclic_region(unsigned long long pfn)
        if (!exclude_unnecessary_pages_cyclic())
                return FALSE;
 
+       if ((info->dump_level & DL_EXCLUDE_FREE) && !info->page_is_buddy)
+               if (!exclude_free_pages())
+                       return FALSE;
+
        return TRUE;
 }
 
@@ -5171,6 +5175,9 @@ get_loads_dumpfile_cyclic(void)
                return FALSE;
        if (!exclude_unnecessary_pages_cyclic())
                return FALSE;
+       if ((info->dump_level & DL_EXCLUDE_FREE) && !info->page_is_buddy)
+               if (!exclude_free_pages())
+                       return FALSE;
 
        if (!(phnum = get_phnum_memory()))
                return FALSE;
makedumpfile.h +9 -0
index 3ccc750..6ce8e23 100644
@@ -1034,6 +1034,15 @@ struct DumpInfo {
        /*
         * for filtering free pages managed by buddy system:
         */
+       /*
+        * Initialized by setup_page_is_buddy(). This can be NULL if
+        *
+        *   1) in non-cyclic mode, or
+        *   2) in cyclic mode, proper page_is_buddy handler fails to
+        *   be detected.
+        *
+        * Then, conventional freelist logic is used instead.
+        */
        int (*page_is_buddy)(unsigned long flags, unsigned int _mapcount,
                             unsigned long private, unsigned int _count);
 };

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#17 lore raw

Hello HATAYAMA-san,

Quoted 37 lines · Daisuke
Quoted 3 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hatayama, Daisuke

[..]>

Quoted 33 lines
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Tuesday, November 13, 2012 4:56 PM

[...]

Quoted 11 lines
Quoted 6 lines

- OFFSET(page._mapcount)
- OFFSET(page.private)
- SIZE(pageflags)
- NUMBER(PG_buddy)
- NUMBER(PG_slab)
- NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE)

And I will post the patch to add the values above to the upstream kernel, so there is no problem on the future kernel.

However, according to my tests, current makedumpfile can't get some of

the

Quoted 7 lines

values above from VMLINUX and can't exclude free pages with the mem_map array logic.
For example, page_is_buddy_v1() will be selected for kernel-3.4 with setup_page_is_buddy() due to not founding NUMBER(PG_buddy) and SIZE(pageflags),
it's miss selection.

Quoted 7 lines

Therefore, I propose to change the policy for excluding free page as below in order to take care of current kernels:

1. If VMCORE (or specified VMCOREINFO) includes the values above, using the mem_map array logic.

2. In other cases, using the current logic which uses free_list even

if

Quoted 2 lines

running on cyclic mode.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Of course, page_is_buddy_v1() and page_is_buddy_v2() should be retain because there is valuable for the user who can prepare VMCOREINFO.

You are corrent. I'll repost the patch set soon. Rc1 or beta, which is better?

The patch I intend is like this, and this will be merged into the patch 06/10.

It's basically good, but more fix is needed for setup_page_is_buddy().

   3706 static void
   3707 setup_page_is_buddy(void)
   3708 {
   3709         if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
   3710                 if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
   3711                         info->page_is_buddy = page_is_buddy_v1;

In case that none of the values needed for mem_map array logic is given, the condition on line 3710 will be met regardless of kernel version. As a result, invalid logic will be used and freelist logic isn't used because page_is_buddy isn't NULL.

Additionally, the case above will be happen when using makedumpfile-1.5.0 for recent kernels, which doesn't export necessary symbols.

So, I think that we need to change the statement on line 3710, but I have no idea without to check kernel version. If you have better way, I will adopt it.

Thanks
Atsushi Kumagai

Quoted 67 lines
$ git diff
makedumpfile.c +10 -3
index 98eb640..f57612d 100644
@@ -3730,8 +3730,8 @@ setup_page_is_buddy(void)
                else if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
                        info->page_is_buddy = page_is_buddy_v3;
                else {
-                       MSG("Can't select page_is_buddy handler; "
-                           "filtering free pages is disabled.\n");
+                       DEBUG_MSG("Can't select page_is_buddy handler; "
+                                 "follow freelist instead of mem_map.\n");
                }
        } else
                info->page_is_buddy = page_is_buddy_v2;
@@ -4118,7 +4118,7 @@ exclude_unnecessary_pages_cyclic(void)
        if (info->dump_level & DL_EXCLUDE_CACHE ||
            info->dump_level & DL_EXCLUDE_CACHE_PRI ||
            info->dump_level & DL_EXCLUDE_USER_DATA ||
-           info->dump_level & DL_EXCLUDE_FREE) {
+           ((info->dump_level & DL_EXCLUDE_FREE) && info->page_is_buddy)) {
 
                gettimeofday(&tv_start, NULL);
 
@@ -4166,6 +4166,10 @@ update_cyclic_region(unsigned long long pfn)
        if (!exclude_unnecessary_pages_cyclic())
                return FALSE;
 
+       if ((info->dump_level & DL_EXCLUDE_FREE) && !info->page_is_buddy)
+               if (!exclude_free_pages())
+                       return FALSE;
+
        return TRUE;
 }
 
@@ -5171,6 +5175,9 @@ get_loads_dumpfile_cyclic(void)
                return FALSE;
        if (!exclude_unnecessary_pages_cyclic())
                return FALSE;
+       if ((info->dump_level & DL_EXCLUDE_FREE) && !info->page_is_buddy)
+               if (!exclude_free_pages())
+                       return FALSE;
 
        if (!(phnum = get_phnum_memory()))
                return FALSE;
makedumpfile.h +9 -0
index 3ccc750..6ce8e23 100644
@@ -1034,6 +1034,15 @@ struct DumpInfo {
        /*
         * for filtering free pages managed by buddy system:
         */
+       /*
+        * Initialized by setup_page_is_buddy(). This can be NULL if
+        *
+        *   1) in non-cyclic mode, or
+        *   2) in cyclic mode, proper page_is_buddy handler fails to
+        *   be detected.
+        *
+        * Then, conventional freelist logic is used instead.
+        */
        int (*page_is_buddy)(unsigned long flags, unsigned int _mapcount,
                             unsigned long private, unsigned int _count);
 };
Quoted 2 lines

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#18 lore raw
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Wednesday, November 14, 2012 4:31 PM

[...]

Quoted 11 lines
Quoted 3 lines · Daisuke
Quoted 3 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hatayama,

Daisuke

Quoted 4 lines

[..]>

Quoted 3 lines
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Tuesday, November 13, 2012 4:56 PM

[...]

Quoted 14 lines

It's basically good, but more fix is needed for setup_page_is_buddy().

   3706 static void
   3707 setup_page_is_buddy(void)
   3708 {
   3709         if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
   3710                 if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
   3711                         info->page_is_buddy = page_is_buddy_v1;

In case that none of the values needed for mem_map array logic is given, the condition on line 3710 will be met regardless of kernel version. As a result, invalid logic will be used and freelist logic isn't used because page_is_buddy isn't NULL.

Quoted 7 lines

Additionally, the case above will be happen when using makedumpfile-1.5.0 for recent kernels, which doesn't export necessary symbols.

So, I think that we need to change the statement on line 3710, but I have no idea without to check kernel version. If you have better way, I will adopt it.

I'll first hard code PAGE_BUDDY_MAPCOUNT_VALUE for v2.6.38 and later. This is a workaround until it is exported from kernel's VMCOREINFO. At the same time I'll check NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) first and then SIZE(pageflags) in setup_page_is_buddy(). By this, we can avoid the issue that page_is_buddy_v1 is wrongly used on recent kernels.

The remaining problematic kernel versions are the ones where:

- PG_buddy is not present, and
- enum pageflags is present but
- enum pageflags is not exported from VMCOREINFO.

These are exactly from v2.6.27 to 2.6.37. I'll cover this range by hard coding PG_buddy. One concern was the fact that value of PG_buddy in this range varies depending on CONFIG_PAGEFLAGS_EXTENDED. But as below, this config is not relevant to the architectures supported by makedumpfile. It's no problem.

BTW, PAGE_BUDDY_MAPCOUNT_VALUE is now defined as macro. This is not useful since we cannot get its value from vmlinux. I'll make a patch to redefine it as enumeration later. It's originally signed integer, -128, so I think it's no problem.

$ git grep ".*CONFIG_PAGEFLAGS_EXTEND.*" ./arch/
arch/um/defconfig:CONFIG_PAGEFLAGS_EXTENDED=y
arch/xtensa/configs/iss_defconfig:CONFIG_PAGEFLAGS_EXTENDED=y
arch/xtensa/configs/s6105_defconfig:CONFIG_PAGEFLAGS_EXTENDED=y

Next diff shows the idea I explain above. I'll add the same explanation in codes as comments. The assumption behind these seems complicated and maintainance would be difficult without any comments explaining why these are being done this way.

$ git diff
makedumpfile.c +23 -9
index 98eb640..a1a39d5 100644
@@ -1215,10 +1215,24 @@ get_value_for_old_linux(void)
                NUMBER(PG_swapcache) = PG_swapcache_ORIGINAL;
        if (NUMBER(PG_slab) == NOT_FOUND_NUMBER)
                NUMBER(PG_slab) = PG_slab_ORIGINAL;
-       if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER
-           && info->kernel_version >= KERNEL_VERSION(2, 6, 17)
-           && info->kernel_version <= KERNEL_VERSION(2, 6, 26))
-               NUMBER(PG_buddy) = PG_buddy_v2_6_17_to_v2_6_26;
+       if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 17)
+                   && info->kernel_version <= KERNEL_VERSION(2, 6, 26))
+                       NUMBER(PG_buddy) = PG_buddy_v2_6_17_to_v2_6_26;
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 27)
+                   && info->kernel_version >= KERNEL_VERSION(2, 6, 37))
+                       NUMBER(PG_buddy) = 18;
+       }
+       if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) == NOT_FOUND_NUMBER) {
+               if (info->kernel_version == KERNEL_VERSION(2, 6, 38))
+                       NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) = -2;
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 39))
+                       NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) = -128;
+       }
+       if (SIZE(pageflags) == NOT_FOUND_STRUCTURE) {
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 27))
+                       SIZE(pageflags) = 4;
+       }
        return TRUE;
 }
 
@@ -3725,13 +3739,13 @@ static void
 setup_page_is_buddy(void)
 {
        if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
-               if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
-                       info->page_is_buddy = page_is_buddy_v1;
-               else if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
+               if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
                        info->page_is_buddy = page_is_buddy_v3;
+               else if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
+                       info->page_is_buddy = page_is_buddy_v1;
                else {
-                       MSG("Can't select page_is_buddy handler; "
-                           "filtering free pages is disabled.\n");
+                       DEBUG_MSG("Can't select page_is_buddy handler; "
+                                 "follow freelist instead of mem_map.\n");
                }
        } else
                info->page_is_buddy = page_is_buddy_v2;

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#19 lore raw

Hello HATAYAMA-san,

Quoted 60 lines · Daisuke
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Wednesday, November 14, 2012 4:31 PM

[...]

Quoted 11 lines
Quoted 3 lines · Daisuke
Quoted 3 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hatayama,

Daisuke

Quoted 4 lines

[..]>

Quoted 3 lines
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Tuesday, November 13, 2012 4:56 PM

[...]

Quoted 14 lines

It's basically good, but more fix is needed for setup_page_is_buddy().

   3706 static void
   3707 setup_page_is_buddy(void)
   3708 {
   3709         if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
   3710                 if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
   3711                         info->page_is_buddy = page_is_buddy_v1;

In case that none of the values needed for mem_map array logic is given, the condition on line 3710 will be met regardless of kernel version. As a result, invalid logic will be used and freelist logic isn't used because page_is_buddy isn't NULL.

Quoted 7 lines

Additionally, the case above will be happen when using makedumpfile-1.5.0 for recent kernels, which doesn't export necessary symbols.

So, I think that we need to change the statement on line 3710, but I have no idea without to check kernel version. If you have better way, I will adopt it.

I'll first hard code PAGE_BUDDY_MAPCOUNT_VALUE for v2.6.38 and later. This is a workaround until it is exported from kernel's VMCOREINFO. At the same time I'll check NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) first and then SIZE(pageflags) in setup_page_is_buddy(). By this, we can avoid the issue that page_is_buddy_v1 is wrongly used on recent kernels.

The remaining problematic kernel versions are the ones where:

- PG_buddy is not present, and
- enum pageflags is present but
- enum pageflags is not exported from VMCOREINFO.

These are exactly from v2.6.27 to 2.6.37. I'll cover this range by hard coding PG_buddy. One concern was the fact that value of PG_buddy in this range varies depending on CONFIG_PAGEFLAGS_EXTENDED. But as below, this config is not relevant to the architectures supported by makedumpfile. It's no problem.

BTW, PAGE_BUDDY_MAPCOUNT_VALUE is now defined as macro. This is not useful since we cannot get its value from vmlinux. I'll make a patch to redefine it as enumeration later. It's originally signed integer, -128, so I think it's no problem.

Quoted 8 lines
$ git grep ".*CONFIG_PAGEFLAGS_EXTEND.*" ./arch/
arch/um/defconfig:CONFIG_PAGEFLAGS_EXTENDED=y
arch/xtensa/configs/iss_defconfig:CONFIG_PAGEFLAGS_EXTENDED=y
arch/xtensa/configs/s6105_defconfig:CONFIG_PAGEFLAGS_EXTENDED=y

Next diff shows the idea I explain above. I'll add the same explanation in codes as comments. The assumption behind these seems complicated and maintainance would be difficult without any comments explaining why these are being done this way.

I think it's OK on the logic of selection for page_is_buddy_vX(). But there remain some cases where page_is_buddy_vX() doesn't work correctly because OFFSET(page.private) and OFFSET(page._mapcount) do not exist. And it's difficult to hard code for them.

So I think setup_page_is_buddy() should be changed like below:

  static void
  setup_page_is_buddy(void)
  {
          if (OFFSET(page.private) == NOT_FOUND_STRUCTURE)
                  info->page_is_buddy = NULL;
          else if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
                  if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER) {
                          if (OFFSET(page._mapcout) != NOT_FOUND_STRUCTURE) {
                                  info->page_is_buddy = page_is_buddy_v3;
                                  return;
                          }
                  } else if (SIZE(pageflags) == NOT_FOUND_STRUCTURE) {
                          info->page_is_buddy = page_is_buddy_v1;
                          return;
                  }
          } else {
                  info->page_is_buddy = page_is_buddy_v2;
                  return;
          }

DEBUG_MSG("Can't select page_is_buddy handler; "
"follow freelist instead of mem_map.\n");

  }

Additionally, I found a small mistake, please see below:

Quoted 10 lines
$ git diff
makedumpfile.c +0 -0
index 98eb640..a1a39d5 100644
@@ -1215,10 +1215,24 @@ get_value_for_old_linux(void)
                NUMBER(PG_swapcache) = PG_swapcache_ORIGINAL;
        if (NUMBER(PG_slab) == NOT_FOUND_NUMBER)
                NUMBER(PG_slab) = PG_slab_ORIGINAL;

makedumpfile.c get_value_for_old_linux(void) · line 1223

Quoted 10 lines
makedumpfile.c +6 -4
-       if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER
-           && info->kernel_version >= KERNEL_VERSION(2, 6, 17)
-           && info->kernel_version <= KERNEL_VERSION(2, 6, 26))
-               NUMBER(PG_buddy) = PG_buddy_v2_6_17_to_v2_6_26;
+       if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 17)
+                   && info->kernel_version <= KERNEL_VERSION(2, 6, 26))
+                       NUMBER(PG_buddy) = PG_buddy_v2_6_17_to_v2_6_26;
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 27)
+                   && info->kernel_version >= KERNEL_VERSION(2, 6, 37))
                                             ^^^
                                              should be '<='

Thanks
Atsushi Kumagai

Quoted 35 lines
makedumpfile.c +17 -5
+                       NUMBER(PG_buddy) = 18;
+       }
+       if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) == NOT_FOUND_NUMBER) {
+               if (info->kernel_version == KERNEL_VERSION(2, 6, 38))
+                       NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) = -2;
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 39))
+                       NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) = -128;
+       }
+       if (SIZE(pageflags) == NOT_FOUND_STRUCTURE) {
+               if (info->kernel_version >= KERNEL_VERSION(2, 6, 27))
+                       SIZE(pageflags) = 4;
+       }
        return TRUE;
 }
 
@@ -3725,13 +3739,13 @@ static void
 setup_page_is_buddy(void)
 {
        if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
-               if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
-                       info->page_is_buddy = page_is_buddy_v1;
-               else if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
+               if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) != NOT_FOUND_NUMBER)
                        info->page_is_buddy = page_is_buddy_v3;
+               else if (SIZE(pageflags) == NOT_FOUND_STRUCTURE)
+                       info->page_is_buddy = page_is_buddy_v1;
                else {
-                       MSG("Can't select page_is_buddy handler; "
-                           "filtering free pages is disabled.\n");
+                       DEBUG_MSG("Can't select page_is_buddy handler; "
+                                 "follow freelist instead of mem_map.\n");
                }
        } else
                info->page_is_buddy = page_is_buddy_v2;
Quoted 2 lines

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#20 lore raw
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Thursday, November 15, 2012 2:20 PM

[...]

Quoted 2 lines

On Thu, 15 Nov 2012 01:55:04 +0000
"Hatayama, Daisuke" <[email protected]> wrote:

[...]

Quoted 34 lines

I think it's OK on the logic of selection for page_is_buddy_vX(). But there remain some cases where page_is_buddy_vX() doesn't work correctly because OFFSET(page.private) and OFFSET(page._mapcount) do not exist. And it's difficult to hard code for them.

So I think setup_page_is_buddy() should be changed like below:

static void
setup_page_is_buddy(void)

  {
          if (OFFSET(page.private) == NOT_FOUND_STRUCTURE)
                  info->page_is_buddy = NULL;
          else if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
                  if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) !=
NOT_FOUND_NUMBER) {
                          if (OFFSET(page._mapcout) !=
NOT_FOUND_STRUCTURE) {
                                  info->page_is_buddy =
page_is_buddy_v3;
                                  return;
                          }
                  } else if (SIZE(pageflags) == NOT_FOUND_STRUCTURE) {
                          info->page_is_buddy = page_is_buddy_v1;
                          return;
                  }
          } else {
                  info->page_is_buddy = page_is_buddy_v2;
                  return;
          }

          DEBUG_MSG("Can't select page_is_buddy handler; "
                    "follow freelist instead of mem_map.\n");
Quoted 2 lines
  }

Agree. I'll rewrite it.

When do you plan to post v1.5.1-rc?

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#21 lore raw

Hello HATAYAMA-san,

Quoted 38 lines · Daisuke
Quoted 3 lines

-----Original Message-----
From: Atsushi Kumagai [mailto:[email protected]]
Sent: Thursday, November 15, 2012 2:20 PM

[...]

Quoted 2 lines

On Thu, 15 Nov 2012 01:55:04 +0000
"Hatayama, Daisuke" <[email protected]> wrote:

[...]

Quoted 31 lines

I think it's OK on the logic of selection for page_is_buddy_vX(). But there remain some cases where page_is_buddy_vX() doesn't work correctly because OFFSET(page.private) and OFFSET(page._mapcount) do not exist. And it's difficult to hard code for them.

So I think setup_page_is_buddy() should be changed like below:

static void
setup_page_is_buddy(void)

  {
          if (OFFSET(page.private) == NOT_FOUND_STRUCTURE)
                  info->page_is_buddy = NULL;
          else if (NUMBER(PG_buddy) == NOT_FOUND_NUMBER) {
                  if (NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE) !=
NOT_FOUND_NUMBER) {
                          if (OFFSET(page._mapcout) !=
NOT_FOUND_STRUCTURE) {
                                  info->page_is_buddy =
page_is_buddy_v3;
                                  return;
                          }
                  } else if (SIZE(pageflags) == NOT_FOUND_STRUCTURE) {
                          info->page_is_buddy = page_is_buddy_v1;
                          return;
                  }
          } else {
                  info->page_is_buddy = page_is_buddy_v2;
                  return;
          }
Quoted 7 lines
Quoted 5 lines

DEBUG_MSG("Can't select page_is_buddy handler; "
"follow freelist instead of mem_map.\n");

  }

Agree. I'll rewrite it.

Thanks.

Quoted 1 line

When do you plan to post v1.5.1-rc?

I will post v1.5.1-rc in Nov 16 as planned, so I would like to get v2 patches by noon tomorrow.

Thanks
Atsushi Kumagai

Quoted 9 lines

Thanks.
HATAYAMA, Daisuke

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec