From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Jialin Wang <wjl.linux@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>
Cc: Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Zi Yan <ziy@nvidia.com>, Khalid Aziz <khalid@kernel.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: compaction: skip DMA-pinned folios during isolation
Date: Tue, 1 Dec 2026 18:48:01 +0100 [thread overview]
Message-ID: <5cda167e-4e2b-4267-b6df-a85242684de7@kernel.org> (raw)
In-Reply-To: <20261201154606.548937-1-wjl.linux@gmail.com>
On 12/1/26 16:46, Jialin Wang wrote:
> Migration fails while a folio is pinned, so isolating it during compaction
> wastes CPU. Currently, isolate_migratepages_block() only checks for extra
> references when folio_mapping() is NULL (anonymous folios not in the
> swapcache). Folios with a mapping are not checked, including:
>
> - shmem folios allocated by cudaHostAlloc() via
> mmap(MAP_SHARED | MAP_ANONYMOUS) and pinned by the NVIDIA driver
> with FOLL_PIN | FOLL_LONGTERM;
> - shmem/memfd folios pinned by VFIO with FOLL_PIN | FOLL_LONGTERM [1];
> - other folios that can be long-term DMA-pinned, such as swapcache
> folios, ramfs folios, and file-backed folios pinned read-only
> (without FOLL_WRITE).
>
> During direct compaction and kcompactd runs, compaction repeatedly
> isolates these pinned folios, unmaps them via rmap, flushes TLBs, fails
> migration, and restores the mappings. On GPU hosts with lots of pinned
> memory and heavy high-order allocations, this makes direct compaction
> very slow and keeps kcompactd at 100% CPU for long periods.
>
> Skip these folios early in isolate_migratepages_block(). To avoid
> hurting other workloads:
>
> - Do not change cc->alloc_contig (such as CMA and virtio-mem).
> - Only target FOLL_PIN, not every extra reference (such as FOLL_GET or
> short-lived pagecache references). Checking for any extra refcount
> could skip normal pagecache folios during read(), or folios with extra
> references that can still migrate (such as AIO ring folios).
> - Add a helper folio_likely_dma_pinned() instead of calling
> folio_maybe_dma_pinned() directly. For folios without _pincount, it
> uses folio_expected_ref_count() so a folio mapped many times (around
> GUP_PIN_COUNTING_BIAS, i.e., 1024) is not always treated as pinned.
> - Check folio_is_longterm_pinnable() so we do not skip folios in areas
> where long-term pinning is not allowed (such as ZONE_MOVABLE and
> MIGRATE_CMA). Any pin there must be short-term.
>
> Also move the !folio_test_lru() check right after
> folio_get_nontail_page(). It makes sure folio_mapping(),
> folio_likely_dma_pinned() (which may call folio_expected_ref_count()),
> and the anonymous refcount check only run on LRU folios. If a page is
> freed and reused as a non-LRU or typed page, we will not inspect its
> non-LRU fields or risk hitting folio_expected_ref_count()'s
> WARN_ON_ONCE().
>
> Benchmark results (8GB VM, 4 vCPUs, 5120MB of 4KB shmem pages pinned with
> FOLL_PIN | FOLL_LONGTERM, 50 x 2MB GFP_TRANSHUGE allocations per trial,
> with fragments memory, mean over 3 trials) [2]:
But what about short-term pins that are long gone until you actually try migrating?
--
Cheers,
David
prev parent reply other threads:[~2026-12-01 17:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:46 [PATCH] mm: compaction: skip DMA-pinned folios during isolation Jialin Wang
2026-12-01 17:48 ` David Hildenbrand (Arm) [this message]
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=5cda167e-4e2b-4267-b6df-a85242684de7@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=khalid@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=wjl.linux@gmail.com \
--cc=ziy@nvidia.com \
/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