linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Usama Arif <usamaarif642@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	david@redhat.com, linux-mm@kvack.org
Cc: hannes@cmpxchg.org, shakeel.butt@linux.dev, riel@surriel.com,
	ziy@nvidia.com, laoar.shao@gmail.com,
	baolin.wang@linux.alibaba.com, lorenzo.stoakes@oracle.com,
	Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com,
	vbabka@suse.cz, jannh@google.com, Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	kernel-team@meta.com, Usama Arif <usamaarif642@gmail.com>
Subject: [PATCH v3 4/7] prctl: introduce PR_THP_POLICY_SYSTEM for the process
Date: Mon, 19 May 2025 23:29:56 +0100	[thread overview]
Message-ID: <20250519223307.3601786-5-usamaarif642@gmail.com> (raw)
In-Reply-To: <20250519223307.3601786-1-usamaarif642@gmail.com>

This is set via the new PR_SET_THP_POLICY prctl.
This will clear VM_HUGEPAGE and VM_NOHUGEPAGE in mm->def_flags
to reset VMA hugepage policy to system specific.
(except in the case of s390 where pgstes are switched
on for userspace process, in which case it will only
clear VM_HUGEPAGE).

Signed-off-by: Usama Arif <usamaarif642@gmail.com>
---
 include/uapi/linux/prctl.h                      |  1 +
 kernel/sys.c                                    | 17 +++++++++++++++++
 tools/include/uapi/linux/prctl.h                |  1 +
 .../trace/beauty/include/uapi/linux/prctl.h     |  1 +
 4 files changed, 20 insertions(+)

diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index 33a6ef6a5a72..508d78bc3364 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -368,5 +368,6 @@ struct prctl_mm_map {
 #define PR_GET_THP_POLICY		79
 #define PR_DEFAULT_MADV_HUGEPAGE	0
 #define PR_DEFAULT_MADV_NOHUGEPAGE	1
+#define PR_THP_POLICY_SYSTEM		2
 
 #endif /* _LINUX_PRCTL_H */
diff --git a/kernel/sys.c b/kernel/sys.c
index 6bb28b3666f7..cffb60632d97 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -2668,6 +2668,8 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			error = PR_DEFAULT_MADV_HUGEPAGE;
 		else if (mm->def_flags & VM_NOHUGEPAGE)
 			error = PR_DEFAULT_MADV_NOHUGEPAGE;
+		else
+			error = PR_THP_POLICY_SYSTEM;
 		mmap_write_unlock(mm);
 		break;
 	case PR_SET_THP_POLICY:
@@ -2688,6 +2690,21 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			if (!error)
 				process_default_madv_hugepage(mm, MADV_NOHUGEPAGE);
 			break;
+		case PR_THP_POLICY_SYSTEM:
+#ifdef CONFIG_S390
+			/*
+			 * When s390 switches on pgstes for its userspace
+			 * process (for kvm), it sets VM_NOHUGEPAGE.
+			 * Do not clear it with system policy.
+			 */
+			if (mm_has_pgste(mm))
+				mm->def_flags &= ~VM_HUGEPAGE;
+			else
+				mm->def_flags &= ~(VM_HUGEPAGE | VM_NOHUGEPAGE);
+#else
+			mm->def_flags &= ~(VM_HUGEPAGE | VM_NOHUGEPAGE);
+#endif
+			break;
 		default:
 			error = -EINVAL;
 			break;
diff --git a/tools/include/uapi/linux/prctl.h b/tools/include/uapi/linux/prctl.h
index e03d0ed890c5..cc209c9a8afb 100644
--- a/tools/include/uapi/linux/prctl.h
+++ b/tools/include/uapi/linux/prctl.h
@@ -332,5 +332,6 @@ struct prctl_mm_map {
 #define PR_GET_THP_POLICY		79
 #define PR_THP_POLICY_DEFAULT_HUGE	0
 #define PR_THP_POLICY_DEFAULT_NOHUGE	1
+#define PR_THP_POLICY_SYSTEM		2
 
 #endif /* _LINUX_PRCTL_H */
diff --git a/tools/perf/trace/beauty/include/uapi/linux/prctl.h b/tools/perf/trace/beauty/include/uapi/linux/prctl.h
index d25458f4db9e..340d5ff769a9 100644
--- a/tools/perf/trace/beauty/include/uapi/linux/prctl.h
+++ b/tools/perf/trace/beauty/include/uapi/linux/prctl.h
@@ -368,5 +368,6 @@ struct prctl_mm_map {
 #define PR_GET_THP_POLICY		79
 #define PR_THP_POLICY_DEFAULT_HUGE	0
 #define PR_THP_POLICY_DEFAULT_NOHUGE	1
+#define PR_THP_POLICY_SYSTEM		2
 
 #endif /* _LINUX_PRCTL_H */
-- 
2.47.1



  parent reply	other threads:[~2025-05-19 22:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-19 22:29 [PATCH v3 0/7] prctl: introduce PR_SET/GET_THP_POLICY Usama Arif
2025-05-19 22:29 ` [PATCH v3 1/7] mm: khugepaged: extract vm flag setting outside of hugepage_madvise Usama Arif
2025-05-20  9:51   ` kernel test robot
2025-05-20 14:43   ` Lorenzo Stoakes
2025-05-20 14:57     ` Usama Arif
2025-05-20 15:13       ` Usama Arif
2025-05-20 15:31       ` Lorenzo Stoakes
2025-05-19 22:29 ` [PATCH v3 2/7] prctl: introduce PR_DEFAULT_MADV_HUGEPAGE for the process Usama Arif
2025-05-19 23:01   ` Jann Horn
2025-05-20  5:23     ` Lorenzo Stoakes
2025-05-20  9:09       ` David Hildenbrand
2025-05-20  9:16         ` Lorenzo Stoakes
2025-05-20  8:48   ` kernel test robot
2025-05-19 22:29 ` [PATCH v3 3/7] prctl: introduce PR_DEFAULT_MADV_NOHUGEPAGE " Usama Arif
2025-05-19 22:29 ` Usama Arif [this message]
2025-05-19 22:29 ` [PATCH v3 5/7] selftests: prctl: introduce tests for PR_DEFAULT_MADV_NOHUGEPAGE Usama Arif
2025-05-19 22:29 ` [PATCH v3 6/7] selftests: prctl: introduce tests for PR_THP_POLICY_DEFAULT_HUGE Usama Arif
2025-05-19 22:29 ` [PATCH v3 7/7] docs: transhuge: document process level THP controls Usama Arif
2025-05-20  5:14 ` [PATCH v3 0/7] prctl: introduce PR_SET/GET_THP_POLICY Lorenzo Stoakes
2025-05-20  7:46   ` Usama Arif
2025-05-20  8:51     ` Lorenzo Stoakes
2025-05-21  2:33 ` Liam R. Howlett
2025-05-21  9:31   ` Usama Arif
2025-05-21 16:37     ` Liam R. Howlett
2025-05-22 12:10 ` Mike Rapoport

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=20250519223307.3601786-5-usamaarif642@gmail.com \
    --to=usamaarif642@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=jannh@google.com \
    --cc=kernel-team@meta.com \
    --cc=laoar.shao@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.com \
    --cc=riel@surriel.com \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=vbabka@suse.cz \
    --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