blob: 01e8631287806fcac2dc16658b6b14da9c7a0e04 [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 {
Jens Axboefd0928d2008-01-24 08:52:45 +010023 void *key;
Tejun Heo283287a2011-12-14 00:33:38 +010024 struct request_queue *q;
Jens Axboefd0928d2008-01-24 08:52:45 +010025
26 struct cfq_queue *cfqq[2];
27
28 struct io_context *ioc;
29
Shaohua Li383cd722011-07-12 14:24:35 +020030 struct cfq_ttime ttime;
Jens Axboefd0928d2008-01-24 08:52:45 +010031
Jens Axboefd0928d2008-01-24 08:52:45 +010032 struct list_head queue_list;
Jens Axboeffc4e752008-02-19 10:02:29 +010033 struct hlist_node cic_list;
Jens Axboefd0928d2008-01-24 08:52:45 +010034
Tejun Heodc869002011-12-14 00:33:38 +010035 unsigned long changed;
36
Tejun Heob2efa052011-12-14 00:33:39 +010037 void (*exit)(struct cfq_io_context *);
38 void (*release)(struct cfq_io_context *);
Fabio Checconi34e6bbf2008-04-02 14:31:02 +020039
40 struct rcu_head rcu_head;
Jens Axboefd0928d2008-01-24 08:52:45 +010041};
42
43/*
Jens Axboed38ecf92008-01-24 08:53:35 +010044 * I/O subsystem state of the associated processes. It is refcounted
45 * and kmalloc'ed. These could be shared between processes.
Jens Axboefd0928d2008-01-24 08:52:45 +010046 */
47struct io_context {
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070048 atomic_long_t refcount;
Jens Axboed38ecf92008-01-24 08:53:35 +010049 atomic_t nr_tasks;
50
51 /* all the fields below are protected by this lock */
52 spinlock_t lock;
Jens Axboefd0928d2008-01-24 08:52:45 +010053
54 unsigned short ioprio;
Vivek Goyal31e4c282009-12-03 12:59:42 -050055
Jens Axboefd0928d2008-01-24 08:52:45 +010056 /*
57 * For request batching
58 */
Jens Axboefd0928d2008-01-24 08:52:45 +010059 int nr_batch_requests; /* Number of requests left in the batch */
Richard Kennedy58c24a62010-02-26 14:00:43 +010060 unsigned long last_waited; /* Time last woken after wait for request */
Jens Axboefd0928d2008-01-24 08:52:45 +010061
Jens Axboe4ac845a2008-01-24 08:44:49 +010062 struct radix_tree_root radix_root;
Jens Axboeffc4e752008-02-19 10:02:29 +010063 struct hlist_head cic_list;
Arnd Bergmann4d2deb42010-02-24 20:01:56 +010064 void __rcu *ioc_data;
Tejun Heob2efa052011-12-14 00:33:39 +010065
66 struct work_struct release_work;
Jens Axboefd0928d2008-01-24 08:52:45 +010067};
68
Jens Axboed38ecf92008-01-24 08:53:35 +010069static inline struct io_context *ioc_task_link(struct io_context *ioc)
70{
71 /*
72 * if ref count is zero, don't allow sharing (ioc is going away, it's
73 * a race).
74 */
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070075 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
Li Zefancbb4f262009-07-31 08:55:48 +020076 atomic_inc(&ioc->nr_tasks);
Jens Axboed38ecf92008-01-24 08:53:35 +010077 return ioc;
Jens Axboed237e5c2008-04-15 09:25:33 +020078 }
Jens Axboed38ecf92008-01-24 08:53:35 +010079
80 return NULL;
81}
82
Louis Rillingb69f2292009-12-04 14:52:42 +010083struct task_struct;
Jens Axboeda9cbc82008-06-30 20:42:08 +020084#ifdef CONFIG_BLOCK
Tejun Heob2efa052011-12-14 00:33:39 +010085void put_io_context(struct io_context *ioc, struct request_queue *locked_q);
Louis Rillingb69f2292009-12-04 14:52:42 +010086void exit_io_context(struct task_struct *task);
Tejun Heo6e736be2011-12-14 00:33:38 +010087struct io_context *get_task_io_context(struct task_struct *task,
88 gfp_t gfp_flags, int node);
Tejun Heodc869002011-12-14 00:33:38 +010089void ioc_ioprio_changed(struct io_context *ioc, int ioprio);
90void ioc_cgroup_changed(struct io_context *ioc);
Jens Axboeda9cbc82008-06-30 20:42:08 +020091#else
Jens Axboeda9cbc82008-06-30 20:42:08 +020092struct io_context;
Tejun Heob2efa052011-12-14 00:33:39 +010093static inline void put_io_context(struct io_context *ioc,
94 struct request_queue *locked_q) { }
Tejun Heo42ec57a2011-12-14 00:33:37 +010095static inline void exit_io_context(struct task_struct *task) { }
Jens Axboeda9cbc82008-06-30 20:42:08 +020096#endif
97
Jens Axboefd0928d2008-01-24 08:52:45 +010098#endif