[RFC PATCH 3/3] mm: Implement for_each_valid_pfn() for CONFIG_SPARSEMEM

David Woodhouse dwmw2 at infradead.org
Thu Apr 3 00:15:41 PDT 2025


On Thu, 2025-04-03 at 08:07 +0100, David Woodhouse wrote:
> 
> I'll see if I can make it neater. I may drop the 'ret' variable
> completely and just turn the match clause into unlock-and-return-true.
> I *like* having a single unlock site. But I think I like simpler loop
> code more than that.

That's better (IMO).

And I note that pfn_valid() already doesn't follow the modern fetish
for having only one unlock site even when it makes the surrounding code
more complex to do so.

static inline bool first_valid_pfn(unsigned long *p_pfn)
{
	unsigned long pfn = *p_pfn;
	unsigned long nr = pfn_to_section_nr(pfn);
	struct mem_section *ms;

	rcu_read_lock_sched();

	while (nr <= __highest_present_section_nr) {
		ms = __pfn_to_section(pfn);

		if (valid_section(ms) &&
		    (early_section(ms) || pfn_section_first_valid(ms, &pfn))) {
			*p_pfn = pfn;
			rcu_read_unlock_sched();
			return true;
		}

		/* Nothing left in this section? Skip to next section */
		nr++;
		pfn = section_nr_to_pfn(nr);
	}

	rcu_read_unlock_sched();

	return false;
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5069 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20250403/8c7dc7b6/attachment.p7s>


More information about the linux-arm-kernel mailing list