From nobody Sat Feb 7 15:11:17 2026 Received: from mta22.hihonor.com (mta22.honor.com [81.70.192.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B216D281505 for ; Thu, 10 Apr 2025 12:03:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.70.192.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744286586; cv=none; b=cuSmxq32gwxDB+68HyHgEfXZ6K9dRnONzlLQ2l8L3LfFUa09L7r1zKgDU6kDxpOmMKTggfnKt9nxPfJT53ZPJb0wa9DgTscfq0dyx/Ts0OWBE63195sGeh9a/My7g8NMOVXr7ibLuJa33eZts7DV5wBsrdohXhUq0g+SOFC1MR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744286586; c=relaxed/simple; bh=2HJEpfvBQlz7dQT60A81j7d32Y9ZWDLfKF+1y5GeKIg=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=GJA8HQ2vy3iNy5j8XuzGjW3oDi+0NH8HrtkxvQgPdqtfslLwJ4OVJrxH45AoE0hIrj9lC/Na7tdUbDjlHemPxGpgG3B018jKqJRlAJzKZKkgT0ksEv3N7Z8Mw125yZNOiBgNdovuR0620TzgA+aFiOTqmB9y5DI5Ey4Bqi6HDfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com; spf=pass smtp.mailfrom=honor.com; arc=none smtp.client-ip=81.70.192.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=honor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=honor.com Received: from w011.hihonor.com (unknown [10.68.20.122]) by mta22.hihonor.com (SkyGuard) with ESMTPS id 4ZYJN20YBlzYl25P; Thu, 10 Apr 2025 20:02:26 +0800 (CST) Received: from a003.hihonor.com (10.68.18.8) by w011.hihonor.com (10.68.20.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 10 Apr 2025 20:03:00 +0800 Received: from a007.hihonor.com (10.68.22.31) by a003.hihonor.com (10.68.18.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 10 Apr 2025 20:03:00 +0800 Received: from a007.hihonor.com ([fe80::e866:83ac:f23b:c25c]) by a007.hihonor.com ([fe80::e866:83ac:f23b:c25c%10]) with mapi id 15.02.1544.011; Thu, 10 Apr 2025 20:03:00 +0800 From: gaoxu To: Andrew Morton CC: Mike Rapoport , "surenb@google.com" , Barry Song <21cnbao@gmail.com>, "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , yipengxiang Subject: [PATCH] mm: simplify zone_idx() Thread-Topic: [PATCH] mm: simplify zone_idx() Thread-Index: AduqEEHvK6kd7fhKS8Kk+tRXk/ygUQ== Date: Thu, 10 Apr 2025 12:03:00 +0000 Message-ID: <2d42decac5194c2c8d897b0424f0dcf3@honor.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 store zone_idx directly in struct zone to simplify and optimize zone_idx() Signed-off-by: gao xu --- 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 =20 const char *name; + enum zone_type zone_idx; =20 #ifdef CONFIG_MEMORY_ISOLATION /* @@ -1536,7 +1537,7 @@ static inline int local_memory_node(int node_id) { re= turn 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) =20 #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 =3D zone_names[idx]; + zone->zone_idx =3D idx; zone->zone_pgdat =3D NODE_DATA(nid); spin_lock_init(&zone->lock); zone_seqlock_init(zone); --=20 2.17.1