iocontext.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef IOCONTEXT_H
  2. #define IOCONTEXT_H
  3. #include <linux/radix-tree.h>
  4. #include <linux/rcupdate.h>
  5. /*
  6. * This is the per-process anticipatory I/O scheduler state.
  7. */
  8. struct as_io_context {
  9. spinlock_t lock;
  10. void (*dtor)(struct as_io_context *aic); /* destructor */
  11. void (*exit)(struct as_io_context *aic); /* called on task exit */
  12. unsigned long state;
  13. atomic_t nr_queued; /* queued reads & sync writes */
  14. atomic_t nr_dispatched; /* number of requests gone to the drivers */
  15. /* IO History tracking */
  16. /* Thinktime */
  17. unsigned long last_end_request;
  18. unsigned long ttime_total;
  19. unsigned long ttime_samples;
  20. unsigned long ttime_mean;
  21. /* Layout pattern */
  22. unsigned int seek_samples;
  23. sector_t last_request_pos;
  24. u64 seek_total;
  25. sector_t seek_mean;
  26. };
  27. struct cfq_queue;
  28. struct cfq_io_context {
  29. void *key;
  30. unsigned long dead_key;
  31. struct cfq_queue *cfqq[2];
  32. struct io_context *ioc;
  33. unsigned long last_end_request;
  34. sector_t last_request_pos;
  35. unsigned long ttime_total;
  36. unsigned long ttime_samples;
  37. unsigned long ttime_mean;
  38. unsigned int seek_samples;
  39. u64 seek_total;
  40. sector_t seek_mean;
  41. struct list_head queue_list;
  42. struct hlist_node cic_list;
  43. void (*dtor)(struct io_context *); /* destructor */
  44. void (*exit)(struct io_context *); /* called on task exit */
  45. struct rcu_head rcu_head;
  46. };
  47. /*
  48. * I/O subsystem state of the associated processes. It is refcounted
  49. * and kmalloc'ed. These could be shared between processes.
  50. */
  51. struct io_context {
  52. atomic_t refcount;
  53. atomic_t nr_tasks;
  54. /* all the fields below are protected by this lock */
  55. spinlock_t lock;
  56. unsigned short ioprio;
  57. unsigned short ioprio_changed;
  58. /*
  59. * For request batching
  60. */
  61. unsigned long last_waited; /* Time last woken after wait for request */
  62. int nr_batch_requests; /* Number of requests left in the batch */
  63. struct as_io_context *aic;
  64. struct radix_tree_root radix_root;
  65. struct hlist_head cic_list;
  66. void *ioc_data;
  67. };
  68. static inline struct io_context *ioc_task_link(struct io_context *ioc)
  69. {
  70. /*
  71. * if ref count is zero, don't allow sharing (ioc is going away, it's
  72. * a race).
  73. */
  74. if (ioc && atomic_inc_not_zero(&ioc->refcount))
  75. return ioc;
  76. return NULL;
  77. }
  78. #endif