Re: [PATCH 4/4] memory_hotplug: use pgdat_resize_lock() when updatingnode_present_pages

From: Cody P Schafer
Date: Wed May 01 2013 - 18:41:12 EST


On 05/01/2013 03:30 PM, David Rientjes wrote:
On Wed, 1 May 2013, Cody P Schafer wrote:

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index a221fac..0bdca10 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -915,6 +915,7 @@ static void node_states_set_node(int node, struct memory_notify *arg)

int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_type)
{
+ unsigned long flags;
unsigned long onlined_pages = 0;
struct zone *zone;
int need_zonelists_rebuild = 0;
@@ -993,7 +994,11 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int online_typ

zone->managed_pages += onlined_pages;
zone->present_pages += onlined_pages;
+
+ pgdat_resize_lock(zone->zone_pgdat, &flags);
zone->zone_pgdat->node_present_pages += onlined_pages;
+ pgdat_resize_unlock(zone->zone_pgdat, &flags);
+
if (onlined_pages) {
node_states_set_node(zone_to_nid(zone), &arg);
if (need_zonelists_rebuild)

Why? You can't get a partial read of a word-sized data structure.


Guaranteed to be stable means that if I'm a reader and pgdat_resize_lock(), node_present_pages had better not change at all until I pgdat_resize_unlock().

If nothing needs this guarantee, we should change the rules of pgdat_resize_lock(). I played it safe and went with following the existing rules.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/