diff mbox series

[SRU,Bionic,1/1] NFS: Correct timing for assigning access cache timestamp

Message ID 20230317021849.22643-2-chengen.du@canonical.com
State New
Headers show
Series Fix the significant increase in NFS ACCESS operations | expand

Commit Message

Chengen Du March 17, 2023, 2:18 a.m. UTC
From: Chengen Du <chengen.du@canonical.com>

BugLink: https://bugs.launchpad.net/bugs/2009325

When the user's login time is newer than the cache's timestamp,
the original entry in the RB-tree will be replaced by a new entry.
Currently, the timestamp is only set if the entry is not found in
the RB-tree, which can cause the timestamp to be undefined when
the entry exists. This may result in a significant increase in
ACCESS operations if the timestamp is set to zero.

Signed-off-by: Chengen Du <chengen.du@canonical.com>
Fixes: 0eb43812c027 ("NFS: Clear the file access cache upon login”)
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
(cherry picked from commit 21fd9e8700de86d1169f6336e97d7a74916ed04a)
Signed-off-by: Chengen Du <chengen.du@canonical.com>
---
 fs/nfs/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index b98b19ca367c..5c05140d5d2e 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -2416,7 +2416,6 @@  static void nfs_access_add_rbtree(struct inode *inode, struct nfs_access_entry *
 		else
 			goto found;
 	}
-	set->timestamp = ktime_get_ns();
 	rb_link_node(&set->rb_node, parent, p);
 	rb_insert_color(&set->rb_node, root_node);
 	list_add_tail(&set->lru, &nfsi->access_cache_entry_lru);
@@ -2438,6 +2437,7 @@  void nfs_access_add_cache(struct inode *inode, struct nfs_access_entry *set)
 	RB_CLEAR_NODE(&cache->rb_node);
 	cache->cred = get_rpccred(set->cred);
 	cache->mask = set->mask;
+	cache->timestamp = ktime_get_ns();
 
 	/* The above field assignments must be visible
 	 * before this item appears on the lru.  We cannot easily