NFS: Use an atomic_long_t to count the number of requests
authorTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 1 Aug 2017 19:39:46 +0000 (15:39 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 15 Aug 2017 15:54:47 +0000 (11:54 -0400)
Rather than forcing us to take the inode->i_lock just in order to bump
the number.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/callback_proc.c
fs/nfs/delegation.c
fs/nfs/inode.c
fs/nfs/pagelist.c
fs/nfs/write.c
include/linux/nfs_fs.h

index 5427cdf04c5a1611934848c78455b299412dd185..14358de173fb9d851433977a0e70b8dcff9f0ff3 100644 (file)
@@ -51,7 +51,7 @@ __be32 nfs4_callback_getattr(void *argp, void *resp,
                goto out_iput;
        res->size = i_size_read(inode);
        res->change_attr = delegation->change_attr;
-       if (nfsi->nrequests != 0)
+       if (nfs_have_writebacks(inode))
                res->change_attr++;
        res->ctime = inode->i_ctime;
        res->mtime = inode->i_mtime;
index d7df5e67b0c1560ff3ea93cccd6a4b21e066cd88..606dd3871f66b0881c2760af3bbc3839748f9bc2 100644 (file)
@@ -1089,7 +1089,7 @@ bool nfs4_delegation_flush_on_close(const struct inode *inode)
        delegation = rcu_dereference(nfsi->delegation);
        if (delegation == NULL || !(delegation->type & FMODE_WRITE))
                goto out;
-       if (nfsi->nrequests < delegation->pagemod_limit)
+       if (atomic_long_read(&nfsi->nrequests) < delegation->pagemod_limit)
                ret = false;
 out:
        rcu_read_unlock();
index 34d9ebbc0dfdf3eb588c6a680477624062081394..0480eb02299a2376e84dac03b60e8b8cea8902c3 100644 (file)
@@ -1285,7 +1285,6 @@ static bool nfs_file_has_buffered_writers(struct nfs_inode *nfsi)
 
 static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 {
-       struct nfs_inode *nfsi = NFS_I(inode);
        unsigned long ret = 0;
 
        if ((fattr->valid & NFS_ATTR_FATTR_PRECHANGE)
@@ -1315,7 +1314,7 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr
        if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE)
                        && (fattr->valid & NFS_ATTR_FATTR_SIZE)
                        && i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size)
-                       && nfsi->nrequests == 0) {
+                       && !nfs_have_writebacks(inode)) {
                i_size_write(inode, nfs_size_to_loff_t(fattr->size));
                ret |= NFS_INO_INVALID_ATTR;
        }
@@ -1823,7 +1822,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                if (new_isize != cur_isize) {
                        /* Do we perhaps have any outstanding writes, or has
                         * the file grown beyond our last write? */
-                       if (nfsi->nrequests == 0 || new_isize > cur_isize) {
+                       if (!nfs_have_writebacks(inode) || new_isize > cur_isize) {
                                i_size_write(inode, new_isize);
                                if (!have_writers)
                                        invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
@@ -2012,7 +2011,7 @@ static void init_once(void *foo)
        INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
        INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
        INIT_LIST_HEAD(&nfsi->commit_info.list);
-       nfsi->nrequests = 0;
+       atomic_long_set(&nfsi->nrequests, 0);
        nfsi->commit_info.ncommit = 0;
        atomic_set(&nfsi->commit_info.rpcs_out, 0);
        init_rwsem(&nfsi->rmdir_sem);
index af6731dd43249fc3a20f3b0a384cfcc758d09c95..ec97c301899b366c6ac1f4a7bb39a806e87fb382 100644 (file)
@@ -258,9 +258,7 @@ nfs_page_group_init(struct nfs_page *req, struct nfs_page *prev)
                        inode = page_file_mapping(req->wb_page)->host;
                        set_bit(PG_INODE_REF, &req->wb_flags);
                        kref_get(&req->wb_kref);
-                       spin_lock(&inode->i_lock);
-                       NFS_I(inode)->nrequests++;
-                       spin_unlock(&inode->i_lock);
+                       atomic_long_inc(&NFS_I(inode)->nrequests);
                }
        }
 }
index 5ab5ca24b48a469340c0d965d7817a23e8912410..08093552f115dcd1b753e10cefe70678140f57d5 100644 (file)
@@ -434,9 +434,7 @@ nfs_destroy_unlinked_subrequests(struct nfs_page *destroy_list,
 
                if (test_and_clear_bit(PG_INODE_REF, &subreq->wb_flags)) {
                        nfs_release_request(subreq);
-                       spin_lock(&inode->i_lock);
-                       NFS_I(inode)->nrequests--;
-                       spin_unlock(&inode->i_lock);
+                       atomic_long_dec(&NFS_I(inode)->nrequests);
                }
 
                /* subreq is now totally disconnected from page group or any
@@ -567,9 +565,7 @@ try_again:
        if (test_and_clear_bit(PG_REMOVE, &head->wb_flags)) {
                set_bit(PG_INODE_REF, &head->wb_flags);
                kref_get(&head->wb_kref);
-               spin_lock(&inode->i_lock);
-               NFS_I(inode)->nrequests++;
-               spin_unlock(&inode->i_lock);
+               atomic_long_inc(&NFS_I(inode)->nrequests);
        }
 
        nfs_page_group_unlock(head);
@@ -755,7 +751,7 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
        nfs_lock_request(req);
 
        spin_lock(&inode->i_lock);
-       if (!nfsi->nrequests &&
+       if (!nfs_have_writebacks(inode) &&
            NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
                inode->i_version++;
        /*
@@ -767,7 +763,7 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
                SetPagePrivate(req->wb_page);
                set_page_private(req->wb_page, (unsigned long)req);
        }
-       nfsi->nrequests++;
+       atomic_long_inc(&nfsi->nrequests);
        /* this a head request for a page group - mark it as having an
         * extra reference so sub groups can follow suit.
         * This flag also informs pgio layer when to bump nrequests when
@@ -786,6 +782,7 @@ static void nfs_inode_remove_request(struct nfs_page *req)
        struct nfs_inode *nfsi = NFS_I(inode);
        struct nfs_page *head;
 
+       atomic_long_dec(&nfsi->nrequests);
        if (nfs_page_group_sync_on_bit(req, PG_REMOVE)) {
                head = req->wb_head;
 
@@ -795,11 +792,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
                        ClearPagePrivate(head->wb_page);
                        clear_bit(PG_MAPPED, &head->wb_flags);
                }
-               nfsi->nrequests--;
-               spin_unlock(&inode->i_lock);
-       } else {
-               spin_lock(&inode->i_lock);
-               nfsi->nrequests--;
                spin_unlock(&inode->i_lock);
        }
 
index 121a702888b49ccaec99838987dfcdd68b81cadb..238fdc4c46df8207efa06dca1cf125bda74e8a87 100644 (file)
@@ -154,7 +154,7 @@ struct nfs_inode {
         */
        __be32                  cookieverf[2];
 
-       unsigned long           nrequests;
+       atomic_long_t           nrequests;
        struct nfs_mds_commit_info commit_info;
 
        /* Open contexts for shared mmap writes */
@@ -511,7 +511,7 @@ extern void nfs_commit_free(struct nfs_commit_data *data);
 static inline int
 nfs_have_writebacks(struct inode *inode)
 {
-       return NFS_I(inode)->nrequests != 0;
+       return atomic_long_read(&NFS_I(inode)->nrequests) != 0;
 }
 
 /*