[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250519223307.3601786-5-usamaarif642@gmail.com>
Date: Mon, 19 May 2025 23:29:56 +0100
From: Usama Arif <usamaarif642@...il.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
david@...hat.com,
linux-mm@...ck.org
Cc: hannes@...xchg.org,
shakeel.butt@...ux.dev,
riel@...riel.com,
ziy@...dia.com,
laoar.shao@...il.com,
baolin.wang@...ux.alibaba.com,
lorenzo.stoakes@...cle.com,
Liam.Howlett@...cle.com,
npache@...hat.com,
ryan.roberts@....com,
vbabka@...e.cz,
jannh@...gle.com,
Arnd Bergmann <arnd@...db.de>,
linux-kernel@...r.kernel.org,
linux-doc@...r.kernel.org,
kernel-team@...a.com,
Usama Arif <usamaarif642@...il.com>
Subject: [PATCH v3 4/7] prctl: introduce PR_THP_POLICY_SYSTEM for the process
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@...il.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
Powered by blists - more mailing lists