iocontext.h 2.0 KB

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