blob: 1b4ccf25b4d22ac109edd6e73ac06ed580141726 [file] [log] [blame]
Jens Axboefd0928d2008-01-24 08:52:45 +01001#ifndef IOCONTEXT_H
2#define IOCONTEXT_H
3
Jens Axboe4ac845a2008-01-24 08:44:49 +01004#include <linux/radix-tree.h>
5
Jens Axboefd0928d2008-01-24 08:52:45 +01006/*
7 * This is the per-process anticipatory I/O scheduler state.
8 */
9struct as_io_context {
10 spinlock_t lock;
11
12 void (*dtor)(struct as_io_context *aic); /* destructor */
13 void (*exit)(struct as_io_context *aic); /* called on task exit */
14
15 unsigned long state;
16 atomic_t nr_queued; /* queued reads & sync writes */
17 atomic_t nr_dispatched; /* number of requests gone to the drivers */
18
19 /* IO History tracking */
20 /* Thinktime */
21 unsigned long last_end_request;
22 unsigned long ttime_total;
23 unsigned long ttime_samples;
24 unsigned long ttime_mean;
25 /* Layout pattern */
26 unsigned int seek_samples;
27 sector_t last_request_pos;
28 u64 seek_total;
29 sector_t seek_mean;
30};
31
32struct cfq_queue;
33struct cfq_io_context {
Jens Axboefd0928d2008-01-24 08:52:45 +010034 void *key;
Jens Axboe4ac845a2008-01-24 08:44:49 +010035 unsigned long dead_key;
Jens Axboefd0928d2008-01-24 08:52:45 +010036
37 struct cfq_queue *cfqq[2];
38
39 struct io_context *ioc;
40
41 unsigned long last_end_request;
42 sector_t last_request_pos;
43
44 unsigned long ttime_total;
45 unsigned long ttime_samples;
46 unsigned long ttime_mean;
47
48 unsigned int seek_samples;
49 u64 seek_total;
50 sector_t seek_mean;
51
52 struct list_head queue_list;
Jens Axboeffc4e752008-02-19 10:02:29 +010053 struct hlist_node cic_list;
Jens Axboefd0928d2008-01-24 08:52:45 +010054
55 void (*dtor)(struct io_context *); /* destructor */
56 void (*exit)(struct io_context *); /* called on task exit */
57};
58
59/*
Jens Axboed38ecf92008-01-24 08:53:35 +010060 * I/O subsystem state of the associated processes. It is refcounted
61 * and kmalloc'ed. These could be shared between processes.
Jens Axboefd0928d2008-01-24 08:52:45 +010062 */
63struct io_context {
64 atomic_t refcount;
Jens Axboed38ecf92008-01-24 08:53:35 +010065 atomic_t nr_tasks;
66
67 /* all the fields below are protected by this lock */
68 spinlock_t lock;
Jens Axboefd0928d2008-01-24 08:52:45 +010069
70 unsigned short ioprio;
71 unsigned short ioprio_changed;
72
73 /*
74 * For request batching
75 */
76 unsigned long last_waited; /* Time last woken after wait for request */
77 int nr_batch_requests; /* Number of requests left in the batch */
78
79 struct as_io_context *aic;
Jens Axboe4ac845a2008-01-24 08:44:49 +010080 struct radix_tree_root radix_root;
Jens Axboeffc4e752008-02-19 10:02:29 +010081 struct hlist_head cic_list;
Jens Axboefd0928d2008-01-24 08:52:45 +010082 void *ioc_data;
83};
84
Jens Axboed38ecf92008-01-24 08:53:35 +010085static inline struct io_context *ioc_task_link(struct io_context *ioc)
86{
87 /*
88 * if ref count is zero, don't allow sharing (ioc is going away, it's
89 * a race).
90 */
91 if (ioc && atomic_inc_not_zero(&ioc->refcount))
92 return ioc;
93
94 return NULL;
95}
96
Jens Axboefd0928d2008-01-24 08:52:45 +010097#endif