From: Steve French <smfrench@gmail.com>
To: linux-cifs@vger.kernel.org
Cc: Shyam Prasad N <sprasad@microsoft.com>
Subject: [PATCH 13/16] cifs: trace points for cached_dir operations
Date: Tue, 23 Jun 2026 15:13:40 -0500 [thread overview]
Message-ID: <20260623201344.2043841-13-stfrench@microsoft.com> (raw)
In-Reply-To: <20260623201344.2043841-1-stfrench@microsoft.com>
From: Shyam Prasad N <sprasad@microsoft.com>
This change introduces ftrace tracepoints for cached_dir operations.
Intended to be used for debugging cached_dir.
Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
---
fs/smb/client/cached_dir.c | 21 ++++++++++-
fs/smb/client/inode.c | 13 +++++++
fs/smb/client/trace.h | 73 ++++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index ecdc6907cf6d..389695b20324 100644
--- a/fs/smb/client/cached_dir.c
+++ b/fs/smb/client/cached_dir.c
@@ -1010,6 +1010,7 @@ bool add_to_cached_dir(struct cached_fid *cfid,
atomic64_sub(-bytes_diff, &cfid->cfids->total_dirents_bytes);
atomic64_sub(-bytes_diff, &cifs_dircache_bytes_used);
}
+ trace_smb3_add_to_cached_dir(cfid, name, namelen, added ? 0 : -1);
return added;
@@ -1040,6 +1041,9 @@ void complete_cached_dir(struct cached_fid *cfid,
cde = &cfid->dirents;
mutex_lock(&cfid->dirents.de_mutex);
finished_cached_dirents_count(cde, ctx, file);
+ trace_smb3_complete_cached_dir(cfid, ctx->pos, cde->pos,
+ cde->is_valid,
+ cde->is_failed);
mutex_unlock(&cfid->dirents.de_mutex);
}
@@ -1075,12 +1079,14 @@ int lookup_cached_dir(struct cached_fid *cfid,
entry = lookup_cached_dirent_entry_locked(&cfid->dirents, name, namelen);
if (!entry || !entry->dirent) {
mutex_unlock(&cfid->dirents.de_mutex);
+ trace_smb3_lookup_cached_dir(cfid, name, namelen, -ENOENT);
return -ENOENT;
}
dirent = entry->dirent;
if (dirent->tombstone) {
mutex_unlock(&cfid->dirents.de_mutex);
+ trace_smb3_lookup_cached_dir(cfid, name, namelen, -ENOENT);
return -ENOENT;
}
@@ -1088,6 +1094,7 @@ int lookup_cached_dir(struct cached_fid *cfid,
memcpy(&result->fattr, &dirent->fattr, sizeof(result->fattr));
mutex_unlock(&cfid->dirents.de_mutex);
+ trace_smb3_lookup_cached_dir(cfid, name, namelen, 0);
return 0;
}
@@ -1125,6 +1132,8 @@ bool update_dirent_in_cached_dir(struct cached_fid *cfid,
updated = update_cached_dirent_locked(&cfid->dirents, name,
namelen, fattr);
mutex_unlock(&cfid->dirents.de_mutex);
+ trace_smb3_update_dirent_in_cached_dir(cfid, name, namelen,
+ updated ? 0 : -ENOENT);
return updated;
}
@@ -1184,6 +1193,7 @@ void cifs_complete_pending_dcache(struct cached_fid *cfid,
mutex_unlock(&cfid->dirents.de_mutex);
cifs_dbg(FYI, "Dcache population of %.*s. status: %d\n",
namelen, name, ret);
+ trace_smb3_dcache_complete(cfid, name, namelen, ret);
}
/*
@@ -1225,6 +1235,7 @@ int cifs_wait_for_pending_dcache(struct cached_fid *cfid,
}
}
+ trace_smb3_dcache_wait(cfid, name, namelen, ret);
return ret;
}
@@ -1399,6 +1410,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
if (cfid == NULL) {
spin_unlock(&cfids->cfid_list_lock);
kfree(utf16_path);
+ trace_smb3_open_cached_dir(NULL, path, strlen(path), -ENOENT);
return -ENOENT;
}
spin_unlock(&cfids->cfid_list_lock);
@@ -1637,6 +1649,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
*ret_cfid = cfid;
atomic_inc(&tcon->num_remote_opens);
}
+ trace_smb3_open_cached_dir(cfid, path, strlen(path), rc);
kfree(utf16_path);
if (is_replayable_error(rc) &&
@@ -1651,7 +1664,6 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
struct cached_fid **ret_cfid)
{
struct cached_fid *cfid;
- struct cached_fid *trace_cfid = NULL;
struct cached_fids *cfids = tcon->cfids;
int rc = -ENOENT;
@@ -1667,6 +1679,7 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
spin_lock(&cfid->cfid_lock);
if (!is_valid_cached_dir(cfid)) {
spin_unlock(&cfid->cfid_lock);
+ rc = -ENOENT;
break;
}
cifs_dbg(FYI, "found a cached file handle by dentry\n");
@@ -1677,10 +1690,15 @@ int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
trace_cfid = cfid;
spin_unlock(&cfid->cfid_lock);
spin_unlock(&cfids->cfid_list_lock);
+ trace_smb3_open_cached_dir_by_dentry(cfid, dentry->d_name.name,
+ dentry->d_name.len, 0);
return rc;
}
}
spin_unlock(&cfids->cfid_list_lock);
+ trace_smb3_open_cached_dir_by_dentry(NULL, dentry->d_name.name,
+ dentry->d_name.len, rc);
+
return rc;
}
@@ -1969,6 +1987,7 @@ static void free_cached_dir(struct cached_fid *cfid)
WARN_ON(work_pending(&cfid->close_work));
WARN_ON(work_pending(&cfid->put_work));
+ trace_smb3_free_cached_dir(cfid, cfid->path, strlen(cfid->path), 0);
dput(cfid->dentry);
diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c
index 631f5fae813b..a139af232bf0 100644
--- a/fs/smb/client/inode.c
+++ b/fs/smb/client/inode.c
@@ -2860,20 +2860,31 @@ cifs_dentry_needs_reval(struct dentry *dentry)
if (!rc && lookup.found && lookup.under_active_lease) {
if (cifs_inode_has_writable_handle(inode)) {
cifs_set_time(dentry, jiffies);
+ trace_smb3_dcache_revalidate(cfid,
+ dentry->d_name.name,
+ dentry->d_name.len, 0);
cifs_put_tlink(tlink);
return false;
}
rc = cifs_fattr_to_inode(inode, &lookup.fattr, false);
if (!rc) {
cifs_set_time(dentry, jiffies);
+ trace_smb3_dcache_revalidate(cfid,
+ dentry->d_name.name,
+ dentry->d_name.len, 0);
cifs_put_tlink(tlink);
return false;
}
if (rc != -ESTALE) {
+ trace_smb3_dcache_revalidate(cfid,
+ dentry->d_name.name,
+ dentry->d_name.len, rc);
cifs_put_tlink(tlink);
return true;
}
}
+ trace_smb3_dcache_revalidate(cfid, dentry->d_name.name,
+ dentry->d_name.len, rc);
}
}
@@ -2883,6 +2894,8 @@ cifs_dentry_needs_reval(struct dentry *dentry)
* cache lookup/update did not satisfy this dentry.
*/
if (force_reval) {
+ trace_smb3_dcache_revalidate(cfid, dentry->d_name.name,
+ dentry->d_name.len, -1);
cifs_put_tlink(tlink);
return true;
}
diff --git a/fs/smb/client/trace.h b/fs/smb/client/trace.h
index 9e120d6fe51c..145d537ed17d 100644
--- a/fs/smb/client/trace.h
+++ b/fs/smb/client/trace.h
@@ -1959,6 +1959,79 @@ TRACE_EVENT(smb3_eio,
__entry->info, __entry->info2)
);
+/*
+ * Trace events for async directory cache population work
+ */
+DECLARE_EVENT_CLASS(smb3_dcache,
+ TP_PROTO(const void *cfid,
+ const char *name,
+ int namelen,
+ int result),
+ TP_ARGS(cfid, name, namelen, result),
+ TP_STRUCT__entry(
+ __field(const void *, cfid)
+ __string(name, name)
+ __field(int, namelen)
+ __field(int, result)
+ ),
+ TP_fast_assign(
+ __entry->cfid = cfid;
+ __assign_str(name);
+ __entry->namelen = namelen;
+ __entry->result = result;
+ ),
+ TP_printk("cfid=%p name=%.*s result=%d",
+ __entry->cfid,
+ __entry->namelen, __get_str(name), __entry->result)
+);
+
+#define DEFINE_SMB3_DCACHE_EVENT(name) \
+DEFINE_EVENT(smb3_dcache, smb3_##name, \
+ TP_PROTO(const void *cfid, \
+ const char *name, \
+ int namelen, \
+ int result), \
+ TP_ARGS(cfid, name, namelen, result))
+
+DEFINE_SMB3_DCACHE_EVENT(dcache_complete);
+DEFINE_SMB3_DCACHE_EVENT(dcache_wait);
+DEFINE_SMB3_DCACHE_EVENT(dcache_revalidate);
+DEFINE_SMB3_DCACHE_EVENT(open_cached_dir);
+DEFINE_SMB3_DCACHE_EVENT(open_cached_dir_by_dentry);
+DEFINE_SMB3_DCACHE_EVENT(free_cached_dir);
+DEFINE_SMB3_DCACHE_EVENT(add_to_cached_dir);
+DEFINE_SMB3_DCACHE_EVENT(lookup_cached_dir);
+DEFINE_SMB3_DCACHE_EVENT(update_dirent_in_cached_dir);
+
+TRACE_EVENT(smb3_complete_cached_dir,
+ TP_PROTO(const void *cfid,
+ loff_t ctx_pos,
+ loff_t cached_pos,
+ int is_valid,
+ int is_failed),
+ TP_ARGS(cfid, ctx_pos, cached_pos, is_valid, is_failed),
+ TP_STRUCT__entry(
+ __field(const void *, cfid)
+ __field(loff_t, ctx_pos)
+ __field(loff_t, cached_pos)
+ __field(int, is_valid)
+ __field(int, is_failed)
+ ),
+ TP_fast_assign(
+ __entry->cfid = cfid;
+ __entry->ctx_pos = ctx_pos;
+ __entry->cached_pos = cached_pos;
+ __entry->is_valid = is_valid;
+ __entry->is_failed = is_failed;
+ ),
+ TP_printk("cfid=%p ctx_pos=%lld cached_pos=%lld is_valid=%d is_failed=%d",
+ __entry->cfid,
+ (long long)__entry->ctx_pos,
+ (long long)__entry->cached_pos,
+ __entry->is_valid,
+ __entry->is_failed)
+);
+
#undef EM
#undef E_
#endif /* _CIFS_TRACE_H */
--
2.53.0
next prev parent reply other threads:[~2026-06-23 20:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 20:13 [PATCH 01/16] cifs: define variable sized buffer for querydir responses Steve French
2026-06-23 20:13 ` [PATCH 02/16] cifs: optimize readdir for small directories Steve French
2026-06-23 20:13 ` [PATCH 03/16] cifs: optimize readdir for larger directories Steve French
2026-06-23 20:13 ` [PATCH 04/16] cifs: reorganize cached dir helpers Steve French
2026-06-23 20:13 ` [PATCH 05/16] cifs: make cfid locks more granular Steve French
2026-06-23 20:13 ` [PATCH 06/16] cifs: query dir should reuse cfid even if not fully cached Steve French
2026-06-23 20:13 ` [PATCH 07/16] cifs: back cached_dirents with page cache Steve French
2026-06-23 20:13 ` [PATCH 08/16] cifs: in place changes to cached_dirents when dir lease is held Steve French
2026-06-23 20:13 ` [PATCH 09/16] cifs: register a shrinker to manage cached_dirents Steve French
2026-06-23 20:13 ` [PATCH 10/16] cifs: option to disable time-based eviction of cache Steve French
2026-06-23 20:13 ` [PATCH 11/16] cifs: option to set unlimited number of cached dirs Steve French
2026-06-23 20:13 ` [PATCH 12/16] cifs: allow dcache population to happen asynchronously Steve French
2026-06-23 20:13 ` Steve French [this message]
2026-06-23 20:13 ` [PATCH 14/16] cifs: discard functions to ensure that mid callbacks get called Steve French
2026-06-23 20:13 ` [PATCH 15/16] cifs: keep cfids in rbtree for efficient lookups Steve French
2026-06-23 20:13 ` [PATCH 16/16] cifs: invalidate cached_dirents if population aborted Steve French
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260623201344.2043841-13-stfrench@microsoft.com \
--to=smfrench@gmail.com \
--cc=linux-cifs@vger.kernel.org \
--cc=sprasad@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.