iocontext.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef IOCONTEXT_H
  2. #define IOCONTEXT_H
  3. #include <linux/radix-tree.h>
  4. #include <linux/rcupdate.h>
  5. #include <linux/workqueue.h>
  6. enum {
  7. ICQ_IOPRIO_CHANGED,
  8. ICQ_CGROUP_CHANGED,
  9. };
  10. struct io_cq {
  11. struct request_queue *q;
  12. struct io_context *ioc;
  13. /*
  14. * q_node and ioc_node link io_cq through icq_list of q and ioc
  15. * respectively. Both fields are unused once ioc_exit_icq() is
  16. * called and shared with __rcu_icq_cache and __rcu_head which are
  17. * used for RCU free of io_cq.
  18. */
  19. union {
  20. struct list_head q_node;
  21. struct kmem_cache *__rcu_icq_cache;
  22. };
  23. union {
  24. struct hlist_node ioc_node;
  25. struct rcu_head __rcu_head;
  26. };
  27. unsigned long changed;
  28. };
  29. /*
  30. * I/O subsystem state of the associated processes. It is refcounted
  31. * and kmalloc'ed. These could be shared between processes.
  32. */
  33. struct io_context {
  34. atomic_long_t refcount;
  35. atomic_t nr_tasks;
  36. /* all the fields below are protected by this lock */
  37. spinlock_t lock;
  38. unsigned short ioprio;
  39. /*
  40. * For request batching
  41. */
  42. int nr_batch_requests; /* Number of requests left in the batch */
  43. unsigned long last_waited; /* Time last woken after wait for request */
  44. struct radix_tree_root icq_tree;
  45. struct io_cq __rcu *icq_hint;
  46. struct hlist_head icq_list;
  47. struct work_struct release_work;
  48. };
  49. static inline struct io_context *ioc_task_link(struct io_context *ioc)
  50. {
  51. /*
  52. * if ref count is zero, don't allow sharing (ioc is going away, it's
  53. * a race).
  54. */
  55. if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
  56. atomic_inc(&ioc->nr_tasks);
  57. return ioc;
  58. }
  59. return NULL;
  60. }
  61. struct task_struct;
  62. #ifdef CONFIG_BLOCK
  63. void put_io_context(struct io_context *ioc, struct request_queue *locked_q);
  64. void exit_io_context(struct task_struct *task);
  65. struct io_context *get_task_io_context(struct task_struct *task,
  66. gfp_t gfp_flags, int node);
  67. void ioc_ioprio_changed(struct io_context *ioc, int ioprio);
  68. void ioc_cgroup_changed(struct io_context *ioc);
  69. #else
  70. struct io_context;
  71. static inline void put_io_context(struct io_context *ioc,
  72. struct request_queue *locked_q) { }
  73. static inline void exit_io_context(struct task_struct *task) { }
  74. #endif
  75. #endif