Re: [PATCH v3 03/12] mm/huge_memory: move THP gfp limit helper into header
From: Baolin Wang
Date: Tue May 12 2026 - 05:12:12 EST
On 4/22/26 1:23 AM, Zi Yan wrote:
On 21 Apr 2026, at 13:21, Kairui Song wrote:
On Tue, Apr 21, 2026 at 9:14 PM Zi Yan <ziy@xxxxxxxxxx> wrote:
On 21 Apr 2026, at 2:16, Kairui Song via B4 Relay wrote:
From: Kairui Song <kasong@xxxxxxxxxxx>
Shmem has some special requirements for THP GFP and has to limit it in
certain zones or provide a more lenient fallback.
We'll use this helper for generic swap THP allocation, which needs to
support shmem. For a typical GFP_HIGHUSER_MOVABLE swap-in, this helper
is basically a no-op. But it's necessary for certain shmem users, mostly
drivers.
No feature change.
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
include/linux/huge_mm.h | 30 ++++++++++++++++++++++++++++++
mm/shmem.c | 30 +++---------------------------
2 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 2949e5acff35..ffe5a120eee4 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -237,6 +237,31 @@ static inline bool thp_vma_suitable_order(struct vm_area_struct *vma,
return true;
}
+/*
+ * Make sure huge_gfp is always more limited than limit_gfp.
+ * Some shmem users want THP allocation to be done less aggressively
+ * and only in certain zone.
+ */
+static inline gfp_t thp_limit_gfp_mask(gfp_t huge_gfp, gfp_t limit_gfp)
Would it be better to rename it to thp_swap_limit_gfp_mask() or something
more descriptive? I am just worried about misuses in the future due to
the generic thp prefix.
Good idea, I wasn't sure if this might be helpful for any other user,
but for now naming it more descriptive does help to avoid misuse.
How about thp_shmem_limit_gfp_mask? Ordinary swap is fine with thp
gfp, only shmem is a bit special.
Sounds good to me. Thanks.
Sounds good to me too. Feel free to add:
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>