From nobody Fri Dec 19 18:25:24 2025 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 645C742A87 for ; Tue, 11 Mar 2025 23:31:18 +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=1741735880; cv=none; b=hHhkCYUq9DQ9NnoXVNeDbTPp22JdF+L4R47jT+4oZP3XhHAoPtb5ouyO5iHgyW82saG2yVwn9MLlOguYSn3PCffza7DsjQhTCyIuEIyS3ck7OBvIRG7vx3IZFphyMr7ot7y7T7CcC182P4nLspAeOKJ0mSxsB7JiAIdH8ytiTgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741735880; c=relaxed/simple; bh=WQTgGWyDwEesTK+r9mqc7KbfBgqE9eIvIxfj1+z9MeU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p9E+uzEOV0xMV+8JwNZuQ1cgF9Ca6HWbKHaM4rArgP7NVIHaAd29sj/IB8xt7lfViOuFQOoZCCY87tkDkCZczO3YbJqXmeFmmpwKtQeMPC7nQhkuuHeG/sHk5+CQqsQdML0i6Ca8zu0A+ZGtDForSvPwJ52p7Q/tA0oEgNbNK18= 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=LhBMrSLA; 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="LhBMrSLA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741735876; 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=JFRXYsV6OcgqgN+/5AlzPbliPGGUfcZP8+g1uf56q6A=; b=LhBMrSLA/J3hRgtfTFuQ/PasKiI536jMaxOF0+J3gjBThaE3EzHTNj2vWQ96SSJ2SOpcBE pu/3fVRdnJ53hxDQMeGTe6+dP5aYhu5uXvAfJ+Mlr4GXJ1MH18lQn/0vKotHaOvfuzgGv3 nlPd5Igp0xHRI6EBb986sB9K+XzV4lk= Received: from mx-prod-mc-05.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-210-2i3KdKclNQ2phTZIy6UYCQ-1; Tue, 11 Mar 2025 19:31:11 -0400 X-MC-Unique: 2i3KdKclNQ2phTZIy6UYCQ-1 X-Mimecast-MFC-AGG-ID: 2i3KdKclNQ2phTZIy6UYCQ_1741735869 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC52A195608A; Tue, 11 Mar 2025 23:31:08 +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 76BAF1828A98; Tue, 11 Mar 2025 23:31:03 +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 v3 1/2] drivers/base/memory: Improve add_boot_memory_block() Date: Wed, 12 Mar 2025 09:30:43 +1000 Message-ID: <20250311233045.148943-2-gshan@redhat.com> In-Reply-To: <20250311233045.148943-1-gshan@redhat.com> References: <20250311233045.148943-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 ++++++++--------- include/linux/mmzone.h | 5 +++++ mm/sparse.c | 5 ----- 3 files changed, 13 insertions(+), 14 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, 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 Fri Dec 19 18:25:24 2025 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 2167F1E9B22 for ; Tue, 11 Mar 2025 23:32:02 +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=1741735924; cv=none; b=oIFFMsaVc1mYiU5vp0IfdTjUDdsxzPvH8SmZeK3Q616lE+2U3k9uAUQYar8Xu0gb0GHaSezirlPPSLiCzau5uIC1uRUEInDPgB+LuZpVoAetfM52CBBUqcwlT4JPnklvckJ5RmG1qh0/X9ApSav08SZ7zeiFdQCRGH6vpufdtq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741735924; c=relaxed/simple; bh=kDfaDRFD6shsKdu/pMXIHDEcVnk7SY3SaYRPT4Slv7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IxE7v4Yw0qfsJc5CFFKGgpkOTyOFWeTLx1KxFXGrX/moSUENZTUI2oDP3y1DLiVjA05iQRAbHbalG5560gaaGXAWIKQai/XUqMDQiFEqXjpGcKwBnnrTIoGhdVthdHY4XdNLH97xChzegy1UYbIU8VMYWhyaJjxa0nQQr7mP5VM= 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=iy/6icOT; 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="iy/6icOT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741735922; 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=8INPd9WvtcPC9yCOdy3J5xeTgC7shZeUYjpA84y5sNU=; b=iy/6icOTiIzV5NQERclvpmQvA7Jr3Pa9EB7PCG7fyOU2gNHYowGw2OPT+huc4EFG0kX9wX o7L0mO9UO2IrO9fdKqtrDYvjBRowHhPpQqSWpTRGu89jcgG66EPuhaRQ9j+IiNijt8C0cs Pdjd/d3WFMFEERANCHLta3EvvKAtwIY= Received: from mx-prod-mc-01.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-661-ABJnKkzSOTuhZSaNGXI1aA-1; Tue, 11 Mar 2025 19:31:16 -0400 X-MC-Unique: ABJnKkzSOTuhZSaNGXI1aA-1 X-Mimecast-MFC-AGG-ID: ABJnKkzSOTuhZSaNGXI1aA_1741735875 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3983419560B0; Tue, 11 Mar 2025 23:31:15 +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 F41F61828A93; Tue, 11 Mar 2025 23:31:09 +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 v3 2/2] drivers/base/memory: Correct the field name in the header Date: Wed, 12 Mar 2025 09:30:44 +1000 Message-ID: <20250311233045.148943-3-gshan@redhat.com> In-Reply-To: <20250311233045.148943-1-gshan@redhat.com> References: <20250311233045.148943-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