aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMel Gorman <mel@csn.ul.ie>2009-05-13 12:34:48 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2009-05-18 06:22:24 -0400
commiteb33575cf67d3f35fa2510210ef92631266e2465 (patch)
tree55dd9958dd10758aa5b1ad0186a3356ae620da44
parente1342f1da06d39b3bbd530e9306347c4438bc6e5 (diff)
[ARM] Double check memmap is actually valid with a memmap has unexpected holes V2
pfn_valid() is meant to be able to tell if a given PFN has valid memmap associated with it or not. In FLATMEM, it is expected that holes always have valid memmap as long as there is valid PFNs either side of the hole. In SPARSEMEM, it is assumed that a valid section has a memmap for the entire section. However, ARM and maybe other embedded architectures in the future free memmap backing holes to save memory on the assumption the memmap is never used. The page_zone linkages are then broken even though pfn_valid() returns true. A walker of the full memmap must then do this additional check to ensure the memmap they are looking at is sane by making sure the zone and PFN linkages are still valid. This is expensive, but walkers of the full memmap are extremely rare. This was caught before for FLATMEM and hacked around but it hits again for SPARSEMEM because the page_zone linkages can look ok where the PFN linkages are totally screwed. This looks like a hatchet job but the reality is that any clean solution would end up consumning all the memory saved by punching these unexpected holes in the memmap. For example, we tried marking the memmap within the section invalid but the section size exceeds the size of the hole in most cases so pfn_valid() starts returning false where valid memmap exists. Shrinking the size of the section would increase memory consumption offsetting the gains. This patch identifies when an architecture is punching unexpected holes in the memmap that the memory model cannot automatically detect and sets ARCH_HAS_HOLES_MEMORYMODEL. At the moment, this is restricted to EP93xx which is the model sub-architecture this has been reported on but may expand later. When set, walkers of the full memmap must call memmap_valid_within() for each PFN and passing in what it expects the page and zone to be for that PFN. If it finds the linkages to be broken, it assumes the memmap is invalid for that PFN. Signed-off-by: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--arch/arm/Kconfig6
-rw-r--r--include/linux/mmzone.h26
-rw-r--r--mm/mmzone.c15
-rw-r--r--mm/vmstat.c19
4 files changed, 48 insertions, 18 deletions
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index e60ec54df334..9d02cdb15b23 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -273,6 +273,7 @@ config ARCH_EP93XX
273 select HAVE_CLK 273 select HAVE_CLK
274 select COMMON_CLKDEV 274 select COMMON_CLKDEV
275 select ARCH_REQUIRE_GPIOLIB 275 select ARCH_REQUIRE_GPIOLIB
276 select ARCH_HAS_HOLES_MEMORYMODEL
276 help 277 help
277 This enables support for the Cirrus EP93xx series of CPUs. 278 This enables support for the Cirrus EP93xx series of CPUs.
278 279
@@ -976,10 +977,9 @@ config OABI_COMPAT
976 UNPREDICTABLE (in fact it can be predicted that it won't work 977 UNPREDICTABLE (in fact it can be predicted that it won't work
977 at all). If in doubt say Y. 978 at all). If in doubt say Y.
978 979
979config ARCH_FLATMEM_HAS_HOLES 980config ARCH_HAS_HOLES_MEMORYMODEL
980 bool 981 bool
981 default y 982 default n
982 depends on FLATMEM
983 983
984# Discontigmem is deprecated 984# Discontigmem is deprecated
985config ARCH_DISCONTIGMEM_ENABLE 985config ARCH_DISCONTIGMEM_ENABLE
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 186ec6ab334d..a47c879e1304 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1097,6 +1097,32 @@ unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long);
1097#define pfn_valid_within(pfn) (1) 1097#define pfn_valid_within(pfn) (1)
1098#endif 1098#endif
1099 1099
1100#ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
1101/*
1102 * pfn_valid() is meant to be able to tell if a given PFN has valid memmap
1103 * associated with it or not. In FLATMEM, it is expected that holes always
1104 * have valid memmap as long as there is valid PFNs either side of the hole.
1105 * In SPARSEMEM, it is assumed that a valid section has a memmap for the
1106 * entire section.
1107 *
1108 * However, an ARM, and maybe other embedded architectures in the future
1109 * free memmap backing holes to save memory on the assumption the memmap is
1110 * never used. The page_zone linkages are then broken even though pfn_valid()
1111 * returns true. A walker of the full memmap must then do this additional
1112 * check to ensure the memmap they are looking at is sane by making sure
1113 * the zone and PFN linkages are still valid. This is expensive, but walkers
1114 * of the full memmap are extremely rare.
1115 */
1116int memmap_valid_within(unsigned long pfn,
1117 struct page *page, struct zone *zone);
1118#else
1119static inline int memmap_valid_within(unsigned long pfn,
1120 struct page *page, struct zone *zone)
1121{
1122 return 1;
1123}
1124#endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */
1125
1100#endif /* !__GENERATING_BOUNDS.H */ 1126#endif /* !__GENERATING_BOUNDS.H */
1101#endif /* !__ASSEMBLY__ */ 1127#endif /* !__ASSEMBLY__ */
1102#endif /* _LINUX_MMZONE_H */ 1128#endif /* _LINUX_MMZONE_H */
diff --git a/mm/mmzone.c b/mm/mmzone.c
index 16ce8b955dcf..f5b7d1760213 100644
--- a/mm/mmzone.c
+++ b/mm/mmzone.c
@@ -6,6 +6,7 @@
6 6
7 7
8#include <linux/stddef.h> 8#include <linux/stddef.h>
9#include <linux/mm.h>
9#include <linux/mmzone.h> 10#include <linux/mmzone.h>
10#include <linux/module.h> 11#include <linux/module.h>
11 12
@@ -72,3 +73,17 @@ struct zoneref *next_zones_zonelist(struct zoneref *z,
72 *zone = zonelist_zone(z); 73 *zone = zonelist_zone(z);
73 return z; 74 return z;
74} 75}
76
77#ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
78int memmap_valid_within(unsigned long pfn,
79 struct page *page, struct zone *zone)
80{
81 if (page_to_pfn(page) != pfn)
82 return 0;
83
84 if (page_zone(page) != zone)
85 return 0;
86
87 return 1;
88}
89#endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 66f6130976cb..74d66dba0cbe 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -509,22 +509,11 @@ static void pagetypeinfo_showblockcount_print(struct seq_file *m,
509 continue; 509 continue;
510 510
511 page = pfn_to_page(pfn); 511 page = pfn_to_page(pfn);
512#ifdef CONFIG_ARCH_FLATMEM_HAS_HOLES 512
513 /* 513 /* Watch for unexpected holes punched in the memmap */
514 * Ordinarily, memory holes in flatmem still have a valid 514 if (!memmap_valid_within(pfn, page, zone))
515 * memmap for the PFN range. However, an architecture for
516 * embedded systems (e.g. ARM) can free up the memmap backing
517 * holes to save memory on the assumption the memmap is
518 * never used. The page_zone linkages are then broken even
519 * though pfn_valid() returns true. Skip the page if the
520 * linkages are broken. Even if this test passed, the impact
521 * is that the counters for the movable type are off but
522 * fragmentation monitoring is likely meaningless on small
523 * systems.
524 */
525 if (page_zone(page) != zone)
526 continue; 515 continue;
527#endif 516
528 mtype = get_pageblock_migratetype(page); 517 mtype = get_pageblock_migratetype(page);
529 518
530 if (mtype < MIGRATE_TYPES) 519 if (mtype < MIGRATE_TYPES)