All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@shadowen.org>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] count defined zones to size ZONE_SHIFT
Date: Wed, 20 Sep 2006 14:54:13 +0100	[thread overview]
Message-ID: <20060920135413.GA7369@shadowen.org> (raw)

With the recent changes allowing ZONE_DMA etc to all be optional,
the ZONE_SHIFT calculation is very hard to follow.  Playing with
the compiler, it seems that the following is portable and IMO
much easier to read and understand.

-apw

=== 8< ===
count defined zones to size ZONE_SHIFT

Simplify calculation of the number of bits we need for ZONES_SHIFT
by adding up the definitions of the defined zones.  We make use of
the property of defined(X) that its value is one when X is defined
and zero otherwise.  From the GCC manuals:

  "defined name and defined (name) are both expressions whose
   value is 1 if name is defined as a macro at the current point
   in the program, and 0 otherwise."

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index b7836c5..9e339da 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -149,15 +149,27 @@ #endif
  * match the requested limits. See gfp_zone() in include/linux/gfp.h
  */
 
-#if !defined(CONFIG_ZONE_DMA32) && !defined(CONFIG_HIGHMEM)
-#if !defined(CONFIG_ZONE_DMA)
+/*
+ * Count the active zones.  Note that the use of defined(X) outside
+ * #if and family is not necessarily defined so ensure we cannot use
+ * it later.  Use __ZONE_COUNT to work out how many shift bits we need.
+ */
+#define __ZONE_COUNT (			\
+	  defined(CONFIG_ZONE_DMA)	\
+	+ defined(CONFIG_ZONE_DMA32)	\
+	+ 1				\
+	+ defined(CONFIG_HIGHMEM)	\
+)
+#if __ZONE_COUNT < 2
 #define ZONES_SHIFT 0
-#else
+#elif __ZONE_COUNT <= 2
 #define ZONES_SHIFT 1
-#endif
-#else
+#elif __ZONE_COUNT <= 4
 #define ZONES_SHIFT 2
+#else
+#error ZONES_SHIFT -- too many zones configured adjust calculation
 #endif
+#undef __ZONE_COUNT
 
 struct zone {
 	/* Fields commonly accessed by the page allocator */

                 reply	other threads:[~2006-09-20 13:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060920135413.GA7369@shadowen.org \
    --to=apw@shadowen.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.