Skip to contentSkip to conversation

use NODES_SHIFT to calculate ZONE_SHIFT

PATCH In review Jesse Barnes 2 participants 3 messages Nov 5, 2003 – Nov 7, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use NODES_SHIFT to calculate ZONE_SHIFT

Now that we have a proper NODES_SHIFT value, we need to use it to define ZONE_SHIFT otherwise we'll spill over 8 bits if we have more than 85 nodes. How does this look? The '+2' should really be log2(MAX_NR_NODES), but I think this is an improvement over what was there.

Thanks,
Jesse

===== include/linux/mm.h 1.133 vs edited =====

include/linux/mm.h +3 -1
@@ -322,8 +322,10 @@
 /*
  * The zone field is never updated after free_area_init_core()
  * sets it, so none of the operations on it need to be atomic.
+ * We'll have up to log2(MAX_NUMNODES * MAX_NR_ZONES) zones
+ * total, so we use NODES_SHIFT here to get enough bits.
  */
-#define ZONE_SHIFT (BITS_PER_LONG - 8)
+#define ZONE_SHIFT (BITS_PER_LONG - (NODES_SHIFT + 2))
 
 struct zone;
 extern struct zone *zone_table[];
#1 lore raw
Quoted 6 lines · [email protected] (Jesse Barnes) wrote:

Now that we have a proper NODES_SHIFT value, we need to use it to define ZONE_SHIFT otherwise we'll spill over 8 bits if we have more than 85 nodes. How does this look? The '+2' should really be log2(MAX_NR_NODES), but I think this is an improvement over what was there.

You mean log2(MAX_NR_ZONES).

How about we do it this way, so at least the duplicated information is on adjacent lines, and they are unlikely to get out of sync?

include/linux/mm.h renamed from include/linux/mm.h~ZONE_SHIFT-from-NODES_SHIFT +3 -1
diff -puN include/linux/mm.h~ZONE_SHIFT-from-NODES_SHIFT include/linux/mm.h
@@ -322,8 +322,10 @@ static inline void put_page(struct page 
 /*
  * The zone field is never updated after free_area_init_core()
  * sets it, so none of the operations on it need to be atomic.
+ * We'll have up to log2(MAX_NUMNODES * MAX_NR_ZONES) zones
+ * total, so we use NODES_SHIFT here to get enough bits.
  */
-#define ZONE_SHIFT (BITS_PER_LONG - 8)
+#define ZONE_SHIFT (BITS_PER_LONG - NODES_SHIFT - MAX_NR_ZONES_SHIFT)
 
 struct zone;
 extern struct zone *zone_table[];
include/linux/mmzone.h renamed from include/linux/mmzone.h~ZONE_SHIFT-from-NODES_SHIFT +4 -1
diff -puN include/linux/mmzone.h~ZONE_SHIFT-from-NODES_SHIFT include/linux/mmzone.h
@@ -159,7 +159,10 @@ struct zone {
 #define ZONE_DMA		0
 #define ZONE_NORMAL		1
 #define ZONE_HIGHMEM		2
-#define MAX_NR_ZONES		3
+
+#define MAX_NR_ZONES		3	/* Sync this with MAX_NR_ZONES_SHIFT */
+#define MAX_NR_ZONES_SHIFT	2	/* ceil(log2(MAX_NR_ZONES)) */
+
 #define GFP_ZONEMASK	0x03
 
 /*

_

#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 6 lines · [email protected] (Jesse Barnes) wrote:

Now that we have a proper NODES_SHIFT value, we need to use it to define ZONE_SHIFT otherwise we'll spill over 8 bits if we have more than 85 nodes. How does this look? The '+2' should really be log2(MAX_NR_NODES), but I think this is an improvement over what was there.

You mean log2(MAX_NR_ZONES).

Yep, sorry.

Quoted 2 lines

How about we do it this way, so at least the duplicated information is on adjacent lines, and they are unlikely to get out of sync?

Yeah, this looks great.

Thanks,
Jesse