backing-dev.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * include/linux/backing-dev.h
  3. *
  4. * low-level device information and state which is propagated up through
  5. * to high-level code.
  6. */
  7. #ifndef _LINUX_BACKING_DEV_H
  8. #define _LINUX_BACKING_DEV_H
  9. #include <asm/atomic.h>
  10. struct page;
  11. /*
  12. * Bits in backing_dev_info.state
  13. */
  14. enum bdi_state {
  15. BDI_pdflush, /* A pdflush thread is working this device */
  16. BDI_write_congested, /* The write queue is getting full */
  17. BDI_read_congested, /* The read queue is getting full */
  18. BDI_unused, /* Available bits start here */
  19. };
  20. typedef int (congested_fn)(void *, int);
  21. struct backing_dev_info {
  22. unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */
  23. unsigned long state; /* Always use atomic bitops on this */
  24. unsigned int capabilities; /* Device capabilities */
  25. congested_fn *congested_fn; /* Function pointer if device is md/dm */
  26. void *congested_data; /* Pointer to aux data for congested func */
  27. void (*unplug_io_fn)(struct backing_dev_info *, struct page *);
  28. void *unplug_io_data;
  29. };
  30. /*
  31. * Flags in backing_dev_info::capability
  32. * - The first two flags control whether dirty pages will contribute to the
  33. * VM's accounting and whether writepages() should be called for dirty pages
  34. * (something that would not, for example, be appropriate for ramfs)
  35. * - These flags let !MMU mmap() govern direct device mapping vs immediate
  36. * copying more easily for MAP_PRIVATE, especially for ROM filesystems
  37. */
  38. #define BDI_CAP_NO_ACCT_DIRTY 0x00000001 /* Dirty pages shouldn't contribute to accounting */
  39. #define BDI_CAP_NO_WRITEBACK 0x00000002 /* Don't write pages back */
  40. #define BDI_CAP_MAP_COPY 0x00000004 /* Copy can be mapped (MAP_PRIVATE) */
  41. #define BDI_CAP_MAP_DIRECT 0x00000008 /* Can be mapped directly (MAP_SHARED) */
  42. #define BDI_CAP_READ_MAP 0x00000010 /* Can be mapped for reading */
  43. #define BDI_CAP_WRITE_MAP 0x00000020 /* Can be mapped for writing */
  44. #define BDI_CAP_EXEC_MAP 0x00000040 /* Can be mapped for execution */
  45. #define BDI_CAP_VMFLAGS \
  46. (BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP)
  47. #if defined(VM_MAYREAD) && \
  48. (BDI_CAP_READ_MAP != VM_MAYREAD || \
  49. BDI_CAP_WRITE_MAP != VM_MAYWRITE || \
  50. BDI_CAP_EXEC_MAP != VM_MAYEXEC)
  51. #error please change backing_dev_info::capabilities flags
  52. #endif
  53. extern struct backing_dev_info default_backing_dev_info;
  54. void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page);
  55. int writeback_acquire(struct backing_dev_info *bdi);
  56. int writeback_in_progress(struct backing_dev_info *bdi);
  57. void writeback_release(struct backing_dev_info *bdi);
  58. static inline int bdi_congested(struct backing_dev_info *bdi, int bdi_bits)
  59. {
  60. if (bdi->congested_fn)
  61. return bdi->congested_fn(bdi->congested_data, bdi_bits);
  62. return (bdi->state & bdi_bits);
  63. }
  64. static inline int bdi_read_congested(struct backing_dev_info *bdi)
  65. {
  66. return bdi_congested(bdi, 1 << BDI_read_congested);
  67. }
  68. static inline int bdi_write_congested(struct backing_dev_info *bdi)
  69. {
  70. return bdi_congested(bdi, 1 << BDI_write_congested);
  71. }
  72. static inline int bdi_rw_congested(struct backing_dev_info *bdi)
  73. {
  74. return bdi_congested(bdi, (1 << BDI_read_congested)|
  75. (1 << BDI_write_congested));
  76. }
  77. void clear_bdi_congested(struct backing_dev_info *bdi, int rw);
  78. void set_bdi_congested(struct backing_dev_info *bdi, int rw);
  79. long congestion_wait(int rw, long timeout);
  80. long congestion_wait_interruptible(int rw, long timeout);
  81. void congestion_end(int rw);
  82. #define bdi_cap_writeback_dirty(bdi) \
  83. (!((bdi)->capabilities & BDI_CAP_NO_WRITEBACK))
  84. #define bdi_cap_account_dirty(bdi) \
  85. (!((bdi)->capabilities & BDI_CAP_NO_ACCT_DIRTY))
  86. #define mapping_cap_writeback_dirty(mapping) \
  87. bdi_cap_writeback_dirty((mapping)->backing_dev_info)
  88. #define mapping_cap_account_dirty(mapping) \
  89. bdi_cap_account_dirty((mapping)->backing_dev_info)
  90. #endif /* _LINUX_BACKING_DEV_H */