writeback.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * include/linux/writeback.h
  3. */
  4. #ifndef WRITEBACK_H
  5. #define WRITEBACK_H
  6. #include <linux/sched.h>
  7. #include <linux/fs.h>
  8. /*
  9. * The 1/4 region under the global dirty thresh is for smooth dirty throttling:
  10. *
  11. * (thresh - thresh/DIRTY_FULL_SCOPE, thresh)
  12. *
  13. * Further beyond, all dirtier tasks will enter a loop waiting (possibly long
  14. * time) for the dirty pages to drop, unless written enough pages.
  15. *
  16. * The global dirty threshold is normally equal to the global dirty limit,
  17. * except when the system suddenly allocates a lot of anonymous memory and
  18. * knocks down the global dirty threshold quickly, in which case the global
  19. * dirty limit will follow down slowly to prevent livelocking all dirtier tasks.
  20. */
  21. #define DIRTY_SCOPE 8
  22. #define DIRTY_FULL_SCOPE (DIRTY_SCOPE / 2)
  23. /*
  24. * 4MB minimal write chunk size
  25. */
  26. #define MIN_WRITEBACK_PAGES (4096UL >> (PAGE_CACHE_SHIFT - 10))
  27. struct backing_dev_info;
  28. /*
  29. * fs/fs-writeback.c
  30. */
  31. enum writeback_sync_modes {
  32. WB_SYNC_NONE, /* Don't wait on anything */
  33. WB_SYNC_ALL, /* Wait on every mapping */
  34. };
  35. /*
  36. * why some writeback work was initiated
  37. */
  38. enum wb_reason {
  39. WB_REASON_BACKGROUND,
  40. WB_REASON_TRY_TO_FREE_PAGES,
  41. WB_REASON_SYNC,
  42. WB_REASON_PERIODIC,
  43. WB_REASON_LAPTOP_TIMER,
  44. WB_REASON_FREE_MORE_MEM,
  45. WB_REASON_FS_FREE_SPACE,
  46. WB_REASON_FORKER_THREAD,
  47. WB_REASON_MAX,
  48. };
  49. extern const char *wb_reason_name[];
  50. /*
  51. * A control structure which tells the writeback code what to do. These are
  52. * always on the stack, and hence need no locking. They are always initialised
  53. * in a manner such that unspecified fields are set to zero.
  54. */
  55. struct writeback_control {
  56. enum writeback_sync_modes sync_mode;
  57. long nr_to_write; /* Write this many pages, and decrement
  58. this for each page written */
  59. long pages_skipped; /* Pages which were not written */
  60. /*
  61. * For a_ops->writepages(): is start or end are non-zero then this is
  62. * a hint that the filesystem need only write out the pages inside that
  63. * byterange. The byte at `end' is included in the writeout request.
  64. */
  65. loff_t range_start;
  66. loff_t range_end;
  67. unsigned for_kupdate:1; /* A kupdate writeback */
  68. unsigned for_background:1; /* A background writeback */
  69. unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
  70. unsigned for_reclaim:1; /* Invoked from the page allocator */
  71. unsigned range_cyclic:1; /* range_start is cyclic */
  72. };
  73. /*
  74. * fs/fs-writeback.c
  75. */
  76. struct bdi_writeback;
  77. int inode_wait(void *);
  78. void writeback_inodes_sb(struct super_block *, enum wb_reason reason);
  79. void writeback_inodes_sb_nr(struct super_block *, unsigned long nr,
  80. enum wb_reason reason);
  81. int writeback_inodes_sb_if_idle(struct super_block *, enum wb_reason reason);
  82. int writeback_inodes_sb_nr_if_idle(struct super_block *, unsigned long nr,
  83. enum wb_reason reason);
  84. void sync_inodes_sb(struct super_block *);
  85. long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages,
  86. enum wb_reason reason);
  87. long wb_do_writeback(struct bdi_writeback *wb, int force_wait);
  88. void wakeup_flusher_threads(long nr_pages, enum wb_reason reason);
  89. /* writeback.h requires fs.h; it, too, is not included from here. */
  90. static inline void wait_on_inode(struct inode *inode)
  91. {
  92. might_sleep();
  93. wait_on_bit(&inode->i_state, __I_NEW, inode_wait, TASK_UNINTERRUPTIBLE);
  94. }
  95. static inline void inode_sync_wait(struct inode *inode)
  96. {
  97. might_sleep();
  98. wait_on_bit(&inode->i_state, __I_SYNC, inode_wait,
  99. TASK_UNINTERRUPTIBLE);
  100. }
  101. /*
  102. * mm/page-writeback.c
  103. */
  104. #ifdef CONFIG_BLOCK
  105. void laptop_io_completion(struct backing_dev_info *info);
  106. void laptop_sync_completion(void);
  107. void laptop_mode_sync(struct work_struct *work);
  108. void laptop_mode_timer_fn(unsigned long data);
  109. #else
  110. static inline void laptop_sync_completion(void) { }
  111. #endif
  112. void throttle_vm_writeout(gfp_t gfp_mask);
  113. extern unsigned long global_dirty_limit;
  114. /* These are exported to sysctl. */
  115. extern int dirty_background_ratio;
  116. extern unsigned long dirty_background_bytes;
  117. extern int vm_dirty_ratio;
  118. extern unsigned long vm_dirty_bytes;
  119. extern unsigned int dirty_writeback_interval;
  120. extern unsigned int dirty_expire_interval;
  121. extern int vm_highmem_is_dirtyable;
  122. extern int block_dump;
  123. extern int laptop_mode;
  124. extern int dirty_background_ratio_handler(struct ctl_table *table, int write,
  125. void __user *buffer, size_t *lenp,
  126. loff_t *ppos);
  127. extern int dirty_background_bytes_handler(struct ctl_table *table, int write,
  128. void __user *buffer, size_t *lenp,
  129. loff_t *ppos);
  130. extern int dirty_ratio_handler(struct ctl_table *table, int write,
  131. void __user *buffer, size_t *lenp,
  132. loff_t *ppos);
  133. extern int dirty_bytes_handler(struct ctl_table *table, int write,
  134. void __user *buffer, size_t *lenp,
  135. loff_t *ppos);
  136. struct ctl_table;
  137. int dirty_writeback_centisecs_handler(struct ctl_table *, int,
  138. void __user *, size_t *, loff_t *);
  139. void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
  140. unsigned long bdi_dirty_limit(struct backing_dev_info *bdi,
  141. unsigned long dirty);
  142. void __bdi_update_bandwidth(struct backing_dev_info *bdi,
  143. unsigned long thresh,
  144. unsigned long bg_thresh,
  145. unsigned long dirty,
  146. unsigned long bdi_thresh,
  147. unsigned long bdi_dirty,
  148. unsigned long start_time);
  149. void page_writeback_init(void);
  150. void balance_dirty_pages_ratelimited_nr(struct address_space *mapping,
  151. unsigned long nr_pages_dirtied);
  152. static inline void
  153. balance_dirty_pages_ratelimited(struct address_space *mapping)
  154. {
  155. balance_dirty_pages_ratelimited_nr(mapping, 1);
  156. }
  157. typedef int (*writepage_t)(struct page *page, struct writeback_control *wbc,
  158. void *data);
  159. int generic_writepages(struct address_space *mapping,
  160. struct writeback_control *wbc);
  161. void tag_pages_for_writeback(struct address_space *mapping,
  162. pgoff_t start, pgoff_t end);
  163. int write_cache_pages(struct address_space *mapping,
  164. struct writeback_control *wbc, writepage_t writepage,
  165. void *data);
  166. int do_writepages(struct address_space *mapping, struct writeback_control *wbc);
  167. void set_page_dirty_balance(struct page *page, int page_mkwrite);
  168. void writeback_set_ratelimit(void);
  169. void tag_pages_for_writeback(struct address_space *mapping,
  170. pgoff_t start, pgoff_t end);
  171. /* pdflush.c */
  172. extern int nr_pdflush_threads; /* Global so it can be exported to sysctl
  173. read-only. */
  174. #endif /* WRITEBACK_H */