iocontext.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef IOCONTEXT_H
  2. #define IOCONTEXT_H
  3. #include <linux/radix-tree.h>
  4. #include <linux/rcupdate.h>
  5. /*
  6. * This is the per-process anticipatory I/O scheduler state.
  7. */
  8. struct as_io_context {
  9. spinlock_t lock;
  10. void (*dtor)(struct as_io_context *aic); /* destructor */
  11. void (*exit)(struct as_io_context *aic); /* called on task exit */
  12. unsigned long state;
  13. atomic_t nr_queued; /* queued reads & sync writes */
  14. atomic_t nr_dispatched; /* number of requests gone to the drivers */
  15. /* IO History tracking */
  16. /* Thinktime */
  17. unsigned long last_end_request;
  18. unsigned long ttime_total;
  19. unsigned long ttime_samples;
  20. unsigned long ttime_mean;
  21. /* Layout pattern */
  22. unsigned int seek_samples;
  23. sector_t last_request_pos;
  24. u64 seek_total;
  25. sector_t seek_mean;
  26. };
  27. struct cfq_queue;
  28. struct cfq_io_context {
  29. void *key;
  30. unsigned long dead_key;
  31. struct cfq_queue *cfqq[2];
  32. struct io_context *ioc;
  33. unsigned long last_end_request;
  34. unsigned long ttime_total;
  35. unsigned long ttime_samples;
  36. unsigned long ttime_mean;
  37. struct list_head queue_list;
  38. struct hlist_node cic_list;
  39. void (*dtor)(struct io_context *); /* destructor */
  40. void (*exit)(struct io_context *); /* called on task exit */
  41. struct rcu_head rcu_head;
  42. };
  43. /*
  44. * I/O subsystem state of the associated processes. It is refcounted
  45. * and kmalloc'ed. These could be shared between processes.
  46. */
  47. struct io_context {
  48. atomic_long_t refcount;
  49. atomic_t nr_tasks;
  50. /* all the fields below are protected by this lock */
  51. spinlock_t lock;
  52. unsigned short ioprio;
  53. unsigned short ioprio_changed;
  54. #ifdef CONFIG_BLK_CGROUP
  55. unsigned short cgroup_changed;
  56. #endif
  57. /*
  58. * For request batching
  59. */
  60. unsigned long last_waited; /* Time last woken after wait for request */
  61. int nr_batch_requests; /* Number of requests left in the batch */
  62. struct as_io_context *aic;
  63. struct radix_tree_root radix_root;
  64. struct hlist_head cic_list;
  65. void *ioc_data;
  66. };
  67. static inline struct io_context *ioc_task_link(struct io_context *ioc)
  68. {
  69. /*
  70. * if ref count is zero, don't allow sharing (ioc is going away, it's
  71. * a race).
  72. */
  73. if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
  74. atomic_inc(&ioc->nr_tasks);
  75. return ioc;
  76. }
  77. return NULL;
  78. }
  79. struct task_struct;
  80. #ifdef CONFIG_BLOCK
  81. int put_io_context(struct io_context *ioc);
  82. void exit_io_context(struct task_struct *task);
  83. struct io_context *get_io_context(gfp_t gfp_flags, int node);
  84. struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
  85. void copy_io_context(struct io_context **pdst, struct io_context **psrc);
  86. #else
  87. static inline void exit_io_context(struct task_struct *task)
  88. {
  89. }
  90. struct io_context;
  91. static inline int put_io_context(struct io_context *ioc)
  92. {
  93. return 1;
  94. }
  95. #endif
  96. #endif