Skip to content

Commit b30d2f0

Browse files
committed
NFS: Refactor nfs_page_find_head_request()
Split out the 2 cases so that we can treat the locking differently. The issue is that the locking in the pageswapcache cache is highly linked to the commit list locking. Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent bd37d6f commit b30d2f0

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

fs/nfs/write.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,41 @@ nfs_page_private_request(struct page *page)
170170
* returns matching head request with reference held, or NULL if not found.
171171
*/
172172
static struct nfs_page *
173-
nfs_page_find_head_request_locked(struct nfs_inode *nfsi, struct page *page)
173+
nfs_page_find_private_request(struct page *page)
174174
{
175+
struct inode *inode = page_file_mapping(page)->host;
175176
struct nfs_page *req;
176177

178+
if (!PagePrivate(page))
179+
return NULL;
180+
spin_lock(&inode->i_lock);
177181
req = nfs_page_private_request(page);
178-
if (!req && unlikely(PageSwapCache(page)))
179-
req = nfs_page_search_commits_for_head_request_locked(nfsi,
180-
page);
181-
182182
if (req) {
183183
WARN_ON_ONCE(req->wb_head != req);
184184
kref_get(&req->wb_kref);
185185
}
186+
spin_unlock(&inode->i_lock);
187+
return req;
188+
}
186189

190+
static struct nfs_page *
191+
nfs_page_find_swap_request(struct page *page)
192+
{
193+
struct inode *inode = page_file_mapping(page)->host;
194+
struct nfs_inode *nfsi = NFS_I(inode);
195+
struct nfs_page *req = NULL;
196+
if (!PageSwapCache(page))
197+
return NULL;
198+
spin_lock(&inode->i_lock);
199+
if (PageSwapCache(page)) {
200+
req = nfs_page_search_commits_for_head_request_locked(nfsi,
201+
page);
202+
if (req) {
203+
WARN_ON_ONCE(req->wb_head != req);
204+
kref_get(&req->wb_kref);
205+
}
206+
}
207+
spin_unlock(&inode->i_lock);
187208
return req;
188209
}
189210

@@ -194,14 +215,11 @@ nfs_page_find_head_request_locked(struct nfs_inode *nfsi, struct page *page)
194215
*/
195216
static struct nfs_page *nfs_page_find_head_request(struct page *page)
196217
{
197-
struct inode *inode = page_file_mapping(page)->host;
198-
struct nfs_page *req = NULL;
218+
struct nfs_page *req;
199219

200-
if (PagePrivate(page) || PageSwapCache(page)) {
201-
spin_lock(&inode->i_lock);
202-
req = nfs_page_find_head_request_locked(NFS_I(inode), page);
203-
spin_unlock(&inode->i_lock);
204-
}
220+
req = nfs_page_find_private_request(page);
221+
if (!req)
222+
req = nfs_page_find_swap_request(page);
205223
return req;
206224
}
207225

0 commit comments

Comments
 (0)