diff mbox series

Some additional cifs patches for 6.5 stable to address issue brought up by kernel regression tracker

Message ID CAH2r5mvHUnxfOU1URs2s6O3As8WLyMEkK+KNdUy6Ct9u+=d5YA@mail.gmail.com
State New
Headers show
Series Some additional cifs patches for 6.5 stable to address issue brought up by kernel regression tracker | expand

Commit Message

Steve French Oct. 24, 2023, 4:32 a.m. UTC
There were a set of issues brought up in 6.5 by the introduction of
the "laundromat" (which cleans up directory leases).  After discussion
and testing with Paulo, Bernd Feige and others, we request that the
following set also be included to address these problems.  They are
all in mainline (added in 6.6) and the patches (from mainline since
they apply cleanly) are also attached.

        238b351d0935 ("smb3: allow controlling length of time
directory entries are cached with dir leases")
        6a50d71d0fff ("smb3: allow controlling maximum number of
cached directories")
        2da338ff752a ("smb3: do not start laundromat thread when dir
leases  disabled")
        3b8bb3171571 ("smb: client: do not start laundromat thread on
nohandlecache")
        e95f3f744650 ("smb: client: make laundromat a delayed worker")
        81ba10959970 ("smb: client: prevent new fids from being
removed by laundromat")

Comments

Sasha Levin Oct. 26, 2023, 1:09 p.m. UTC | #1
On Mon, Oct 23, 2023 at 11:32:21PM -0500, Steve French wrote:
>There were a set of issues brought up in 6.5 by the introduction of
>the "laundromat" (which cleans up directory leases).  After discussion
>and testing with Paulo, Bernd Feige and others, we request that the
>following set also be included to address these problems.  They are
>all in mainline (added in 6.6) and the patches (from mainline since
>they apply cleanly) are also attached.
>
>        238b351d0935 ("smb3: allow controlling length of time
>directory entries are cached with dir leases")
>        6a50d71d0fff ("smb3: allow controlling maximum number of
>cached directories")
>        2da338ff752a ("smb3: do not start laundromat thread when dir
>leases  disabled")
>        3b8bb3171571 ("smb: client: do not start laundromat thread on
>nohandlecache")
>        e95f3f744650 ("smb: client: make laundromat a delayed worker")
>        81ba10959970 ("smb: client: prevent new fids from being
>removed by laundromat")

Queued up, thanks!
diff mbox series

Patch

From 238b351d0935df568ecb3dc5aef25971778f0f7c Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Wed, 30 Aug 2023 22:48:41 -0500
Subject: [PATCH 29/50] smb3: allow controlling length of time directory
 entries are cached with dir leases

Currently with directory leases we cache directory contents for a fixed period
of time (default 30 seconds) but for many workloads this is too short.  Allow
configuring the maximum amount of time directory entries are cached when a
directory lease is held on that directory. Add module load parm "max_dir_cache"

For example to set the timeout to 10 minutes you would do:

  echo 600 > /sys/module/cifs/parameters/dir_cache_timeout

or to disable caching directory contents:

  echo 0 > /sys/module/cifs/parameters/dir_cache_timeout

Reviewed-by: Bharath SM <bharathsm@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/smb/client/cached_dir.c |  4 ++--
 fs/smb/client/cifsfs.c     | 10 ++++++++++
 fs/smb/client/cifsglob.h   |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index 2d5e9a9d5b8b..9d84c4a7bd0c 100644
--- a/fs/smb/client/cached_dir.c
+++ b/fs/smb/client/cached_dir.c
@@ -145,7 +145,7 @@  int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 	const char *npath;
 
 	if (tcon == NULL || tcon->cfids == NULL || tcon->nohandlecache ||
-	    is_smb1_server(tcon->ses->server))
+	    is_smb1_server(tcon->ses->server) || (dir_cache_timeout == 0))
 		return -EOPNOTSUPP;
 
 	ses = tcon->ses;
@@ -582,7 +582,7 @@  cifs_cfids_laundromat_thread(void *p)
 			return 0;
 		spin_lock(&cfids->cfid_list_lock);
 		list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {
-			if (time_after(jiffies, cfid->time + HZ * 30)) {
+			if (time_after(jiffies, cfid->time + HZ * dir_cache_timeout)) {
 				list_del(&cfid->entry);
 				list_add(&cfid->entry, &entry);
 				cfids->num_entries--;
diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c
index 73c44e097a69..52612bb52bd7 100644
--- a/fs/smb/client/cifsfs.c
+++ b/fs/smb/client/cifsfs.c
@@ -117,6 +117,10 @@  module_param(cifs_max_pending, uint, 0444);
 MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server for "
 				   "CIFS/SMB1 dialect (N/A for SMB3) "
 				   "Default: 32767 Range: 2 to 32767.");
+unsigned int dir_cache_timeout = 30;
+module_param(dir_cache_timeout, uint, 0644);
+MODULE_PARM_DESC(dir_cache_timeout, "Number of seconds to cache directory contents for which we have a lease. Default: 30 "
+				 "Range: 1 to 65000 seconds, 0 to disable caching dir contents");
 #ifdef CONFIG_CIFS_STATS2
 unsigned int slow_rsp_threshold = 1;
 module_param(slow_rsp_threshold, uint, 0644);
@@ -1679,6 +1683,12 @@  init_cifs(void)
 			 CIFS_MAX_REQ);
 	}
 
+	/* Limit max to about 18 hours, and setting to zero disables directory entry caching */
+	if (dir_cache_timeout > 65000) {
+		dir_cache_timeout = 65000;
+		cifs_dbg(VFS, "dir_cache_timeout set to max of 65000 seconds\n");
+	}
+
 	cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
 	if (!cifsiod_wq) {
 		rc = -ENOMEM;
diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h
index 259e231f8b4f..501426ee39e7 100644
--- a/fs/smb/client/cifsglob.h
+++ b/fs/smb/client/cifsglob.h
@@ -2016,6 +2016,7 @@  extern unsigned int CIFSMaxBufSize;  /* max size not including hdr */
 extern unsigned int cifs_min_rcv;    /* min size of big ntwrk buf pool */
 extern unsigned int cifs_min_small;  /* min size of small buf pool */
 extern unsigned int cifs_max_pending; /* MAX requests at once to server*/
+extern unsigned int dir_cache_timeout; /* max time for directory lease caching of dir */
 extern bool disable_legacy_dialects;  /* forbid vers=1.0 and vers=2.0 mounts */
 extern atomic_t mid_count;
 
-- 
2.39.2