iocontext.h 2.0 KB

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