The patch titled Subject: mm: factor out next_present_section_nr() has been added to the -mm tree. Its filename is mm-factor-out-next_present_section_nr.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-factor-out-next_present_section_nr.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-factor-out-next_present_section_nr.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: David Hildenbrand <david@xxxxxxxxxx> Subject: mm: factor out next_present_section_nr() Let's move it to the header and use the shorter variant from mm/page_alloc.c (the original one will also check "__highest_present_section_nr + 1", which is not necessary). While at it, make the section_nr in next_pfn() const. In next_pfn(), we now return section_nr_to_pfn(-1) instead of -1 once we exceed __highest_present_section_nr, which doesn't make a difference i= n the caller as it is big enough (>=3D all sane end_pfn). Link: http://lkml.kernel.org/r/20200113144035.10848-3-david@xxxxxxxxxx Signed-off-by: David Hildenbrand <david@xxxxxxxxxx> Cc: Baoquan He <bhe@xxxxxxxxxx> Cc: Dan Williams <dan.j.williams@xxxxxxxxx> Cc: "Jin, Zhi" <zhi.jin@xxxxxxxxx> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Cc: "Kirill A. Shutemov" <kirill@xxxxxxxxxxxxx> Cc: Mel Gorman <mgorman@xxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Oscar Salvador <osalvador@xxxxxxx> Cc: Pavel Tatashin <pasha.tatashin@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/mmzone.h | 10 ++++++++++ mm/page_alloc.c | 11 ++--------- mm/sparse.c | 10 ---------- 3 files changed, 12 insertions(+), 19 deletions(-) --- a/include/linux/mmzone.h~mm-factor-out-next_present_section_nr +++ a/include/linux/mmzone.h @@ -1379,6 +1379,16 @@ static inline int pfn_present(unsigned l return present_section(__nr_to_section(pfn_to_section_nr(pfn))); } +static inline unsigned long next_present_section_nr(unsigned long section_nr) +{ + while (++section_nr <= __highest_present_section_nr) { + if (present_section_nr(section_nr)) + return section_nr; + } + + return -1; +} + /* * These are _only_ used during initialisation, therefore they * can use __initdata ... They could have names to indicate --- a/mm/page_alloc.c~mm-factor-out-next_present_section_nr +++ a/mm/page_alloc.c @@ -5852,18 +5852,11 @@ overlap_memmap_init(unsigned long zone, /* Skip PFNs that belong to non-present sections */ static inline __meminit unsigned long next_pfn(unsigned long pfn) { - unsigned long section_nr; + const unsigned long section_nr = pfn_to_section_nr(++pfn); - section_nr = pfn_to_section_nr(++pfn); if (present_section_nr(section_nr)) return pfn; - - while (++section_nr <= __highest_present_section_nr) { - if (present_section_nr(section_nr)) - return section_nr_to_pfn(section_nr); - } - - return -1; + return section_nr_to_pfn(next_present_section_nr(section_nr)); } #else static inline __meminit unsigned long next_pfn(unsigned long pfn) --- a/mm/sparse.c~mm-factor-out-next_present_section_nr +++ a/mm/sparse.c @@ -198,16 +198,6 @@ static void section_mark_present(struct ms->section_mem_map |= SECTION_MARKED_PRESENT; } -static inline unsigned long next_present_section_nr(unsigned long section_nr) -{ - do { - section_nr++; - if (present_section_nr(section_nr)) - return section_nr; - } while ((section_nr <= __highest_present_section_nr)); - - return -1; -} #define for_each_present_section_nr(start, section_nr) \ for (section_nr = next_present_section_nr(start-1); \ ((section_nr != -1) && \ _ Patches currently in -mm which might be from david@xxxxxxxxxx are mm-fix-uninitialized-memmaps-on-a-partially-populated-last-section.patch fs-proc-pagec-allow-inspection-of-last-section-and-fix-end-detection.patch mm-initialize-memmap-of-unavailable-memory-directly.patch mm-memory_hotplug-dont-free-usage-map-when-removing-a-re-added-early-section.patch drivers-base-memoryc-cache-blocks-in-radix-tree-to-accelerate-lookup-fix-2.patch mm-memory_hotplug-poison-memmap-in-remove_pfn_range_from_zone.patch mm-memory_hotplug-we-always-have-a-zone-in-find_smallestbiggest_section_pfn.patch mm-memory_hotplug-dont-check-for-all-holes-in-shrink_zone_span.patch mm-memory_hotplug-drop-local-variables-in-shrink_zone_span.patch mm-memory_hotplug-cleanup-__remove_pages.patch mm-memory_hotplug-drop-valid_start-valid_end-from-test_pages_in_a_zone.patch mm-page_alloc-fix-and-rework-pfn-handling-in-memmap_init_zone.patch mm-factor-out-next_present_section_nr.patch