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