Skip to content

Commit 4eef304

Browse files
htejunaxboe
authored andcommitted
blkcg: move per-queue blkg list heads and counters to queue and blkg
Currently, specific policy implementations are responsible for maintaining list and number of blkgs. This duplicates code unnecessarily, and hinders factoring common code and providing blkcg API with better defined semantics. After this patch, request_queue hosts list heads and counters and blkg has list nodes for both policies. This patch only relocates the necessary fields and the next patch will actually move management code into blkcg core. Note that request_queue->blkg_list[] and ->nr_blkgs[] are hardcoded to have 2 elements. This is to avoid include dependency and will be removed by the next patch. This patch doesn't introduce any behavior change. -v2: Now unnecessary conditional on CONFIG_BLK_CGROUP_MODULE removed as pointed out by Vivek. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c176826 commit 4eef304

6 files changed

Lines changed: 54 additions & 54 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ static struct blkio_group *blkg_alloc(struct blkio_cgroup *blkcg,
499499

500500
spin_lock_init(&blkg->stats_lock);
501501
rcu_assign_pointer(blkg->q, q);
502+
INIT_LIST_HEAD(&blkg->q_node[0]);
503+
INIT_LIST_HEAD(&blkg->q_node[1]);
502504
blkg->blkcg = blkcg;
503505
blkg->plid = pol->plid;
504506
blkg->refcnt = 1;

‎block/blk-cgroup.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ struct blkg_policy_data {
178178
struct blkio_group {
179179
/* Pointer to the associated request_queue, RCU protected */
180180
struct request_queue __rcu *q;
181+
struct list_head q_node[BLKIO_NR_POLICIES];
181182
struct hlist_node blkcg_node;
182183
struct blkio_cgroup *blkcg;
183184
/* Store cgroup path */

‎block/blk-core.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
547547
INIT_LIST_HEAD(&q->queue_head);
548548
INIT_LIST_HEAD(&q->timeout_list);
549549
INIT_LIST_HEAD(&q->icq_list);
550+
#ifdef CONFIG_BLK_CGROUP
551+
INIT_LIST_HEAD(&q->blkg_list[0]);
552+
INIT_LIST_HEAD(&q->blkg_list[1]);
553+
#endif
550554
INIT_LIST_HEAD(&q->flush_queue[0]);
551555
INIT_LIST_HEAD(&q->flush_queue[1]);
552556
INIT_LIST_HEAD(&q->flush_data_in_flight);

‎block/blk-throttle.c‎

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ struct throtl_rb_root {
4141
#define rb_entry_tg(node) rb_entry((node), struct throtl_grp, rb_node)
4242

4343
struct throtl_grp {
44-
/* List of throtl groups on the request queue*/
45-
struct hlist_node tg_node;
46-
4744
/* active throtl group service_tree member */
4845
struct rb_node rb_node;
4946

@@ -83,9 +80,6 @@ struct throtl_grp {
8380

8481
struct throtl_data
8582
{
86-
/* List of throtl groups */
87-
struct hlist_head tg_list;
88-
8983
/* service tree for active throtl groups */
9084
struct throtl_rb_root tg_service_tree;
9185

@@ -152,7 +146,6 @@ static void throtl_init_blkio_group(struct blkio_group *blkg)
152146
{
153147
struct throtl_grp *tg = blkg_to_tg(blkg);
154148

155-
INIT_HLIST_NODE(&tg->tg_node);
156149
RB_CLEAR_NODE(&tg->rb_node);
157150
bio_list_init(&tg->bio_lists[0]);
158151
bio_list_init(&tg->bio_lists[1]);
@@ -167,11 +160,9 @@ static void throtl_init_blkio_group(struct blkio_group *blkg)
167160
static void throtl_link_blkio_group(struct request_queue *q,
168161
struct blkio_group *blkg)
169162
{
170-
struct throtl_data *td = q->td;
171-
struct throtl_grp *tg = blkg_to_tg(blkg);
172-
173-
hlist_add_head(&tg->tg_node, &td->tg_list);
174-
td->nr_undestroyed_grps++;
163+
list_add(&blkg->q_node[BLKIO_POLICY_THROTL],
164+
&q->blkg_list[BLKIO_POLICY_THROTL]);
165+
q->nr_blkgs[BLKIO_POLICY_THROTL]++;
175166
}
176167

177168
static struct
@@ -711,8 +702,8 @@ static int throtl_select_dispatch(struct throtl_data *td, struct bio_list *bl)
711702

712703
static void throtl_process_limit_change(struct throtl_data *td)
713704
{
714-
struct throtl_grp *tg;
715-
struct hlist_node *pos, *n;
705+
struct request_queue *q = td->queue;
706+
struct blkio_group *blkg, *n;
716707

717708
if (!td->limits_changed)
718709
return;
@@ -721,7 +712,10 @@ static void throtl_process_limit_change(struct throtl_data *td)
721712

722713
throtl_log(td, "limits changed");
723714

724-
hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
715+
list_for_each_entry_safe(blkg, n, &q->blkg_list[BLKIO_POLICY_THROTL],
716+
q_node[BLKIO_POLICY_THROTL]) {
717+
struct throtl_grp *tg = blkg_to_tg(blkg);
718+
725719
if (!tg->limits_changed)
726720
continue;
727721

@@ -822,26 +816,31 @@ throtl_schedule_delayed_work(struct throtl_data *td, unsigned long delay)
822816
static void
823817
throtl_destroy_tg(struct throtl_data *td, struct throtl_grp *tg)
824818
{
819+
struct blkio_group *blkg = tg_to_blkg(tg);
820+
825821
/* Something wrong if we are trying to remove same group twice */
826-
BUG_ON(hlist_unhashed(&tg->tg_node));
822+
WARN_ON_ONCE(list_empty(&blkg->q_node[BLKIO_POLICY_THROTL]));
827823

828-
hlist_del_init(&tg->tg_node);
824+
list_del_init(&blkg->q_node[BLKIO_POLICY_THROTL]);
829825

830826
/*
831827
* Put the reference taken at the time of creation so that when all
832828
* queues are gone, group can be destroyed.
833829
*/
834830
blkg_put(tg_to_blkg(tg));
835-
td->nr_undestroyed_grps--;
831+
td->queue->nr_blkgs[BLKIO_POLICY_THROTL]--;
836832
}
837833

838834
static bool throtl_release_tgs(struct throtl_data *td, bool release_root)
839835
{
840-
struct hlist_node *pos, *n;
841-
struct throtl_grp *tg;
836+
struct request_queue *q = td->queue;
837+
struct blkio_group *blkg, *n;
842838
bool empty = true;
843839

844-
hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
840+
list_for_each_entry_safe(blkg, n, &q->blkg_list[BLKIO_POLICY_THROTL],
841+
q_node[BLKIO_POLICY_THROTL]) {
842+
struct throtl_grp *tg = blkg_to_tg(blkg);
843+
845844
/* skip root? */
846845
if (!release_root && tg == td->root_tg)
847846
continue;
@@ -851,7 +850,7 @@ static bool throtl_release_tgs(struct throtl_data *td, bool release_root)
851850
* it from cgroup list, then it will take care of destroying
852851
* cfqg also.
853852
*/
854-
if (!blkiocg_del_blkio_group(tg_to_blkg(tg)))
853+
if (!blkiocg_del_blkio_group(blkg))
855854
throtl_destroy_tg(td, tg);
856855
else
857856
empty = false;
@@ -1114,7 +1113,6 @@ int blk_throtl_init(struct request_queue *q)
11141113
if (!td)
11151114
return -ENOMEM;
11161115

1117-
INIT_HLIST_HEAD(&td->tg_list);
11181116
td->tg_service_tree = THROTL_RB_ROOT;
11191117
td->limits_changed = false;
11201118
INIT_DELAYED_WORK(&td->throtl_work, blk_throtl_work);
@@ -1144,7 +1142,7 @@ int blk_throtl_init(struct request_queue *q)
11441142
void blk_throtl_exit(struct request_queue *q)
11451143
{
11461144
struct throtl_data *td = q->td;
1147-
bool wait = false;
1145+
bool wait;
11481146

11491147
BUG_ON(!td);
11501148

@@ -1154,8 +1152,7 @@ void blk_throtl_exit(struct request_queue *q)
11541152
throtl_release_tgs(td, true);
11551153

11561154
/* If there are other groups */
1157-
if (td->nr_undestroyed_grps > 0)
1158-
wait = true;
1155+
wait = q->nr_blkgs[BLKIO_POLICY_THROTL];
11591156

11601157
spin_unlock_irq(q->queue_lock);
11611158

‎block/cfq-iosched.c‎

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ struct cfq_group {
208208
unsigned long saved_workload_slice;
209209
enum wl_type_t saved_workload;
210210
enum wl_prio_t saved_serving_prio;
211-
#ifdef CONFIG_CFQ_GROUP_IOSCHED
212-
struct hlist_node cfqd_node;
213-
#endif
211+
214212
/* number of requests that are on the dispatch list or inside driver */
215213
int dispatched;
216214
struct cfq_ttime ttime;
@@ -302,12 +300,6 @@ struct cfq_data {
302300
struct cfq_queue oom_cfqq;
303301

304302
unsigned long last_delayed_sync;
305-
306-
/* List of cfq groups being managed on this device*/
307-
struct hlist_head cfqg_list;
308-
309-
/* Number of groups which are on blkcg->blkg_list */
310-
unsigned int nr_blkcg_linked_grps;
311303
};
312304

313305
static inline struct cfq_group *blkg_to_cfqg(struct blkio_group *blkg)
@@ -1056,13 +1048,9 @@ static void cfq_update_blkio_group_weight(struct request_queue *q,
10561048
static void cfq_link_blkio_group(struct request_queue *q,
10571049
struct blkio_group *blkg)
10581050
{
1059-
struct cfq_data *cfqd = q->elevator->elevator_data;
1060-
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
1061-
1062-
cfqd->nr_blkcg_linked_grps++;
1063-
1064-
/* Add group on cfqd list */
1065-
hlist_add_head(&cfqg->cfqd_node, &cfqd->cfqg_list);
1051+
list_add(&blkg->q_node[BLKIO_POLICY_PROP],
1052+
&q->blkg_list[BLKIO_POLICY_PROP]);
1053+
q->nr_blkgs[BLKIO_POLICY_PROP]++;
10661054
}
10671055

10681056
static void cfq_init_blkio_group(struct blkio_group *blkg)
@@ -1110,13 +1098,15 @@ static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg)
11101098

11111099
static void cfq_destroy_cfqg(struct cfq_data *cfqd, struct cfq_group *cfqg)
11121100
{
1101+
struct blkio_group *blkg = cfqg_to_blkg(cfqg);
1102+
11131103
/* Something wrong if we are trying to remove same group twice */
1114-
BUG_ON(hlist_unhashed(&cfqg->cfqd_node));
1104+
BUG_ON(list_empty(&blkg->q_node[BLKIO_POLICY_PROP]));
11151105

1116-
hlist_del_init(&cfqg->cfqd_node);
1106+
list_del_init(&blkg->q_node[BLKIO_POLICY_PROP]);
11171107

1118-
BUG_ON(cfqd->nr_blkcg_linked_grps <= 0);
1119-
cfqd->nr_blkcg_linked_grps--;
1108+
BUG_ON(cfqd->queue->nr_blkgs[BLKIO_POLICY_PROP] <= 0);
1109+
cfqd->queue->nr_blkgs[BLKIO_POLICY_PROP]--;
11201110

11211111
/*
11221112
* Put the reference taken at the time of creation so that when all
@@ -1127,18 +1117,19 @@ static void cfq_destroy_cfqg(struct cfq_data *cfqd, struct cfq_group *cfqg)
11271117

11281118
static bool cfq_release_cfq_groups(struct cfq_data *cfqd)
11291119
{
1130-
struct hlist_node *pos, *n;
1131-
struct cfq_group *cfqg;
1120+
struct request_queue *q = cfqd->queue;
1121+
struct blkio_group *blkg, *n;
11321122
bool empty = true;
11331123

1134-
hlist_for_each_entry_safe(cfqg, pos, n, &cfqd->cfqg_list, cfqd_node) {
1124+
list_for_each_entry_safe(blkg, n, &q->blkg_list[BLKIO_POLICY_PROP],
1125+
q_node[BLKIO_POLICY_PROP]) {
11351126
/*
11361127
* If cgroup removal path got to blk_group first and removed
11371128
* it from cgroup list, then it will take care of destroying
11381129
* cfqg also.
11391130
*/
1140-
if (!cfq_blkiocg_del_blkio_group(cfqg_to_blkg(cfqg)))
1141-
cfq_destroy_cfqg(cfqd, cfqg);
1131+
if (!cfq_blkiocg_del_blkio_group(blkg))
1132+
cfq_destroy_cfqg(cfqd, blkg_to_cfqg(blkg));
11421133
else
11431134
empty = false;
11441135
}
@@ -3558,13 +3549,13 @@ static void cfq_exit_queue(struct elevator_queue *e)
35583549
cfq_put_async_queues(cfqd);
35593550
cfq_release_cfq_groups(cfqd);
35603551

3552+
#ifdef CONFIG_BLK_CGROUP
35613553
/*
35623554
* If there are groups which we could not unlink from blkcg list,
35633555
* wait for a rcu period for them to be freed.
35643556
*/
3565-
if (cfqd->nr_blkcg_linked_grps)
3566-
wait = true;
3567-
3557+
wait = q->nr_blkgs[BLKIO_POLICY_PROP];
3558+
#endif
35683559
spin_unlock_irq(q->queue_lock);
35693560

35703561
cfq_shutdown_timer_wq(cfqd);

‎include/linux/blkdev.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ struct request_queue {
362362
struct list_head timeout_list;
363363

364364
struct list_head icq_list;
365+
#ifdef CONFIG_BLK_CGROUP
366+
/* XXX: array size hardcoded to avoid include dependency (temporary) */
367+
struct list_head blkg_list[2];
368+
int nr_blkgs[2];
369+
#endif
365370

366371
struct queue_limits limits;
367372

0 commit comments

Comments
 (0)