Skip to content

Commit 29418aa

Browse files
Mel Gormantorvalds
authored andcommitted
nfs: disable data cache revalidation for swapfiles
The VM does not like PG_private set on PG_swapcache pages. As suggested by Trond in http://lkml.org/lkml/2006/8/25/348, this patch disables NFS data cache revalidation on swap files. as it does not make sense to have other clients change the file while it is being used as swap. This avoids setting PG_private on swap pages, since there ought to be no further races with invalidate_inode_pages2() to deal with. Since we cannot set PG_private we cannot use page->private which is already used by PG_swapcache pages to store the nfs_page. Thus augment the new nfs_page_find_request logic. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Mel Gorman <mgorman@suse.de> Acked-by: Rik van Riel <riel@redhat.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: David S. Miller <davem@davemloft.net> Cc: Eric B Munson <emunson@mgebm.net> Cc: Eric Paris <eparis@redhat.com> Cc: James Morris <jmorris@namei.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Mike Christie <michaelc@cs.wisc.edu> Cc: Neil Brown <neilb@suse.de> Cc: Sebastian Andrzej Siewior <sebastian@breakpoint.cc> Cc: Trond Myklebust <Trond.Myklebust@netapp.com> Cc: Xiaotian Feng <dfeng@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d56b4dd commit 29418aa

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

‎fs/nfs/inode.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
882882
struct nfs_inode *nfsi = NFS_I(inode);
883883
int ret = 0;
884884

885+
/* swapfiles are not supposed to be shared. */
886+
if (IS_SWAPFILE(inode))
887+
goto out;
888+
885889
if (nfs_mapping_need_revalidate_inode(inode)) {
886890
ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
887891
if (ret < 0)

‎fs/nfs/write.c‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,28 @@ static void nfs_context_set_write_error(struct nfs_open_context *ctx, int error)
139139
set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
140140
}
141141

142-
static struct nfs_page *nfs_page_find_request_locked(struct page *page)
142+
static struct nfs_page *
143+
nfs_page_find_request_locked(struct nfs_inode *nfsi, struct page *page)
143144
{
144145
struct nfs_page *req = NULL;
145146

146-
if (PagePrivate(page)) {
147+
if (PagePrivate(page))
147148
req = (struct nfs_page *)page_private(page);
148-
if (req != NULL)
149-
kref_get(&req->wb_kref);
149+
else if (unlikely(PageSwapCache(page))) {
150+
struct nfs_page *freq, *t;
151+
152+
/* Linearly search the commit list for the correct req */
153+
list_for_each_entry_safe(freq, t, &nfsi->commit_info.list, wb_list) {
154+
if (freq->wb_page == page) {
155+
req = freq;
156+
break;
157+
}
158+
}
150159
}
160+
161+
if (req)
162+
kref_get(&req->wb_kref);
163+
151164
return req;
152165
}
153166

@@ -157,7 +170,7 @@ static struct nfs_page *nfs_page_find_request(struct page *page)
157170
struct nfs_page *req = NULL;
158171

159172
spin_lock(&inode->i_lock);
160-
req = nfs_page_find_request_locked(page);
173+
req = nfs_page_find_request_locked(NFS_I(inode), page);
161174
spin_unlock(&inode->i_lock);
162175
return req;
163176
}
@@ -258,7 +271,7 @@ static struct nfs_page *nfs_find_and_lock_request(struct page *page, bool nonblo
258271

259272
spin_lock(&inode->i_lock);
260273
for (;;) {
261-
req = nfs_page_find_request_locked(page);
274+
req = nfs_page_find_request_locked(NFS_I(inode), page);
262275
if (req == NULL)
263276
break;
264277
if (nfs_lock_request(req))
@@ -413,9 +426,15 @@ static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
413426
spin_lock(&inode->i_lock);
414427
if (!nfsi->npages && NFS_PROTO(inode)->have_delegation(inode, FMODE_WRITE))
415428
inode->i_version++;
416-
set_bit(PG_MAPPED, &req->wb_flags);
417-
SetPagePrivate(req->wb_page);
418-
set_page_private(req->wb_page, (unsigned long)req);
429+
/*
430+
* Swap-space should not get truncated. Hence no need to plug the race
431+
* with invalidate/truncate.
432+
*/
433+
if (likely(!PageSwapCache(req->wb_page))) {
434+
set_bit(PG_MAPPED, &req->wb_flags);
435+
SetPagePrivate(req->wb_page);
436+
set_page_private(req->wb_page, (unsigned long)req);
437+
}
419438
nfsi->npages++;
420439
kref_get(&req->wb_kref);
421440
spin_unlock(&inode->i_lock);
@@ -432,9 +451,11 @@ static void nfs_inode_remove_request(struct nfs_page *req)
432451
BUG_ON (!NFS_WBACK_BUSY(req));
433452

434453
spin_lock(&inode->i_lock);
435-
set_page_private(req->wb_page, 0);
436-
ClearPagePrivate(req->wb_page);
437-
clear_bit(PG_MAPPED, &req->wb_flags);
454+
if (likely(!PageSwapCache(req->wb_page))) {
455+
set_page_private(req->wb_page, 0);
456+
ClearPagePrivate(req->wb_page);
457+
clear_bit(PG_MAPPED, &req->wb_flags);
458+
}
438459
nfsi->npages--;
439460
spin_unlock(&inode->i_lock);
440461
nfs_release_request(req);
@@ -730,7 +751,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
730751
spin_lock(&inode->i_lock);
731752

732753
for (;;) {
733-
req = nfs_page_find_request_locked(page);
754+
req = nfs_page_find_request_locked(NFS_I(inode), page);
734755
if (req == NULL)
735756
goto out_unlock;
736757

@@ -1744,7 +1765,7 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
17441765
*/
17451766
int nfs_wb_page(struct inode *inode, struct page *page)
17461767
{
1747-
loff_t range_start = page_offset(page);
1768+
loff_t range_start = page_file_offset(page);
17481769
loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
17491770
struct writeback_control wbc = {
17501771
.sync_mode = WB_SYNC_ALL,

0 commit comments

Comments
 (0)