]> www.infradead.org Git - users/dwmw2/linux.git/commit
mm: Implement for_each_valid_pfn() for CONFIG_SPARSEMEM
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 2 Apr 2025 17:58:36 +0000 (18:58 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Fri, 25 Apr 2025 22:57:53 +0000 (23:57 +0100)
commit55bebbb0931e4139798454a8a54375f14b911f62
treec82ccd4482cf0cc5073699fc0fe08addf4bf407c
parentd68fe39883dfea92e1163f9fb8f59cc44f460fa1
mm: Implement for_each_valid_pfn() for CONFIG_SPARSEMEM

Implement for_each_valid_pfn() based on two helper functions.

The first_valid_pfn() function largely mirrors pfn_valid(), calling into
a pfn_section_first_valid() helper which is trivial for the !VMEMMAP case,
and in the VMEMMAP case will skip to the next subsection as needed.

Since next_valid_pfn() knows that its argument *is* a valid PFN, it
doesn't need to do any checking at all while iterating over the low bits
within a (sub)section mask; the whole (sub)section is either present or
not.

Note that the VMEMMAP version of pfn_section_first_valid() may return a
value *higher* than end_pfn when skipping to the next subsection, and
first_valid_pfn() happily returns that higher value. This is fine.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
include/linux/mmzone.h