lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240222115323.4925-1-xiangzao@linux.alibaba.com>
Date: Thu, 22 Feb 2024 19:53:23 +0800
From: Yuanhe Shu <xiangzao@...ux.alibaba.com>
To: akpm@...ux-foundation.org
Cc: linux-mm@...ck.org,
	linux-kernel@...r.kernel.org,
	xiangzao@...ux.alibaba.com,
	liusong@...ux.alibaba.com
Subject: [PATCH] mm, thp: display [never] for defrag when THP is set to never

When transparent_hugepage is set to never by cmdline or echo, defrag
still show what it used to be and can be modified which makes user
confusing whether defrag would take effect.

Actually if transparent_hugepage is set to never, defrag will not take
effect. Just Display never and remain unchangeable to for defrag when
transparent_hugepage is set to never.

Suggested-by: Liu Song <liusong@...ux.alibaba.com>
Signed-off-by: Yuanhe Shu <xiangzao@...ux.alibaba.com>
---
 mm/huge_memory.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 94c958f7ebb5..03cd22a87b93 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -349,21 +349,25 @@ static ssize_t defrag_show(struct kobject *kobj,
 {
 	const char *output;
 
-	if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
-		     &transparent_hugepage_flags))
-		output = "[always] defer defer+madvise madvise never";
-	else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
-			  &transparent_hugepage_flags))
-		output = "always [defer] defer+madvise madvise never";
-	else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG,
-			  &transparent_hugepage_flags))
-		output = "always defer [defer+madvise] madvise never";
-	else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
-			  &transparent_hugepage_flags))
-		output = "always defer defer+madvise [madvise] never";
-	else
+	if (!test_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags) &&
+	    !test_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags))
 		output = "always defer defer+madvise madvise [never]";
-
+	else {
+		if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_DIRECT_FLAG,
+			&transparent_hugepage_flags))
+			output = "[always] defer defer+madvise madvise never";
+		else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG,
+				&transparent_hugepage_flags))
+			output = "always [defer] defer+madvise madvise never";
+		else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG,
+				&transparent_hugepage_flags))
+			output = "always defer [defer+madvise] madvise never";
+		else if (test_bit(TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
+				&transparent_hugepage_flags))
+			output = "always defer defer+madvise [madvise] never";
+		else
+			output = "always defer defer+madvise madvise [never]";
+	}
 	return sysfs_emit(buf, "%s\n", output);
 }
 
@@ -371,6 +375,12 @@ static ssize_t defrag_store(struct kobject *kobj,
 			    struct kobj_attribute *attr,
 			    const char *buf, size_t count)
 {
+	if (!test_bit(TRANSPARENT_HUGEPAGE_FLAG, &transparent_hugepage_flags) &&
+	    !test_bit(TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG, &transparent_hugepage_flags)) {
+		pr_warn("transparent_hugepage not enabled, defrag takes no effect\n");
+		return -EINVAL;
+	}
+
 	if (sysfs_streq(buf, "always")) {
 		clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_FLAG, &transparent_hugepage_flags);
 		clear_bit(TRANSPARENT_HUGEPAGE_DEFRAG_KSWAPD_OR_MADV_FLAG, &transparent_hugepage_flags);
-- 
2.39.3


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ