diff options
author | Tejun Heo <tj@kernel.org> | 2012-03-05 16:15:14 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-03-06 15:27:23 -0500 |
commit | 0381411e4b1a52cee134eb73750e5e3cc1155d09 (patch) | |
tree | 32aa1d0b8a2ca8277e60e8b78dd731d193440924 /block/blk-cgroup.h | |
parent | 923adde1be1df57cebd80c563058e503376645e8 (diff) |
blkcg: let blkcg core handle policy private data allocation
Currently, blkg's are embedded in private data blkcg policy private
data structure and thus allocated and freed by policies. This leads
to duplicate codes in policies, hinders implementing common part in
blkcg core with strong semantics, and forces duplicate blkg's for the
same cgroup-q association.
This patch introduces struct blkg_policy_data which is a separate data
structure chained from blkg. Policies specifies the amount of private
data it needs in its blkio_policy_type->pdata_size and blkcg core
takes care of allocating them along with blkg which can be accessed
using blkg_to_pdata(). blkg can be determined from pdata using
pdata_to_blkg(). blkio_alloc_group_fn() method is accordingly updated
to blkio_init_group_fn().
For consistency, tg_of_blkg() and cfqg_of_blkg() are replaced with
blkg_to_tg() and blkg_to_cfqg() respectively, and functions to map in
the reverse direction are added.
Except that policy specific data now lives in a separate data
structure from blkg, this patch doesn't introduce any functional
difference.
This will be used to unify blkg's for different policies.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-cgroup.h')
-rw-r--r-- | block/blk-cgroup.h | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h index 3bc171080e93..9537819c29c6 100644 --- a/block/blk-cgroup.h +++ b/block/blk-cgroup.h | |||
@@ -159,6 +159,15 @@ struct blkio_group_conf { | |||
159 | u64 bps[2]; | 159 | u64 bps[2]; |
160 | }; | 160 | }; |
161 | 161 | ||
162 | /* per-blkg per-policy data */ | ||
163 | struct blkg_policy_data { | ||
164 | /* the blkg this per-policy data belongs to */ | ||
165 | struct blkio_group *blkg; | ||
166 | |||
167 | /* pol->pdata_size bytes of private data used by policy impl */ | ||
168 | char pdata[] __aligned(__alignof__(unsigned long long)); | ||
169 | }; | ||
170 | |||
162 | struct blkio_group { | 171 | struct blkio_group { |
163 | /* Pointer to the associated request_queue, RCU protected */ | 172 | /* Pointer to the associated request_queue, RCU protected */ |
164 | struct request_queue __rcu *q; | 173 | struct request_queue __rcu *q; |
@@ -177,10 +186,11 @@ struct blkio_group { | |||
177 | struct blkio_group_stats stats; | 186 | struct blkio_group_stats stats; |
178 | /* Per cpu stats pointer */ | 187 | /* Per cpu stats pointer */ |
179 | struct blkio_group_stats_cpu __percpu *stats_cpu; | 188 | struct blkio_group_stats_cpu __percpu *stats_cpu; |
189 | |||
190 | struct blkg_policy_data *pd; | ||
180 | }; | 191 | }; |
181 | 192 | ||
182 | typedef struct blkio_group *(blkio_alloc_group_fn)(struct request_queue *q, | 193 | typedef void (blkio_init_group_fn)(struct blkio_group *blkg); |
183 | struct blkio_cgroup *blkcg); | ||
184 | typedef void (blkio_link_group_fn)(struct request_queue *q, | 194 | typedef void (blkio_link_group_fn)(struct request_queue *q, |
185 | struct blkio_group *blkg); | 195 | struct blkio_group *blkg); |
186 | typedef void (blkio_unlink_group_fn)(struct request_queue *q, | 196 | typedef void (blkio_unlink_group_fn)(struct request_queue *q, |
@@ -198,7 +208,7 @@ typedef void (blkio_update_group_write_iops_fn)(struct request_queue *q, | |||
198 | struct blkio_group *blkg, unsigned int write_iops); | 208 | struct blkio_group *blkg, unsigned int write_iops); |
199 | 209 | ||
200 | struct blkio_policy_ops { | 210 | struct blkio_policy_ops { |
201 | blkio_alloc_group_fn *blkio_alloc_group_fn; | 211 | blkio_init_group_fn *blkio_init_group_fn; |
202 | blkio_link_group_fn *blkio_link_group_fn; | 212 | blkio_link_group_fn *blkio_link_group_fn; |
203 | blkio_unlink_group_fn *blkio_unlink_group_fn; | 213 | blkio_unlink_group_fn *blkio_unlink_group_fn; |
204 | blkio_clear_queue_fn *blkio_clear_queue_fn; | 214 | blkio_clear_queue_fn *blkio_clear_queue_fn; |
@@ -213,6 +223,7 @@ struct blkio_policy_type { | |||
213 | struct list_head list; | 223 | struct list_head list; |
214 | struct blkio_policy_ops ops; | 224 | struct blkio_policy_ops ops; |
215 | enum blkio_policy_id plid; | 225 | enum blkio_policy_id plid; |
226 | size_t pdata_size; /* policy specific private data size */ | ||
216 | }; | 227 | }; |
217 | 228 | ||
218 | extern int blkcg_init_queue(struct request_queue *q); | 229 | extern int blkcg_init_queue(struct request_queue *q); |
@@ -224,6 +235,38 @@ extern void blkio_policy_register(struct blkio_policy_type *); | |||
224 | extern void blkio_policy_unregister(struct blkio_policy_type *); | 235 | extern void blkio_policy_unregister(struct blkio_policy_type *); |
225 | extern void blkg_destroy_all(struct request_queue *q); | 236 | extern void blkg_destroy_all(struct request_queue *q); |
226 | 237 | ||
238 | /** | ||
239 | * blkg_to_pdata - get policy private data | ||
240 | * @blkg: blkg of interest | ||
241 | * @pol: policy of interest | ||
242 | * | ||
243 | * Return pointer to private data associated with the @blkg-@pol pair. | ||
244 | */ | ||
245 | static inline void *blkg_to_pdata(struct blkio_group *blkg, | ||
246 | struct blkio_policy_type *pol) | ||
247 | { | ||
248 | return blkg ? blkg->pd->pdata : NULL; | ||
249 | } | ||
250 | |||
251 | /** | ||
252 | * pdata_to_blkg - get blkg associated with policy private data | ||
253 | * @pdata: policy private data of interest | ||
254 | * @pol: policy @pdata is for | ||
255 | * | ||
256 | * @pdata is policy private data for @pol. Determine the blkg it's | ||
257 | * associated with. | ||
258 | */ | ||
259 | static inline struct blkio_group *pdata_to_blkg(void *pdata, | ||
260 | struct blkio_policy_type *pol) | ||
261 | { | ||
262 | if (pdata) { | ||
263 | struct blkg_policy_data *pd = | ||
264 | container_of(pdata, struct blkg_policy_data, pdata); | ||
265 | return pd->blkg; | ||
266 | } | ||
267 | return NULL; | ||
268 | } | ||
269 | |||
227 | static inline char *blkg_path(struct blkio_group *blkg) | 270 | static inline char *blkg_path(struct blkio_group *blkg) |
228 | { | 271 | { |
229 | return blkg->path; | 272 | return blkg->path; |
@@ -244,6 +287,10 @@ static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { } | |||
244 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } | 287 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } |
245 | static inline void blkg_destroy_all(struct request_queue *q) { } | 288 | static inline void blkg_destroy_all(struct request_queue *q) { } |
246 | 289 | ||
290 | static inline void *blkg_to_pdata(struct blkio_group *blkg, | ||
291 | struct blkio_policy_type *pol) { return NULL; } | ||
292 | static inline struct blkio_group *pdata_to_blkg(void *pdata, | ||
293 | struct blkio_policy_type *pol) { return NULL; } | ||
247 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } | 294 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } |
248 | 295 | ||
249 | #endif | 296 | #endif |