linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Leesoo Ahn <lsahn@ooseel.net>
To: lsahn@ooseel.net
Cc: Leesoo Ahn <lsahn@wewakecorp.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm: sparse: clarify a variable name and its value
Date: Sun,  9 Jun 2024 00:21:14 +0900	[thread overview]
Message-ID: <20240608152114.867961-1-lsahn@wewakecorp.com> (raw)

Setting 'limit' variable to 0 might seem like it means "no limit". But
in the memblock API, 0 actually means the 'MEMBLOCK_ALLOC_ACCESSIBLE'
enum, which limits the physical address range based on
'memblock.current_limit'. This can be confusing.

To make things clearer, I suggest renaming the variable to
'limit_or_flag'. This name shows that the variable can either be a
number for limits or an enum for a flag. This way, readers will easily
understand what kind of value is being passed to the memblock API and
how it works without needing to look into the API details.

Signed-off-by: Leesoo Ahn <lsahn@ooseel.net>
---
 mm/sparse.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/mm/sparse.c b/mm/sparse.c
index de40b2c73406..80e50ba26f24 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -333,7 +333,7 @@ sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
 					 unsigned long size)
 {
 	struct mem_section_usage *usage;
-	unsigned long goal, limit;
+	unsigned long goal, limit_or_flag;
 	int nid;
 	/*
 	 * A page may contain usemaps for other sections preventing the
@@ -346,12 +346,13 @@ sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
 	 * this problem.
 	 */
 	goal = pgdat_to_phys(pgdat) & (PAGE_SECTION_MASK << PAGE_SHIFT);
-	limit = goal + (1UL << PA_SECTION_SHIFT);
+	limit_or_flag = goal + (1UL << PA_SECTION_SHIFT);
 	nid = early_pfn_to_nid(goal >> PAGE_SHIFT);
 again:
-	usage = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, goal, limit, nid);
-	if (!usage && limit) {
-		limit = 0;
+	usage = memblock_alloc_try_nid(size, SMP_CACHE_BYTES, goal,
+				limit_or_flag, nid);
+	if (!usage && (limit_or_flag != MEMBLOCK_ALLOC_ACCESSIBLE)) {
+		limit_or_flag = MEMBLOCK_ALLOC_ACCESSIBLE;
 		goto again;
 	}
 	return usage;
-- 
2.34.1



             reply	other threads:[~2024-06-08 15:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-08 15:21 Leesoo Ahn [this message]
2024-06-09 21:03 ` Andrew Morton
2024-06-10  3:39   ` Leesoo Ahn
2024-06-10  6:06     ` Mike Rapoport
2024-06-10  8:20       ` Leesoo Ahn

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=20240608152114.867961-1-lsahn@wewakecorp.com \
    --to=lsahn@ooseel.net \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lsahn@wewakecorp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox