blob: 0e6d4828a77a358edd3c77ef7d14eecc6f6001b3 [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 Szeredie4ad08f2008-04-30 00:54:37 -070012#include <linux/fs.h>
Jens Axboe03ba3782009-09-09 09:08:54 +020013#include <linux/sched.h>
Tejun Heoa212b102015-05-22 17:13:33 -040014#include <linux/blkdev.h>
Jens Axboe03ba3782009-09-09 09:08:54 +020015#include <linux/writeback.h>
Tejun Heo52ebea72015-05-22 17:13:37 -040016#include <linux/blk-cgroup.h>
Tejun Heo66114ca2015-05-22 17:13:32 -040017#include <linux/backing-dev-defs.h>
Christoph Hellwigde1414a2015-01-14 10:42:36 +010018
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 Heoc00ddad2015-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 Heo9ecf48662015-05-22 17:13:54 -040029void wb_start_background_writeback(struct bdi_writeback *wb);
Tejun Heof0054bb2015-05-22 17:13:30 -040030void wb_workfn(struct work_struct *work);
Tejun Heof0054bb2015-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 Heod6c10f12015-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 Heod6c10f12015-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 Heo95a46c62015-05-22 17:13:47 -040043static inline bool bdi_has_dirty_io(struct backing_dev_info *bdi)
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -070044{
Tejun Heo95a46c62015-05-22 17:13:47 -040045 /*
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);
Peter Zijlstrae0bf68d2007-10-16 23:25:46 -070050}
51
Tejun Heo93f78d82015-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 Heo93f78d82015-05-22 17:13:27 -040055 __percpu_counter_add(&wb->stat[item], amount, WB_STAT_BATCH);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070056}
57
Tejun Heo93f78d82015-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 Heo93f78d82015-05-22 17:13:27 -040061 __add_wb_stat(wb, item, 1);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070062}
63
Tejun Heo93f78d82015-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 Heo93f78d82015-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 Heo93f78d82015-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 Heo93f78d82015-05-22 17:13:27 -040076 __add_wb_stat(wb, item, -1);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070077}
78
Tejun Heo93f78d82015-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 Heo93f78d82015-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 Heo93f78d82015-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 Heo93f78d82015-05-22 17:13:27 -040090 return percpu_counter_read_positive(&wb->stat[item]);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070091}
92
Tejun Heo93f78d82015-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 Heo93f78d82015-05-22 17:13:27 -040096 return percpu_counter_sum_positive(&wb->stat[item]);
Peter Zijlstrab2e8fb62007-10-16 23:25:47 -070097}
98
Tejun Heo93f78d82015-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 Heo93f78d82015-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 Heo93f78d82015-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 Heo93f78d82015-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 Heo93f78d82015-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 Szeredie4ad08f2008-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 Heo89e9b9e2015-05-22 17:13:36 -0400143 *
144 * BDI_CAP_CGROUP_WRITEBACK: Supports cgroup-aware writeback.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 */
Miklos Szeredie4ad08f2008-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 Heo89e9b9e2015-05-22 17:13:36 -0400151#define BDI_CAP_CGROUP_WRITEBACK 0x00000020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Miklos Szeredie4ad08f2008-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 Heobc058732015-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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Tejun Heobc058732015-05-22 17:13:53 -0400167 return test_bit(WB_writeback_running, &wb->state);
168}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Tejun Heoa212b102015-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 Heoec8a6f22015-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 Heoec8a6f22015-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 Heoec8a6f22015-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 Szeredie4ad08f2008-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 Szeredie4ad08f2008-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 Szeredie4ad08f2008-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 Szeredie4ad08f2008-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 Szeredie4ad08f2008-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 Szeredie4ad08f2008-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 Heo89e9b9e2015-05-22 17:13:36 -0400237#ifdef CONFIG_CGROUP_WRITEBACK
238
Tejun Heo52ebea72015-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 Heo52ebea72015-05-22 17:13:37 -0400245void wb_memcg_offline(struct mem_cgroup *memcg);
246void wb_blkcg_offline(struct blkcg *blkcg);
Tejun Heo703c2702015-05-22 17:13:44 -0400247int inode_congested(struct inode *inode, int cong_bits);
Tejun Heo52ebea72015-05-22 17:13:37 -0400248
Tejun Heo89e9b9e2015-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) &&
Tejun Heo46b15ca2015-06-16 18:48:31 -0400262 (inode->i_sb->s_iflags & SB_I_CGROUPWB);
Tejun Heo89e9b9e2015-05-22 17:13:36 -0400263}
264
Tejun Heo52ebea72015-05-22 17:13:37 -0400265/**
Tejun Heo52ebea72015-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 Heoaaa2cac2015-05-28 14:50:55 -0400324 * inode_to_wb_is_valid - test whether an inode has a wb associated
325 * @inode: inode of interest
326 *
327 * Returns %true if @inode has a wb associated. May be called without any
328 * locking.
329 */
330static inline bool inode_to_wb_is_valid(struct inode *inode)
331{
332 return inode->i_wb;
333}
334
335/**
Tejun Heo52ebea72015-05-22 17:13:37 -0400336 * inode_to_wb - determine the wb of an inode
337 * @inode: inode of interest
338 *
Tejun Heoaaa2cac2015-05-28 14:50:55 -0400339 * Returns the wb @inode is currently associated with. The caller must be
340 * holding either @inode->i_lock, @inode->i_mapping->tree_lock, or the
341 * associated wb's list_lock.
Tejun Heo52ebea72015-05-22 17:13:37 -0400342 */
343static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
344{
Tejun Heoaaa2cac2015-05-28 14:50:55 -0400345#ifdef CONFIG_LOCKDEP
346 WARN_ON_ONCE(debug_locks &&
347 (!lockdep_is_held(&inode->i_lock) &&
348 !lockdep_is_held(&inode->i_mapping->tree_lock) &&
349 !lockdep_is_held(&inode->i_wb->list_lock)));
350#endif
Tejun Heo52ebea72015-05-22 17:13:37 -0400351 return inode->i_wb;
352}
353
Tejun Heo682aa8e2015-05-28 14:50:53 -0400354/**
355 * unlocked_inode_to_wb_begin - begin unlocked inode wb access transaction
356 * @inode: target inode
357 * @lockedp: temp bool output param, to be passed to the end function
358 *
359 * The caller wants to access the wb associated with @inode but isn't
360 * holding inode->i_lock, mapping->tree_lock or wb->list_lock. This
361 * function determines the wb associated with @inode and ensures that the
362 * association doesn't change until the transaction is finished with
363 * unlocked_inode_to_wb_end().
364 *
365 * The caller must call unlocked_inode_to_wb_end() with *@lockdep
366 * afterwards and can't sleep during transaction. IRQ may or may not be
367 * disabled on return.
368 */
369static inline struct bdi_writeback *
370unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
371{
372 rcu_read_lock();
373
374 /*
375 * Paired with store_release in inode_switch_wb_work_fn() and
376 * ensures that we see the new wb if we see cleared I_WB_SWITCH.
377 */
378 *lockedp = smp_load_acquire(&inode->i_state) & I_WB_SWITCH;
379
380 if (unlikely(*lockedp))
381 spin_lock_irq(&inode->i_mapping->tree_lock);
Tejun Heoaaa2cac2015-05-28 14:50:55 -0400382
383 /*
384 * Protected by either !I_WB_SWITCH + rcu_read_lock() or tree_lock.
385 * inode_to_wb() will bark. Deref directly.
386 */
387 return inode->i_wb;
Tejun Heo682aa8e2015-05-28 14:50:53 -0400388}
389
390/**
391 * unlocked_inode_to_wb_end - end inode wb access transaction
392 * @inode: target inode
393 * @locked: *@lockedp from unlocked_inode_to_wb_begin()
394 */
395static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
396{
397 if (unlikely(locked))
398 spin_unlock_irq(&inode->i_mapping->tree_lock);
399
400 rcu_read_unlock();
401}
402
Tejun Heoebe41ab2015-05-22 17:13:50 -0400403struct wb_iter {
404 int start_blkcg_id;
405 struct radix_tree_iter tree_iter;
406 void **slot;
407};
408
409static inline struct bdi_writeback *__wb_iter_next(struct wb_iter *iter,
410 struct backing_dev_info *bdi)
411{
412 struct radix_tree_iter *titer = &iter->tree_iter;
413
414 WARN_ON_ONCE(!rcu_read_lock_held());
415
416 if (iter->start_blkcg_id >= 0) {
417 iter->slot = radix_tree_iter_init(titer, iter->start_blkcg_id);
418 iter->start_blkcg_id = -1;
419 } else {
420 iter->slot = radix_tree_next_slot(iter->slot, titer, 0);
421 }
422
423 if (!iter->slot)
424 iter->slot = radix_tree_next_chunk(&bdi->cgwb_tree, titer, 0);
425 if (iter->slot)
426 return *iter->slot;
427 return NULL;
428}
429
430static inline struct bdi_writeback *__wb_iter_init(struct wb_iter *iter,
431 struct backing_dev_info *bdi,
432 int start_blkcg_id)
433{
434 iter->start_blkcg_id = start_blkcg_id;
435
436 if (start_blkcg_id)
437 return __wb_iter_next(iter, bdi);
438 else
439 return &bdi->wb;
440}
441
442/**
443 * bdi_for_each_wb - walk all wb's of a bdi in ascending blkcg ID order
444 * @wb_cur: cursor struct bdi_writeback pointer
445 * @bdi: bdi to walk wb's of
446 * @iter: pointer to struct wb_iter to be used as iteration buffer
447 * @start_blkcg_id: blkcg ID to start iteration from
448 *
449 * Iterate @wb_cur through the wb's (bdi_writeback's) of @bdi in ascending
450 * blkcg ID order starting from @start_blkcg_id. @iter is struct wb_iter
451 * to be used as temp storage during iteration. rcu_read_lock() must be
452 * held throughout iteration.
453 */
454#define bdi_for_each_wb(wb_cur, bdi, iter, start_blkcg_id) \
455 for ((wb_cur) = __wb_iter_init(iter, bdi, start_blkcg_id); \
456 (wb_cur); (wb_cur) = __wb_iter_next(iter, bdi))
457
Tejun Heo89e9b9e2015-05-22 17:13:36 -0400458#else /* CONFIG_CGROUP_WRITEBACK */
459
460static inline bool inode_cgwb_enabled(struct inode *inode)
461{
462 return false;
463}
464
Tejun Heo52ebea72015-05-22 17:13:37 -0400465static inline struct bdi_writeback_congested *
466wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp)
467{
468 return bdi->wb.congested;
469}
470
471static inline void wb_congested_put(struct bdi_writeback_congested *congested)
472{
473}
474
Tejun Heo52ebea72015-05-22 17:13:37 -0400475static inline struct bdi_writeback *wb_find_current(struct backing_dev_info *bdi)
476{
477 return &bdi->wb;
478}
479
480static inline struct bdi_writeback *
481wb_get_create_current(struct backing_dev_info *bdi, gfp_t gfp)
482{
483 return &bdi->wb;
484}
485
Tejun Heoaaa2cac2015-05-28 14:50:55 -0400486static inline bool inode_to_wb_is_valid(struct inode *inode)
487{
488 return true;
489}
490
Tejun Heo52ebea72015-05-22 17:13:37 -0400491static inline struct bdi_writeback *inode_to_wb(struct inode *inode)
492{
493 return &inode_to_bdi(inode)->wb;
494}
495
Tejun Heo682aa8e2015-05-28 14:50:53 -0400496static inline struct bdi_writeback *
497unlocked_inode_to_wb_begin(struct inode *inode, bool *lockedp)
498{
499 return inode_to_wb(inode);
500}
501
502static inline void unlocked_inode_to_wb_end(struct inode *inode, bool locked)
503{
504}
505
Tejun Heo52ebea72015-05-22 17:13:37 -0400506static inline void wb_memcg_offline(struct mem_cgroup *memcg)
507{
508}
509
510static inline void wb_blkcg_offline(struct blkcg *blkcg)
511{
512}
513
Tejun Heoebe41ab2015-05-22 17:13:50 -0400514struct wb_iter {
515 int next_id;
516};
517
518#define bdi_for_each_wb(wb_cur, bdi, iter, start_blkcg_id) \
519 for ((iter)->next_id = (start_blkcg_id); \
520 ({ (wb_cur) = !(iter)->next_id++ ? &(bdi)->wb : NULL; }); )
521
Tejun Heo703c2702015-05-22 17:13:44 -0400522static inline int inode_congested(struct inode *inode, int cong_bits)
523{
524 return wb_congested(&inode_to_bdi(inode)->wb, cong_bits);
525}
526
Tejun Heo89e9b9e2015-05-22 17:13:36 -0400527#endif /* CONFIG_CGROUP_WRITEBACK */
528
Tejun Heo703c2702015-05-22 17:13:44 -0400529static inline int inode_read_congested(struct inode *inode)
530{
531 return inode_congested(inode, 1 << WB_sync_congested);
532}
533
534static inline int inode_write_congested(struct inode *inode)
535{
536 return inode_congested(inode, 1 << WB_async_congested);
537}
538
539static inline int inode_rw_congested(struct inode *inode)
540{
541 return inode_congested(inode, (1 << WB_sync_congested) |
542 (1 << WB_async_congested));
543}
544
Tejun Heoec8a6f22015-05-22 17:13:41 -0400545static inline int bdi_congested(struct backing_dev_info *bdi, int cong_bits)
546{
547 return wb_congested(&bdi->wb, cong_bits);
548}
549
550static inline int bdi_read_congested(struct backing_dev_info *bdi)
551{
552 return bdi_congested(bdi, 1 << WB_sync_congested);
553}
554
555static inline int bdi_write_congested(struct backing_dev_info *bdi)
556{
557 return bdi_congested(bdi, 1 << WB_async_congested);
558}
559
560static inline int bdi_rw_congested(struct backing_dev_info *bdi)
561{
562 return bdi_congested(bdi, (1 << WB_sync_congested) |
563 (1 << WB_async_congested));
564}
565
Tejun Heo89e9b9e2015-05-22 17:13:36 -0400566#endif /* _LINUX_BACKING_DEV_H */