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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200226161404.14136-8-longman@redhat.com>
Date:   Wed, 26 Feb 2020 11:14:00 -0500
From:   Waiman Long <longman@...hat.com>
To:     Alexander Viro <viro@...iv.linux.org.uk>,
        Jonathan Corbet <corbet@....net>,
        Luis Chamberlain <mcgrof@...nel.org>,
        Kees Cook <keescook@...omium.org>,
        Iurii Zaikin <yzaikin@...gle.com>
Cc:     linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        linux-doc@...r.kernel.org,
        Mauro Carvalho Chehab <mchehab+samsung@...nel.org>,
        Eric Biggers <ebiggers@...gle.com>,
        Dave Chinner <david@...morbit.com>,
        Eric Sandeen <sandeen@...hat.com>,
        Waiman Long <longman@...hat.com>
Subject: [PATCH 07/11] fs/dcache: Add static key negative_reclaim_enable

Add a static_key negative_reclaim_enable to optimize the default case
where negative dentry directory limit "dentry-dir-max" is not set.

Signed-off-by: Waiman Long <longman@...hat.com>
---
 fs/dcache.c     | 30 ++++++++++++++++++++++++++++--
 kernel/sysctl.c |  3 ++-
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index c5364c2ed5d8..149c0a6c1a6e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -32,6 +32,7 @@
 #include <linux/bit_spinlock.h>
 #include <linux/rculist_bl.h>
 #include <linux/list_lru.h>
+#include <linux/jump_label.h>
 #include "internal.h"
 #include "mount.h"
 
@@ -134,11 +135,13 @@ int dcache_dentry_dir_max_sysctl __read_mostly;
 EXPORT_SYMBOL_GPL(dcache_dentry_dir_max_sysctl);
 
 static LLIST_HEAD(negative_reclaim_list);
+static DEFINE_STATIC_KEY_FALSE(negative_reclaim_enable);
 static void negative_reclaim_check(struct dentry *parent);
 static void negative_reclaim_workfn(struct work_struct *work);
 static DECLARE_WORK(negative_reclaim_work, negative_reclaim_workfn);
 
 #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
+proc_handler proc_dcache_dentry_dir_max;
 
 /*
  * Here we resort to our own counters instead of using generic per-cpu counters
@@ -188,6 +191,27 @@ int proc_nr_dentry(struct ctl_table *table, int write, void __user *buffer,
 	dentry_stat.nr_negative = get_nr_dentry_negative();
 	return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
 }
+
+/*
+ * Sysctl proc handler for dcache_dentry_dir_max_sysctl
+ */
+int proc_dcache_dentry_dir_max(struct ctl_table *ctl, int write,
+			       void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	int old = dcache_dentry_dir_max_sysctl;
+	int ret;
+
+	ret = proc_dointvec_minmax(ctl, write, buffer, lenp, ppos);
+
+	if (!write || ret || (dcache_dentry_dir_max_sysctl == old))
+		return ret;
+
+	if (!old && dcache_dentry_dir_max_sysctl)
+		static_branch_enable(&negative_reclaim_enable);
+	else if (old && !dcache_dentry_dir_max_sysctl)
+		static_branch_disable(&negative_reclaim_enable);
+	return 0;
+}
 #endif
 
 /*
@@ -876,7 +900,8 @@ void dput(struct dentry *dentry)
 		if (likely(retain_dentry(dentry))) {
 			struct dentry *neg_parent = NULL;
 
-			if (d_is_negative(dentry)) {
+			if (static_branch_unlikely(&negative_reclaim_enable) &&
+			    d_is_negative(dentry)) {
 				neg_parent = dentry->d_parent;
 				rcu_read_lock();
 			}
@@ -886,7 +911,8 @@ void dput(struct dentry *dentry)
 			 * Negative dentry reclaim check is only done when
 			 * a negative dentry is being put into a LRU list.
 			 */
-			if (neg_parent)
+			if (static_branch_unlikely(&negative_reclaim_enable) &&
+			    neg_parent)
 				negative_reclaim_check(neg_parent);
 			return;
 		}
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cd0a83ff1029..9a4b0a1376e8 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -119,6 +119,7 @@ extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
 extern int sysctl_nr_trim_pages;
 #endif
 extern int dcache_dentry_dir_max_sysctl;
+extern proc_handler proc_dcache_dentry_dir_max;
 
 /* Constants used for minimum and  maximum */
 #ifdef CONFIG_LOCKUP_DETECTOR
@@ -1956,7 +1957,7 @@ static struct ctl_table fs_table[] = {
 		.data		= &dcache_dentry_dir_max_sysctl,
 		.maxlen		= sizeof(dcache_dentry_dir_max_sysctl),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
+		.proc_handler	= proc_dcache_dentry_dir_max,
 		.extra1		= &zero,
 	},
 	{ }
-- 
2.18.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ