diff options
author | Tejun Heo <tj@kernel.org> | 2012-03-05 16:15:28 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-03-06 15:27:24 -0500 |
commit | 4f85cb96d9d2fbbb7160db855a6beee1baced5e5 (patch) | |
tree | 5472bba04490da05fa6ca8f780431b37bd7375cb | |
parent | 852c788f8365062c8a383c5a93f7f7289977cb50 (diff) |
block: make block cgroup policies follow bio task association
Implement bio_blkio_cgroup() which returns the blkcg associated with
the bio if exists or %current's blkcg, and use it in blk-throttle and
cfq-iosched propio. This makes both cgroup policies honor task
association for the bio instead of always assuming %current.
As nobody is using bio_set_task() yet, this doesn't introduce any
behavior change.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | block/blk-cgroup.c | 11 | ||||
-rw-r--r-- | block/blk-cgroup.h | 4 | ||||
-rw-r--r-- | block/blk-throttle.c | 2 | ||||
-rw-r--r-- | block/cfq-iosched.c | 21 |
4 files changed, 23 insertions, 15 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 27d39a810cb6..ee962f327ba5 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c | |||
@@ -71,12 +71,19 @@ struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup) | |||
71 | } | 71 | } |
72 | EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup); | 72 | EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup); |
73 | 73 | ||
74 | struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk) | 74 | static struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk) |
75 | { | 75 | { |
76 | return container_of(task_subsys_state(tsk, blkio_subsys_id), | 76 | return container_of(task_subsys_state(tsk, blkio_subsys_id), |
77 | struct blkio_cgroup, css); | 77 | struct blkio_cgroup, css); |
78 | } | 78 | } |
79 | EXPORT_SYMBOL_GPL(task_blkio_cgroup); | 79 | |
80 | struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio) | ||
81 | { | ||
82 | if (bio && bio->bi_css) | ||
83 | return container_of(bio->bi_css, struct blkio_cgroup, css); | ||
84 | return task_blkio_cgroup(current); | ||
85 | } | ||
86 | EXPORT_SYMBOL_GPL(bio_blkio_cgroup); | ||
80 | 87 | ||
81 | static inline void blkio_update_group_weight(struct blkio_group *blkg, | 88 | static inline void blkio_update_group_weight(struct blkio_group *blkg, |
82 | int plid, unsigned int weight) | 89 | int plid, unsigned int weight) |
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h index 66eaefefcbd2..98cd8533378f 100644 --- a/block/blk-cgroup.h +++ b/block/blk-cgroup.h | |||
@@ -379,7 +379,7 @@ static inline void blkiocg_set_start_empty_time(struct blkio_group *blkg, | |||
379 | #ifdef CONFIG_BLK_CGROUP | 379 | #ifdef CONFIG_BLK_CGROUP |
380 | extern struct blkio_cgroup blkio_root_cgroup; | 380 | extern struct blkio_cgroup blkio_root_cgroup; |
381 | extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); | 381 | extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); |
382 | extern struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk); | 382 | extern struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio); |
383 | extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, | 383 | extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, |
384 | struct request_queue *q); | 384 | struct request_queue *q); |
385 | struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg, | 385 | struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg, |
@@ -413,7 +413,7 @@ struct cgroup; | |||
413 | static inline struct blkio_cgroup * | 413 | static inline struct blkio_cgroup * |
414 | cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } | 414 | cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } |
415 | static inline struct blkio_cgroup * | 415 | static inline struct blkio_cgroup * |
416 | task_blkio_cgroup(struct task_struct *tsk) { return NULL; } | 416 | bio_blkio_cgroup(struct bio *bio) { return NULL; } |
417 | 417 | ||
418 | static inline struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, | 418 | static inline struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, |
419 | void *key) { return NULL; } | 419 | void *key) { return NULL; } |
diff --git a/block/blk-throttle.c b/block/blk-throttle.c index bfa5168249eb..08b7ab292a80 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c | |||
@@ -900,7 +900,7 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio) | |||
900 | * just update the dispatch stats in lockless manner and return. | 900 | * just update the dispatch stats in lockless manner and return. |
901 | */ | 901 | */ |
902 | rcu_read_lock(); | 902 | rcu_read_lock(); |
903 | blkcg = task_blkio_cgroup(current); | 903 | blkcg = bio_blkio_cgroup(bio); |
904 | tg = throtl_lookup_tg(td, blkcg); | 904 | tg = throtl_lookup_tg(td, blkcg); |
905 | if (tg) { | 905 | if (tg) { |
906 | if (tg_no_rule_group(tg, rw)) { | 906 | if (tg_no_rule_group(tg, rw)) { |
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index abac87337d70..f2387b50f82e 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c | |||
@@ -467,8 +467,9 @@ static inline int cfqg_busy_async_queues(struct cfq_data *cfqd, | |||
467 | } | 467 | } |
468 | 468 | ||
469 | static void cfq_dispatch_insert(struct request_queue *, struct request *); | 469 | static void cfq_dispatch_insert(struct request_queue *, struct request *); |
470 | static struct cfq_queue *cfq_get_queue(struct cfq_data *, bool, | 470 | static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, bool is_sync, |
471 | struct io_context *, gfp_t); | 471 | struct io_context *ioc, struct bio *bio, |
472 | gfp_t gfp_mask); | ||
472 | 473 | ||
473 | static inline struct cfq_io_cq *icq_to_cic(struct io_cq *icq) | 474 | static inline struct cfq_io_cq *icq_to_cic(struct io_cq *icq) |
474 | { | 475 | { |
@@ -2601,7 +2602,7 @@ static void cfq_init_prio_data(struct cfq_queue *cfqq, struct io_context *ioc) | |||
2601 | cfq_clear_cfqq_prio_changed(cfqq); | 2602 | cfq_clear_cfqq_prio_changed(cfqq); |
2602 | } | 2603 | } |
2603 | 2604 | ||
2604 | static void changed_ioprio(struct cfq_io_cq *cic) | 2605 | static void changed_ioprio(struct cfq_io_cq *cic, struct bio *bio) |
2605 | { | 2606 | { |
2606 | struct cfq_data *cfqd = cic_to_cfqd(cic); | 2607 | struct cfq_data *cfqd = cic_to_cfqd(cic); |
2607 | struct cfq_queue *cfqq; | 2608 | struct cfq_queue *cfqq; |
@@ -2613,7 +2614,7 @@ static void changed_ioprio(struct cfq_io_cq *cic) | |||
2613 | if (cfqq) { | 2614 | if (cfqq) { |
2614 | struct cfq_queue *new_cfqq; | 2615 | struct cfq_queue *new_cfqq; |
2615 | new_cfqq = cfq_get_queue(cfqd, BLK_RW_ASYNC, cic->icq.ioc, | 2616 | new_cfqq = cfq_get_queue(cfqd, BLK_RW_ASYNC, cic->icq.ioc, |
2616 | GFP_ATOMIC); | 2617 | bio, GFP_ATOMIC); |
2617 | if (new_cfqq) { | 2618 | if (new_cfqq) { |
2618 | cic->cfqq[BLK_RW_ASYNC] = new_cfqq; | 2619 | cic->cfqq[BLK_RW_ASYNC] = new_cfqq; |
2619 | cfq_put_queue(cfqq); | 2620 | cfq_put_queue(cfqq); |
@@ -2671,7 +2672,7 @@ static void changed_cgroup(struct cfq_io_cq *cic) | |||
2671 | 2672 | ||
2672 | static struct cfq_queue * | 2673 | static struct cfq_queue * |
2673 | cfq_find_alloc_queue(struct cfq_data *cfqd, bool is_sync, | 2674 | cfq_find_alloc_queue(struct cfq_data *cfqd, bool is_sync, |
2674 | struct io_context *ioc, gfp_t gfp_mask) | 2675 | struct io_context *ioc, struct bio *bio, gfp_t gfp_mask) |
2675 | { | 2676 | { |
2676 | struct blkio_cgroup *blkcg; | 2677 | struct blkio_cgroup *blkcg; |
2677 | struct cfq_queue *cfqq, *new_cfqq = NULL; | 2678 | struct cfq_queue *cfqq, *new_cfqq = NULL; |
@@ -2681,7 +2682,7 @@ cfq_find_alloc_queue(struct cfq_data *cfqd, bool is_sync, | |||
2681 | retry: | 2682 | retry: |
2682 | rcu_read_lock(); | 2683 | rcu_read_lock(); |
2683 | 2684 | ||
2684 | blkcg = task_blkio_cgroup(current); | 2685 | blkcg = bio_blkio_cgroup(bio); |
2685 | 2686 | ||
2686 | cfqg = cfq_lookup_create_cfqg(cfqd, blkcg); | 2687 | cfqg = cfq_lookup_create_cfqg(cfqd, blkcg); |
2687 | 2688 | ||
@@ -2746,7 +2747,7 @@ cfq_async_queue_prio(struct cfq_data *cfqd, int ioprio_class, int ioprio) | |||
2746 | 2747 | ||
2747 | static struct cfq_queue * | 2748 | static struct cfq_queue * |
2748 | cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct io_context *ioc, | 2749 | cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct io_context *ioc, |
2749 | gfp_t gfp_mask) | 2750 | struct bio *bio, gfp_t gfp_mask) |
2750 | { | 2751 | { |
2751 | const int ioprio = task_ioprio(ioc); | 2752 | const int ioprio = task_ioprio(ioc); |
2752 | const int ioprio_class = task_ioprio_class(ioc); | 2753 | const int ioprio_class = task_ioprio_class(ioc); |
@@ -2759,7 +2760,7 @@ cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct io_context *ioc, | |||
2759 | } | 2760 | } |
2760 | 2761 | ||
2761 | if (!cfqq) | 2762 | if (!cfqq) |
2762 | cfqq = cfq_find_alloc_queue(cfqd, is_sync, ioc, gfp_mask); | 2763 | cfqq = cfq_find_alloc_queue(cfqd, is_sync, ioc, bio, gfp_mask); |
2763 | 2764 | ||
2764 | /* | 2765 | /* |
2765 | * pin the queue now that it's allocated, scheduler exit will prune it | 2766 | * pin the queue now that it's allocated, scheduler exit will prune it |
@@ -3316,7 +3317,7 @@ cfq_set_request(struct request_queue *q, struct request *rq, struct bio *bio, | |||
3316 | /* handle changed notifications */ | 3317 | /* handle changed notifications */ |
3317 | changed = icq_get_changed(&cic->icq); | 3318 | changed = icq_get_changed(&cic->icq); |
3318 | if (unlikely(changed & ICQ_IOPRIO_CHANGED)) | 3319 | if (unlikely(changed & ICQ_IOPRIO_CHANGED)) |
3319 | changed_ioprio(cic); | 3320 | changed_ioprio(cic, bio); |
3320 | #ifdef CONFIG_CFQ_GROUP_IOSCHED | 3321 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
3321 | if (unlikely(changed & ICQ_CGROUP_CHANGED)) | 3322 | if (unlikely(changed & ICQ_CGROUP_CHANGED)) |
3322 | changed_cgroup(cic); | 3323 | changed_cgroup(cic); |
@@ -3325,7 +3326,7 @@ cfq_set_request(struct request_queue *q, struct request *rq, struct bio *bio, | |||
3325 | new_queue: | 3326 | new_queue: |
3326 | cfqq = cic_to_cfqq(cic, is_sync); | 3327 | cfqq = cic_to_cfqq(cic, is_sync); |
3327 | if (!cfqq || cfqq == &cfqd->oom_cfqq) { | 3328 | if (!cfqq || cfqq == &cfqd->oom_cfqq) { |
3328 | cfqq = cfq_get_queue(cfqd, is_sync, cic->icq.ioc, gfp_mask); | 3329 | cfqq = cfq_get_queue(cfqd, is_sync, cic->icq.ioc, bio, gfp_mask); |
3329 | cic_set_cfqq(cic, cfqq, is_sync); | 3330 | cic_set_cfqq(cic, cfqq, is_sync); |
3330 | } else { | 3331 | } else { |
3331 | /* | 3332 | /* |