0001
0002 #ifndef __LINUX_BACKING_DEV_DEFS_H
0003 #define __LINUX_BACKING_DEV_DEFS_H
0004
0005 #include <linux/list.h>
0006 #include <linux/radix-tree.h>
0007 #include <linux/rbtree.h>
0008 #include <linux/spinlock.h>
0009 #include <linux/percpu_counter.h>
0010 #include <linux/percpu-refcount.h>
0011 #include <linux/flex_proportions.h>
0012 #include <linux/timer.h>
0013 #include <linux/workqueue.h>
0014 #include <linux/kref.h>
0015 #include <linux/refcount.h>
0016
0017 struct page;
0018 struct device;
0019 struct dentry;
0020
0021
0022
0023
0024 enum wb_state {
0025 WB_registered,
0026 WB_writeback_running,
0027 WB_has_dirty_io,
0028 WB_start_all,
0029 };
0030
0031 enum wb_stat_item {
0032 WB_RECLAIMABLE,
0033 WB_WRITEBACK,
0034 WB_DIRTIED,
0035 WB_WRITTEN,
0036 NR_WB_STAT_ITEMS
0037 };
0038
0039 #define WB_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
0040
0041
0042
0043
0044 enum wb_reason {
0045 WB_REASON_BACKGROUND,
0046 WB_REASON_VMSCAN,
0047 WB_REASON_SYNC,
0048 WB_REASON_PERIODIC,
0049 WB_REASON_LAPTOP_TIMER,
0050 WB_REASON_FS_FREE_SPACE,
0051
0052
0053
0054
0055
0056
0057 WB_REASON_FORKER_THREAD,
0058 WB_REASON_FOREIGN_FLUSH,
0059
0060 WB_REASON_MAX,
0061 };
0062
0063 struct wb_completion {
0064 atomic_t cnt;
0065 wait_queue_head_t *waitq;
0066 };
0067
0068 #define __WB_COMPLETION_INIT(_waitq) \
0069 (struct wb_completion){ .cnt = ATOMIC_INIT(1), .waitq = (_waitq) }
0070
0071
0072
0073
0074
0075
0076
0077
0078 #define WB_COMPLETION_INIT(bdi) __WB_COMPLETION_INIT(&(bdi)->wb_waitq)
0079
0080 #define DEFINE_WB_COMPLETION(cmpl, bdi) \
0081 struct wb_completion cmpl = WB_COMPLETION_INIT(bdi)
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 struct bdi_writeback {
0106 struct backing_dev_info *bdi;
0107
0108 unsigned long state;
0109 unsigned long last_old_flush;
0110
0111 struct list_head b_dirty;
0112 struct list_head b_io;
0113 struct list_head b_more_io;
0114 struct list_head b_dirty_time;
0115 spinlock_t list_lock;
0116
0117 atomic_t writeback_inodes;
0118 struct percpu_counter stat[NR_WB_STAT_ITEMS];
0119
0120 unsigned long bw_time_stamp;
0121 unsigned long dirtied_stamp;
0122 unsigned long written_stamp;
0123 unsigned long write_bandwidth;
0124 unsigned long avg_write_bandwidth;
0125
0126
0127
0128
0129
0130
0131
0132 unsigned long dirty_ratelimit;
0133 unsigned long balanced_dirty_ratelimit;
0134
0135 struct fprop_local_percpu completions;
0136 int dirty_exceeded;
0137 enum wb_reason start_all_reason;
0138
0139 spinlock_t work_lock;
0140 struct list_head work_list;
0141 struct delayed_work dwork;
0142 struct delayed_work bw_dwork;
0143
0144 unsigned long dirty_sleep;
0145
0146 struct list_head bdi_node;
0147
0148 #ifdef CONFIG_CGROUP_WRITEBACK
0149 struct percpu_ref refcnt;
0150 struct fprop_local_percpu memcg_completions;
0151 struct cgroup_subsys_state *memcg_css;
0152 struct cgroup_subsys_state *blkcg_css;
0153 struct list_head memcg_node;
0154 struct list_head blkcg_node;
0155 struct list_head b_attached;
0156 struct list_head offline_node;
0157
0158 union {
0159 struct work_struct release_work;
0160 struct rcu_head rcu;
0161 };
0162 #endif
0163 };
0164
0165 struct backing_dev_info {
0166 u64 id;
0167 struct rb_node rb_node;
0168 struct list_head bdi_list;
0169 unsigned long ra_pages;
0170 unsigned long io_pages;
0171
0172 struct kref refcnt;
0173 unsigned int capabilities;
0174 unsigned int min_ratio;
0175 unsigned int max_ratio, max_prop_frac;
0176
0177
0178
0179
0180
0181 atomic_long_t tot_write_bandwidth;
0182
0183 struct bdi_writeback wb;
0184 struct list_head wb_list;
0185 #ifdef CONFIG_CGROUP_WRITEBACK
0186 struct radix_tree_root cgwb_tree;
0187 struct mutex cgwb_release_mutex;
0188 struct rw_semaphore wb_switch_rwsem;
0189 #endif
0190 wait_queue_head_t wb_waitq;
0191
0192 struct device *dev;
0193 char dev_name[64];
0194 struct device *owner;
0195
0196 struct timer_list laptop_mode_wb_timer;
0197
0198 #ifdef CONFIG_DEBUG_FS
0199 struct dentry *debug_dir;
0200 #endif
0201 };
0202
0203 struct wb_lock_cookie {
0204 bool locked;
0205 unsigned long flags;
0206 };
0207
0208 #ifdef CONFIG_CGROUP_WRITEBACK
0209
0210
0211
0212
0213
0214 static inline bool wb_tryget(struct bdi_writeback *wb)
0215 {
0216 if (wb != &wb->bdi->wb)
0217 return percpu_ref_tryget(&wb->refcnt);
0218 return true;
0219 }
0220
0221
0222
0223
0224
0225 static inline void wb_get(struct bdi_writeback *wb)
0226 {
0227 if (wb != &wb->bdi->wb)
0228 percpu_ref_get(&wb->refcnt);
0229 }
0230
0231
0232
0233
0234
0235
0236 static inline void wb_put_many(struct bdi_writeback *wb, unsigned long nr)
0237 {
0238 if (WARN_ON_ONCE(!wb->bdi)) {
0239
0240
0241
0242
0243 return;
0244 }
0245
0246 if (wb != &wb->bdi->wb)
0247 percpu_ref_put_many(&wb->refcnt, nr);
0248 }
0249
0250
0251
0252
0253
0254 static inline void wb_put(struct bdi_writeback *wb)
0255 {
0256 wb_put_many(wb, 1);
0257 }
0258
0259
0260
0261
0262
0263
0264
0265 static inline bool wb_dying(struct bdi_writeback *wb)
0266 {
0267 return percpu_ref_is_dying(&wb->refcnt);
0268 }
0269
0270 #else
0271
0272 static inline bool wb_tryget(struct bdi_writeback *wb)
0273 {
0274 return true;
0275 }
0276
0277 static inline void wb_get(struct bdi_writeback *wb)
0278 {
0279 }
0280
0281 static inline void wb_put(struct bdi_writeback *wb)
0282 {
0283 }
0284
0285 static inline void wb_put_many(struct bdi_writeback *wb, unsigned long nr)
0286 {
0287 }
0288
0289 static inline bool wb_dying(struct bdi_writeback *wb)
0290 {
0291 return false;
0292 }
0293
0294 #endif
0295
0296 #endif