]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/suse-2.6.27.31/patches.suse/SoN-29-nfs-swapper.patch
Merge branch 'master' of git://git.ipfire.org/ipfire-2.x
[people/teissler/ipfire-2.x.git] / src / patches / suse-2.6.27.31 / patches.suse / SoN-29-nfs-swapper.patch
1 From: Peter Zijlstra <a.p.zijlstra@chello.nl>
2 Subject: nfs: disable data cache revalidation for swapfiles
3 Patch-mainline: No
4 References: FATE#303834
5
6 Do as Trond suggested:
7 http://lkml.org/lkml/2006/8/25/348
8
9 Disable NFS data cache revalidation on swap files since it doesn't really
10 make sense to have other clients change the file while you are using it.
11
12 Thereby we can stop setting PG_private on swap pages, since there ought to
13 be no further races with invalidate_inode_pages2() to deal with.
14
15 And since we cannot set PG_private we cannot use page->private (which is
16 already used by PG_swapcache pages anyway) to store the nfs_page. Thus
17 augment the new nfs_page_find_request logic.
18
19 Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
20 Acked-by: Neil Brown <neilb@suse.de>
21 Acked-by: Suresh Jayaraman <sjayaraman@suse.de>
22
23 ---
24 fs/nfs/inode.c | 6 ++++
25 fs/nfs/write.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++-----------
26 2 files changed, 64 insertions(+), 13 deletions(-)
27
28 --- a/fs/nfs/inode.c
29 +++ b/fs/nfs/inode.c
30 @@ -824,6 +824,12 @@ int nfs_revalidate_mapping_nolock(struct
31 struct nfs_inode *nfsi = NFS_I(inode);
32 int ret = 0;
33
34 + /*
35 + * swapfiles are not supposed to be shared.
36 + */
37 + if (IS_SWAPFILE(inode))
38 + goto out;
39 +
40 if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
41 || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
42 ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
43 --- a/fs/nfs/write.c
44 +++ b/fs/nfs/write.c
45 @@ -104,25 +104,62 @@ static void nfs_context_set_write_error(
46 set_bit(NFS_CONTEXT_ERROR_WRITE, &ctx->flags);
47 }
48
49 -static struct nfs_page *nfs_page_find_request_locked(struct page *page)
50 +static struct nfs_page *
51 +__nfs_page_find_request_locked(struct nfs_inode *nfsi, struct page *page, int get)
52 {
53 struct nfs_page *req = NULL;
54
55 - if (PagePrivate(page)) {
56 + if (PagePrivate(page))
57 req = (struct nfs_page *)page_private(page);
58 - if (req != NULL)
59 - kref_get(&req->wb_kref);
60 - }
61 + else if (unlikely(PageSwapCache(page)))
62 + req = radix_tree_lookup(&nfsi->nfs_page_tree, page_file_index(page));
63 +
64 + if (get && req)
65 + kref_get(&req->wb_kref);
66 +
67 return req;
68 }
69
70 +static inline struct nfs_page *
71 +nfs_page_find_request_locked(struct nfs_inode *nfsi, struct page *page)
72 +{
73 + return __nfs_page_find_request_locked(nfsi, page, 1);
74 +}
75 +
76 +static int __nfs_page_has_request(struct page *page)
77 +{
78 + struct inode *inode = page_file_mapping(page)->host;
79 + struct nfs_page *req = NULL;
80 +
81 + spin_lock(&inode->i_lock);
82 + req = __nfs_page_find_request_locked(NFS_I(inode), page, 0);
83 + spin_unlock(&inode->i_lock);
84 +
85 + /*
86 + * hole here plugged by the caller holding onto PG_locked
87 + */
88 +
89 + return req != NULL;
90 +}
91 +
92 +static inline int nfs_page_has_request(struct page *page)
93 +{
94 + if (PagePrivate(page))
95 + return 1;
96 +
97 + if (unlikely(PageSwapCache(page)))
98 + return __nfs_page_has_request(page);
99 +
100 + return 0;
101 +}
102 +
103 static struct nfs_page *nfs_page_find_request(struct page *page)
104 {
105 struct inode *inode = page_file_mapping(page)->host;
106 struct nfs_page *req = NULL;
107
108 spin_lock(&inode->i_lock);
109 - req = nfs_page_find_request_locked(page);
110 + req = nfs_page_find_request_locked(NFS_I(inode), page);
111 spin_unlock(&inode->i_lock);
112 return req;
113 }
114 @@ -226,7 +263,7 @@ static int nfs_page_async_flush(struct n
115
116 spin_lock(&inode->i_lock);
117 for(;;) {
118 - req = nfs_page_find_request_locked(page);
119 + req = nfs_page_find_request_locked(NFS_I(inode), page);
120 if (req == NULL) {
121 spin_unlock(&inode->i_lock);
122 return 0;
123 @@ -349,8 +386,14 @@ static int nfs_inode_add_request(struct
124 if (nfs_have_delegation(inode, FMODE_WRITE))
125 nfsi->change_attr++;
126 }
127 - SetPagePrivate(req->wb_page);
128 - set_page_private(req->wb_page, (unsigned long)req);
129 + /*
130 + * Swap-space should not get truncated. Hence no need to plug the race
131 + * with invalidate/truncate.
132 + */
133 + if (likely(!PageSwapCache(req->wb_page))) {
134 + SetPagePrivate(req->wb_page);
135 + set_page_private(req->wb_page, (unsigned long)req);
136 + }
137 nfsi->npages++;
138 kref_get(&req->wb_kref);
139 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
140 @@ -372,8 +415,10 @@ static void nfs_inode_remove_request(str
141 BUG_ON (!NFS_WBACK_BUSY(req));
142
143 spin_lock(&inode->i_lock);
144 - set_page_private(req->wb_page, 0);
145 - ClearPagePrivate(req->wb_page);
146 + if (likely(!PageSwapCache(req->wb_page))) {
147 + set_page_private(req->wb_page, 0);
148 + ClearPagePrivate(req->wb_page);
149 + }
150 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
151 nfsi->npages--;
152 if (!nfsi->npages) {
153 @@ -577,7 +622,7 @@ static struct nfs_page *nfs_try_to_updat
154 spin_lock(&inode->i_lock);
155
156 for (;;) {
157 - req = nfs_page_find_request_locked(page);
158 + req = nfs_page_find_request_locked(NFS_I(inode), page);
159 if (req == NULL)
160 goto out_unlock;
161
162 @@ -1488,7 +1533,7 @@ int nfs_wb_page_cancel(struct inode *ino
163 if (ret < 0)
164 goto out;
165 }
166 - if (!PagePrivate(page))
167 + if (!nfs_page_has_request(page))
168 return 0;
169 ret = nfs_sync_mapping_wait(page_file_mapping(page), &wbc, FLUSH_INVALIDATE);
170 out: