iocontext.h 1.9 KB

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