Tejun Heo | 66114ca | 2015-05-22 17:13:32 -0400 | [diff] [blame] | 1 | #ifndef __LINUX_BACKING_DEV_DEFS_H |
| 2 | #define __LINUX_BACKING_DEV_DEFS_H |
| 3 | |
| 4 | #include <linux/list.h> |
| 5 | #include <linux/spinlock.h> |
| 6 | #include <linux/percpu_counter.h> |
| 7 | #include <linux/flex_proportions.h> |
| 8 | #include <linux/timer.h> |
| 9 | #include <linux/workqueue.h> |
| 10 | |
| 11 | struct page; |
| 12 | struct device; |
| 13 | struct dentry; |
| 14 | |
| 15 | /* |
| 16 | * Bits in bdi_writeback.state |
| 17 | */ |
| 18 | enum wb_state { |
Tejun Heo | 66114ca | 2015-05-22 17:13:32 -0400 | [diff] [blame] | 19 | WB_registered, /* bdi_register() was done */ |
| 20 | WB_writeback_running, /* Writeback is in progress */ |
| 21 | }; |
| 22 | |
Tejun Heo | 4aa9c69 | 2015-05-22 17:13:35 -0400 | [diff] [blame^] | 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 | |
Tejun Heo | 66114ca | 2015-05-22 17:13:32 -0400 | [diff] [blame] | 28 | typedef int (congested_fn)(void *, int); |
| 29 | |
| 30 | enum wb_stat_item { |
| 31 | WB_RECLAIMABLE, |
| 32 | WB_WRITEBACK, |
| 33 | WB_DIRTIED, |
| 34 | WB_WRITTEN, |
| 35 | NR_WB_STAT_ITEMS |
| 36 | }; |
| 37 | |
| 38 | #define WB_STAT_BATCH (8*(1+ilog2(nr_cpu_ids))) |
| 39 | |
Tejun Heo | 4aa9c69 | 2015-05-22 17:13:35 -0400 | [diff] [blame^] | 40 | struct bdi_writeback_congested { |
| 41 | unsigned long state; /* WB_[a]sync_congested flags */ |
| 42 | }; |
| 43 | |
Tejun Heo | 66114ca | 2015-05-22 17:13:32 -0400 | [diff] [blame] | 44 | struct bdi_writeback { |
| 45 | struct backing_dev_info *bdi; /* our parent bdi */ |
| 46 | |
| 47 | unsigned long state; /* Always use atomic bitops on this */ |
| 48 | unsigned long last_old_flush; /* last old data flush */ |
| 49 | |
| 50 | struct list_head b_dirty; /* dirty inodes */ |
| 51 | struct list_head b_io; /* parked for writeback */ |
| 52 | struct list_head b_more_io; /* parked for more writeback */ |
| 53 | struct list_head b_dirty_time; /* time stamps are dirty */ |
| 54 | spinlock_t list_lock; /* protects the b_* lists */ |
| 55 | |
| 56 | struct percpu_counter stat[NR_WB_STAT_ITEMS]; |
| 57 | |
Tejun Heo | 4aa9c69 | 2015-05-22 17:13:35 -0400 | [diff] [blame^] | 58 | struct bdi_writeback_congested *congested; |
| 59 | |
Tejun Heo | 66114ca | 2015-05-22 17:13:32 -0400 | [diff] [blame] | 60 | unsigned long bw_time_stamp; /* last time write bw is updated */ |
| 61 | unsigned long dirtied_stamp; |
| 62 | unsigned long written_stamp; /* pages written at bw_time_stamp */ |
| 63 | unsigned long write_bandwidth; /* the estimated write bandwidth */ |
| 64 | unsigned long avg_write_bandwidth; /* further smoothed write bw */ |
| 65 | |
| 66 | /* |
| 67 | * The base dirty throttle rate, re-calculated on every 200ms. |
| 68 | * All the bdi tasks' dirty rate will be curbed under it. |
| 69 | * @dirty_ratelimit tracks the estimated @balanced_dirty_ratelimit |
| 70 | * in small steps and is much more smooth/stable than the latter. |
| 71 | */ |
| 72 | unsigned long dirty_ratelimit; |
| 73 | unsigned long balanced_dirty_ratelimit; |
| 74 | |
| 75 | struct fprop_local_percpu completions; |
| 76 | int dirty_exceeded; |
| 77 | |
| 78 | spinlock_t work_lock; /* protects work_list & dwork scheduling */ |
| 79 | struct list_head work_list; |
| 80 | struct delayed_work dwork; /* work item used for writeback */ |
| 81 | }; |
| 82 | |
| 83 | struct backing_dev_info { |
| 84 | struct list_head bdi_list; |
| 85 | unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ |
| 86 | unsigned int capabilities; /* Device capabilities */ |
| 87 | congested_fn *congested_fn; /* Function pointer if device is md/dm */ |
| 88 | void *congested_data; /* Pointer to aux data for congested func */ |
| 89 | |
| 90 | char *name; |
| 91 | |
| 92 | unsigned int min_ratio; |
| 93 | unsigned int max_ratio, max_prop_frac; |
| 94 | |
| 95 | struct bdi_writeback wb; /* default writeback info for this bdi */ |
Tejun Heo | 4aa9c69 | 2015-05-22 17:13:35 -0400 | [diff] [blame^] | 96 | struct bdi_writeback_congested wb_congested; |
Tejun Heo | 66114ca | 2015-05-22 17:13:32 -0400 | [diff] [blame] | 97 | |
| 98 | struct device *dev; |
| 99 | |
| 100 | struct timer_list laptop_mode_wb_timer; |
| 101 | |
| 102 | #ifdef CONFIG_DEBUG_FS |
| 103 | struct dentry *debug_dir; |
| 104 | struct dentry *debug_stats; |
| 105 | #endif |
| 106 | }; |
| 107 | |
| 108 | enum { |
| 109 | BLK_RW_ASYNC = 0, |
| 110 | BLK_RW_SYNC = 1, |
| 111 | }; |
| 112 | |
| 113 | void clear_bdi_congested(struct backing_dev_info *bdi, int sync); |
| 114 | void set_bdi_congested(struct backing_dev_info *bdi, int sync); |
| 115 | |
| 116 | #endif /* __LINUX_BACKING_DEV_DEFS_H */ |