Skip to content

Commit 14a4e21

Browse files
rientjestorvalds
authored andcommitted
mm, thp: only collapse hugepages to nodes with affinity for zone_reclaim_mode
Commit 9f1b868 ("mm: thp: khugepaged: add policy for finding target node") improved the previous khugepaged logic which allocated a transparent hugepages from the node of the first page being collapsed. However, it is still possible to collapse pages to remote memory which may suffer from additional access latency. With the current policy, it is possible that 255 pages (with PAGE_SHIFT == 12) will be collapsed remotely if the majority are allocated from that node. When zone_reclaim_mode is enabled, it means the VM should make every attempt to allocate locally to prevent NUMA performance degradation. In this case, we do not want to collapse hugepages to remote nodes that would suffer from increased access latency. Thus, when zone_reclaim_mode is enabled, only allow collapsing to nodes with RECLAIM_DISTANCE or less. There is no functional change for systems that disable zone_reclaim_mode. Signed-off-by: David Rientjes <rientjes@google.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Mel Gorman <mgorman@suse.de> Cc: Rik van Riel <riel@redhat.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Bob Liu <bob.liu@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fed400a commit 14a4e21

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎mm/huge_memory.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,30 @@ static void khugepaged_alloc_sleep(void)
22332233

22342234
static int khugepaged_node_load[MAX_NUMNODES];
22352235

2236+
static bool khugepaged_scan_abort(int nid)
2237+
{
2238+
int i;
2239+
2240+
/*
2241+
* If zone_reclaim_mode is disabled, then no extra effort is made to
2242+
* allocate memory locally.
2243+
*/
2244+
if (!zone_reclaim_mode)
2245+
return false;
2246+
2247+
/* If there is a count for this node already, it must be acceptable */
2248+
if (khugepaged_node_load[nid])
2249+
return false;
2250+
2251+
for (i = 0; i < MAX_NUMNODES; i++) {
2252+
if (!khugepaged_node_load[i])
2253+
continue;
2254+
if (node_distance(nid, i) > RECLAIM_DISTANCE)
2255+
return true;
2256+
}
2257+
return false;
2258+
}
2259+
22362260
#ifdef CONFIG_NUMA
22372261
static int khugepaged_find_target_node(void)
22382262
{
@@ -2545,6 +2569,8 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
25452569
* hit record.
25462570
*/
25472571
node = page_to_nid(page);
2572+
if (khugepaged_scan_abort(node))
2573+
goto out_unmap;
25482574
khugepaged_node_load[node]++;
25492575
VM_BUG_ON_PAGE(PageCompound(page), page);
25502576
if (!PageLRU(page) || PageLocked(page) || !PageAnon(page))

0 commit comments

Comments
 (0)