blob: 5037a0ad231245b3b2779c81bf76f912df467879 [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>
Fabio Checconi34e6bbf2008-04-02 14:31:02 +02005#include <linux/rcupdate.h>
Jens Axboe4ac845a2008-01-24 08:44:49 +01006
Jens Axboefd0928d2008-01-24 08:52:45 +01007struct cfq_queue;
Shaohua Li383cd722011-07-12 14:24:35 +02008struct cfq_ttime {
9 unsigned long last_end_request;
10
11 unsigned long ttime_total;
12 unsigned long ttime_samples;
13 unsigned long ttime_mean;
14};
15
Jens Axboefd0928d2008-01-24 08:52:45 +010016struct cfq_io_context {
Jens Axboefd0928d2008-01-24 08:52:45 +010017 void *key;
18
19 struct cfq_queue *cfqq[2];
20
21 struct io_context *ioc;
22
Shaohua Li383cd722011-07-12 14:24:35 +020023 struct cfq_ttime ttime;
Jens Axboefd0928d2008-01-24 08:52:45 +010024
Jens Axboefd0928d2008-01-24 08:52:45 +010025 struct list_head queue_list;
Jens Axboeffc4e752008-02-19 10:02:29 +010026 struct hlist_node cic_list;
Jens Axboefd0928d2008-01-24 08:52:45 +010027
28 void (*dtor)(struct io_context *); /* destructor */
29 void (*exit)(struct io_context *); /* called on task exit */
Fabio Checconi34e6bbf2008-04-02 14:31:02 +020030
31 struct rcu_head rcu_head;
Jens Axboefd0928d2008-01-24 08:52:45 +010032};
33
34/*
Jens Axboed38ecf92008-01-24 08:53:35 +010035 * I/O subsystem state of the associated processes. It is refcounted
36 * and kmalloc'ed. These could be shared between processes.
Jens Axboefd0928d2008-01-24 08:52:45 +010037 */
38struct io_context {
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070039 atomic_long_t refcount;
Jens Axboed38ecf92008-01-24 08:53:35 +010040 atomic_t nr_tasks;
41
42 /* all the fields below are protected by this lock */
43 spinlock_t lock;
Jens Axboefd0928d2008-01-24 08:52:45 +010044
45 unsigned short ioprio;
46 unsigned short ioprio_changed;
47
Ben Blum67523c42010-03-10 15:22:11 -080048#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
Vivek Goyal31e4c282009-12-03 12:59:42 -050049 unsigned short cgroup_changed;
50#endif
51
Jens Axboefd0928d2008-01-24 08:52:45 +010052 /*
53 * For request batching
54 */
Jens Axboefd0928d2008-01-24 08:52:45 +010055 int nr_batch_requests; /* Number of requests left in the batch */
Richard Kennedy58c24a62010-02-26 14:00:43 +010056 unsigned long last_waited; /* Time last woken after wait for request */
Jens Axboefd0928d2008-01-24 08:52:45 +010057
Jens Axboe4ac845a2008-01-24 08:44:49 +010058 struct radix_tree_root radix_root;
Jens Axboeffc4e752008-02-19 10:02:29 +010059 struct hlist_head cic_list;
Arnd Bergmann4d2deb42010-02-24 20:01:56 +010060 void __rcu *ioc_data;
Jens Axboefd0928d2008-01-24 08:52:45 +010061};
62
Jens Axboed38ecf92008-01-24 08:53:35 +010063static inline struct io_context *ioc_task_link(struct io_context *ioc)
64{
65 /*
66 * if ref count is zero, don't allow sharing (ioc is going away, it's
67 * a race).
68 */
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070069 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
Li Zefancbb4f262009-07-31 08:55:48 +020070 atomic_inc(&ioc->nr_tasks);
Jens Axboed38ecf92008-01-24 08:53:35 +010071 return ioc;
Jens Axboed237e5c2008-04-15 09:25:33 +020072 }
Jens Axboed38ecf92008-01-24 08:53:35 +010073
74 return NULL;
75}
76
Louis Rillingb69f2292009-12-04 14:52:42 +010077struct task_struct;
Jens Axboeda9cbc82008-06-30 20:42:08 +020078#ifdef CONFIG_BLOCK
79int put_io_context(struct io_context *ioc);
Louis Rillingb69f2292009-12-04 14:52:42 +010080void exit_io_context(struct task_struct *task);
Jens Axboeda9cbc82008-06-30 20:42:08 +020081struct io_context *get_io_context(gfp_t gfp_flags, int node);
82struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
Jens Axboeda9cbc82008-06-30 20:42:08 +020083#else
Louis Rillingb69f2292009-12-04 14:52:42 +010084static inline void exit_io_context(struct task_struct *task)
Jens Axboeda9cbc82008-06-30 20:42:08 +020085{
86}
87
88struct io_context;
89static inline int put_io_context(struct io_context *ioc)
90{
91 return 1;
92}
93#endif
94
Jens Axboefd0928d2008-01-24 08:52:45 +010095#endif