* + mm-huge_memory-disallow-hugepages-if-the-system-wide-thp-sysfs-settings-are-disabled.patch added to mm-new branch
@ 2025-06-05 21:40 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2025-06-05 21:40 UTC (permalink / raw)
To: mm-commits, ziy, ryan.roberts, npache, lorenzo.stoakes,
liam.howlett, hughd, dev.jain, david, baolin.wang, akpm
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 5790 bytes --]
The patch titled
Subject: mm: huge_memory: disallow hugepages if the system-wide THP sysfs settings are disabled
has been added to the -mm mm-new branch. Its filename is
mm-huge_memory-disallow-hugepages-if-the-system-wide-thp-sysfs-settings-are-disabled.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-huge_memory-disallow-hugepages-if-the-system-wide-thp-sysfs-settings-are-disabled.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.
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 the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Baolin Wang <baolin.wang@linux.alibaba.com>
Subject: mm: huge_memory: disallow hugepages if the system-wide THP sysfs settings are disabled
Date: Thu, 5 Jun 2025 16:00:58 +0800
Patch series "fix MADV_COLLAPSE issue if THP settings are disabled", v2.
As we discussed in the previous thread [1], the MADV_COLLAPSE will ignore
the system-wide anon/shmem THP sysfs settings, which means that even
though we have disabled the anon/shmem THP configuration, MADV_COLLAPSE
will still attempt to collapse into a anon/shmem THP. This violates the
rule we have agreed upon: never means never. This patch set will address
this issue.
This patch (of 2):
MADV_COLLAPSE will ignore the system-wide Anon THP sysfs settings, which
means that even though we have disabled the Anon THP configuration,
MADV_COLLAPSE will still attempt to collapse into a Anon THP. This
violates the rule we have agreed upon: never means never.
Another rule for madvise, referring to David's suggestion: “allowing for
collapsing in a VM without VM_HUGEPAGE in the "madvise" mode would be
fine".
To address this issue, should check whether the Anon THP configuration is
disabled in thp_vma_allowable_orders(), even when the TVA_ENFORCE_SYSFS
flag is set.
In summary, the current strategy is:
1. If always & orders == 0, and madvise & orders == 0, and
hugepage_global_enabled() == false (global THP settings are not
enabled), it means mTHP of that orders are prohibited from being used,
then madvise_collapse() is forbidden for that orders.
2. If always & orders == 0, and madvise & orders == 0, and
hugepage_global_enabled() == true (global THP settings are enabled),
and inherit & orders == 0, it means mTHP of that orders are still
prohibited from being used, thus madvise_collapse() is not allowed for
that orders.
Link: https://lkml.kernel.org/r/8eefb0809c598fadaa4a022634fba5689a4f3257.1749109709.git.baolin.wang@linux.alibaba.com
Link: https://lore.kernel.org/all/1f00fdc3-a3a3-464b-8565-4c1b23d34f8d@linux.alibaba.com/ [1]
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/huge_mm.h | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
--- a/include/linux/huge_mm.h~mm-huge_memory-disallow-hugepages-if-the-system-wide-thp-sysfs-settings-are-disabled
+++ a/include/linux/huge_mm.h
@@ -287,20 +287,35 @@ unsigned long thp_vma_allowable_orders(s
unsigned long orders)
{
/* Optimization to check if required orders are enabled early. */
- if ((tva_flags & TVA_ENFORCE_SYSFS) && vma_is_anonymous(vma)) {
- unsigned long mask = READ_ONCE(huge_anon_orders_always);
+ if (vma_is_anonymous(vma)) {
+ unsigned long always = READ_ONCE(huge_anon_orders_always);
+ unsigned long madvise = READ_ONCE(huge_anon_orders_madvise);
+ unsigned long inherit = READ_ONCE(huge_anon_orders_inherit);
+ unsigned long mask = always | madvise;
+ /*
+ * If the system-wide THP/mTHP sysfs settings are disabled,
+ * then we should never allow hugepages.
+ */
+ if (!(mask & orders) && !(hugepage_global_enabled() && (inherit & orders)))
+ return 0;
+
+ if (!(tva_flags & TVA_ENFORCE_SYSFS))
+ goto skip;
+
+ mask = always;
if (vm_flags & VM_HUGEPAGE)
- mask |= READ_ONCE(huge_anon_orders_madvise);
+ mask |= madvise;
if (hugepage_global_always() ||
((vm_flags & VM_HUGEPAGE) && hugepage_global_enabled()))
- mask |= READ_ONCE(huge_anon_orders_inherit);
+ mask |= inherit;
orders &= mask;
if (!orders)
return 0;
}
+skip:
return __thp_vma_allowable_orders(vma, vm_flags, tva_flags, orders);
}
_
Patches currently in -mm which might be from baolin.wang@linux.alibaba.com are
mm-fix-the-inaccurate-memory-statistics-issue-for-users.patch
mm-huge_memory-disallow-hugepages-if-the-system-wide-thp-sysfs-settings-are-disabled.patch
mm-shmem-disallow-hugepages-if-the-system-wide-shmem-thp-sysfs-settings-are-disabled.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-06-05 21:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05 21:40 + mm-huge_memory-disallow-hugepages-if-the-system-wide-thp-sysfs-settings-are-disabled.patch added to mm-new branch Andrew Morton
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.