blob: 2c2b6da96b3c5de2a1e5c916a216ffeb8faaecdb [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
Tejun Heodc869002011-12-14 00:33:38 +010016enum {
17 CIC_IOPRIO_CHANGED,
18 CIC_CGROUP_CHANGED,
19};
20
Jens Axboefd0928d2008-01-24 08:52:45 +010021struct cfq_io_context {
Jens Axboefd0928d2008-01-24 08:52:45 +010022 void *key;
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
Jens Axboefd0928d2008-01-24 08:52:45 +010036 void (*dtor)(struct io_context *); /* destructor */
37 void (*exit)(struct io_context *); /* called on task exit */
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;
Jens Axboefd0928d2008-01-24 08:52:45 +010064};
65
Jens Axboed38ecf92008-01-24 08:53:35 +010066static inline struct io_context *ioc_task_link(struct io_context *ioc)
67{
68 /*
69 * if ref count is zero, don't allow sharing (ioc is going away, it's
70 * a race).
71 */
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070072 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
Li Zefancbb4f262009-07-31 08:55:48 +020073 atomic_inc(&ioc->nr_tasks);
Jens Axboed38ecf92008-01-24 08:53:35 +010074 return ioc;
Jens Axboed237e5c2008-04-15 09:25:33 +020075 }
Jens Axboed38ecf92008-01-24 08:53:35 +010076
77 return NULL;
78}
79
Louis Rillingb69f2292009-12-04 14:52:42 +010080struct task_struct;
Jens Axboeda9cbc82008-06-30 20:42:08 +020081#ifdef CONFIG_BLOCK
Tejun Heo42ec57a2011-12-14 00:33:37 +010082void put_io_context(struct io_context *ioc);
Louis Rillingb69f2292009-12-04 14:52:42 +010083void exit_io_context(struct task_struct *task);
Tejun Heo6e736be2011-12-14 00:33:38 +010084struct io_context *get_task_io_context(struct task_struct *task,
85 gfp_t gfp_flags, int node);
Tejun Heodc869002011-12-14 00:33:38 +010086void ioc_ioprio_changed(struct io_context *ioc, int ioprio);
87void ioc_cgroup_changed(struct io_context *ioc);
Jens Axboeda9cbc82008-06-30 20:42:08 +020088#else
Jens Axboeda9cbc82008-06-30 20:42:08 +020089struct io_context;
Tejun Heo42ec57a2011-12-14 00:33:37 +010090static inline void put_io_context(struct io_context *ioc) { }
91static inline void exit_io_context(struct task_struct *task) { }
Jens Axboeda9cbc82008-06-30 20:42:08 +020092#endif
93
Jens Axboefd0928d2008-01-24 08:52:45 +010094#endif