Skip to content

Commit 36805aa

Browse files
committed
Merge branch 'for-3.11/core' of git://git.kernel.dk/linux-block
Pull core block IO updates from Jens Axboe: "Here are the core IO block bits for 3.11. It contains: - A tweak to the reserved tag logic from Jan, for weirdo devices with just 3 free tags. But for those it improves things substantially for random writes. - Periodic writeback fix from Jan. Marked for stable as well. - Fix for a race condition in IO scheduler switching from Jianpeng. - The hierarchical blk-cgroup support from Tejun. This is the grunt of the series. - blk-throttle fix from Vivek. Just a note that I'm in the middle of a relocation, whole family is flying out tomorrow. Hence I will be awal the remainder of this week, but back at work again on Monday the 15th. CC'ing Tejun, since any potential "surprises" will most likely be from the blk-cgroup work. But it's been brewing for a while and sitting in my tree and linux-next for a long time, so should be solid." * 'for-3.11/core' of git://git.kernel.dk/linux-block: (36 commits) elevator: Fix a race in elevator switching block: Reserve only one queue tag for sync IO if only 3 tags are available writeback: Fix periodic writeback after fs mount blk-throttle: implement proper hierarchy support blk-throttle: implement throtl_grp->has_rules[] blk-throttle: Account for child group's start time in parent while bio climbs up blk-throttle: add throtl_qnode for dispatch fairness blk-throttle: make throtl_pending_timer_fn() ready for hierarchy blk-throttle: make tg_dispatch_one_bio() ready for hierarchy blk-throttle: make blk_throtl_bio() ready for hierarchy blk-throttle: make blk_throtl_drain() ready for hierarchy blk-throttle: dispatch from throtl_pending_timer_fn() blk-throttle: implement dispatch looping blk-throttle: separate out throtl_service_queue->pending_timer from throtl_data->dispatch_work blk-throttle: set REQ_THROTTLED from throtl_charge_bio() and gate stats update with it blk-throttle: implement sq_to_tg(), sq_to_td() and throtl_log() blk-throttle: add throtl_service_queue->parent_sq blk-throttle: generalize update_disptime optimization in blk_throtl_bio() blk-throttle: dispatch to throtl_data->service_queue.bio_lists[] blk-throttle: move bio_lists[] and friends to throtl_service_queue ...
2 parents 6d2fa9e + d50235b commit 36805aa

12 files changed

Lines changed: 905 additions & 434 deletions

File tree

‎Documentation/cgroups/blkio-controller.txt‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,33 +94,34 @@ Throttling/Upper Limit policy
9494

9595
Hierarchical Cgroups
9696
====================
97-
- Currently only CFQ supports hierarchical groups. For throttling,
98-
cgroup interface does allow creation of hierarchical cgroups and
99-
internally it treats them as flat hierarchy.
10097

101-
If somebody created a hierarchy like as follows.
98+
Both CFQ and throttling implement hierarchy support; however,
99+
throttling's hierarchy support is enabled iff "sane_behavior" is
100+
enabled from cgroup side, which currently is a development option and
101+
not publicly available.
102+
103+
If somebody created a hierarchy like as follows.
102104

103105
root
104106
/ \
105107
test1 test2
106108
|
107109
test3
108110

109-
CFQ will handle the hierarchy correctly but and throttling will
110-
practically treat all groups at same level. For details on CFQ
111-
hierarchy support, refer to Documentation/block/cfq-iosched.txt.
112-
Throttling will treat the hierarchy as if it looks like the
113-
following.
111+
CFQ by default and throttling with "sane_behavior" will handle the
112+
hierarchy correctly. For details on CFQ hierarchy support, refer to
113+
Documentation/block/cfq-iosched.txt. For throttling, all limits apply
114+
to the whole subtree while all statistics are local to the IOs
115+
directly generated by tasks in that cgroup.
116+
117+
Throttling without "sane_behavior" enabled from cgroup side will
118+
practically treat all groups at same level as if it looks like the
119+
following.
114120

115121
pivot
116122
/ / \ \
117123
root test1 test2 test3
118124

119-
Nesting cgroups, while allowed, isn't officially supported and blkio
120-
genereates warning when cgroups nest. Once throttling implements
121-
hierarchy support, hierarchy will be supported and the warning will
122-
be removed.
123-
124125
Various user visible config options
125126
===================================
126127
CONFIG_BLK_CGROUP

‎block/blk-cgroup.c‎

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,6 @@ EXPORT_SYMBOL_GPL(blkcg_root);
3232

3333
static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS];
3434

35-
static struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
36-
struct request_queue *q, bool update_hint);
37-
38-
/**
39-
* blkg_for_each_descendant_pre - pre-order walk of a blkg's descendants
40-
* @d_blkg: loop cursor pointing to the current descendant
41-
* @pos_cgrp: used for iteration
42-
* @p_blkg: target blkg to walk descendants of
43-
*
44-
* Walk @c_blkg through the descendants of @p_blkg. Must be used with RCU
45-
* read locked. If called under either blkcg or queue lock, the iteration
46-
* is guaranteed to include all and only online blkgs. The caller may
47-
* update @pos_cgrp by calling cgroup_rightmost_descendant() to skip
48-
* subtree.
49-
*/
50-
#define blkg_for_each_descendant_pre(d_blkg, pos_cgrp, p_blkg) \
51-
cgroup_for_each_descendant_pre((pos_cgrp), (p_blkg)->blkcg->css.cgroup) \
52-
if (((d_blkg) = __blkg_lookup(cgroup_to_blkcg(pos_cgrp), \
53-
(p_blkg)->q, false)))
54-
5535
static bool blkcg_policy_enabled(struct request_queue *q,
5636
const struct blkcg_policy *pol)
5737
{
@@ -71,18 +51,8 @@ static void blkg_free(struct blkcg_gq *blkg)
7151
if (!blkg)
7252
return;
7353

74-
for (i = 0; i < BLKCG_MAX_POLS; i++) {
75-
struct blkcg_policy *pol = blkcg_policy[i];
76-
struct blkg_policy_data *pd = blkg->pd[i];
77-
78-
if (!pd)
79-
continue;
80-
81-
if (pol && pol->pd_exit_fn)
82-
pol->pd_exit_fn(blkg);
83-
84-
kfree(pd);
85-
}
54+
for (i = 0; i < BLKCG_MAX_POLS; i++)
55+
kfree(blkg->pd[i]);
8656

8757
blk_exit_rl(&blkg->rl);
8858
kfree(blkg);
@@ -134,10 +104,6 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
134104
blkg->pd[i] = pd;
135105
pd->blkg = blkg;
136106
pd->plid = i;
137-
138-
/* invoke per-policy init */
139-
if (pol->pd_init_fn)
140-
pol->pd_init_fn(blkg);
141107
}
142108

143109
return blkg;
@@ -158,8 +124,8 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
158124
* @q's bypass state. If @update_hint is %true, the caller should be
159125
* holding @q->queue_lock and lookup hint is updated on success.
160126
*/
161-
static struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
162-
struct request_queue *q, bool update_hint)
127+
struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg, struct request_queue *q,
128+
bool update_hint)
163129
{
164130
struct blkcg_gq *blkg;
165131

@@ -234,16 +200,25 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
234200
}
235201
blkg = new_blkg;
236202

237-
/* link parent and insert */
203+
/* link parent */
238204
if (blkcg_parent(blkcg)) {
239205
blkg->parent = __blkg_lookup(blkcg_parent(blkcg), q, false);
240206
if (WARN_ON_ONCE(!blkg->parent)) {
241-
blkg = ERR_PTR(-EINVAL);
207+
ret = -EINVAL;
242208
goto err_put_css;
243209
}
244210
blkg_get(blkg->parent);
245211
}
246212

213+
/* invoke per-policy init */
214+
for (i = 0; i < BLKCG_MAX_POLS; i++) {
215+
struct blkcg_policy *pol = blkcg_policy[i];
216+
217+
if (blkg->pd[i] && pol->pd_init_fn)
218+
pol->pd_init_fn(blkg);
219+
}
220+
221+
/* insert */
247222
spin_lock(&blkcg->lock);
248223
ret = radix_tree_insert(&blkcg->blkg_tree, q->id, blkg);
249224
if (likely(!ret)) {
@@ -394,30 +369,38 @@ static void blkg_destroy_all(struct request_queue *q)
394369
q->root_rl.blkg = NULL;
395370
}
396371

397-
static void blkg_rcu_free(struct rcu_head *rcu_head)
372+
/*
373+
* A group is RCU protected, but having an rcu lock does not mean that one
374+
* can access all the fields of blkg and assume these are valid. For
375+
* example, don't try to follow throtl_data and request queue links.
376+
*
377+
* Having a reference to blkg under an rcu allows accesses to only values
378+
* local to groups like group stats and group rate limits.
379+
*/
380+
void __blkg_release_rcu(struct rcu_head *rcu_head)
398381
{
399-
blkg_free(container_of(rcu_head, struct blkcg_gq, rcu_head));
400-
}
382+
struct blkcg_gq *blkg = container_of(rcu_head, struct blkcg_gq, rcu_head);
383+
int i;
384+
385+
/* tell policies that this one is being freed */
386+
for (i = 0; i < BLKCG_MAX_POLS; i++) {
387+
struct blkcg_policy *pol = blkcg_policy[i];
388+
389+
if (blkg->pd[i] && pol->pd_exit_fn)
390+
pol->pd_exit_fn(blkg);
391+
}
401392

402-
void __blkg_release(struct blkcg_gq *blkg)
403-
{
404393
/* release the blkcg and parent blkg refs this blkg has been holding */
405394
css_put(&blkg->blkcg->css);
406-
if (blkg->parent)
395+
if (blkg->parent) {
396+
spin_lock_irq(blkg->q->queue_lock);
407397
blkg_put(blkg->parent);
398+
spin_unlock_irq(blkg->q->queue_lock);
399+
}
408400

409-
/*
410-
* A group is freed in rcu manner. But having an rcu lock does not
411-
* mean that one can access all the fields of blkg and assume these
412-
* are valid. For example, don't try to follow throtl_data and
413-
* request queue links.
414-
*
415-
* Having a reference to blkg under an rcu allows acess to only
416-
* values local to groups like group stats and group rate limits
417-
*/
418-
call_rcu(&blkg->rcu_head, blkg_rcu_free);
401+
blkg_free(blkg);
419402
}
420-
EXPORT_SYMBOL_GPL(__blkg_release);
403+
EXPORT_SYMBOL_GPL(__blkg_release_rcu);
421404

422405
/*
423406
* The next function used by blk_queue_for_each_rl(). It's a bit tricky
@@ -928,14 +911,6 @@ struct cgroup_subsys blkio_subsys = {
928911
.subsys_id = blkio_subsys_id,
929912
.base_cftypes = blkcg_files,
930913
.module = THIS_MODULE,
931-
932-
/*
933-
* blkio subsystem is utterly broken in terms of hierarchy support.
934-
* It treats all cgroups equally regardless of where they're
935-
* located in the hierarchy - all cgroups are treated as if they're
936-
* right below the root. Fix it and remove the following.
937-
*/
938-
.broken_hierarchy = true,
939914
};
940915
EXPORT_SYMBOL_GPL(blkio_subsys);
941916

‎block/blk-cgroup.h‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static inline void blkg_get(struct blkcg_gq *blkg)
266266
blkg->refcnt++;
267267
}
268268

269-
void __blkg_release(struct blkcg_gq *blkg);
269+
void __blkg_release_rcu(struct rcu_head *rcu);
270270

271271
/**
272272
* blkg_put - put a blkg reference
@@ -279,9 +279,43 @@ static inline void blkg_put(struct blkcg_gq *blkg)
279279
lockdep_assert_held(blkg->q->queue_lock);
280280
WARN_ON_ONCE(blkg->refcnt <= 0);
281281
if (!--blkg->refcnt)
282-
__blkg_release(blkg);
282+
call_rcu(&blkg->rcu_head, __blkg_release_rcu);
283283
}
284284

285+
struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg, struct request_queue *q,
286+
bool update_hint);
287+
288+
/**
289+
* blkg_for_each_descendant_pre - pre-order walk of a blkg's descendants
290+
* @d_blkg: loop cursor pointing to the current descendant
291+
* @pos_cgrp: used for iteration
292+
* @p_blkg: target blkg to walk descendants of
293+
*
294+
* Walk @c_blkg through the descendants of @p_blkg. Must be used with RCU
295+
* read locked. If called under either blkcg or queue lock, the iteration
296+
* is guaranteed to include all and only online blkgs. The caller may
297+
* update @pos_cgrp by calling cgroup_rightmost_descendant() to skip
298+
* subtree.
299+
*/
300+
#define blkg_for_each_descendant_pre(d_blkg, pos_cgrp, p_blkg) \
301+
cgroup_for_each_descendant_pre((pos_cgrp), (p_blkg)->blkcg->css.cgroup) \
302+
if (((d_blkg) = __blkg_lookup(cgroup_to_blkcg(pos_cgrp), \
303+
(p_blkg)->q, false)))
304+
305+
/**
306+
* blkg_for_each_descendant_post - post-order walk of a blkg's descendants
307+
* @d_blkg: loop cursor pointing to the current descendant
308+
* @pos_cgrp: used for iteration
309+
* @p_blkg: target blkg to walk descendants of
310+
*
311+
* Similar to blkg_for_each_descendant_pre() but performs post-order
312+
* traversal instead. Synchronization rules are the same.
313+
*/
314+
#define blkg_for_each_descendant_post(d_blkg, pos_cgrp, p_blkg) \
315+
cgroup_for_each_descendant_post((pos_cgrp), (p_blkg)->blkcg->css.cgroup) \
316+
if (((d_blkg) = __blkg_lookup(cgroup_to_blkcg(pos_cgrp), \
317+
(p_blkg)->q, false)))
318+
285319
/**
286320
* blk_get_rl - get request_list to use
287321
* @q: request_queue of interest

‎block/blk-tag.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,16 @@ int blk_queue_start_tag(struct request_queue *q, struct request *rq)
348348
*/
349349
max_depth = bqt->max_depth;
350350
if (!rq_is_sync(rq) && max_depth > 1) {
351-
max_depth -= 2;
352-
if (!max_depth)
351+
switch (max_depth) {
352+
case 2:
353353
max_depth = 1;
354+
break;
355+
case 3:
356+
max_depth = 2;
357+
break;
358+
default:
359+
max_depth -= 2;
360+
}
354361
if (q->in_flight[BLK_RW_ASYNC] > max_depth)
355362
return 1;
356363
}

0 commit comments

Comments
 (0)