Skip to content

Commit 2ecbe06

Browse files
Hao Liakpm00
authored andcommitted
mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
N_NORMAL_MEMORY is initialized from zone population at boot, but memory hotplug currently only updates N_MEMORY. As a result, a node that gains normal memory via hotplug can remain invisible to users iterating over N_NORMAL_MEMORY, while a node that loses its last normal memory can stay incorrectly marked as such. The most visible effect is that /sys/devices/system/node/has_normal_memory does not report a node even after that node has gained normal memory via hotplug. Also, list_lru-based shrinkers can undercount objects on such a node and may skip reclaim on that node entirely, which can lead to a higher memory footprint than expected. Restore N_NORMAL_MEMORY maintenance directly in online_pages() and offline_pages(). Set the bit when a node that currently lacks normal memory onlines pages into a zone <= ZONE_NORMAL, and clear it when offlining removes the last present pages from zones <= ZONE_NORMAL. This restores the intended semantics without bringing back the old status_change_nid_normal notifier plumbing which was removed in 8d2882a. Current users that benefit include list_lru, zswap, nfsd filecache, hugetlb_cgroup, and has_normal_memory sysfs reporting. Link: https://lkml.kernel.org/r/[email protected] Fixes: 8d2882a ("mm,memory_hotplug: remove status_change_nid_normal and update documentation") Signed-off-by: Hao Li <[email protected]> Reviewed-by: Harry Yoo (Oracle) <[email protected]> Acked-by: Vlastimil Babka (SUSE) <[email protected]> Reviewed-by: Joshua Hahn <[email protected]> Acked-by: David Hildenbrand (Arm) <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 0199390 commit 2ecbe06

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

mm/memory_hotplug.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,13 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
12091209

12101210
if (node_arg.nid >= 0)
12111211
node_set_state(nid, N_MEMORY);
1212+
/*
1213+
* Check whether we are adding normal memory to the node for the first
1214+
* time.
1215+
*/
1216+
if (!node_state(nid, N_NORMAL_MEMORY) && zone_idx(zone) <= ZONE_NORMAL)
1217+
node_set_state(nid, N_NORMAL_MEMORY);
1218+
12121219
if (need_zonelists_rebuild)
12131220
build_all_zonelists(NULL);
12141221

@@ -1908,6 +1915,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
19081915
unsigned long flags;
19091916
char *reason;
19101917
int ret;
1918+
unsigned long normal_pages = 0;
1919+
enum zone_type zt;
19111920

19121921
/*
19131922
* {on,off}lining is constrained to full memory sections (or more
@@ -2055,6 +2064,17 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
20552064
/* reinitialise watermarks and update pcp limits */
20562065
init_per_zone_wmark_min();
20572066

2067+
/*
2068+
* Check whether this operation removes the last normal memory from
2069+
* the node. We do this before clearing N_MEMORY to avoid the possible
2070+
* transient "!N_MEMORY && N_NORMAL_MEMORY" state.
2071+
*/
2072+
if (zone_idx(zone) <= ZONE_NORMAL) {
2073+
for (zt = 0; zt <= ZONE_NORMAL; zt++)
2074+
normal_pages += pgdat->node_zones[zt].present_pages;
2075+
if (!normal_pages)
2076+
node_clear_state(node, N_NORMAL_MEMORY);
2077+
}
20582078
/*
20592079
* Make sure to mark the node as memory-less before rebuilding the zone
20602080
* list. Otherwise this node would still appear in the fallback lists.

0 commit comments

Comments
 (0)