Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2349129ybv; Fri, 21 Feb 2020 13:54:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzKRedSPKe0MEFrbaxydu4dppD+xtBT0d36aFSeV6Gq2U2trYLYcjZcxEXEjtGRonwLcOTU X-Received: by 2002:aca:ab51:: with SMTP id u78mr3771133oie.21.1582322087388; Fri, 21 Feb 2020 13:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582322087; cv=none; d=google.com; s=arc-20160816; b=p/Fryl5i71wKA6MrqaOYeIpl2rYjPDB7nEs2ond0/oehnKO72mmMmBdjRLJc9/4qE2 aNu+SJstpoSBUDaDw+0lDJRiUVBdhLjrTm9ievLG2sjvwwgNag9e1+cWXSDZ6AX4Ih8n BzaBTo20RWw3eI7NAU7vXBkUH4dUADWaQIFL+eVogvDKJpdVQyIXwFMK29HeQhlkyHkZ 8TIGmaGGI3rxoGsRjpamg8PFCU+pWpQK09eepmDjy2EOAmNhHZvsuGY3a+ehPfc6stcN v99w7iGuLsvVB1dNQrKWHwqe9jed6shPcqHqmd0X9KFRabFvxjKATbzTrAOTADlsfcGM S35Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DoXziB1tsgHVTTfVNfEqWtNDdk0N2kfsdzWOBN6+heU=; b=NyEPmT2UiW2/ObWV+VEdje1nGWxlB5q8N82dFnO7oIeoFOcjIReoo9rGNV21in5Icb 02GUkvJ7cpPzw+cY2HyDSLITmYluKdhBxgvGi2SzcKXgKYZU272Pf0mmcnx8MP6kgcNl 3KmNPB32kXpaQ+1DLuQbo2S5Va9wDpp6k1KyKoUCDOXBq71P3CeFURkpQS/kX7/EX3aN 9m4jsXboyZAok1/rf3zEBGYAWC23Q14bVZJ7gChptyUEFw4RSo9zU7Vnm/ShwiKbMtDE 87dqlJhqMzYrQKBHRf769n2pCQEqn6G6kj0HrBbxA8DmM5n+niDFigzH0UmM7bTPG7xJ gJeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f187si1433553oia.218.2020.02.21.13.54.35; Fri, 21 Feb 2020 13:54:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728704AbgBUVyB (ORCPT + 99 others); Fri, 21 Feb 2020 16:54:01 -0500 Received: from shelob.surriel.com ([96.67.55.147]:44752 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726725AbgBUVxz (ORCPT ); Fri, 21 Feb 2020 16:53:55 -0500 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1j5GF1-0002PL-PR; Fri, 21 Feb 2020 16:53:47 -0500 From: Rik van Riel To: linux-kernel@vger.kernel.org, riel@fb.com Cc: kernel-team@fb.com, akpm@linux-foundation.org, linux-mm@kvack.org, mhocko@kernel.org, vbabka@suse.cz, mgorman@techsingularity.net, rientjes@google.com, aarcange@redhat.com, Rik van Riel Subject: [PATCH 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Date: Fri, 21 Feb 2020 16:53:43 -0500 Message-Id: <3289dc5e6c4c3174999598d8293adf8ed3e93b57.1582321645.git.riel@surriel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code to implement THP migrations already exists, and the code for CMA to clear out a region of memory already exists. Only a few small tweaks are needed to allow CMA to move THP memory when attempting an allocation from alloc_contig_range. With these changes, migrating THPs from a CMA area works when allocating a 1GB hugepage from CMA memory. Signed-off-by: Rik van Riel --- mm/compaction.c | 16 +++++++++------- mm/page_alloc.c | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 672d3c78c6ab..f3e05c91df62 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -894,12 +894,12 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, /* * Regardless of being on LRU, compound pages such as THP and - * hugetlbfs are not to be compacted. We can potentially save - * a lot of iterations if we skip them at once. The check is - * racy, but we can consider only valid values and the only - * danger is skipping too much. + * hugetlbfs are not to be compacted most of the time. We can + * potentially save a lot of iterations if we skip them at + * once. The check is racy, but we can consider only valid + * values and the only danger is skipping too much. */ - if (PageCompound(page)) { + if (PageCompound(page) && !cc->alloc_contig) { const unsigned int order = compound_order(page); if (likely(order < MAX_ORDER)) @@ -969,7 +969,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, * and it's on LRU. It can only be a THP so the order * is safe to read and it's 0 for tail pages. */ - if (unlikely(PageCompound(page))) { + if (unlikely(PageCompound(page) && !cc->alloc_contig)) { low_pfn += compound_nr(page) - 1; goto isolate_fail; } @@ -981,7 +981,9 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (__isolate_lru_page(page, isolate_mode) != 0) goto isolate_fail; - VM_BUG_ON_PAGE(PageCompound(page), page); + /* The whole page is taken off the LRU; skip the tail pages. */ + if (PageCompound(page)) + low_pfn += compound_nr(page) - 1; /* Successfully isolated */ del_page_from_lru_list(page, lruvec, page_lru(page)); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a36736812596..38c8ddfcecc8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8253,14 +8253,16 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, /* * Hugepages are not in LRU lists, but they're movable. + * THPs are on the LRU, but need to be counted as #small pages. * We need not scan over tail pages because we don't * handle each tail page individually in migration. */ - if (PageHuge(page)) { + if (PageTransHuge(page)) { struct page *head = compound_head(page); unsigned int skip_pages; - if (!hugepage_migration_supported(page_hstate(head))) + if (PageHuge(page) && + !hugepage_migration_supported(page_hstate(head))) return page; skip_pages = compound_nr(head) - (page - head); -- 2.24.1