iocontext.h 2.0 KB

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