From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,wangkefeng.wang@huawei.com,
stable@vger.kernel.org,osalvador@suse.de,osalvador@kernel.org,
muchun.song@linux.dev,lance.yang@linux.dev,fvdl@google.com,david@kernel.org,
azpijr@gmail.com,zhengqi.arch@bytedance.com,akpm@linux-foundation.org
Subject: + mm-gup-allow-long-term-pins-of-cma-allocated-hugetlb-folios.patch added to mm-new branch
Date: Tue, 17 Nov 2026 19:31:06 -0800 [thread overview]
Message-ID: <20261118033106.CDD451F000D2@smtp.kernel.org> (raw)
The patch titled
Subject: mm: gup: allow long-term pins of CMA-allocated HugeTLB folios
has been added to the -mm mm-new branch. Its filename is
mm-gup-allow-long-term-pins-of-cma-allocated-hugetlb-folios.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-gup-allow-long-term-pins-of-cma-allocated-hugetlb-folios.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Qi Zheng <zhengqi.arch@bytedance.com>
Subject: mm: gup: allow long-term pins of CMA-allocated HugeTLB folios
Date: Tue, 17 Nov 2026 17:33:58 +0800
Long-term pinning rejects HugeTLB folios explicitly allocated from CMA,
causing unnecessary migration or pinning failures. These folios already
own their CMA memory and do not need to be migrated out for future CMA
allocations.
Add cma_folio_is_longterm_pinnable() to recognize these allocations
through HPG_cma. Allow them to be pinned even in ZONE_MOVABLE, since
memory blocks overlapping boot-time CMA areas cannot be offlined.
Ordinary movable allocations that borrow CMA memory remain unpinnable.
Link: https://lore.kernel.org/295af6601ce79f2c2b3dc4352a3279f0e6ac513e.1794907279.git.zhengqi.arch@bytedance.com
Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages using cma")
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Muchun Song <muchun.song@linux.dev>
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Muchun Song <muchun.song@linux.dev>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Reviewed-by: Frank van der Linden <fvdl@google.com>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: "Oscar Salvador (SUSE)" <osalvador@kernel.org>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: <stable@vger.kernel.org>
include/linux/cma.h | 3 +++
include/linux/mm.h | 9 ++++++---
mm/cma.c | 11 +++++++++++
3 files changed, 20 insertions(+), 3 deletions(-)
--- a/include/linux/cma.h~mm-gup-allow-long-term-pins-of-cma-allocated-hugetlb-folios
+++ a/include/linux/cma.h
@@ -21,6 +21,9 @@
#define CMA_MIN_ALIGNMENT_BYTES (PAGE_SIZE * CMA_MIN_ALIGNMENT_PAGES)
struct cma;
+struct folio;
+
+bool cma_folio_is_longterm_pinnable(struct folio *folio);
extern unsigned long totalcma_pages;
extern phys_addr_t cma_get_base(const struct cma *cma);
--- a/include/linux/mm.h~mm-gup-allow-long-term-pins-of-cma-allocated-hugetlb-folios
+++ a/include/linux/mm.h
@@ -38,6 +38,7 @@
#include <linux/bitops.h>
#include <linux/iommu-debug-pagealloc.h>
#include <linux/kcsan-checks.h>
+#include <linux/cma.h>
struct mempolicy;
struct anon_vma;
@@ -2984,15 +2985,18 @@ static inline bool is_zero_folio(const s
return is_zero_page(&folio->page);
}
-/* MIGRATE_CMA and ZONE_MOVABLE do not allow pin folios */
#ifdef CONFIG_MIGRATION
+/*
+ * MIGRATE_CMA and ZONE_MOVABLE folios cannot normally be long-term pinned.
+ * CMA may allow pinning folios explicitly allocated from its areas.
+ */
static inline bool folio_is_longterm_pinnable(struct folio *folio)
{
#ifdef CONFIG_CMA
int mt = folio_migratetype(folio);
if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE)
- return false;
+ return cma_folio_is_longterm_pinnable(folio);
#endif
/* The zero page can be "pinned" but gets special handling. */
if (is_zero_folio(folio))
@@ -3011,7 +3015,6 @@ static inline bool folio_is_longterm_pin
/* Otherwise, non-movable zone folios can be pinned. */
return !folio_is_zone_movable(folio);
-
}
#else
static inline bool folio_is_longterm_pinnable(struct folio *folio)
--- a/mm/cma.c~mm-gup-allow-long-term-pins-of-cma-allocated-hugetlb-folios
+++ a/mm/cma.c
@@ -29,6 +29,7 @@
#include <linux/highmem.h>
#include <linux/io.h>
#include <linux/kmemleak.h>
+#include <linux/hugetlb.h>
#include <trace/events/cma.h>
#include "internal.h"
@@ -38,6 +39,16 @@
struct cma cma_areas[MAX_CMA_AREAS];
unsigned int cma_area_count;
+bool cma_folio_is_longterm_pinnable(struct folio *folio)
+{
+ /*
+ * Explicitly allocated CMA folios own their CMA memory and can be
+ * pinned even in ZONE_MOVABLE, as CMA memory cannot be offlined.
+ * For now, only HugeTLB tracks these allocations with a folio flag.
+ */
+ return folio_test_hugetlb(folio) && folio_test_hugetlb_cma(folio);
+}
+
phys_addr_t cma_get_base(const struct cma *cma)
{
WARN_ON_ONCE(cma->nranges != 1);
_
Patches currently in -mm which might be from zhengqi.arch@bytedance.com are
x86-hugetlb-disable-default-cma-reservations-on-32-bit-kernel.patch
mm-gup-allow-long-term-pins-of-cma-allocated-hugetlb-folios.patch
mm-hugetlb-fix-gfp-mask-propagation-to-cma.patch
reply other threads:[~2026-11-18 3:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261118033106.CDD451F000D2@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=azpijr@gmail.com \
--cc=david@kernel.org \
--cc=fvdl@google.com \
--cc=lance.yang@linux.dev \
--cc=mm-commits@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@kernel.org \
--cc=osalvador@suse.de \
--cc=stable@vger.kernel.org \
--cc=wangkefeng.wang@huawei.com \
--cc=zhengqi.arch@bytedance.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.