From nobody Sun Feb 8 04:17:53 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 9AB6F79FD for ; Tue, 11 Mar 2025 00:47:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741654081; cv=none; b=jUc4BJIBNt9rK0ahG0YNg04EFfVJmmpAa2QAWp+3tSIpi16FzgmPC+LoOvoEKLlkTN0kjVDVPho2GGk/rs+B+Fy5UacA36rVM8qCJcc4P1pWjmdAwsQ47D62XPtE2zjO6I4kIPz2rX9WUyc89m985y4yWolMjXa1MMuEu8dQbfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741654081; c=relaxed/simple; bh=KAljwSvGX1g+l2eBUttGm0UZUh5aUyhM+EPHYMjqKvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HITA6PkfR4iWuc5uEWTgZlMIjKOY3wPcmsMgbsdhLpjUv5FjFVdNt+qBDOzfYmfcShSWMJa6SBxCz4C6IByT1CAWjHY9qum5k2CT+oZj15jlMKsvIcTbBZeXFson5Cl/jKJPoMgzuy6vnpqDjjG70h7vNm3Db1Zkdvm30HVyv+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jBjvCMTP; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jBjvCMTP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741654077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hgrxg5qAPOx7K2ONkn1MCXNcggxF5k+2r/MNYL/OtKg=; b=jBjvCMTPIHxrur7h8NvCAjTB7oogy8vHiWG5etwvodDenkF6by7yauvfUHV2Z5Nn86QGaW Ruh6GttvYEjn3SNZbG/DdiEIEfI0EFSSzVbdfwzqanFffQ1w06hF+cMAdrmUL07r/QxZn1 ALdrkncqqUTQgSSnfY+ohQ6LNM4vokM= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-491-eQAVUnAIOIizaZ8uLe3bPw-1; Mon, 10 Mar 2025 20:47:56 -0400 X-MC-Unique: eQAVUnAIOIizaZ8uLe3bPw-1 X-Mimecast-MFC-AGG-ID: eQAVUnAIOIizaZ8uLe3bPw_1741654075 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C90271956048; Tue, 11 Mar 2025 00:47:54 +0000 (UTC) Received: from gshan-thinkpadx1nanogen2.remote.csb (unknown [10.64.136.79]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 611301828A8A; Tue, 11 Mar 2025 00:47:48 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com Subject: [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr() Date: Tue, 11 Mar 2025 10:46:55 +1000 Message-ID: <20250311004657.82985-2-gshan@redhat.com> In-Reply-To: <20250311004657.82985-1-gshan@redhat.com> References: <20250311004657.82985-1-gshan@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Expose for_each_present_section_nr() to be used by drivers/base/memory in the next patch. No functional changes intended. Signed-off-by: Gavin Shan --- include/linux/mmzone.h | 5 +++++ mm/sparse.c | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 9540b41894da..0f6646da34d7 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -2097,6 +2097,11 @@ static inline unsigned long next_present_section_nr(= unsigned long section_nr) return -1; } =20 +#define for_each_present_section_nr(start, section_nr) \ + for (section_nr =3D next_present_section_nr(start - 1); \ + section_nr !=3D -1; \ + section_nr =3D next_present_section_nr(section_nr)) + /* * These are _only_ used during initialisation, therefore they * can use __initdata ... They could have names to indicate diff --git a/mm/sparse.c b/mm/sparse.c index 133b033d0cba..fe77d523ab8d 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -170,11 +170,6 @@ static void __section_mark_present(struct mem_section = *ms, ms->section_mem_map |=3D SECTION_MARKED_PRESENT; } =20 -#define for_each_present_section_nr(start, section_nr) \ - for (section_nr =3D next_present_section_nr(start-1); \ - section_nr !=3D -1; \ - section_nr =3D next_present_section_nr(section_nr)) - static inline unsigned long first_present_section_nr(void) { return next_present_section_nr(-1); --=20 2.48.1 From nobody Sun Feb 8 04:17:53 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 AEFBD1DE8B4 for ; Tue, 11 Mar 2025 00:48:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741654088; cv=none; b=Qh6zZejHt/VjwHk3i1hJ4qXyARUGAaMr2V+in4gFwPUNyEkA+xFfOpwNX+nsw0aDruAaqEXDuBzZk4XjgtuBmOL1nmyBW5+rbQNrmFn8pAbEIyz+E8qicRJjUOqvEQt4v4b4URYhDkoulf9h/p5HwK4kxg32EZiKWA62CmEP+Ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741654088; c=relaxed/simple; bh=YmERs+rW+18w2qxrqcTji7wgIx7X4oERW4u69t6kWLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=scCtj1KgzW1bI97YNyN9R7GI9dOq3Nxv2wbztOfBTeMzOML8PFVR5HNTbp39rs3Hnn8aVOAy9czOtSMO+QFqE6aztVskVif2urg8tnc4ofFnFfmSXIGZRU7HlICeBjavTVXlhvHvqGsqBfGp63ktcsr4wfJ/ZbyOgCqAYn1p+O4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RhCg4FLI; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RhCg4FLI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741654085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e0HbzPi7UYXU5CIv0zG6CMHVf7Xivfr/axNQwtv2yW0=; b=RhCg4FLIhjJPxApp0lapcLBA+uRfJUHe+LJoMFR5vayfGZ08fo5M+AZtSshnxWDE7s2Rhe GNOeRURrMsBENanr38wOI8rCzq/euSxAEL1DE8mS/5DIbtd9C9YnUcoHUB1CFQXjUr9vE6 fJ39oyIbtSL8WgqjOIDZP1s3wep5vSg= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-2V7kjy-6PcKacCUXDWDGxA-1; Mon, 10 Mar 2025 20:48:02 -0400 X-MC-Unique: 2V7kjy-6PcKacCUXDWDGxA-1 X-Mimecast-MFC-AGG-ID: 2V7kjy-6PcKacCUXDWDGxA_1741654081 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AC2F01800263; Tue, 11 Mar 2025 00:48:00 +0000 (UTC) Received: from gshan-thinkpadx1nanogen2.remote.csb (unknown [10.64.136.79]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BEDBC18001E9; Tue, 11 Mar 2025 00:47:55 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com Subject: [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block() Date: Tue, 11 Mar 2025 10:46:56 +1000 Message-ID: <20250311004657.82985-3-gshan@redhat.com> In-Reply-To: <20250311004657.82985-1-gshan@redhat.com> References: <20250311004657.82985-1-gshan@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" It's unnecessary to count the present sections for the specified block since the block will be added if any section in the block is present. Besides, for_each_present_section_nr() can be reused as Andrew Morton suggested. Improve by using for_each_present_section_nr() and dropping the unnecessary @section_count. No functional changes intended. Signed-off-by: Gavin Shan Acked-by: David Hildenbrand Acked-by: Oscar Salvador --- drivers/base/memory.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 348c5dbbfa68..f66e9d537c12 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -822,18 +822,17 @@ static int add_memory_block(unsigned long block_id, u= nsigned long state, =20 static int __init add_boot_memory_block(unsigned long base_section_nr) { - int section_count =3D 0; unsigned long nr; =20 - for (nr =3D base_section_nr; nr < base_section_nr + sections_per_block; - nr++) - if (present_section_nr(nr)) - section_count++; + for_each_present_section_nr(base_section_nr, nr) { + if (nr >=3D (base_section_nr + sections_per_block)) + break; =20 - if (section_count =3D=3D 0) - return 0; - return add_memory_block(memory_block_id(base_section_nr), - MEM_ONLINE, NULL, NULL); + return add_memory_block(memory_block_id(base_section_nr), + MEM_ONLINE, NULL, NULL); + } + + return 0; } =20 static int add_hotplug_memory_block(unsigned long block_id, --=20 2.48.1 From nobody Sun Feb 8 04:17:53 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 CC5A01DEFF3 for ; Tue, 11 Mar 2025 00:48:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741654094; cv=none; b=rt74Mvv4A5CWsLZxiwaTkPOv1F7vDPsg/6D0ADR86Ape/6X+ZUnPZaqScxvTm8vnwYoYW1COn8NcoC/0IysPNJJ8HCSUq58pAg/sG6wvu7DNXZBMdNKkv74yA45oIe9TULwzuiqHCrdIjqIOHktQjPdJ1pMi91ST2MWSW33ilX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741654094; c=relaxed/simple; bh=5YZNUGJCJYr7l4LPbz+b90tbdzv/yRHsXo30mMOf/jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BIH5vGIXEvDNXkoNe522gB7NbGgNe0PsAX+EtCA6/gklRZ1q11hh5hmW6vEaIqFfv6na4B2zxY4eLLR97lZrkBS6hvzjhVHu3IzslzuQZlmgfX3Q56H0Eqxkbh0GXxmbaD9D8V+t5cve8+/1Xr4BsS9pjEVcjYOAedgRAPGDFSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QtVjT8YH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QtVjT8YH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741654092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eE53Ah3+LX+rmJRq+jfZ6lpqQieXXNgXZwY62OeKfdE=; b=QtVjT8YHiNv/Xo5x3AFFGrwEEhYuA0uNO8WlLvBGAIC8oEtHuIph0SuL7e6hA7ugyUpKAr v43P05gpQ3vhxxLV7K92Xhr5cy+eLiBfdWkzaJ33eEWS4raVjMn0Axl5GdSJCdL3C+8stu xP4HChrqCnL11PANNVNF15KZT8ZJUPA= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362--IaUVPyZNbqlfswGgtIVzQ-1; Mon, 10 Mar 2025 20:48:08 -0400 X-MC-Unique: -IaUVPyZNbqlfswGgtIVzQ-1 X-Mimecast-MFC-AGG-ID: -IaUVPyZNbqlfswGgtIVzQ_1741654087 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0B9ED180AF53; Tue, 11 Mar 2025 00:48:07 +0000 (UTC) Received: from gshan-thinkpadx1nanogen2.remote.csb (unknown [10.64.136.79]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8DA511800373; Tue, 11 Mar 2025 00:48:01 +0000 (UTC) From: Gavin Shan To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, david@redhat.com, osalvador@suse.de, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, akpm@linux-foundation.org, shan.gavin@gmail.com Subject: [PATCH v2 3/3] drivers/base/memory: Correct the field name in the header Date: Tue, 11 Mar 2025 10:46:57 +1000 Message-ID: <20250311004657.82985-4-gshan@redhat.com> In-Reply-To: <20250311004657.82985-1-gshan@redhat.com> References: <20250311004657.82985-1-gshan@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Replace @blocks with @memory_blocks to match with the definition of struct memory_group. Signed-off-by: Gavin Shan Acked-by: David Hildenbrand Acked-by: Oscar Salvador --- include/linux/memory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/memory.h b/include/linux/memory.h index c0afee5d126e..12daa6ec7d09 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -25,7 +25,7 @@ /** * struct memory_group - a logical group of memory blocks * @nid: The node id for all memory blocks inside the memory group. - * @blocks: List of all memory blocks belonging to this memory group. + * @memory_blocks: List of all memory blocks belonging to this memory grou= p. * @present_kernel_pages: Present (online) memory outside ZONE_MOVABLE of = this * memory group. * @present_movable_pages: Present (online) memory in ZONE_MOVABLE of this --=20 2.48.1