backing-dev-defs.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef __LINUX_BACKING_DEV_DEFS_H
  2. #define __LINUX_BACKING_DEV_DEFS_H
  3. #include <linux/list.h>
  4. #include <linux/radix-tree.h>
  5. #include <linux/rbtree.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/percpu_counter.h>
  8. #include <linux/percpu-refcount.h>
  9. #include <linux/flex_proportions.h>
  10. #include <linux/timer.h>
  11. #include <linux/workqueue.h>
  12. struct page;
  13. struct device;
  14. struct dentry;
  15. /*
  16. * Bits in bdi_writeback.state
  17. */
  18. enum wb_state {
  19. WB_registered, /* bdi_register() was done */
  20. WB_writeback_running, /* Writeback is in progress */
  21. WB_has_dirty_io, /* Dirty inodes on ->b_{dirty|io|more_io} */
  22. };
  23. enum wb_congested_state {
  24. WB_async_congested, /* The async (write) queue is getting full */
  25. WB_sync_congested, /* The sync queue is getting full */
  26. };
  27. typedef int (congested_fn)(void *, int);
  28. enum wb_stat_item {
  29. WB_RECLAIMABLE,
  30. WB_WRITEBACK,
  31. WB_DIRTIED,
  32. WB_WRITTEN,
  33. NR_WB_STAT_ITEMS
  34. };
  35. #define WB_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
  36. /*
  37. * For cgroup writeback, multiple wb's may map to the same blkcg. Those
  38. * wb's can operate mostly independently but should share the congested
  39. * state. To facilitate such sharing, the congested state is tracked using
  40. * the following struct which is created on demand, indexed by blkcg ID on
  41. * its bdi, and refcounted.
  42. */
  43. struct bdi_writeback_congested {
  44. unsigned long state; /* WB_[a]sync_congested flags */
  45. #ifdef CONFIG_CGROUP_WRITEBACK
  46. struct backing_dev_info *bdi; /* the associated bdi */
  47. atomic_t refcnt; /* nr of attached wb's and blkg */
  48. int blkcg_id; /* ID of the associated blkcg */
  49. struct rb_node rb_node; /* on bdi->cgwb_congestion_tree */
  50. #endif
  51. };
  52. /*
  53. * Each wb (bdi_writeback) can perform writeback operations, is measured
  54. * and throttled, independently. Without cgroup writeback, each bdi
  55. * (bdi_writeback) is served by its embedded bdi->wb.
  56. *
  57. * On the default hierarchy, blkcg implicitly enables memcg. This allows
  58. * using memcg's page ownership for attributing writeback IOs, and every
  59. * memcg - blkcg combination can be served by its own wb by assigning a
  60. * dedicated wb to each memcg, which enables isolation across different
  61. * cgroups and propagation of IO back pressure down from the IO layer upto
  62. * the tasks which are generating the dirty pages to be written back.
  63. *
  64. * A cgroup wb is indexed on its bdi by the ID of the associated memcg,
  65. * refcounted with the number of inodes attached to it, and pins the memcg
  66. * and the corresponding blkcg. As the corresponding blkcg for a memcg may
  67. * change as blkcg is disabled and enabled higher up in the hierarchy, a wb
  68. * is tested for blkcg after lookup and removed from index on mismatch so
  69. * that a new wb for the combination can be created.
  70. */
  71. struct bdi_writeback {
  72. struct backing_dev_info *bdi; /* our parent bdi */
  73. unsigned long state; /* Always use atomic bitops on this */
  74. unsigned long last_old_flush; /* last old data flush */
  75. struct list_head b_dirty; /* dirty inodes */
  76. struct list_head b_io; /* parked for writeback */
  77. struct list_head b_more_io; /* parked for more writeback */
  78. struct list_head b_dirty_time; /* time stamps are dirty */
  79. spinlock_t list_lock; /* protects the b_* lists */
  80. struct percpu_counter stat[NR_WB_STAT_ITEMS];
  81. struct bdi_writeback_congested *congested;
  82. unsigned long bw_time_stamp; /* last time write bw is updated */
  83. unsigned long dirtied_stamp;
  84. unsigned long written_stamp; /* pages written at bw_time_stamp */
  85. unsigned long write_bandwidth; /* the estimated write bandwidth */
  86. unsigned long avg_write_bandwidth; /* further smoothed write bw */
  87. /*
  88. * The base dirty throttle rate, re-calculated on every 200ms.
  89. * All the bdi tasks' dirty rate will be curbed under it.
  90. * @dirty_ratelimit tracks the estimated @balanced_dirty_ratelimit
  91. * in small steps and is much more smooth/stable than the latter.
  92. */
  93. unsigned long dirty_ratelimit;
  94. unsigned long balanced_dirty_ratelimit;
  95. struct fprop_local_percpu completions;
  96. int dirty_exceeded;
  97. spinlock_t work_lock; /* protects work_list & dwork scheduling */
  98. struct list_head work_list;
  99. struct delayed_work dwork; /* work item used for writeback */
  100. #ifdef CONFIG_CGROUP_WRITEBACK
  101. struct percpu_ref refcnt; /* used only for !root wb's */
  102. struct cgroup_subsys_state *memcg_css; /* the associated memcg */
  103. struct cgroup_subsys_state *blkcg_css; /* and blkcg */
  104. struct list_head memcg_node; /* anchored at memcg->cgwb_list */
  105. struct list_head blkcg_node; /* anchored at blkcg->cgwb_list */
  106. union {
  107. struct work_struct release_work;
  108. struct rcu_head rcu;
  109. };
  110. #endif
  111. };
  112. struct backing_dev_info {
  113. struct list_head bdi_list;
  114. unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */
  115. unsigned int capabilities; /* Device capabilities */
  116. congested_fn *congested_fn; /* Function pointer if device is md/dm */
  117. void *congested_data; /* Pointer to aux data for congested func */
  118. char *name;
  119. unsigned int min_ratio;
  120. unsigned int max_ratio, max_prop_frac;
  121. struct bdi_writeback wb; /* the root writeback info for this bdi */
  122. struct bdi_writeback_congested wb_congested; /* its congested state */
  123. #ifdef CONFIG_CGROUP_WRITEBACK
  124. struct radix_tree_root cgwb_tree; /* radix tree of active cgroup wbs */
  125. struct rb_root cgwb_congested_tree; /* their congested states */
  126. atomic_t usage_cnt; /* counts both cgwbs and cgwb_contested's */
  127. #endif
  128. struct device *dev;
  129. struct timer_list laptop_mode_wb_timer;
  130. #ifdef CONFIG_DEBUG_FS
  131. struct dentry *debug_dir;
  132. struct dentry *debug_stats;
  133. #endif
  134. };
  135. enum {
  136. BLK_RW_ASYNC = 0,
  137. BLK_RW_SYNC = 1,
  138. };
  139. void clear_wb_congested(struct bdi_writeback_congested *congested, int sync);
  140. void set_wb_congested(struct bdi_writeback_congested *congested, int sync);
  141. static inline void clear_bdi_congested(struct backing_dev_info *bdi, int sync)
  142. {
  143. clear_wb_congested(bdi->wb.congested, sync);
  144. }
  145. static inline void set_bdi_congested(struct backing_dev_info *bdi, int sync)
  146. {
  147. set_wb_congested(bdi->wb.congested, sync);
  148. }
  149. #endif /* __LINUX_BACKING_DEV_DEFS_H */