iocontext.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef IOCONTEXT_H
  2. #define IOCONTEXT_H
  3. #include <linux/radix-tree.h>
  4. #include <linux/rcupdate.h>
  5. struct cfq_queue;
  6. struct cfq_ttime {
  7. unsigned long last_end_request;
  8. unsigned long ttime_total;
  9. unsigned long ttime_samples;
  10. unsigned long ttime_mean;
  11. };
  12. struct cfq_io_context {
  13. void *key;
  14. struct request_queue *q;
  15. struct cfq_queue *cfqq[2];
  16. struct io_context *ioc;
  17. struct cfq_ttime ttime;
  18. struct list_head queue_list;
  19. struct hlist_node cic_list;
  20. void (*dtor)(struct io_context *); /* destructor */
  21. void (*exit)(struct io_context *); /* called on task exit */
  22. struct rcu_head rcu_head;
  23. };
  24. /*
  25. * I/O subsystem state of the associated processes. It is refcounted
  26. * and kmalloc'ed. These could be shared between processes.
  27. */
  28. struct io_context {
  29. atomic_long_t refcount;
  30. atomic_t nr_tasks;
  31. /* all the fields below are protected by this lock */
  32. spinlock_t lock;
  33. unsigned short ioprio;
  34. unsigned short ioprio_changed;
  35. #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
  36. unsigned short cgroup_changed;
  37. #endif
  38. /*
  39. * For request batching
  40. */
  41. int nr_batch_requests; /* Number of requests left in the batch */
  42. unsigned long last_waited; /* Time last woken after wait for request */
  43. struct radix_tree_root radix_root;
  44. struct hlist_head cic_list;
  45. void __rcu *ioc_data;
  46. };
  47. static inline struct io_context *ioc_task_link(struct io_context *ioc)
  48. {
  49. /*
  50. * if ref count is zero, don't allow sharing (ioc is going away, it's
  51. * a race).
  52. */
  53. if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
  54. atomic_inc(&ioc->nr_tasks);
  55. return ioc;
  56. }
  57. return NULL;
  58. }
  59. struct task_struct;
  60. #ifdef CONFIG_BLOCK
  61. void put_io_context(struct io_context *ioc);
  62. void exit_io_context(struct task_struct *task);
  63. struct io_context *get_task_io_context(struct task_struct *task,
  64. gfp_t gfp_flags, int node);
  65. #else
  66. struct io_context;
  67. static inline void put_io_context(struct io_context *ioc) { }
  68. static inline void exit_io_context(struct task_struct *task) { }
  69. #endif
  70. #endif