blob: 079aea8fd8a80f9ea7ea5d01f08631ad7b5ce29d [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;
Tejun Heo283287a2011-12-14 00:33:38 +010018 struct request_queue *q;
Jens Axboefd0928d2008-01-24 08:52:45 +010019
20 struct cfq_queue *cfqq[2];
21
22 struct io_context *ioc;
23
Shaohua Li383cd722011-07-12 14:24:35 +020024 struct cfq_ttime ttime;
Jens Axboefd0928d2008-01-24 08:52:45 +010025
Jens Axboefd0928d2008-01-24 08:52:45 +010026 struct list_head queue_list;
Jens Axboeffc4e752008-02-19 10:02:29 +010027 struct hlist_node cic_list;
Jens Axboefd0928d2008-01-24 08:52:45 +010028
29 void (*dtor)(struct io_context *); /* destructor */
30 void (*exit)(struct io_context *); /* called on task exit */
Fabio Checconi34e6bbf2008-04-02 14:31:02 +020031
32 struct rcu_head rcu_head;
Jens Axboefd0928d2008-01-24 08:52:45 +010033};
34
35/*
Jens Axboed38ecf92008-01-24 08:53:35 +010036 * I/O subsystem state of the associated processes. It is refcounted
37 * and kmalloc'ed. These could be shared between processes.
Jens Axboefd0928d2008-01-24 08:52:45 +010038 */
39struct io_context {
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070040 atomic_long_t refcount;
Jens Axboed38ecf92008-01-24 08:53:35 +010041 atomic_t nr_tasks;
42
43 /* all the fields below are protected by this lock */
44 spinlock_t lock;
Jens Axboefd0928d2008-01-24 08:52:45 +010045
46 unsigned short ioprio;
47 unsigned short ioprio_changed;
48
Ben Blum67523c42010-03-10 15:22:11 -080049#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
Vivek Goyal31e4c282009-12-03 12:59:42 -050050 unsigned short cgroup_changed;
51#endif
52
Jens Axboefd0928d2008-01-24 08:52:45 +010053 /*
54 * For request batching
55 */
Jens Axboefd0928d2008-01-24 08:52:45 +010056 int nr_batch_requests; /* Number of requests left in the batch */
Richard Kennedy58c24a62010-02-26 14:00:43 +010057 unsigned long last_waited; /* Time last woken after wait for request */
Jens Axboefd0928d2008-01-24 08:52:45 +010058
Jens Axboe4ac845a2008-01-24 08:44:49 +010059 struct radix_tree_root radix_root;
Jens Axboeffc4e752008-02-19 10:02:29 +010060 struct hlist_head cic_list;
Arnd Bergmann4d2deb42010-02-24 20:01:56 +010061 void __rcu *ioc_data;
Jens Axboefd0928d2008-01-24 08:52:45 +010062};
63
Jens Axboed38ecf92008-01-24 08:53:35 +010064static inline struct io_context *ioc_task_link(struct io_context *ioc)
65{
66 /*
67 * if ref count is zero, don't allow sharing (ioc is going away, it's
68 * a race).
69 */
Nikanth Karthikesand9c7d392009-06-10 12:57:06 -070070 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
Li Zefancbb4f262009-07-31 08:55:48 +020071 atomic_inc(&ioc->nr_tasks);
Jens Axboed38ecf92008-01-24 08:53:35 +010072 return ioc;
Jens Axboed237e5c2008-04-15 09:25:33 +020073 }
Jens Axboed38ecf92008-01-24 08:53:35 +010074
75 return NULL;
76}
77
Louis Rillingb69f2292009-12-04 14:52:42 +010078struct task_struct;
Jens Axboeda9cbc82008-06-30 20:42:08 +020079#ifdef CONFIG_BLOCK
Tejun Heo42ec57a2011-12-14 00:33:37 +010080void put_io_context(struct io_context *ioc);
Louis Rillingb69f2292009-12-04 14:52:42 +010081void exit_io_context(struct task_struct *task);
Tejun Heo6e736be2011-12-14 00:33:38 +010082struct io_context *get_task_io_context(struct task_struct *task,
83 gfp_t gfp_flags, int node);
Jens Axboeda9cbc82008-06-30 20:42:08 +020084#else
Jens Axboeda9cbc82008-06-30 20:42:08 +020085struct io_context;
Tejun Heo42ec57a2011-12-14 00:33:37 +010086static inline void put_io_context(struct io_context *ioc) { }
87static inline void exit_io_context(struct task_struct *task) { }
Jens Axboeda9cbc82008-06-30 20:42:08 +020088#endif
89
Jens Axboefd0928d2008-01-24 08:52:45 +010090#endif