Skip to content

Commit 86b27be

Browse files
osalvadorvilardagatorvalds
authored andcommitted
mm/memory_hotplug.c: clean up node_states_check_changes_offline()
This patch, as the previous one, gets rid of the wrong if statements. While at it, I realized that the comments are sometimes very confusing, to say the least, and wrong. For example: ___ zone_last = ZONE_MOVABLE; /* * check whether node_states[N_HIGH_MEMORY] will be changed * If we try to offline the last present @nr_pages from the node, * we can determind we will need to clear the node from * node_states[N_HIGH_MEMORY]. */ for (; zt <= zone_last; zt++) present_pages += pgdat->node_zones[zt].present_pages; if (nr_pages >= present_pages) arg->status_change_nid = zone_to_nid(zone); else arg->status_change_nid = -1; ___ In case the node gets empry, it must be removed from N_MEMORY. We already check N_HIGH_MEMORY a bit above within the CONFIG_HIGHMEM ifdef code. Not to say that status_change_nid is for N_MEMORY, and not for N_HIGH_MEMORY. So I re-wrote some of the comments to what I think is better. [osalvador@suse.de: address feedback from Pavel] Link: http://lkml.kernel.org/r/20180921132634.10103-5-osalvador@techadventures.net Link: http://lkml.kernel.org/r/20180919100819.25518-6-osalvador@techadventures.net Signed-off-by: Oscar Salvador <osalvador@suse.de> Reviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: David Hildenbrand <david@redhat.com> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: <yasu.isimatu@gmail.com> Cc: Mathieu Malaterre <malat@debian.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8efe33f commit 86b27be

1 file changed

Lines changed: 29 additions & 51 deletions

File tree

‎mm/memory_hotplug.c‎

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,75 +1463,53 @@ static void node_states_check_changes_offline(unsigned long nr_pages,
14631463
{
14641464
struct pglist_data *pgdat = zone->zone_pgdat;
14651465
unsigned long present_pages = 0;
1466-
enum zone_type zt, zone_last = ZONE_NORMAL;
1466+
enum zone_type zt;
14671467

1468-
/*
1469-
* If we have HIGHMEM or movable node, node_states[N_NORMAL_MEMORY]
1470-
* contains nodes which have zones of 0...ZONE_NORMAL,
1471-
* set zone_last to ZONE_NORMAL.
1472-
*
1473-
* If we don't have HIGHMEM nor movable node,
1474-
* node_states[N_NORMAL_MEMORY] contains nodes which have zones of
1475-
* 0...ZONE_MOVABLE, set zone_last to ZONE_MOVABLE.
1476-
*/
1477-
if (N_MEMORY == N_NORMAL_MEMORY)
1478-
zone_last = ZONE_MOVABLE;
1468+
arg->status_change_nid = -1;
1469+
arg->status_change_nid_normal = -1;
1470+
arg->status_change_nid_high = -1;
14791471

14801472
/*
1481-
* check whether node_states[N_NORMAL_MEMORY] will be changed.
1482-
* If the memory to be offline is in a zone of 0...zone_last,
1483-
* and it is the last present memory, 0...zone_last will
1484-
* become empty after offline , thus we can determind we will
1485-
* need to clear the node from node_states[N_NORMAL_MEMORY].
1473+
* Check whether node_states[N_NORMAL_MEMORY] will be changed.
1474+
* If the memory to be offline is within the range
1475+
* [0..ZONE_NORMAL], and it is the last present memory there,
1476+
* the zones in that range will become empty after the offlining,
1477+
* thus we can determine that we need to clear the node from
1478+
* node_states[N_NORMAL_MEMORY].
14861479
*/
1487-
for (zt = 0; zt <= zone_last; zt++)
1480+
for (zt = 0; zt <= ZONE_NORMAL; zt++)
14881481
present_pages += pgdat->node_zones[zt].present_pages;
1489-
if (zone_idx(zone) <= zone_last && nr_pages >= present_pages)
1482+
if (zone_idx(zone) <= ZONE_NORMAL && nr_pages >= present_pages)
14901483
arg->status_change_nid_normal = zone_to_nid(zone);
1491-
else
1492-
arg->status_change_nid_normal = -1;
14931484

14941485
#ifdef CONFIG_HIGHMEM
14951486
/*
1496-
* If we have movable node, node_states[N_HIGH_MEMORY]
1497-
* contains nodes which have zones of 0...ZONE_HIGHMEM,
1498-
* set zone_last to ZONE_HIGHMEM.
1499-
*
1500-
* If we don't have movable node, node_states[N_NORMAL_MEMORY]
1501-
* contains nodes which have zones of 0...ZONE_MOVABLE,
1502-
* set zone_last to ZONE_MOVABLE.
1487+
* node_states[N_HIGH_MEMORY] contains nodes which
1488+
* have normal memory or high memory.
1489+
* Here we add the present_pages belonging to ZONE_HIGHMEM.
1490+
* If the zone is within the range of [0..ZONE_HIGHMEM), and
1491+
* we determine that the zones in that range become empty,
1492+
* we need to clear the node for N_HIGH_MEMORY.
15031493
*/
1504-
zone_last = ZONE_HIGHMEM;
1505-
if (N_MEMORY == N_HIGH_MEMORY)
1506-
zone_last = ZONE_MOVABLE;
1507-
1508-
for (; zt <= zone_last; zt++)
1509-
present_pages += pgdat->node_zones[zt].present_pages;
1510-
if (zone_idx(zone) <= zone_last && nr_pages >= present_pages)
1494+
present_pages += pgdat->node_zones[ZONE_HIGHMEM].present_pages;
1495+
if (zone_idx(zone) <= ZONE_HIGHMEM && nr_pages >= present_pages)
15111496
arg->status_change_nid_high = zone_to_nid(zone);
1512-
else
1513-
arg->status_change_nid_high = -1;
1514-
#else
1515-
arg->status_change_nid_high = arg->status_change_nid_normal;
15161497
#endif
15171498

15181499
/*
1519-
* node_states[N_HIGH_MEMORY] contains nodes which have 0...ZONE_MOVABLE
1500+
* We have accounted the pages from [0..ZONE_NORMAL), and
1501+
* in case of CONFIG_HIGHMEM the pages from ZONE_HIGHMEM
1502+
* as well.
1503+
* Here we count the possible pages from ZONE_MOVABLE.
1504+
* If after having accounted all the pages, we see that the nr_pages
1505+
* to be offlined is over or equal to the accounted pages,
1506+
* we know that the node will become empty, and so, we can clear
1507+
* it for N_MEMORY as well.
15201508
*/
1521-
zone_last = ZONE_MOVABLE;
1509+
present_pages += pgdat->node_zones[ZONE_MOVABLE].present_pages;
15221510

1523-
/*
1524-
* check whether node_states[N_HIGH_MEMORY] will be changed
1525-
* If we try to offline the last present @nr_pages from the node,
1526-
* we can determind we will need to clear the node from
1527-
* node_states[N_HIGH_MEMORY].
1528-
*/
1529-
for (; zt <= zone_last; zt++)
1530-
present_pages += pgdat->node_zones[zt].present_pages;
15311511
if (nr_pages >= present_pages)
15321512
arg->status_change_nid = zone_to_nid(zone);
1533-
else
1534-
arg->status_change_nid = -1;
15351513
}
15361514

15371515
static void node_states_clear_node(int node, struct memory_notify *arg)

0 commit comments

Comments
 (0)