]> git.baikalelectronics.ru Git - kernel.git/commitdiff
mm: factor out next_present_section_nr()
authorDavid Hildenbrand <david@redhat.com>
Tue, 4 Feb 2020 01:34:02 +0000 (17:34 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 4 Feb 2020 03:05:23 +0000 (03:05 +0000)
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 in
the caller as it is big enough (>= all sane end_pfn).

Link: http://lkml.kernel.org/r/20200113144035.10848-3-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: "Jin, Zhi" <zhi.jin@intel.com>
Cc: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Pavel Tatashin <pasha.tatashin@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/mmzone.h
mm/page_alloc.c
mm/sparse.c

index c2bc309d163451177ca2ed3c50b8a064f73e7550..462f6873905a3b8fe35526a818b7c2945b1b7f8d 100644 (file)
@@ -1379,6 +1379,16 @@ static inline int pfn_present(unsigned long pfn)
        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
index 461ed73bc30f4ef28f8b4a19c1e44888c3166767..494f74a1725d629a5f78436ec4dd518f88355902 100644 (file)
@@ -5852,18 +5852,11 @@ overlap_memmap_init(unsigned long zone, unsigned long *pfn)
 /* 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)
index 3918fc3eaef1fe029c678032f25cf0c5642f3c1d..c184b69460b7bd53198a5e31cfd56bf39b0016e5 100644 (file)
@@ -198,16 +198,6 @@ static void section_mark_present(struct mem_section *ms)
        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) &&                             \