blob: 12ab3bb0d2d0a369c5b147cfa6be8fab708f681d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/linux/backing-dev.h
3 *
4 * low-level device information and state which is propagated up through
5 * to high-level code.
6 */
7
8#ifndef _LINUX_BACKING_DEV_H
9#define _LINUX_BACKING_DEV_H
10
Peter Zijlstracf0ca9f2008-04-30 00:54:32 -070011#include <linux/kernel.h>
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -070012#include <linux/fs.h>
Jens Axboe03ba3782009-09-09 09:08:54 +020013#include <linux/sched.h>
Tejun Heo0b6d7572015-05-22 17:13:33 -040014#include <linux/blkdev.h>
Jens Axboe03ba3782009-09-09 09:08:54 +020015#include <linux/writeback.h>
Tejun Heo6b385782015-05-22 17:13:37 -040016#include <linux/blk-cgroup.h>
Tejun Heo9d6e9852015-05-22 17:13:32 -040017#include <linux/backing-dev-defs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Mikulas Patocka8077c0d2013-10-14 12:14:13 -040019int __must_check bdi_init(struct backing_dev_info *bdi);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070020void bdi_destroy(struct backing_dev_info *bdi);
21
Joe Perchesd2cc4dd2012-11-29 08:37:03 -060022__printf(3, 4)
Peter Zijlstracf0ca9f2008-04-30 00:54:32 -070023int bdi_register(struct backing_dev_info *bdi, struct device *parent,
24 const char *fmt, ...);
25int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
Christoph Hellwigb4caecd2015-01-14 10:42:32 +010026int __must_check bdi_setup_and_register(struct backing_dev_info *, char *);
Tejun Heo283c54c2015-05-22 17:13:51 -040027void wb_start_writeback(struct bdi_writeback *wb, long nr_pages,
28 bool range_cyclic, enum wb_reason reason);
Tejun Heo5f618482015-05-22 17:13:54 -040029void wb_start_background_writeback(struct bdi_writeback *wb);
Tejun Heoc9b0f222015-05-22 17:13:30 -040030void wb_workfn(struct work_struct *work);
Tejun Heoc9b0f222015-05-22 17:13:30 -040031void wb_wakeup_delayed(struct bdi_writeback *wb);
Peter Zijlstracf0ca9f2008-04-30 00:54:32 -070032
Jens Axboe03ba3782009-09-09 09:08:54 +020033extern spinlock_t bdi_lock;
Jens Axboe66f3b8e2009-09-02 09:19:46 +020034extern struct list_head bdi_list;
35
Tejun Heo839a8e82013-04-01 19:08:06 -070036extern struct workqueue_struct *bdi_wq;
37
Tejun Heo00913372015-05-22 17:13:45 -040038static inline bool wb_has_dirty_io(struct bdi_writeback *wb)
Jens Axboe03ba3782009-09-09 09:08:54 +020039{
Tejun Heo00913372015-05-22 17:13:45 -040040 return test_bit(WB_has_dirty_io, &wb->state);
Jens Axboe03ba3782009-09-09 09:08:54 +020041}
42
Tejun Heo42969232015-05-22 17:13:47 -040043static inline bool bdi_has_dirty_io(struct backing_dev_info *bdi)
44{
45 /*
46 * @bdi->tot_write_bandwidth is guaranteed to be > 0 if there are
47 * any dirty wbs. See wb_update_write_bandwidth().
48 */
49 return atomic_long_read(&bdi->tot_write_bandwidth);
50}
51
Tejun Heo9ce34202015-05-22 17:13:27 -040052static inline void __add_wb_stat(struct bdi_writeback *wb,
53 enum wb_stat_item item, s64 amount)
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -070054{
Tejun Heo9ce34202015-05-22 17:13:27 -040055 __percpu_counter_add(&wb->stat[item], amount, WB_STAT_BATCH);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -070056}
57
Tejun Heo9ce34202015-05-22 17:13:27 -040058static inline void __inc_wb_stat(struct bdi_writeback *wb,
59 enum wb_stat_item item)
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -070060{
Tejun Heo9ce34202015-05-22 17:13:27 -040061 __add_wb_stat(wb, item, 1);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070062}
63
Tejun Heo9ce34202015-05-22 17:13:27 -040064static inline void inc_wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070065{
66 unsigned long flags;
67
68 local_irq_save(flags);
Tejun Heo9ce34202015-05-22 17:13:27 -040069 __inc_wb_stat(wb, item);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070070 local_irq_restore(flags);
71}
72
Tejun Heo9ce34202015-05-22 17:13:27 -040073static inline void __dec_wb_stat(struct bdi_writeback *wb,
74 enum wb_stat_item item)
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070075{
Tejun Heo9ce34202015-05-22 17:13:27 -040076 __add_wb_stat(wb, item, -1);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070077}
78
Tejun Heo9ce34202015-05-22 17:13:27 -040079static inline void dec_wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070080{
81 unsigned long flags;
82
83 local_irq_save(flags);
Tejun Heo9ce34202015-05-22 17:13:27 -040084 __dec_wb_stat(wb, item);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070085 local_irq_restore(flags);
86}
87
Tejun Heo9ce34202015-05-22 17:13:27 -040088static inline s64 wb_stat(struct bdi_writeback *wb, enum wb_stat_item item)
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070089{
Tejun Heo9ce34202015-05-22 17:13:27 -040090 return percpu_counter_read_positive(&wb->stat[item]);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070091}
92
Tejun Heo9ce34202015-05-22 17:13:27 -040093static inline s64 __wb_stat_sum(struct bdi_writeback *wb,
94 enum wb_stat_item item)
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070095{
Tejun Heo9ce34202015-05-22 17:13:27 -040096 return percpu_counter_sum_positive(&wb->stat[item]);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070097}
98
Tejun Heo9ce34202015-05-22 17:13:27 -040099static inline s64 wb_stat_sum(struct bdi_writeback *wb, enum wb_stat_item item)
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -0700100{
101 s64 sum;
102 unsigned long flags;
103
104 local_irq_save(flags);
Tejun Heo9ce34202015-05-22 17:13:27 -0400105 sum = __wb_stat_sum(wb, item);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -0700106 local_irq_restore(flags);
107
108 return sum;
109}
110
Tejun Heo9ce34202015-05-22 17:13:27 -0400111extern void wb_writeout_inc(struct bdi_writeback *wb);
Miklos Szeredidd5656e2008-04-30 00:54:37 -0700112
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -0700113/*
114 * maximal error of a stat counter.
115 */
Tejun Heo9ce34202015-05-22 17:13:27 -0400116static inline unsigned long wb_stat_error(struct bdi_writeback *wb)
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -0700117{
118#ifdef CONFIG_SMP
Tejun Heo9ce34202015-05-22 17:13:27 -0400119 return nr_cpu_ids * WB_STAT_BATCH;
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -0700120#else
121 return 1;
122#endif
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -0700123}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Peter Zijlstra189d3c42008-04-30 00:54:35 -0700125int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
Peter Zijlstraa42dde02008-04-30 00:54:36 -0700126int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
Peter Zijlstra189d3c42008-04-30 00:54:35 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/*
129 * Flags in backing_dev_info::capability
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700130 *
131 * The first three flags control whether dirty pages will contribute to the
132 * VM's accounting and whether writepages() should be called for dirty pages
133 * (something that would not, for example, be appropriate for ramfs)
134 *
135 * WARNING: these flags are closely related and should not normally be
136 * used separately. The BDI_CAP_NO_ACCT_AND_WRITEBACK combines these
137 * three flags into a single convenience macro.
138 *
139 * BDI_CAP_NO_ACCT_DIRTY: Dirty pages shouldn't contribute to accounting
140 * BDI_CAP_NO_WRITEBACK: Don't write pages back
141 * BDI_CAP_NO_ACCT_WB: Don't automatically account writeback pages
Maxim Patlasov5a537482013-09-11 14:22:46 -0700142 * BDI_CAP_STRICTLIMIT: Keep number of dirty pages below bdi threshold.
Tejun Heo0632c4c2015-05-22 17:13:36 -0400143 *
144 * BDI_CAP_CGROUP_WRITEBACK: Supports cgroup-aware writeback.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 */
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700146#define BDI_CAP_NO_ACCT_DIRTY 0x00000001
147#define BDI_CAP_NO_WRITEBACK 0x00000002
Christoph Hellwigb4caecd2015-01-14 10:42:32 +0100148#define BDI_CAP_NO_ACCT_WB 0x00000004
149#define BDI_CAP_STABLE_WRITES 0x00000008
150#define BDI_CAP_STRICTLIMIT 0x00000010
Tejun Heo0632c4c2015-05-22 17:13:36 -0400151#define BDI_CAP_CGROUP_WRITEBACK 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700153#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
154 (BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB)
155
Jörn Engel5129a462010-04-25 08:54:42 +0200156extern struct backing_dev_info noop_backing_dev_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Tejun Heo876a21b2015-05-22 17:13:53 -0400158/**
159 * writeback_in_progress - determine whether there is writeback in progress
160 * @wb: bdi_writeback of interest
161 *
162 * Determine whether there is writeback waiting to be handled against a
163 * bdi_writeback.
164 */
165static inline bool writeback_in_progress(struct bdi_writeback *wb)
166{
167 return test_bit(WB_writeback_running, &wb->state);
168}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Tejun Heo0b6d7572015-05-22 17:13:33 -0400170static inline struct backing_dev_info *inode_to_bdi(struct inode *inode)
171{
172 struct super_block *sb;
173
174 if (!inode)
175 return &noop_backing_dev_info;
176
177 sb = inode->i_sb;
178#ifdef CONFIG_BLOCK
179 if (sb_is_blkdev_sb(sb))
180 return blk_get_backing_dev_info(I_BDEV(inode));
181#endif
182 return sb->s_bdi;
183}
184
Tejun Heo5de85152015-05-22 17:13:41 -0400185static inline int wb_congested(struct bdi_writeback *wb, int cong_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Tejun Heo5de85152015-05-22 17:13:41 -0400187 struct backing_dev_info *bdi = wb->bdi;
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (bdi->congested_fn)
Tejun Heo5de85152015-05-22 17:13:41 -0400190 return bdi->congested_fn(bdi->congested_data, cong_bits);
191 return wb->congested->state & cong_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
Jens Axboe8aa7e842009-07-09 14:52:32 +0200194long congestion_wait(int sync, long timeout);
Mel Gorman0e093d992010-10-26 14:21:45 -0700195long wait_iff_congested(struct zone *zone, int sync, long timeout);
Wanpeng Li3965c9a2012-07-31 16:41:52 -0700196int pdflush_proc_obsolete(struct ctl_table *table, int write,
197 void __user *buffer, size_t *lenp, loff_t *ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Darrick J. Wong7d311cd2013-02-21 16:42:48 -0800199static inline bool bdi_cap_stable_pages_required(struct backing_dev_info *bdi)
200{
201 return bdi->capabilities & BDI_CAP_STABLE_WRITES;
202}
203
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700204static inline bool bdi_cap_writeback_dirty(struct backing_dev_info *bdi)
205{
206 return !(bdi->capabilities & BDI_CAP_NO_WRITEBACK);
207}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700209static inline bool bdi_cap_account_dirty(struct backing_dev_info *bdi)
210{
211 return !(bdi->capabilities & BDI_CAP_NO_ACCT_DIRTY);
212}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700214static inline bool bdi_cap_account_writeback(struct backing_dev_info *bdi)
215{
216 /* Paranoia: BDI_CAP_NO_WRITEBACK implies BDI_CAP_NO_ACCT_WB */
217 return !(bdi->capabilities & (BDI_CAP_NO_ACCT_WB |
218 BDI_CAP_NO_WRITEBACK));
219}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700221static inline bool mapping_cap_writeback_dirty(struct address_space *mapping)
222{
Christoph Hellwigde1414a2015-01-14 10:42:36 +0100223 return bdi_cap_writeback_dirty(inode_to_bdi(mapping->host));
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700224}
225
226static inline bool mapping_cap_account_dirty(struct address_space *mapping)
227{
Christoph Hellwigde1414a2015-01-14 10:42:36 +0100228 return bdi_cap_account_dirty(inode_to_bdi(mapping->host));
Miklos Szeredie4ad08fe2008-04-30 00:54:37 -0700229}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Jens Axboe03ba3782009-09-09 09:08:54 +0200231static inline int bdi_sched_wait(void *word)
232{
233 schedule();
234 return 0;
235}
236
Tejun Heo0632c4c2015-05-22 17:13:36 -0400237#ifdef CONFIG_CGROUP_WRITEBACK
238
Tejun Heo6b385782015-05-22 17:13:37 -0400239struct bdi_writeback_congested *
240wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp);
241void wb_congested_put(struct bdi_writeback_congested *congested);
242struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi,
243 struct cgroup_subsys_state *memcg_css,
244 gfp_t gfp);
Tejun Heo6b385782015-05-22 17:13:37 -0400245void wb_memcg_offline(struct mem_cgroup *memcg);
246void wb_blkcg_offline(struct blkcg *blkcg);
Tejun Heo28928452015-05-22 17:13:44 -0400247int inode_congested(struct inode *inode, int cong_bits);
Tejun Heo6b385782015-05-22 17:13:37 -0400248
Tejun Heo0632c4c2015-05-22 17:13:36 -0400249/**
250 * inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode
251 * @inode: inode of interest
252 *
253 * cgroup writeback requires support from both the bdi and filesystem.
254 * Test whether @inode has both.
255 */
256static inline bool inode_cgwb_enabled(struct inode *inode)
257{
258 struct backing_dev_info *bdi = inode_to_bdi(inode);
259
260 return bdi_cap_account_dirty(bdi) &&
261 (bdi->capabilities & BDI_CAP_CGROUP_WRITEBACK) &&
262 (inode->i_sb->s_type->fs_flags & FS_CGROUP_WRITEBACK);
263}
264
Tejun Heo6b385782015-05-22 17:13:37 -0400265/**
Tejun Heo6b385782015-05-22 17:13:37 -0400266 * wb_find_current - find wb for %current on a bdi
267 * @bdi: bdi of interest
268 *
269 * Find the wb of @bdi which matches both the memcg and blkcg of %current.
270 * Must be called under rcu_read_lock() which protects the returend wb.
271 * NULL if not found.
272 */
273static inline struct bdi_writeback *wb_find_current(struct backing_dev_info *bdi)
274{
275 struct cgroup_subsys_state *memcg_css;
276 struct bdi_writeback *wb;
277
278 memcg_css = task_css(current, memory_cgrp_id);
279 if (!memcg_css->parent)
280 return &bdi->wb;
281
282 wb = radix_tree_lookup(&bdi->cgwb_tree, memcg_css->id);
283
284 /*
285 * %current's blkcg equals the effective blkcg of its memcg. No
286 * need to use the relatively expensive cgroup_get_e_css().
287 */
288 if (likely(wb && wb->blkcg_css == task_css(current, blkio_cgrp_id)))
289 return wb;
290 return NULL;
291}
292
293/**
294 * wb_get_create_current - get or create wb for %current on a bdi
295 * @bdi: bdi of interest
296 * @gfp: allocation mask
297 *
298 * Equivalent to wb_get_create() on %current's memcg. This function is
299 * called from a relatively hot path and optimizes the common cases using
300 * wb_find_current().
301 */
302static inline struct bdi_writeback *
303wb_get_create_current(struct backing_dev_info *bdi, gfp_t gfp)
304{
305 struct bdi_writeback *wb;
306
307 rcu_read_lock();
308 wb = wb_find_current(bdi);
309 if (wb && unlikely(!wb_tryget(wb)))
310 wb = NULL;
311 rcu_read_unlock();
312
313 if (unlikely(!wb)) {
314 struct cgroup_subsys_state *memcg_css;
315
316 memcg_css = task_get_css(current, memory_cgrp_id);
317 wb = wb_get_create(bdi, memcg_css, gfp);
318 css_put(memcg_css);
319 }
320 return wb;
321}
322
323/**
Tejun Heo6b385782015-05-22 17:13:37 -0400324 * inode_to_wb - determine the wb of an inode
325 * @inode: inode of interest
326 *
327 * Returns the wb @inode is currently associated with.
328 */
329static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
330{
331 return inode->i_wb;
332}
333
Tejun Heob034f6f2015-05-28 14:50:53 -0400334/**
335 * unlocked_inode_to_wb_begin - begin unlocked inode wb access transaction
336 * @inode: target inode
337 * @lockedp: temp bool output param, to be passed to the end function
338 *
339 * The caller wants to access the wb associated with @inode but isn't
340 * holding inode->i_lock, mapping->tree_lock or wb->list_lock. This
341 * function determines the wb associated with @inode and ensures that the
342 * association doesn't change until the transaction is finished with
343 * unlocked_inode_to_wb_end().
344 *
345 * The caller must call unlocked_inode_to_wb_end() with *@lockdep
346 * afterwards and can't sleep during transaction. IRQ may or may not be
347 * disabled on return.
348 */
349static inline struct bdi_writeback *
350unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
351{
352 rcu_read_lock();
353
354 /*
355 * Paired with store_release in inode_switch_wb_work_fn() and
356 * ensures that we see the new wb if we see cleared I_WB_SWITCH.
357 */
358 *lockedp = smp_load_acquire(&inode->i_state) & I_WB_SWITCH;
359
360 if (unlikely(*lockedp))
361 spin_lock_irq(&inode->i_mapping->tree_lock);
362 return inode_to_wb(inode);
363}
364
365/**
366 * unlocked_inode_to_wb_end - end inode wb access transaction
367 * @inode: target inode
368 * @locked: *@lockedp from unlocked_inode_to_wb_begin()
369 */
370static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
371{
372 if (unlikely(locked))
373 spin_unlock_irq(&inode->i_mapping->tree_lock);
374
375 rcu_read_unlock();
376}
377
Tejun Heob3997c82015-05-22 17:13:50 -0400378struct wb_iter {
379 int start_blkcg_id;
380 struct radix_tree_iter tree_iter;
381 void **slot;
382};
383
384static inline struct bdi_writeback *__wb_iter_next(struct wb_iter *iter,
385 struct backing_dev_info *bdi)
386{
387 struct radix_tree_iter *titer = &iter->tree_iter;
388
389 WARN_ON_ONCE(!rcu_read_lock_held());
390
391 if (iter->start_blkcg_id >= 0) {
392 iter->slot = radix_tree_iter_init(titer, iter->start_blkcg_id);
393 iter->start_blkcg_id = -1;
394 } else {
395 iter->slot = radix_tree_next_slot(iter->slot, titer, 0);
396 }
397
398 if (!iter->slot)
399 iter->slot = radix_tree_next_chunk(&bdi->cgwb_tree, titer, 0);
400 if (iter->slot)
401 return *iter->slot;
402 return NULL;
403}
404
405static inline struct bdi_writeback *__wb_iter_init(struct wb_iter *iter,
406 struct backing_dev_info *bdi,
407 int start_blkcg_id)
408{
409 iter->start_blkcg_id = start_blkcg_id;
410
411 if (start_blkcg_id)
412 return __wb_iter_next(iter, bdi);
413 else
414 return &bdi->wb;
415}
416
417/**
418 * bdi_for_each_wb - walk all wb's of a bdi in ascending blkcg ID order
419 * @wb_cur: cursor struct bdi_writeback pointer
420 * @bdi: bdi to walk wb's of
421 * @iter: pointer to struct wb_iter to be used as iteration buffer
422 * @start_blkcg_id: blkcg ID to start iteration from
423 *
424 * Iterate @wb_cur through the wb's (bdi_writeback's) of @bdi in ascending
425 * blkcg ID order starting from @start_blkcg_id. @iter is struct wb_iter
426 * to be used as temp storage during iteration. rcu_read_lock() must be
427 * held throughout iteration.
428 */
429#define bdi_for_each_wb(wb_cur, bdi, iter, start_blkcg_id) \
430 for ((wb_cur) = __wb_iter_init(iter, bdi, start_blkcg_id); \
431 (wb_cur); (wb_cur) = __wb_iter_next(iter, bdi))
432
Tejun Heo0632c4c2015-05-22 17:13:36 -0400433#else /* CONFIG_CGROUP_WRITEBACK */
434
435static inline bool inode_cgwb_enabled(struct inode *inode)
436{
437 return false;
438}
439
Tejun Heo6b385782015-05-22 17:13:37 -0400440static inline struct bdi_writeback_congested *
441wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp)
442{
443 return bdi->wb.congested;
444}
445
446static inline void wb_congested_put(struct bdi_writeback_congested *congested)
447{
448}
449
Tejun Heo6b385782015-05-22 17:13:37 -0400450static inline struct bdi_writeback *wb_find_current(struct backing_dev_info *bdi)
451{
452 return &bdi->wb;
453}
454
455static inline struct bdi_writeback *
456wb_get_create_current(struct backing_dev_info *bdi, gfp_t gfp)
457{
458 return &bdi->wb;
459}
460
Tejun Heo6b385782015-05-22 17:13:37 -0400461static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
462{
463 return &inode_to_bdi(inode)->wb;
464}
465
Tejun Heob034f6f2015-05-28 14:50:53 -0400466static inline struct bdi_writeback *
467unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
468{
469 return inode_to_wb(inode);
470}
471
472static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
473{
474}
475
Tejun Heo6b385782015-05-22 17:13:37 -0400476static inline void wb_memcg_offline(struct mem_cgroup *memcg)
477{
478}
479
480static inline void wb_blkcg_offline(struct blkcg *blkcg)
481{
482}
483
Tejun Heob3997c82015-05-22 17:13:50 -0400484struct wb_iter {
485 int next_id;
486};
487
488#define bdi_for_each_wb(wb_cur, bdi, iter, start_blkcg_id) \
489 for ((iter)->next_id = (start_blkcg_id); \
490 ({ (wb_cur) = !(iter)->next_id++ ? &(bdi)->wb : NULL; }); )
491
Tejun Heo28928452015-05-22 17:13:44 -0400492static inline int inode_congested(struct inode *inode, int cong_bits)
493{
494 return wb_congested(&inode_to_bdi(inode)->wb, cong_bits);
495}
496
Tejun Heo0632c4c2015-05-22 17:13:36 -0400497#endif /* CONFIG_CGROUP_WRITEBACK */
498
Tejun Heo28928452015-05-22 17:13:44 -0400499static inline int inode_read_congested(struct inode *inode)
500{
501 return inode_congested(inode, 1 << WB_sync_congested);
502}
503
504static inline int inode_write_congested(struct inode *inode)
505{
506 return inode_congested(inode, 1 << WB_async_congested);
507}
508
509static inline int inode_rw_congested(struct inode *inode)
510{
511 return inode_congested(inode, (1 << WB_sync_congested) |
512 (1 << WB_async_congested));
513}
514
Tejun Heo5de85152015-05-22 17:13:41 -0400515static inline int bdi_congested(struct backing_dev_info *bdi, int cong_bits)
516{
517 return wb_congested(&bdi->wb, cong_bits);
518}
519
520static inline int bdi_read_congested(struct backing_dev_info *bdi)
521{
522 return bdi_congested(bdi, 1 << WB_sync_congested);
523}
524
525static inline int bdi_write_congested(struct backing_dev_info *bdi)
526{
527 return bdi_congested(bdi, 1 << WB_async_congested);
528}
529
530static inline int bdi_rw_congested(struct backing_dev_info *bdi)
531{
532 return bdi_congested(bdi, (1 << WB_sync_congested) |
533 (1 << WB_async_congested));
534}
535
Tejun Heo0632c4c2015-05-22 17:13:36 -0400536#endif /* _LINUX_BACKING_DEV_H */