blob: b2b75a54f252d34738f11b1246bd18f3e09aec75 [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>
Tejun Heob2efa052011-12-14 00:33:39 +01006#include <linux/workqueue.h>
Jens Axboe4ac845a2008-01-24 08:44:49 +01007
Jens Axboefd0928d2008-01-24 08:52:45 +01008struct cfq_queue;
Shaohua Li383cd722011-07-12 14:24:35 +02009struct cfq_ttime {
10 unsigned long last_end_request;
11
12 unsigned long ttime_total;
13 unsigned long ttime_samples;
14 unsigned long ttime_mean;
15};
16
Tejun Heodc869002011-12-14 00:33:38 +010017enum {
18 CIC_IOPRIO_CHANGED,
19 CIC_CGROUP_CHANGED,
20};
21
Jens Axboefd0928d2008-01-24 08:52:45 +010022struct cfq_io_context {
Tejun Heo283287a2011-12-14 00:33:38 +010023 struct request_queue *q;
Jens Axboefd0928d2008-01-24 08:52:45 +010024
25 struct cfq_queue *cfqq[2];
26
27 struct io_context *ioc;
28
Shaohua Li383cd722011-07-12 14:24:35 +020029 struct cfq_ttime ttime;
Jens Axboefd0928d2008-01-24 08:52:45 +010030
Jens Axboefd0928d2008-01-24 08:52:45 +010031 struct list_head queue_list;
Jens Axboeffc4e752008-02-19 10:02:29 +010032 struct hlist_node cic_list;
Jens Axboefd0928d2008-01-24 08:52:45 +010033
Tejun Heodc869002011-12-14 00:33:38 +010034 unsigned long changed;
35
Tejun Heob2efa052011-12-14 00:33:39 +010036 void (*exit)(struct cfq_io_context *);
37 void (*release)(struct cfq_io_context *);
Fabio Checconi34e6bbf2008-04-02 14:31:02 +020038
39 struct rcu_head rcu_head;
Jens Axboefd0928d2008-01-24 08:52:45 +010040};
41
42/*
Jens Axboed38ecf92008-01-24 08:53:35 +010043 * I/O subsystem state of the associated processes. It is refcounted
44 * and kmalloc'ed. These could be shared between processes.
Jens Axboefd0928d2008-01-24 08:52:45 +010045 */
46struct io_context {
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070047 atomic_long_t refcount;
Jens Axboed38ecf92008-01-24 08:53:35 +010048 atomic_t nr_tasks;
49
50 /* all the fields below are protected by this lock */
51 spinlock_t lock;
Jens Axboefd0928d2008-01-24 08:52:45 +010052
53 unsigned short ioprio;
Vivek Goyal31e4c282009-12-03 12:59:42 -050054
Jens Axboefd0928d2008-01-24 08:52:45 +010055 /*
56 * For request batching
57 */
Jens Axboefd0928d2008-01-24 08:52:45 +010058 int nr_batch_requests; /* Number of requests left in the batch */
Richard Kennedy58c24a62010-02-26 14:00:43 +010059 unsigned long last_waited; /* Time last woken after wait for request */
Jens Axboefd0928d2008-01-24 08:52:45 +010060
Jens Axboe4ac845a2008-01-24 08:44:49 +010061 struct radix_tree_root radix_root;
Jens Axboeffc4e752008-02-19 10:02:29 +010062 struct hlist_head cic_list;
Arnd Bergmann4d2deb42010-02-24 20:01:56 +010063 void __rcu *ioc_data;
Tejun Heob2efa052011-12-14 00:33:39 +010064
65 struct work_struct release_work;
Jens Axboefd0928d2008-01-24 08:52:45 +010066};
67
Jens Axboed38ecf92008-01-24 08:53:35 +010068static 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 */
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070074 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
Li Zefancbb4f262009-07-31 08:55:48 +020075 atomic_inc(&ioc->nr_tasks);
Jens Axboed38ecf92008-01-24 08:53:35 +010076 return ioc;
Jens Axboed237e5c2008-04-15 09:25:33 +020077 }
Jens Axboed38ecf92008-01-24 08:53:35 +010078
79 return NULL;
80}
81
Louis Rillingb69f2292009-12-04 14:52:42 +010082struct task_struct;
Jens Axboeda9cbc82008-06-30 20:42:08 +020083#ifdef CONFIG_BLOCK
Tejun Heob2efa052011-12-14 00:33:39 +010084void put_io_context(struct io_context *ioc, struct request_queue *locked_q);
Louis Rillingb69f2292009-12-04 14:52:42 +010085void exit_io_context(struct task_struct *task);
Tejun Heo6e736be2011-12-14 00:33:38 +010086struct io_context *get_task_io_context(struct task_struct *task,
87 gfp_t gfp_flags, int node);
Tejun Heodc869002011-12-14 00:33:38 +010088void ioc_ioprio_changed(struct io_context *ioc, int ioprio);
89void ioc_cgroup_changed(struct io_context *ioc);
Jens Axboeda9cbc82008-06-30 20:42:08 +020090#else
Jens Axboeda9cbc82008-06-30 20:42:08 +020091struct io_context;
Tejun Heob2efa052011-12-14 00:33:39 +010092static inline void put_io_context(struct io_context *ioc,
93 struct request_queue *locked_q) { }
Tejun Heo42ec57a2011-12-14 00:33:37 +010094static inline void exit_io_context(struct task_struct *task) { }
Jens Axboeda9cbc82008-06-30 20:42:08 +020095#endif
96
Jens Axboefd0928d2008-01-24 08:52:45 +010097#endif