blkcg: make blkcg_print_blkgs() grab q locks instead of blkcg lock
Instead of holding blkcg->lock while walking ->blkg_list and executing prfill(), RCU walk ->blkg_list and hold the blkg's queue lock while executing prfill(). This makes prfill() implementations easier as stats are mostly protected by queue lock. This will be used to implement hierarchical stats. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
parent
548bc8e1b3
commit
810ecfa765
1 changed files with 9 additions and 5 deletions
|
@ -504,8 +504,9 @@ static const char *blkg_dev_name(struct blkcg_gq *blkg)
|
||||||
*
|
*
|
||||||
* This function invokes @prfill on each blkg of @blkcg if pd for the
|
* This function invokes @prfill on each blkg of @blkcg if pd for the
|
||||||
* policy specified by @pol exists. @prfill is invoked with @sf, the
|
* policy specified by @pol exists. @prfill is invoked with @sf, the
|
||||||
* policy data and @data. If @show_total is %true, the sum of the return
|
* policy data and @data and the matching queue lock held. If @show_total
|
||||||
* values from @prfill is printed with "Total" label at the end.
|
* is %true, the sum of the return values from @prfill is printed with
|
||||||
|
* "Total" label at the end.
|
||||||
*
|
*
|
||||||
* This is to be used to construct print functions for
|
* This is to be used to construct print functions for
|
||||||
* cftype->read_seq_string method.
|
* cftype->read_seq_string method.
|
||||||
|
@ -520,11 +521,14 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
|
||||||
struct hlist_node *n;
|
struct hlist_node *n;
|
||||||
u64 total = 0;
|
u64 total = 0;
|
||||||
|
|
||||||
spin_lock_irq(&blkcg->lock);
|
rcu_read_lock();
|
||||||
hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
|
hlist_for_each_entry_rcu(blkg, n, &blkcg->blkg_list, blkcg_node) {
|
||||||
|
spin_lock_irq(blkg->q->queue_lock);
|
||||||
if (blkcg_policy_enabled(blkg->q, pol))
|
if (blkcg_policy_enabled(blkg->q, pol))
|
||||||
total += prfill(sf, blkg->pd[pol->plid], data);
|
total += prfill(sf, blkg->pd[pol->plid], data);
|
||||||
spin_unlock_irq(&blkcg->lock);
|
spin_unlock_irq(blkg->q->queue_lock);
|
||||||
|
}
|
||||||
|
rcu_read_unlock();
|
||||||
|
|
||||||
if (show_total)
|
if (show_total)
|
||||||
seq_printf(sf, "Total %llu\n", (unsigned long long)total);
|
seq_printf(sf, "Total %llu\n", (unsigned long long)total);
|
||||||
|
|
Loading…
Add table
Reference in a new issue