From: Rik van Riel <riel@surriel.com>
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 <riel@surriel.com>
Subject: [PATCH 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations
Date: Fri, 21 Feb 2020 16:53:43 -0500 [thread overview]
Message-ID: <3289dc5e6c4c3174999598d8293adf8ed3e93b57.1582321645.git.riel@surriel.com> (raw)
In-Reply-To: <cover.1582321645.git.riel@surriel.com>
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 <riel@surriel.com>
---
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
next prev parent reply other threads:[~2020-02-21 21:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-21 21:53 [PATCH 0/2] fix THP migration for CMA allocations Rik van Riel
2020-02-21 21:53 ` [PATCH 1/2] mm,compaction,cma: add alloc_contig flag to compact_control Rik van Riel
2020-02-24 15:04 ` Vlastimil Babka
2020-02-21 21:53 ` Rik van Riel [this message]
2020-02-21 22:31 ` [PATCH 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Zi Yan
2020-02-21 22:35 ` Rik van Riel
2020-02-24 15:29 ` Vlastimil Babka
2020-02-25 18:44 ` Rik van Riel
2020-02-26 9:48 ` Vlastimil Babka
2020-02-26 17:53 ` Rik van Riel
2020-02-28 15:17 ` Vlastimil Babka
2020-03-01 2:24 ` Rik van Riel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3289dc5e6c4c3174999598d8293adf8ed3e93b57.1582321645.git.riel@surriel.com \
--to=riel@surriel.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=riel@fb.com \
--cc=rientjes@google.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).