Skip to content

Commit 3705fd2

Browse files
davidhildenbrandshaoyingxu
authored andcommitted
mm,memory_hotplug: factor out adjusting present pages into adjust_present_page_count()
Let's have a single place (inspired by adjust_managed_page_count()) where we adjust present pages. In contrast to adjust_managed_page_count(), only memory onlining or offlining is allowed to modify the number of present pages. Link: https://lkml.kernel.org/r/20210421102701.25051-4-osalvador@suse.de Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Oscar Salvador <osalvador@suse.de> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Pavel Tatashin <pasha.tatashin@soleen.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> (cherry picked from commit f990114)
1 parent 80a6563 commit 3705fd2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mm/memory_hotplug.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,16 @@ struct zone *zone_for_pfn_range(int online_type, int nid,
777777
return default_zone_for_pfn(nid, start_pfn, nr_pages);
778778
}
779779

780+
static void adjust_present_page_count(struct zone *zone, long nr_pages)
781+
{
782+
unsigned long flags;
783+
784+
zone->present_pages += nr_pages;
785+
pgdat_resize_lock(zone->zone_pgdat, &flags);
786+
zone->zone_pgdat->node_present_pages += nr_pages;
787+
pgdat_resize_unlock(zone->zone_pgdat, &flags);
788+
}
789+
780790
int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
781791
int online_type, int nid)
782792
{
@@ -832,11 +842,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
832842
}
833843

834844
online_pages_range(pfn, nr_pages);
835-
zone->present_pages += nr_pages;
836-
837-
pgdat_resize_lock(zone->zone_pgdat, &flags);
838-
zone->zone_pgdat->node_present_pages += nr_pages;
839-
pgdat_resize_unlock(zone->zone_pgdat, &flags);
845+
adjust_present_page_count(zone, nr_pages);
840846

841847
node_states_set_node(nid, &arg);
842848
if (need_zonelists_rebuild)
@@ -1602,11 +1608,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages)
16021608

16031609
/* removal success */
16041610
adjust_managed_page_count(pfn_to_page(start_pfn), -nr_pages);
1605-
zone->present_pages -= nr_pages;
1606-
1607-
pgdat_resize_lock(zone->zone_pgdat, &flags);
1608-
zone->zone_pgdat->node_present_pages -= nr_pages;
1609-
pgdat_resize_unlock(zone->zone_pgdat, &flags);
1611+
adjust_present_page_count(zone, -nr_pages);
16101612

16111613
init_per_zone_wmark_min();
16121614

0 commit comments

Comments
 (0)