2 * include/linux/writeback.h
7 #include <linux/sched.h>
8 #include <linux/workqueue.h>
10 #include <linux/flex_proportions.h>
12 DECLARE_PER_CPU(int, dirty_throttle_leaks);
15 * The 1/4 region under the global dirty thresh is for smooth dirty throttling:
17 * (thresh - thresh/DIRTY_FULL_SCOPE, thresh)
19 * Further beyond, all dirtier tasks will enter a loop waiting (possibly long
20 * time) for the dirty pages to drop, unless written enough pages.
22 * The global dirty threshold is normally equal to the global dirty limit,
23 * except when the system suddenly allocates a lot of anonymous memory and
24 * knocks down the global dirty threshold quickly, in which case the global
25 * dirty limit will follow down slowly to prevent livelocking all dirtier tasks.
28 #define DIRTY_FULL_SCOPE (DIRTY_SCOPE / 2)
30 struct backing_dev_info;
35 enum writeback_sync_modes {
36 WB_SYNC_NONE, /* Don't wait on anything */
37 WB_SYNC_ALL, /* Wait on every mapping */
41 * why some writeback work was initiated
45 WB_REASON_TRY_TO_FREE_PAGES,
48 WB_REASON_LAPTOP_TIMER,
49 WB_REASON_FREE_MORE_MEM,
50 WB_REASON_FS_FREE_SPACE,
52 * There is no bdi forker thread any more and works are done
53 * by emergency worker, however, this is TPs userland visible
54 * and we'll be exposing exactly the same information,
55 * so it has a mismatch name.
57 WB_REASON_FORKER_THREAD,
63 * A control structure which tells the writeback code what to do. These are
64 * always on the stack, and hence need no locking. They are always initialised
65 * in a manner such that unspecified fields are set to zero.
67 struct writeback_control {
68 long nr_to_write; /* Write this many pages, and decrement
69 this for each page written */
70 long pages_skipped; /* Pages which were not written */
73 * For a_ops->writepages(): if start or end are non-zero then this is
74 * a hint that the filesystem need only write out the pages inside that
75 * byterange. The byte at `end' is included in the writeout request.
80 enum writeback_sync_modes sync_mode;
82 unsigned for_kupdate:1; /* A kupdate writeback */
83 unsigned for_background:1; /* A background writeback */
84 unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
85 unsigned for_reclaim:1; /* Invoked from the page allocator */
86 unsigned range_cyclic:1; /* range_start is cyclic */
87 unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
91 * A wb_domain represents a domain that wb's (bdi_writeback's) belong to
92 * and are measured against each other in. There always is one global
93 * domain, global_wb_domain, that every wb in the system is a member of.
94 * This allows measuring the relative bandwidth of each wb to distribute
95 * dirtyable memory accordingly.
99 * Scale the writeback cache size proportional to the relative
102 * We do this by keeping a floating proportion between BDIs, based
103 * on page writeback completions [end_page_writeback()]. Those
104 * devices that write out pages fastest will get the larger share,
105 * while the slower will get a smaller share.
107 * We use page writeout completions because we are interested in
108 * getting rid of dirty pages. Having them written out is the
111 * We introduce a concept of time, a period over which we measure
112 * these events, because demand can/will vary over time. The length
113 * of this period itself is measured in page writeback completions.
115 struct fprop_global completions;
116 struct timer_list period_timer; /* timer for aging of completions */
117 unsigned long period_time;
123 struct bdi_writeback;
124 void writeback_inodes_sb(struct super_block *, enum wb_reason reason);
125 void writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
126 enum wb_reason reason);
127 bool try_to_writeback_inodes_sb(struct super_block *, enum wb_reason reason);
128 bool try_to_writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
129 enum wb_reason reason);
130 void sync_inodes_sb(struct super_block *);
131 void wakeup_flusher_threads(long nr_pages, enum wb_reason reason);
132 void inode_wait_for_writeback(struct inode *inode);
134 /* writeback.h requires fs.h; it, too, is not included from here. */
135 static inline void wait_on_inode(struct inode *inode)
138 wait_on_bit(&inode->i_state, __I_NEW, TASK_UNINTERRUPTIBLE);
142 * mm/page-writeback.c
145 void laptop_io_completion(struct backing_dev_info *info);
146 void laptop_sync_completion(void);
147 void laptop_mode_sync(struct work_struct *work);
148 void laptop_mode_timer_fn(unsigned long data);
150 static inline void laptop_sync_completion(void) { }
152 void throttle_vm_writeout(gfp_t gfp_mask);
153 bool zone_dirty_ok(struct zone *zone);
154 int wb_domain_init(struct wb_domain *dom, gfp_t gfp);
156 extern unsigned long global_dirty_limit;
158 /* These are exported to sysctl. */
159 extern int dirty_background_ratio;
160 extern unsigned long dirty_background_bytes;
161 extern int vm_dirty_ratio;
162 extern unsigned long vm_dirty_bytes;
163 extern unsigned int dirty_writeback_interval;
164 extern unsigned int dirty_expire_interval;
165 extern unsigned int dirtytime_expire_interval;
166 extern int vm_highmem_is_dirtyable;
167 extern int block_dump;
168 extern int laptop_mode;
170 extern int dirty_background_ratio_handler(struct ctl_table *table, int write,
171 void __user *buffer, size_t *lenp,
173 extern int dirty_background_bytes_handler(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp,
176 extern int dirty_ratio_handler(struct ctl_table *table, int write,
177 void __user *buffer, size_t *lenp,
179 extern int dirty_bytes_handler(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp,
182 int dirtytime_interval_handler(struct ctl_table *table, int write,
183 void __user *buffer, size_t *lenp, loff_t *ppos);
186 int dirty_writeback_centisecs_handler(struct ctl_table *, int,
187 void __user *, size_t *, loff_t *);
189 void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
190 unsigned long wb_calc_thresh(struct bdi_writeback *wb, unsigned long thresh);
192 void wb_update_bandwidth(struct bdi_writeback *wb, unsigned long start_time);
193 void page_writeback_init(void);
194 void balance_dirty_pages_ratelimited(struct address_space *mapping);
196 typedef int (*writepage_t)(struct page *page, struct writeback_control *wbc,
199 int generic_writepages(struct address_space *mapping,
200 struct writeback_control *wbc);
201 void tag_pages_for_writeback(struct address_space *mapping,
202 pgoff_t start, pgoff_t end);
203 int write_cache_pages(struct address_space *mapping,
204 struct writeback_control *wbc, writepage_t writepage,
206 int do_writepages(struct address_space *mapping, struct writeback_control *wbc);
207 void writeback_set_ratelimit(void);
208 void tag_pages_for_writeback(struct address_space *mapping,
209 pgoff_t start, pgoff_t end);
211 void account_page_redirty(struct page *page);
213 #endif /* WRITEBACK_H */