summaryrefslogtreecommitdiffstats
path: root/include/linux/writeback.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2015-06-02 10:39:48 -0400
committerJens Axboe <axboe@fb.com>2015-06-02 10:39:48 -0400
commitb16b1deb553adcd7b3b7ce3e6d6fd1b923f314da (patch)
tree90818c22fd780699cdcb7c35b12f47b860de682a /include/linux/writeback.h
parent21c6321fbb3a3787af07f1bc031d713a707fb69c (diff)
writeback: make writeback_control track the inode being written back
Currently, for cgroup writeback, the IO submission paths directly associate the bio's with the blkcg from inode_to_wb_blkcg_css(); however, it'd be necessary to keep more writeback context to implement foreign inode writeback detection. wbc (writeback_control) is the natural fit for the extra context - it persists throughout the writeback of each inode and is passed all the way down to IO submission paths. This patch adds wbc_attach_and_unlock_inode(), wbc_detach_inode(), and wbc_attach_fdatawrite_inode() which are used to associate wbc with the inode being written back. IO submission paths now use wbc_init_bio() instead of directly associating bio's with blkcg themselves. This leaves inode_to_wb_blkcg_css() w/o any user. The function is removed. wbc currently only tracks the associated wb (bdi_writeback). Future patches will add more for foreign inode detection. The association is established under i_lock which will be depended upon when migrating foreign inodes to other wb's. As currently, once established, inode to wb association never changes, going through wbc when initializing bio's doesn't cause any behavior changes. v2: submit_blk_blkcg() now checks whether the wbc is associated with a wb before dereferencing it. This can happen when pageout() is writing pages directly without going through the usual writeback path. As pageout() path is single-threaded, we don't want it to be blocked behind a slow cgroup and ultimately want it to delegate actual writing to the usual writeback path. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Jan Kara <jack@suse.cz> Cc: Wu Fengguang <fengguang.wu@intel.com> Cc: Greg Thelen <gthelen@google.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'include/linux/writeback.h')
-rw-r--r--include/linux/writeback.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index 6726b7e56beb..8f964e558af5 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -86,6 +86,9 @@ struct writeback_control {
86 unsigned for_reclaim:1; /* Invoked from the page allocator */ 86 unsigned for_reclaim:1; /* Invoked from the page allocator */
87 unsigned range_cyclic:1; /* range_start is cyclic */ 87 unsigned range_cyclic:1; /* range_start is cyclic */
88 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ 88 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
89#ifdef CONFIG_CGROUP_WRITEBACK
90 struct bdi_writeback *wb; /* wb this writeback is issued under */
91#endif
89}; 92};
90 93
91/* 94/*
@@ -176,7 +179,14 @@ static inline void wait_on_inode(struct inode *inode)
176 179
177#ifdef CONFIG_CGROUP_WRITEBACK 180#ifdef CONFIG_CGROUP_WRITEBACK
178 181
182#include <linux/cgroup.h>
183#include <linux/bio.h>
184
179void __inode_attach_wb(struct inode *inode, struct page *page); 185void __inode_attach_wb(struct inode *inode, struct page *page);
186void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
187 struct inode *inode)
188 __releases(&inode->i_lock);
189void wbc_detach_inode(struct writeback_control *wbc);
180 190
181/** 191/**
182 * inode_attach_wb - associate an inode with its wb 192 * inode_attach_wb - associate an inode with its wb
@@ -207,6 +217,44 @@ static inline void inode_detach_wb(struct inode *inode)
207 } 217 }
208} 218}
209 219
220/**
221 * wbc_attach_fdatawrite_inode - associate wbc and inode for fdatawrite
222 * @wbc: writeback_control of interest
223 * @inode: target inode
224 *
225 * This function is to be used by __filemap_fdatawrite_range(), which is an
226 * alternative entry point into writeback code, and first ensures @inode is
227 * associated with a bdi_writeback and attaches it to @wbc.
228 */
229static inline void wbc_attach_fdatawrite_inode(struct writeback_control *wbc,
230 struct inode *inode)
231{
232 spin_lock(&inode->i_lock);
233 inode_attach_wb(inode, NULL);
234 wbc_attach_and_unlock_inode(wbc, inode);
235}
236
237/**
238 * wbc_init_bio - writeback specific initializtion of bio
239 * @wbc: writeback_control for the writeback in progress
240 * @bio: bio to be initialized
241 *
242 * @bio is a part of the writeback in progress controlled by @wbc. Perform
243 * writeback specific initialization. This is used to apply the cgroup
244 * writeback context.
245 */
246static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio)
247{
248 /*
249 * pageout() path doesn't attach @wbc to the inode being written
250 * out. This is intentional as we don't want the function to block
251 * behind a slow cgroup. Ultimately, we want pageout() to kick off
252 * regular writeback instead of writing things out itself.
253 */
254 if (wbc->wb)
255 bio_associate_blkcg(bio, wbc->wb->blkcg_css);
256}
257
210#else /* CONFIG_CGROUP_WRITEBACK */ 258#else /* CONFIG_CGROUP_WRITEBACK */
211 259
212static inline void inode_attach_wb(struct inode *inode, struct page *page) 260static inline void inode_attach_wb(struct inode *inode, struct page *page)
@@ -217,6 +265,26 @@ static inline void inode_detach_wb(struct inode *inode)
217{ 265{
218} 266}
219 267
268static inline void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
269 struct inode *inode)
270 __releases(&inode->i_lock)
271{
272 spin_unlock(&inode->i_lock);
273}
274
275static inline void wbc_attach_fdatawrite_inode(struct writeback_control *wbc,
276 struct inode *inode)
277{
278}
279
280static inline void wbc_detach_inode(struct writeback_control *wbc)
281{
282}
283
284static inline void wbc_init_bio(struct writeback_control *wbc, struct bio *bio)
285{
286}
287
220#endif /* CONFIG_CGROUP_WRITEBACK */ 288#endif /* CONFIG_CGROUP_WRITEBACK */
221 289
222/* 290/*