All of lore.kernel.org
 help / color / mirror / Atom feed
From: gaoxu <gaoxu2@honor.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Mike Rapoport <rppt@kernel.org>,
	"surenb@google.com" <surenb@google.com>,
	Barry Song <21cnbao@gmail.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	yipengxiang <yipengxiang@honor.com>
Subject: [PATCH] mm: simplify zone_idx()
Date: Thu, 10 Apr 2025 12:03:00 +0000	[thread overview]
Message-ID: <2d42decac5194c2c8d897b0424f0dcf3@honor.com> (raw)

store zone_idx directly in struct zone to simplify and optimize zone_idx()

Signed-off-by: gao xu <gaoxu2@honor.com>
---
 include/linux/mmzone.h | 3 ++-
 mm/mm_init.c           | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 4c95fcc9e..7b14f577d 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -941,6 +941,7 @@ struct zone {
 #endif
 
 	const char		*name;
+	enum zone_type	zone_idx;
 
 #ifdef CONFIG_MEMORY_ISOLATION
 	/*
@@ -1536,7 +1537,7 @@ static inline int local_memory_node(int node_id) { return node_id; };
 /*
  * zone_idx() returns 0 for the ZONE_DMA zone, 1 for the ZONE_NORMAL zone, etc.
  */
-#define zone_idx(zone)		((zone) - (zone)->zone_pgdat->node_zones)
+#define zone_idx(zone)		((zone)->zone_idx)
 
 #ifdef CONFIG_ZONE_DEVICE
 static inline bool zone_is_zone_device(struct zone *zone)
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 9659689b8..a7f7264f1 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1425,6 +1425,7 @@ static void __meminit zone_init_internals(struct zone *zone, enum zone_type idx,
 	atomic_long_set(&zone->managed_pages, remaining_pages);
 	zone_set_nid(zone, nid);
 	zone->name = zone_names[idx];
+	zone->zone_idx = idx;
 	zone->zone_pgdat = NODE_DATA(nid);
 	spin_lock_init(&zone->lock);
 	zone_seqlock_init(zone);
-- 
2.17.1

             reply	other threads:[~2025-04-10 12:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10 12:03 gaoxu [this message]
2025-04-10 14:41 ` [PATCH] mm: simplify zone_idx() Mike Rapoport
2025-04-10 21:59   ` Barry Song
2025-04-12  8:34     ` 回复: " gaoxu
2025-04-12  9:15       ` Barry Song
2025-04-12 10:06         ` 回复: " gaoxu
2025-04-13 21:57           ` Barry Song
2025-04-13 23:20             ` Matthew Wilcox
2025-04-15 12:34               ` gaoxu
2025-04-15 14:49                 ` Matthew Wilcox

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=2d42decac5194c2c8d897b0424f0dcf3@honor.com \
    --to=gaoxu2@honor.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=yipengxiang@honor.com \
    /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.