writeback.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * A control structure which tells the writeback code what to do. These are
  37. * always on the stack, and hence need no locking. They are always initialised
  38. * in a manner such that unspecified fields are set to zero.
  39. */
  40. struct writeback_control {
  41. enum writeback_sync_modes sync_mode;
  42. long nr_to_write; /* Write this many pages, and decrement
  43. this for each page written */
  44. long pages_skipped; /* Pages which were not written */
  45. /*
  46. * For a_ops->writepages(): is start or end are non-zero then this is
  47. * a hint that the filesystem need only write out the pages inside that
  48. * byterange. The byte at `end' is included in the writeout request.
  49. */
  50. loff_t range_start;
  51. loff_t range_end;
  52. unsigned for_kupdate:1; /* A kupdate writeback */
  53. unsigned for_background:1; /* A background writeback */
  54. unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
  55. unsigned for_reclaim:1; /* Invoked from the page allocator */
  56. unsigned range_cyclic:1; /* range_start is cyclic */
  57. };
  58. /*
  59. * fs/fs-writeback.c
  60. */
  61. struct bdi_writeback;
  62. int inode_wait(void *);
  63. void writeback_inodes_sb(struct super_block *);
  64. void writeback_inodes_sb_nr(struct super_block *, unsigned long nr);
  65. int writeback_inodes_sb_if_idle(struct super_block *);
  66. int writeback_inodes_sb_nr_if_idle(struct super_block *, unsigned long nr);
  67. void sync_inodes_sb(struct super_block *);
  68. long writeback_inodes_wb(struct bdi_writeback *wb, long nr_pages);
  69. long wb_do_writeback(struct bdi_writeback *wb, int force_wait);
  70. void wakeup_flusher_threads(long nr_pages);
  71. /* writeback.h requires fs.h; it, too, is not included from here. */
  72. static inline void wait_on_inode(struct inode *inode)
  73. {
  74. might_sleep();
  75. wait_on_bit(&inode->i_state, __I_NEW, inode_wait, TASK_UNINTERRUPTIBLE);
  76. }
  77. static inline void inode_sync_wait(struct inode *inode)
  78. {
  79. might_sleep();
  80. wait_on_bit(&inode->i_state, __I_SYNC, inode_wait,
  81. TASK_UNINTERRUPTIBLE);
  82. }
  83. /*
  84. * mm/page-writeback.c
  85. */
  86. #ifdef CONFIG_BLOCK
  87. void laptop_io_completion(struct backing_dev_info *info);
  88. void laptop_sync_completion(void);
  89. void laptop_mode_sync(struct work_struct *work);
  90. void laptop_mode_timer_fn(unsigned long data);
  91. #else
  92. static inline void laptop_sync_completion(void) { }
  93. #endif
  94. void throttle_vm_writeout(gfp_t gfp_mask);
  95. extern unsigned long global_dirty_limit;
  96. /* These are exported to sysctl. */
  97. extern int dirty_background_ratio;
  98. extern unsigned long dirty_background_bytes;
  99. extern int vm_dirty_ratio;
  100. extern unsigned long vm_dirty_bytes;
  101. extern unsigned int dirty_writeback_interval;
  102. extern unsigned int dirty_expire_interval;
  103. extern int vm_highmem_is_dirtyable;
  104. extern int block_dump;
  105. extern int laptop_mode;
  106. extern unsigned long determine_dirtyable_memory(void);
  107. extern int dirty_background_ratio_handler(struct ctl_table *table, int write,
  108. void __user *buffer, size_t *lenp,
  109. loff_t *ppos);
  110. extern int dirty_background_bytes_handler(struct ctl_table *table, int write,
  111. void __user *buffer, size_t *lenp,
  112. loff_t *ppos);
  113. extern int dirty_ratio_handler(struct ctl_table *table, int write,
  114. void __user *buffer, size_t *lenp,
  115. loff_t *ppos);
  116. extern int dirty_bytes_handler(struct ctl_table *table, int write,
  117. void __user *buffer, size_t *lenp,
  118. loff_t *ppos);
  119. struct ctl_table;
  120. int dirty_writeback_centisecs_handler(struct ctl_table *, int,
  121. void __user *, size_t *, loff_t *);
  122. void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty);
  123. unsigned long bdi_dirty_limit(struct backing_dev_info *bdi,
  124. unsigned long dirty);
  125. void __bdi_update_bandwidth(struct backing_dev_info *bdi,
  126. unsigned long thresh,
  127. unsigned long bg_thresh,
  128. unsigned long dirty,
  129. unsigned long bdi_thresh,
  130. unsigned long bdi_dirty,
  131. unsigned long start_time);
  132. void page_writeback_init(void);
  133. void balance_dirty_pages_ratelimited_nr(struct address_space *mapping,
  134. unsigned long nr_pages_dirtied);
  135. static inline void
  136. balance_dirty_pages_ratelimited(struct address_space *mapping)
  137. {
  138. balance_dirty_pages_ratelimited_nr(mapping, 1);
  139. }
  140. typedef int (*writepage_t)(struct page *page, struct writeback_control *wbc,
  141. void *data);
  142. int generic_writepages(struct address_space *mapping,
  143. struct writeback_control *wbc);
  144. void tag_pages_for_writeback(struct address_space *mapping,
  145. pgoff_t start, pgoff_t end);
  146. int write_cache_pages(struct address_space *mapping,
  147. struct writeback_control *wbc, writepage_t writepage,
  148. void *data);
  149. int do_writepages(struct address_space *mapping, struct writeback_control *wbc);
  150. void set_page_dirty_balance(struct page *page, int page_mkwrite);
  151. void writeback_set_ratelimit(void);
  152. void tag_pages_for_writeback(struct address_space *mapping,
  153. pgoff_t start, pgoff_t end);
  154. /* pdflush.c */
  155. extern int nr_pdflush_threads; /* Global so it can be exported to sysctl
  156. read-only. */
  157. #endif /* WRITEBACK_H */