mm,memory_hotplug: Drop unneeded locking
Subsystems (2)
Oscar Salvador
maintainerRFC PATCH 1/1 mm,memory_hotplug: Drop unneeded locking
Currently, memory-hotplug code takes zone's span_writelock and pgdat's resize_lock when resizing the node/zone's spanned pages via {move_pfn_range_to_zone(),remove_pfn_range_from_zone()} and when resizing node and zone's present pages via adjust_present_page_count().
These locks are also taken during the initialization of the system at boot time, where it protects parallel struct page initialization, but they should not really be needed in memory-hotplug where all operations are a) synchronized on device level and b) serialized by the mem_hotplug_lock lock.
---
During the review of [1], it was brought up that we might need to revisit the locking scheme in memory-hotplug code wrt. node and zone locks. Given that memory-hotplug is serialized and synchronized by memory-hotplug lock and the device, I do not think we need to hold zone/node's resize lock anymore. After the system has been brought up, memory-hotplug is the only code allow to touch {spanned,present}_pages, so it cannot really go off when serialized by its own lock. Or am I missing something?
The only think I am not really sure is: if the from remove_pfn_range_from_zone, shrink_zone_span, update_pgdat_span and move_pfn_range_to_zone can really go (because those functions are already serialized by the memory-hotplug lock), what about mhp_(de)init_memmap_on_memory that calls those functions? Those are not protected by the lock. I have to confess that when it comes to locking in this code, I always have to scratch my head.
[1] https://patchwork.kernel.org/project/linux-mm/patch/[email protected]/
mm/memory_hotplug.c | 10 ---------- 1 file changed, 10 deletions(-)
mm/memory_hotplug.c +0 -10
@@ -329,7 +329,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,unsigned long pfn;int nid =zone_to_nid (zone); -zone_span_writelock (zone);if (zone->zone_start_pfn == start_pfn) {/* * If the section is smallest section in the zone, it need
@@ -362,7 +361,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, zone->spanned_pages =0 ; } } -zone_span_writeunlock (zone); }static void update_pgdat_span (struct pglist_data *pgdat)
@@ -424,10 +422,8 @@ void __ref remove_pfn_range_from_zone(struct zone *zone,clear_zone_contiguous (zone); -pgdat_resize_lock (zone->zone_pgdat, &flags);shrink_zone_span (zone, start_pfn, start_pfn + nr_pages);update_pgdat_span (pgdat); -pgdat_resize_unlock (zone->zone_pgdat, &flags);set_zone_contiguous (zone); }
@@ -639,14 +635,10 @@ void __ref move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,clear_zone_contiguous (zone);/* TODO Huh pgdat is irqsave while zone is not. It used to be like that before */ -pgdat_resize_lock (pgdat, &flags); -zone_span_writelock (zone);if (zone_is_empty (zone))init_currently_empty_zone (zone, start_pfn, nr_pages);resize_zone_range (zone, start_pfn, nr_pages); -zone_span_writeunlock (zone);resize_pgdat_range (pgdat, start_pfn, nr_pages); -pgdat_resize_unlock (pgdat, &flags);/* * Subsection population requires care in pfn_to_online_page().
@@ -739,9 +731,7 @@ void adjust_present_page_count(struct zone *zone, long nr_pages)unsigned long flags; zone->present_pages += nr_pages; -pgdat_resize_lock (zone->zone_pgdat, &flags); zone->zone_pgdat->node_present_pages += nr_pages; -pgdat_resize_unlock (zone->zone_pgdat, &flags); } int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages,
Signature · 1 line
2.16.3
Quoted 13 lines · Oscar Salvador
Currently, memory-hotplug code takes zone's
span_writelockand pgdat'sresize_lockwhen resizing the node/zone's spanned pages via {move_pfn_range_to_zone(),remove_pfn_range_from_zone()} and when resizing node and zone's present pages viaadjust_present_page_count().These locks are also taken during the initialization of the system at boot time, where it protects parallel struct page initialization, but they should not really be needed in memory-hotplug where all operations are a) synchronized on device level and b) serialized by the
mem_hotplug_locklock.Signed-off-by Oscar Salvador <[email protected]>
Quoted 15 lines
---
During the review of [1], it was brought up that we might need to revisit the locking scheme in memory-hotplug code wrt. node and zone locks. Given that memory-hotplug is serialized and synchronized by memory-hotplug lock and the device, I do not think we need to hold zone/node's resize lock anymore. After the system has been brought up, memory-hotplug is the only code allow to touch {spanned,present}_pages, so it cannot really go off when serialized by its own lock. Or am I missing something?
The only think I am not really sure is: if the fromremove_pfn_range_from_zone,shrink_zone_span,update_pgdat_spanandmove_pfn_range_to_zonecan really go (because those functions are already serialized by the memory-hotplug lock), what about mhp_(de)init_memmap_on_memory that calls those functions? Those are not protected by the lock. I have to confess that when it comes to locking in this code, I always have to scratch my head.
Whenever onlining/offlining memory blocks we're holding the device hotplug lock. So memory hot(un)plug code is completely synchronized.
If necessary at some point, we could pull the memory hotplug lock further out. But I doubt it is necessary at this point.
AFAIK, memory hot(un)plug isn't possible while we're still initializing the memmap, so this should be fine.
Quoted 37 lines
[1] https://patchwork.kernel.org/project/linux-mm/patch/[email protected]/
mm/memory_hotplug.c | 10 ---------- 1 file changed, 10 deletions(-)mm/memory_hotplug.c +0
-4@@ -329,7 +329,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,unsigned long pfn;int nid =zone_to_nid (zone); -zone_span_writelock (zone);if (zone->zone_start_pfn == start_pfn) {/* * If the section is smallest section in the zone, it need @@ -362,7 +361,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn, zone->spanned_pages =0 ; } } -zone_span_writeunlock (zone); }static void update_pgdat_span (struct pglist_data *pgdat)@@ -424,10 +422,8 @@ void __ref remove_pfn_range_from_zone(struct zone *zone,clear_zone_contiguous (zone); -pgdat_resize_lock (zone->zone_pgdat, &flags);shrink_zone_span (zone, start_pfn, start_pfn + nr_pages);update_pgdat_span (pgdat); -pgdat_resize_unlock (zone->zone_pgdat, &flags);set_zone_contiguous (zone); }
mm/memory_hotplug.c void __ref move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn, · line 637
Quoted 3 lines
mm/memory_hotplug.c +0
-0@@ -639,14 +635,10 @@ void __ref move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,clear_zone_contiguous (zone);/* TODO Huh pgdat is irqsave while zone is not. It used to be like that before */
I think you can drop this comment now as well.
Signature · 3 lines
Thanks, David / dhildenb