Skip to content

Commit 238b351

Browse files
author
Steve French
committed
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 <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent efc0b0b commit 238b351

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

fs/smb/client/cached_dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
145145
const char *npath;
146146

147147
if (tcon == NULL || tcon->cfids == NULL || tcon->nohandlecache ||
148-
is_smb1_server(tcon->ses->server))
148+
is_smb1_server(tcon->ses->server) || (dir_cache_timeout == 0))
149149
return -EOPNOTSUPP;
150150

151151
ses = tcon->ses;
@@ -582,7 +582,7 @@ cifs_cfids_laundromat_thread(void *p)
582582
return 0;
583583
spin_lock(&cfids->cfid_list_lock);
584584
list_for_each_entry_safe(cfid, q, &cfids->entries, entry) {
585-
if (time_after(jiffies, cfid->time + HZ * 30)) {
585+
if (time_after(jiffies, cfid->time + HZ * dir_cache_timeout)) {
586586
list_del(&cfid->entry);
587587
list_add(&cfid->entry, &entry);
588588
cfids->num_entries--;

fs/smb/client/cifsfs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ module_param(cifs_max_pending, uint, 0444);
117117
MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server for "
118118
"CIFS/SMB1 dialect (N/A for SMB3) "
119119
"Default: 32767 Range: 2 to 32767.");
120+
unsigned int dir_cache_timeout = 30;
121+
module_param(dir_cache_timeout, uint, 0644);
122+
MODULE_PARM_DESC(dir_cache_timeout, "Number of seconds to cache directory contents for which we have a lease. Default: 30 "
123+
"Range: 1 to 65000 seconds, 0 to disable caching dir contents");
120124
#ifdef CONFIG_CIFS_STATS2
121125
unsigned int slow_rsp_threshold = 1;
122126
module_param(slow_rsp_threshold, uint, 0644);
@@ -1679,6 +1683,12 @@ init_cifs(void)
16791683
CIFS_MAX_REQ);
16801684
}
16811685

1686+
/* Limit max to about 18 hours, and setting to zero disables directory entry caching */
1687+
if (dir_cache_timeout > 65000) {
1688+
dir_cache_timeout = 65000;
1689+
cifs_dbg(VFS, "dir_cache_timeout set to max of 65000 seconds\n");
1690+
}
1691+
16821692
cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
16831693
if (!cifsiod_wq) {
16841694
rc = -ENOMEM;

fs/smb/client/cifsglob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,7 @@ extern unsigned int CIFSMaxBufSize; /* max size not including hdr */
20162016
extern unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
20172017
extern unsigned int cifs_min_small; /* min size of small buf pool */
20182018
extern unsigned int cifs_max_pending; /* MAX requests at once to server*/
2019+
extern unsigned int dir_cache_timeout; /* max time for directory lease caching of dir */
20192020
extern bool disable_legacy_dialects; /* forbid vers=1.0 and vers=2.0 mounts */
20202021
extern atomic_t mid_count;
20212022

0 commit comments

Comments
 (0)