From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8D4520330 for ; Thu, 5 Jun 2025 21:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749159609; cv=none; b=ZFEJJ3Qgn5KeF4FLcW7DhLNxmCS2qZ0NkKgbR+nCiGPD4ntMLImq6Yd2EKtd5gJ7CPtgyG3iI9qmtRTN1U/LQ2MxS8TFYYIxD3af7GwBplOFoB/ZVuKOskX0Ylz8Fl9JOVs3+Yhea5GLr3t2pjdjXePkPid6J6M2KkgME4xzbRk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749159609; c=relaxed/simple; bh=Ds0xl7Mimb1Me1Dg4xpMA4hZc8VzhFD3sslY+kYPvhM=; h=Date:To:From:Subject:Message-Id; b=PkxM3a5S5zTYqX88dQMY//43dAxsZf8puoZb3pAT6556BrY6qB8ZYcDJoJ5RWwxEyy4OVDWPPM5ZTjVlakjQkEYNU1Ngsa/oxB35Is5NtuXKPzR8i5Uw8/6wGMn5a6ingSj6HbN3xDZ4qX+o6XDd7+RCz5KgrpWteREqAPZ31dQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=a0Ib2a3b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="a0Ib2a3b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BCD1C4CEE7; Thu, 5 Jun 2025 21:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1749159609; bh=Ds0xl7Mimb1Me1Dg4xpMA4hZc8VzhFD3sslY+kYPvhM=; h=Date:To:From:Subject:From; b=a0Ib2a3bZMkUmHFQAFZVeGp8S2N4b3Y2Qs+3qdbKP9tOsIWleLrbMGIjkyy+Yr0CR wZV/ok06E42vBZiprQCPXyRQdCddMAgkxeXHvm9AQMNuxusuMlGZkNNrJYLAudWq6T QWlWnbj7Fvm99ZMpfhWDpvho24UbGs+kTcTVB+ro= Date: Thu, 05 Jun 2025 14:40:08 -0700 To: mm-commits@vger.kernel.org,ziy@nvidia.com,ryan.roberts@arm.com,npache@redhat.com,lorenzo.stoakes@oracle.com,liam.howlett@oracle.com,hughd@google.com,dev.jain@arm.com,david@redhat.com,baolin.wang@linux.alibaba.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-huge_memory-disallow-hugepages-if-the-system-wide-thp-sysfs-settings-are-disabled.patch added to mm-new branch Message-Id: <20250605214009.3BCD1C4CEE7@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 Reviewed-by: Zi Yan Cc: David Hildenbrand Cc: Dev Jain Cc: Hugh Dickins Cc: Liam Howlett Cc: Lorenzo Stoakes Cc: Mariano Pache Cc: Ryan Roberts Signed-off-by: Andrew Morton --- 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