NFS: Reduce lock contention in nfs_try_to_update_request()
authorTrond Myklebust <trond.myklebust@primarydata.com>
Mon, 17 Jul 2017 13:37:12 +0000 (09:37 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 15 Aug 2017 15:54:46 +0000 (11:54 -0400)
Micro-optimisation to move the lockless check into the for(;;) loop.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/write.c

index 06e150c4e31513ce72d7f66a432c7e2a699d0880..bb019096c331ab28bff4d2cbb8687ef7f44eeb95 100644 (file)
@@ -1097,13 +1097,12 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
        unsigned int end;
        int error;
 
-       if (!PagePrivate(page))
-               return NULL;
-
        end = offset + bytes;
-       spin_lock(&inode->i_lock);
 
        for (;;) {
+               if (!(PagePrivate(page) || PageSwapCache(page)))
+                       return NULL;
+               spin_lock(&inode->i_lock);
                req = nfs_page_find_head_request_locked(NFS_I(inode), page);
                if (req == NULL)
                        goto out_unlock;
@@ -1132,7 +1131,6 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
                nfs_release_request(req);
                if (error != 0)
                        goto out_err;
-               spin_lock(&inode->i_lock);
        }
 
        /* Okay, the request matches. Update the region */