Skip to content

Commit b571cfc

Browse files
Christoph Hellwigamschuma-ntap
authored andcommitted
nfs: don't reuse partially completed requests in nfs_lock_and_join_requests
When NFS requests are split into sub-requests, nfs_inode_remove_request calls nfs_page_group_sync_on_bit to set PG_REMOVE on this sub-request and only completes the head requests once PG_REMOVE is set on all requests. This means that when nfs_lock_and_join_requests sees a PG_REMOVE bit, I/O on the request is in progress and has partially completed. If such a request is returned to nfs_try_to_update_request, it could be extended with the newly dirtied region and I/O for the combined range will be re-scheduled, leading to extra I/O. Change the logic to instead restart the search for a request when any PG_REMOVE bit is set, as the completion handler will remove the request as soon as it can take the page group lock. This not only avoid extending the I/O but also does the right thing for the callers that want to cancel or flush the request. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent f1b7c75 commit b571cfc

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

fs/nfs/write.c

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,31 +144,6 @@ static void nfs_io_completion_put(struct nfs_io_completion *ioc)
144144
kref_put(&ioc->refcount, nfs_io_completion_release);
145145
}
146146

147-
static void
148-
nfs_page_set_inode_ref(struct nfs_page *req, struct inode *inode)
149-
{
150-
if (!test_and_set_bit(PG_INODE_REF, &req->wb_flags)) {
151-
kref_get(&req->wb_kref);
152-
atomic_long_inc(&NFS_I(inode)->nrequests);
153-
}
154-
}
155-
156-
static int
157-
nfs_cancel_remove_inode(struct nfs_page *req, struct inode *inode)
158-
{
159-
int ret;
160-
161-
if (!test_bit(PG_REMOVE, &req->wb_flags))
162-
return 0;
163-
ret = nfs_page_group_lock(req);
164-
if (ret)
165-
return ret;
166-
if (test_and_clear_bit(PG_REMOVE, &req->wb_flags))
167-
nfs_page_set_inode_ref(req, inode);
168-
nfs_page_group_unlock(req);
169-
return 0;
170-
}
171-
172147
/**
173148
* nfs_folio_find_head_request - find head request associated with a folio
174149
* @folio: pointer to folio
@@ -566,6 +541,7 @@ static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio)
566541
struct inode *inode = folio->mapping->host;
567542
struct nfs_page *head, *subreq;
568543
struct nfs_commit_info cinfo;
544+
bool removed;
569545
int ret;
570546

571547
/*
@@ -590,25 +566,40 @@ static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio)
590566
goto retry;
591567
}
592568

593-
ret = nfs_cancel_remove_inode(head, inode);
594-
if (ret < 0)
595-
goto out_unlock;
596-
597569
ret = nfs_page_group_lock(head);
598570
if (ret < 0)
599571
goto out_unlock;
600572

573+
removed = test_bit(PG_REMOVE, &head->wb_flags);
574+
601575
/* lock each request in the page group */
602576
for (subreq = head->wb_this_page;
603577
subreq != head;
604578
subreq = subreq->wb_this_page) {
579+
if (test_bit(PG_REMOVE, &subreq->wb_flags))
580+
removed = true;
605581
ret = nfs_page_group_lock_subreq(head, subreq);
606582
if (ret < 0)
607583
goto out_unlock;
608584
}
609585

610586
nfs_page_group_unlock(head);
611587

588+
/*
589+
* If PG_REMOVE is set on any request, I/O on that request has
590+
* completed, but some requests were still under I/O at the time
591+
* we locked the head request.
592+
*
593+
* In that case the above wait for all requests means that all I/O
594+
* has now finished, and we can restart from a clean slate. Let the
595+
* old requests go away and start from scratch instead.
596+
*/
597+
if (removed) {
598+
nfs_unroll_locks(head, head);
599+
nfs_unlock_and_release_request(head);
600+
goto retry;
601+
}
602+
612603
nfs_init_cinfo_from_inode(&cinfo, inode);
613604
nfs_join_page_group(head, &cinfo, inode);
614605
return head;

0 commit comments

Comments
 (0)