linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zone configration check function [1/2]
@ 2007-02-20  5:30 KAMEZAWA Hiroyuki
  2007-02-20  5:34 ` [PATCH] remove zone ifdefs under mm/ [2/2] KAMEZAWA Hiroyuki
  0 siblings, 1 reply; 2+ messages in thread
From: KAMEZAWA Hiroyuki @ 2007-02-20  5:30 UTC (permalink / raw)
  To: linux-mm

An idea for remove #ifdefs...

This defines not configured zones ids as ids bigger than MAX_NR_ZONES.
We can use is_cofigured_zone(zone_id) for accessing specific zones
instead of inserting #ifdefs in the middle of funcs.

(*)MAX_NR_ZONES means as it does now.

This patch is against 2.6.20.

Signed-Off-By: KAMEZAWA Hiroyuki <kamezaw.hiroyu@jp.fujitsu.com>


Index: linux-2.6.20-devel/include/linux/mmzone.h
===================================================================
--- linux-2.6.20-devel.orig/include/linux/mmzone.h
+++ linux-2.6.20-devel/include/linux/mmzone.h
@@ -136,9 +136,23 @@ enum zone_type {
 	 */
 	ZONE_HIGHMEM,
 #endif
-	MAX_NR_ZONES
+	MAX_NR_ZONES,
+	/* Below is invalid zone ids depends on config */
+#ifndef CONFIG_ZONE_DMA32
+	ZONE_DMA32,
+#endif
+#ifndef CONFIG_ZONE_HIGHMEM
+	ZONE_HIGHMEM,
+#endif
+	ALL_POSSIBLE_ZONES
+#
 };
 
+static inline int is_configured_zone(enum zone_type id)
+{
+	return (id < MAX_NR_ZONES);
+}
+
 /*
  * When a memory allocation must conform to specific limitations (such
  * as being suitable for DMA) the caller will pass in hints to the
@@ -480,11 +494,9 @@ static inline int populated_zone(struct 
 
 static inline int is_highmem_idx(enum zone_type idx)
 {
-#ifdef CONFIG_HIGHMEM
+	if (!is_configured_zone(ZONE_HIGHMEM))
+		return 0;
 	return (idx == ZONE_HIGHMEM);
-#else
-	return 0;
-#endif
 }
 
 static inline int is_normal_idx(enum zone_type idx)
@@ -500,11 +512,9 @@ static inline int is_normal_idx(enum zon
  */
 static inline int is_highmem(struct zone *zone)
 {
-#ifdef CONFIG_HIGHMEM
+	if (!is_configured_zone(ZONE_HIGHMEM))
+		return 0;
 	return zone == zone->zone_pgdat->node_zones + ZONE_HIGHMEM;
-#else
-	return 0;
-#endif
 }
 
 static inline int is_normal(struct zone *zone)
@@ -514,11 +524,9 @@ static inline int is_normal(struct zone 
 
 static inline int is_dma32(struct zone *zone)
 {
-#ifdef CONFIG_ZONE_DMA32
+	if (!is_configured_zone(ZONE_DMA32))
+		return 0;
 	return zone == zone->zone_pgdat->node_zones + ZONE_DMA32;
-#else
-	return 0;
-#endif
 }
 
 static inline int is_dma(struct zone *zone)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] remove zone ifdefs under mm/ [2/2]
  2007-02-20  5:30 [PATCH] zone configration check function [1/2] KAMEZAWA Hiroyuki
@ 2007-02-20  5:34 ` KAMEZAWA Hiroyuki
  0 siblings, 0 replies; 2+ messages in thread
From: KAMEZAWA Hiroyuki @ 2007-02-20  5:34 UTC (permalink / raw)
  To: linux-mm

remove #ifdefs of CONFIG_HIGHMEM/DMA32.(as an example)

Signed-Off-By: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

Index: linux-2.6.20-devel/mm/page_alloc.c
===================================================================
--- linux-2.6.20-devel.orig/mm/page_alloc.c
+++ linux-2.6.20-devel/mm/page_alloc.c
@@ -72,28 +72,11 @@ static void __free_pages_ok(struct page 
  * TBD: should special case ZONE_DMA32 machines here - in those we normally
  * don't need any ZONE_NORMAL reservation
  */
-int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1] = {
-	 256,
-#ifdef CONFIG_ZONE_DMA32
-	 256,
-#endif
-#ifdef CONFIG_HIGHMEM
-	 32
-#endif
-};
+int sysctl_lowmem_reserve_ratio[MAX_NR_ZONES-1];
 
 EXPORT_SYMBOL(totalram_pages);
 
-static char * const zone_names[MAX_NR_ZONES] = {
-	 "DMA",
-#ifdef CONFIG_ZONE_DMA32
-	 "DMA32",
-#endif
-	 "Normal",
-#ifdef CONFIG_HIGHMEM
-	 "HighMem"
-#endif
-};
+static char * zone_names[ALL_POSSIBLE_ZONES];
 
 int min_free_kbytes = 1024;
 
@@ -132,6 +115,29 @@ static unsigned long __initdata dma_rese
 #endif /* CONFIG_MEMORY_HOTPLUG_RESERVE */
 #endif /* CONFIG_ARCH_POPULATES_NODE_MAP */
 
+static char dma_string[] = "DMA";
+static char normal_string[] = "Normal";
+static char dma32_string[] = "DMA32";
+static char highmem_string[] = "Highmem";
+
+static void __meminit init_zone_variables(void)
+{
+	if (zone_names[ZONE_DMA] == dma_string)
+		return;
+	zone_names[ZONE_DMA] =  dma_string;
+	zone_names[ZONE_DMA32] =  dma32_string;
+	zone_names[ZONE_NORMAL] =  normal_string;
+	zone_names[ZONE_HIGHMEM] = highmem_string;
+	sysctl_lowmem_reserve_ratio[ZONE_NORMAL] = 256;
+	if (is_configured_zone(ZONE_DMA32))
+		sysctl_lowmem_reserve_ratio[ZONE_DMA32] = 256;
+	if (is_configured_zone(ZONE_HIGHMEM))
+		sysctl_lowmem_reserve_ratio[ZONE_HIGHMEM] = 16;
+
+}
+
+
+
 #ifdef CONFIG_DEBUG_VM
 static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 {
@@ -1530,13 +1536,13 @@ void si_meminfo_node(struct sysinfo *val
 
 	val->totalram = pgdat->node_present_pages;
 	val->freeram = nr_free_pages_pgdat(pgdat);
-#ifdef CONFIG_HIGHMEM
-	val->totalhigh = pgdat->node_zones[ZONE_HIGHMEM].present_pages;
-	val->freehigh = pgdat->node_zones[ZONE_HIGHMEM].free_pages;
-#else
-	val->totalhigh = 0;
-	val->freehigh = 0;
-#endif
+	if (is_configured_zone(ZONE_HIGHMEM)) {
+		val->totalhigh = pgdat->node_zones[ZONE_HIGHMEM].present_pages;
+		val->freehigh = pgdat->node_zones[ZONE_HIGHMEM].free_pages;
+	} else {
+		val->totalhigh = 0;
+		val->freehigh = 0;
+	}
 	val->mem_unit = PAGE_SIZE;
 }
 #endif
@@ -2621,6 +2627,7 @@ static void __meminit free_area_init_cor
 	unsigned long zone_start_pfn = pgdat->node_start_pfn;
 	int ret;
 
+	init_zone_variables();
 	pgdat_resize_init(pgdat);
 	pgdat->nr_zones = 0;
 	init_waitqueue_head(&pgdat->kswapd_wait);
Index: linux-2.6.20-devel/mm/page-writeback.c
===================================================================
--- linux-2.6.20-devel.orig/mm/page-writeback.c
+++ linux-2.6.20-devel/mm/page-writeback.c
@@ -131,12 +131,11 @@ get_dirty_limits(long *pbackground, long
 	unsigned long available_memory = vm_total_pages;
 	struct task_struct *tsk;
 
-#ifdef CONFIG_HIGHMEM
 	/*
 	 * We always exclude high memory from our count.
 	 */
-	available_memory -= totalhigh_pages;
-#endif
+	if (is_configured_zone(ZONE_HIGHMEM))
+		available_memory -= totalhigh_pages;
 
 
 	unmapped_ratio = 100 - ((global_page_state(NR_FILE_MAPPED) +

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-20  5:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-20  5:30 [PATCH] zone configration check function [1/2] KAMEZAWA Hiroyuki
2007-02-20  5:34 ` [PATCH] remove zone ifdefs under mm/ [2/2] KAMEZAWA Hiroyuki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox