Commit 6715ddf94576ff39f5d1cda8d4c568d3b79e82ec

Authored by Lai Jiangshan
Committed by Linus Torvalds
1 parent 4b0ef1fe8a

hotplug: update nodemasks management

Update nodemasks management for N_MEMORY.

[lliubbo@gmail.com: fix build]
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Hillf Danton <dhillf@gmail.com>
Cc: Lin Feng <linfeng@cn.fujitsu.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Bob Liu <lliubbo@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 77 additions and 16 deletions Side-by-side Diff

Documentation/memory-hotplug.txt
... ... @@ -390,6 +390,7 @@
390 390 unsigned long start_pfn;
391 391 unsigned long nr_pages;
392 392 int status_change_nid_normal;
  393 + int status_change_nid_high;
393 394 int status_change_nid;
394 395 }
395 396  
... ... @@ -397,7 +398,9 @@
397 398 nr_pages is # of pages of online/offline memory.
398 399 status_change_nid_normal is set node id when N_NORMAL_MEMORY of nodemask
399 400 is (will be) set/clear, if this is -1, then nodemask status is not changed.
400   -status_change_nid is set node id when N_HIGH_MEMORY of nodemask is (will be)
  401 +status_change_nid_high is set node id when N_HIGH_MEMORY of nodemask
  402 +is (will be) set/clear, if this is -1, then nodemask status is not changed.
  403 +status_change_nid is set node id when N_MEMORY of nodemask is (will be)
401 404 set/clear. It means a new(memoryless) node gets new memory by online and a
402 405 node loses all memory. If this is -1, then nodemask status is not changed.
403 406 If status_changed_nid* >= 0, callback should create/discard structures for the
include/linux/memory.h
... ... @@ -54,6 +54,7 @@
54 54 unsigned long start_pfn;
55 55 unsigned long nr_pages;
56 56 int status_change_nid_normal;
  57 + int status_change_nid_high;
57 58 int status_change_nid;
58 59 };
59 60  
... ... @@ -595,13 +595,15 @@
595 595 enum zone_type zone_last = ZONE_NORMAL;
596 596  
597 597 /*
598   - * If we have HIGHMEM, node_states[N_NORMAL_MEMORY] contains nodes
599   - * which have 0...ZONE_NORMAL, set zone_last to ZONE_NORMAL.
  598 + * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY]
  599 + * contains nodes which have zones of 0...ZONE_NORMAL,
  600 + * set zone_last to ZONE_NORMAL.
600 601 *
601   - * If we don't have HIGHMEM, node_states[N_NORMAL_MEMORY] contains nodes
602   - * which have 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE.
  602 + * If we don't have HIGHMEM nor movable node,
  603 + * node_states[N_NORMAL_MEMORY] contains nodes which have zones of
  604 + * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE.
603 605 */
604   - if (N_HIGH_MEMORY == N_NORMAL_MEMORY)
  606 + if (N_MEMORY == N_NORMAL_MEMORY)
605 607 zone_last = ZONE_MOVABLE;
606 608  
607 609 /*
608 610  
609 611  
610 612  
... ... @@ -615,12 +617,34 @@
615 617 else
616 618 arg->status_change_nid_normal = -1;
617 619  
  620 +#ifdef CONFIG_HIGHMEM
618 621 /*
  622 + * If we have movable node, node_states[N_HIGH_MEMORY]
  623 + * contains nodes which have zones of 0...ZONE_HIGHMEM,
  624 + * set zone_last to ZONE_HIGHMEM.
  625 + *
  626 + * If we don't have movable node, node_states[N_NORMAL_MEMORY]
  627 + * contains nodes which have zones of 0...ZONE_MOVABLE,
  628 + * set zone_last to ZONE_MOVABLE.
  629 + */
  630 + zone_last = ZONE_HIGHMEM;
  631 + if (N_MEMORY == N_HIGH_MEMORY)
  632 + zone_last = ZONE_MOVABLE;
  633 +
  634 + if (zone_idx(zone) <= zone_last && !node_state(nid, N_HIGH_MEMORY))
  635 + arg->status_change_nid_high = nid;
  636 + else
  637 + arg->status_change_nid_high = -1;
  638 +#else
  639 + arg->status_change_nid_high = arg->status_change_nid_normal;
  640 +#endif
  641 +
  642 + /*
619 643 * if the node don't have memory befor online, we will need to
620   - * set the node to node_states[N_HIGH_MEMORY] after the memory
  644 + * set the node to node_states[N_MEMORY] after the memory
621 645 * is online.
622 646 */
623   - if (!node_state(nid, N_HIGH_MEMORY))
  647 + if (!node_state(nid, N_MEMORY))
624 648 arg->status_change_nid = nid;
625 649 else
626 650 arg->status_change_nid = -1;
... ... @@ -631,7 +655,10 @@
631 655 if (arg->status_change_nid_normal >= 0)
632 656 node_set_state(node, N_NORMAL_MEMORY);
633 657  
634   - node_set_state(node, N_HIGH_MEMORY);
  658 + if (arg->status_change_nid_high >= 0)
  659 + node_set_state(node, N_HIGH_MEMORY);
  660 +
  661 + node_set_state(node, N_MEMORY);
635 662 }
636 663  
637 664  
638 665  
639 666  
... ... @@ -1099,13 +1126,15 @@
1099 1126 enum zone_type zt, zone_last = ZONE_NORMAL;
1100 1127  
1101 1128 /*
1102   - * If we have HIGHMEM, node_states[N_NORMAL_MEMORY] contains nodes
1103   - * which have 0...ZONE_NORMAL, set zone_last to ZONE_NORMAL.
  1129 + * If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY]
  1130 + * contains nodes which have zones of 0...ZONE_NORMAL,
  1131 + * set zone_last to ZONE_NORMAL.
1104 1132 *
1105   - * If we don't have HIGHMEM, node_states[N_NORMAL_MEMORY] contains nodes
1106   - * which have 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE.
  1133 + * If we don't have HIGHMEM nor movable node,
  1134 + * node_states[N_NORMAL_MEMORY] contains nodes which have zones of
  1135 + * 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE.
1107 1136 */
1108   - if (N_HIGH_MEMORY == N_NORMAL_MEMORY)
  1137 + if (N_MEMORY == N_NORMAL_MEMORY)
1109 1138 zone_last = ZONE_MOVABLE;
1110 1139  
1111 1140 /*
1112 1141  
... ... @@ -1122,7 +1151,31 @@
1122 1151 else
1123 1152 arg->status_change_nid_normal = -1;
1124 1153  
  1154 +#ifdef CONFIG_HIGHMEM
1125 1155 /*
  1156 + * If we have movable node, node_states[N_HIGH_MEMORY]
  1157 + * contains nodes which have zones of 0...ZONE_HIGHMEM,
  1158 + * set zone_last to ZONE_HIGHMEM.
  1159 + *
  1160 + * If we don't have movable node, node_states[N_NORMAL_MEMORY]
  1161 + * contains nodes which have zones of 0...ZONE_MOVABLE,
  1162 + * set zone_last to ZONE_MOVABLE.
  1163 + */
  1164 + zone_last = ZONE_HIGHMEM;
  1165 + if (N_MEMORY == N_HIGH_MEMORY)
  1166 + zone_last = ZONE_MOVABLE;
  1167 +
  1168 + for (; zt <= zone_last; zt++)
  1169 + present_pages += pgdat->node_zones[zt].present_pages;
  1170 + if (zone_idx(zone) <= zone_last && nr_pages >= present_pages)
  1171 + arg->status_change_nid_high = zone_to_nid(zone);
  1172 + else
  1173 + arg->status_change_nid_high = -1;
  1174 +#else
  1175 + arg->status_change_nid_high = arg->status_change_nid_normal;
  1176 +#endif
  1177 +
  1178 + /*
1126 1179 * node_states[N_HIGH_MEMORY] contains nodes which have 0...ZONE_MOVABLE
1127 1180 */
1128 1181 zone_last = ZONE_MOVABLE;
1129 1182  
... ... @@ -1146,9 +1199,13 @@
1146 1199 if (arg->status_change_nid_normal >= 0)
1147 1200 node_clear_state(node, N_NORMAL_MEMORY);
1148 1201  
1149   - if ((N_HIGH_MEMORY != N_NORMAL_MEMORY) &&
1150   - (arg->status_change_nid >= 0))
  1202 + if ((N_MEMORY != N_NORMAL_MEMORY) &&
  1203 + (arg->status_change_nid_high >= 0))
1151 1204 node_clear_state(node, N_HIGH_MEMORY);
  1205 +
  1206 + if ((N_MEMORY != N_HIGH_MEMORY) &&
  1207 + (arg->status_change_nid >= 0))
  1208 + node_clear_state(node, N_MEMORY);
1152 1209 }
1153 1210  
1154 1211 static int __ref __offline_pages(unsigned long start_pfn,