2019-04-30 18:42:40 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-04-19 14:48:24 +00:00
|
|
|
/*
|
|
|
|
* cgroups support for the BFQ I/O scheduler.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/cgroup.h>
|
|
|
|
#include <linux/elevator.h>
|
|
|
|
#include <linux/ktime.h>
|
|
|
|
#include <linux/rbtree.h>
|
|
|
|
#include <linux/ioprio.h>
|
|
|
|
#include <linux/sbitmap.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
|
|
|
#include "bfq-iosched.h"
|
|
|
|
|
2019-06-06 10:26:24 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
2019-06-06 10:26:22 +00:00
|
|
|
static int bfq_stat_init(struct bfq_stat *stat, gfp_t gfp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = percpu_counter_init(&stat->cpu_cnt, 0, gfp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
atomic64_set(&stat->aux_cnt, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfq_stat_exit(struct bfq_stat *stat)
|
|
|
|
{
|
|
|
|
percpu_counter_destroy(&stat->cpu_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_stat_add - add a value to a bfq_stat
|
|
|
|
* @stat: target bfq_stat
|
|
|
|
* @val: value to add
|
|
|
|
*
|
|
|
|
* Add @val to @stat. The caller must ensure that IRQ on the same CPU
|
|
|
|
* don't re-enter this function for the same counter.
|
|
|
|
*/
|
|
|
|
static inline void bfq_stat_add(struct bfq_stat *stat, uint64_t val)
|
|
|
|
{
|
|
|
|
percpu_counter_add_batch(&stat->cpu_cnt, val, BLKG_STAT_CPU_BATCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_stat_read - read the current value of a bfq_stat
|
|
|
|
* @stat: bfq_stat to read
|
|
|
|
*/
|
|
|
|
static inline uint64_t bfq_stat_read(struct bfq_stat *stat)
|
|
|
|
{
|
|
|
|
return percpu_counter_sum_positive(&stat->cpu_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_stat_reset - reset a bfq_stat
|
|
|
|
* @stat: bfq_stat to reset
|
|
|
|
*/
|
|
|
|
static inline void bfq_stat_reset(struct bfq_stat *stat)
|
|
|
|
{
|
|
|
|
percpu_counter_set(&stat->cpu_cnt, 0);
|
|
|
|
atomic64_set(&stat->aux_cnt, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_stat_add_aux - add a bfq_stat into another's aux count
|
|
|
|
* @to: the destination bfq_stat
|
|
|
|
* @from: the source
|
|
|
|
*
|
|
|
|
* Add @from's count including the aux one to @to's aux count.
|
|
|
|
*/
|
|
|
|
static inline void bfq_stat_add_aux(struct bfq_stat *to,
|
|
|
|
struct bfq_stat *from)
|
|
|
|
{
|
|
|
|
atomic64_add(bfq_stat_read(from) + atomic64_read(&from->aux_cnt),
|
|
|
|
&to->aux_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blkg_prfill_stat - prfill callback for bfq_stat
|
|
|
|
* @sf: seq_file to print to
|
|
|
|
* @pd: policy private data of interest
|
|
|
|
* @off: offset to the bfq_stat in @pd
|
|
|
|
*
|
|
|
|
* prfill callback for printing a bfq_stat.
|
|
|
|
*/
|
|
|
|
static u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd,
|
|
|
|
int off)
|
|
|
|
{
|
|
|
|
return __blkg_prfill_u64(sf, pd, bfq_stat_read((void *)pd + off));
|
|
|
|
}
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
/* bfqg stats flags */
|
|
|
|
enum bfqg_stats_flags {
|
|
|
|
BFQG_stats_waiting = 0,
|
|
|
|
BFQG_stats_idling,
|
|
|
|
BFQG_stats_empty,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BFQG_FLAG_FNS(name) \
|
|
|
|
static void bfqg_stats_mark_##name(struct bfqg_stats *stats) \
|
|
|
|
{ \
|
|
|
|
stats->flags |= (1 << BFQG_stats_##name); \
|
|
|
|
} \
|
|
|
|
static void bfqg_stats_clear_##name(struct bfqg_stats *stats) \
|
|
|
|
{ \
|
|
|
|
stats->flags &= ~(1 << BFQG_stats_##name); \
|
|
|
|
} \
|
|
|
|
static int bfqg_stats_##name(struct bfqg_stats *stats) \
|
|
|
|
{ \
|
|
|
|
return (stats->flags & (1 << BFQG_stats_##name)) != 0; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
BFQG_FLAG_FNS(waiting)
|
|
|
|
BFQG_FLAG_FNS(idling)
|
|
|
|
BFQG_FLAG_FNS(empty)
|
|
|
|
#undef BFQG_FLAG_FNS
|
|
|
|
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
/* This should be called with the scheduler lock held. */
|
2017-04-19 14:48:24 +00:00
|
|
|
static void bfqg_stats_update_group_wait_time(struct bfqg_stats *stats)
|
|
|
|
{
|
2018-05-09 09:08:51 +00:00
|
|
|
u64 now;
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
if (!bfqg_stats_waiting(stats))
|
|
|
|
return;
|
|
|
|
|
2018-05-09 09:08:51 +00:00
|
|
|
now = ktime_get_ns();
|
|
|
|
if (now > stats->start_group_wait_time)
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add(&stats->group_wait_time,
|
2017-04-19 14:48:24 +00:00
|
|
|
now - stats->start_group_wait_time);
|
|
|
|
bfqg_stats_clear_waiting(stats);
|
|
|
|
}
|
|
|
|
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
/* This should be called with the scheduler lock held. */
|
2017-04-19 14:48:24 +00:00
|
|
|
static void bfqg_stats_set_start_group_wait_time(struct bfq_group *bfqg,
|
|
|
|
struct bfq_group *curr_bfqg)
|
|
|
|
{
|
|
|
|
struct bfqg_stats *stats = &bfqg->stats;
|
|
|
|
|
|
|
|
if (bfqg_stats_waiting(stats))
|
|
|
|
return;
|
|
|
|
if (bfqg == curr_bfqg)
|
|
|
|
return;
|
2018-05-09 09:08:51 +00:00
|
|
|
stats->start_group_wait_time = ktime_get_ns();
|
2017-04-19 14:48:24 +00:00
|
|
|
bfqg_stats_mark_waiting(stats);
|
|
|
|
}
|
|
|
|
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
/* This should be called with the scheduler lock held. */
|
2017-04-19 14:48:24 +00:00
|
|
|
static void bfqg_stats_end_empty_time(struct bfqg_stats *stats)
|
|
|
|
{
|
2018-05-09 09:08:51 +00:00
|
|
|
u64 now;
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
if (!bfqg_stats_empty(stats))
|
|
|
|
return;
|
|
|
|
|
2018-05-09 09:08:51 +00:00
|
|
|
now = ktime_get_ns();
|
|
|
|
if (now > stats->start_empty_time)
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add(&stats->empty_time,
|
2017-04-19 14:48:24 +00:00
|
|
|
now - stats->start_empty_time);
|
|
|
|
bfqg_stats_clear_empty(stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_stats_update_dequeue(struct bfq_group *bfqg)
|
|
|
|
{
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add(&bfqg->stats.dequeue, 1);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfqg_stats *stats = &bfqg->stats;
|
|
|
|
|
|
|
|
if (blkg_rwstat_total(&stats->queued))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* group is already marked empty. This can happen if bfqq got new
|
|
|
|
* request in parent group and moved to this group while being added
|
|
|
|
* to service tree. Just ignore the event and move on.
|
|
|
|
*/
|
|
|
|
if (bfqg_stats_empty(stats))
|
|
|
|
return;
|
|
|
|
|
2018-05-09 09:08:51 +00:00
|
|
|
stats->start_empty_time = ktime_get_ns();
|
2017-04-19 14:48:24 +00:00
|
|
|
bfqg_stats_mark_empty(stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_stats_update_idle_time(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfqg_stats *stats = &bfqg->stats;
|
|
|
|
|
|
|
|
if (bfqg_stats_idling(stats)) {
|
2018-05-09 09:08:51 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2017-04-19 14:48:24 +00:00
|
|
|
|
2018-05-09 09:08:51 +00:00
|
|
|
if (now > stats->start_idle_time)
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add(&stats->idle_time,
|
2017-04-19 14:48:24 +00:00
|
|
|
now - stats->start_idle_time);
|
|
|
|
bfqg_stats_clear_idling(stats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfqg_stats *stats = &bfqg->stats;
|
|
|
|
|
2018-05-09 09:08:51 +00:00
|
|
|
stats->start_idle_time = ktime_get_ns();
|
2017-04-19 14:48:24 +00:00
|
|
|
bfqg_stats_mark_idling(stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfqg_stats *stats = &bfqg->stats;
|
|
|
|
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add(&stats->avg_queue_size_sum,
|
2017-04-19 14:48:24 +00:00
|
|
|
blkg_rwstat_total(&stats->queued));
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add(&stats->avg_queue_size_samples, 1);
|
2017-04-19 14:48:24 +00:00
|
|
|
bfqg_stats_update_group_wait_time(stats);
|
|
|
|
}
|
|
|
|
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
|
|
|
|
unsigned int op)
|
|
|
|
{
|
|
|
|
blkg_rwstat_add(&bfqg->stats.queued, op, 1);
|
|
|
|
bfqg_stats_end_empty_time(&bfqg->stats);
|
|
|
|
if (!(bfqq == ((struct bfq_data *)bfqg->bfqd)->in_service_queue))
|
|
|
|
bfqg_stats_set_start_group_wait_time(bfqg, bfqq_group(bfqq));
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op)
|
|
|
|
{
|
|
|
|
blkg_rwstat_add(&bfqg->stats.queued, op, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op)
|
|
|
|
{
|
|
|
|
blkg_rwstat_add(&bfqg->stats.merged, op, 1);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:08:51 +00:00
|
|
|
void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
|
|
|
|
u64 io_start_time_ns, unsigned int op)
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
{
|
|
|
|
struct bfqg_stats *stats = &bfqg->stats;
|
2018-05-09 09:08:51 +00:00
|
|
|
u64 now = ktime_get_ns();
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
|
2018-05-09 09:08:51 +00:00
|
|
|
if (now > io_start_time_ns)
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
blkg_rwstat_add(&stats->service_time, op,
|
2018-05-09 09:08:51 +00:00
|
|
|
now - io_start_time_ns);
|
|
|
|
if (io_start_time_ns > start_time_ns)
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
blkg_rwstat_add(&stats->wait_time, op,
|
2018-05-09 09:08:51 +00:00
|
|
|
io_start_time_ns - start_time_ns);
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:26:24 +00:00
|
|
|
#else /* CONFIG_BFQ_CGROUP_DEBUG */
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
|
|
|
|
void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
|
|
|
|
unsigned int op) { }
|
|
|
|
void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op) { }
|
|
|
|
void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op) { }
|
2018-05-09 09:08:51 +00:00
|
|
|
void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
|
|
|
|
u64 io_start_time_ns, unsigned int op) { }
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
void bfqg_stats_update_dequeue(struct bfq_group *bfqg) { }
|
|
|
|
void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg) { }
|
|
|
|
void bfqg_stats_update_idle_time(struct bfq_group *bfqg) { }
|
|
|
|
void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg) { }
|
|
|
|
void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg) { }
|
|
|
|
|
2019-06-06 10:26:24 +00:00
|
|
|
#endif /* CONFIG_BFQ_CGROUP_DEBUG */
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_BFQ_GROUP_IOSCHED
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
/*
|
|
|
|
* blk-cgroup policy-related handlers
|
|
|
|
* The following functions help in converting between blk-cgroup
|
|
|
|
* internal structures and BFQ-specific structures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct bfq_group *pd_to_bfqg(struct blkg_policy_data *pd)
|
|
|
|
{
|
|
|
|
return pd ? container_of(pd, struct bfq_group, pd) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
return pd_to_blkg(&bfqg->pd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bfq_group *blkg_to_bfqg(struct blkcg_gq *blkg)
|
|
|
|
{
|
|
|
|
return pd_to_bfqg(blkg_to_pd(blkg, &blkcg_policy_bfq));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bfq_group handlers
|
|
|
|
* The following functions help in navigating the bfq_group hierarchy
|
|
|
|
* by allowing to find the parent of a bfq_group or the bfq_group
|
|
|
|
* associated to a bfq_queue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct bfq_group *bfqg_parent(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct blkcg_gq *pblkg = bfqg_to_blkg(bfqg)->parent;
|
|
|
|
|
|
|
|
return pblkg ? blkg_to_bfqg(pblkg) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bfq_group *bfqq_group(struct bfq_queue *bfqq)
|
|
|
|
{
|
|
|
|
struct bfq_entity *group_entity = bfqq->entity.parent;
|
|
|
|
|
|
|
|
return group_entity ? container_of(group_entity, struct bfq_group,
|
|
|
|
entity) :
|
|
|
|
bfqq->bfqd->root_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following two functions handle get and put of a bfq_group by
|
|
|
|
* wrapping the related blk-cgroup hooks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void bfqg_get(struct bfq_group *bfqg)
|
|
|
|
{
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
bfqg->ref++;
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 18:42:08 +00:00
|
|
|
static void bfqg_put(struct bfq_group *bfqg)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
bfqg->ref--;
|
|
|
|
|
|
|
|
if (bfqg->ref == 0)
|
|
|
|
kfree(bfqg);
|
|
|
|
}
|
|
|
|
|
2020-08-11 06:43:40 +00:00
|
|
|
static void bfqg_and_blkg_get(struct bfq_group *bfqg)
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
{
|
|
|
|
/* see comments in bfq_bic_update_cgroup for why refcounting bfqg */
|
|
|
|
bfqg_get(bfqg);
|
|
|
|
|
|
|
|
blkg_get(bfqg_to_blkg(bfqg));
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfqg_and_blkg_put(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
blkg_put(bfqg_to_blkg(bfqg));
|
2018-09-06 08:05:44 +00:00
|
|
|
|
|
|
|
bfqg_put(bfqg);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 19:18:00 +00:00
|
|
|
void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq)
|
|
|
|
{
|
|
|
|
struct bfq_group *bfqg = blkg_to_bfqg(rq->bio->bi_blkg);
|
|
|
|
|
2019-12-05 12:53:11 +00:00
|
|
|
if (!bfqg)
|
|
|
|
return;
|
|
|
|
|
2019-11-07 19:18:00 +00:00
|
|
|
blkg_rwstat_add(&bfqg->stats.bytes, rq->cmd_flags, blk_rq_bytes(rq));
|
|
|
|
blkg_rwstat_add(&bfqg->stats.ios, rq->cmd_flags, 1);
|
|
|
|
}
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
/* @stats = 0 */
|
|
|
|
static void bfqg_stats_reset(struct bfqg_stats *stats)
|
|
|
|
{
|
2019-06-06 10:26:24 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
2017-04-19 14:48:24 +00:00
|
|
|
/* queued stats shouldn't be cleared */
|
|
|
|
blkg_rwstat_reset(&stats->merged);
|
|
|
|
blkg_rwstat_reset(&stats->service_time);
|
|
|
|
blkg_rwstat_reset(&stats->wait_time);
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_reset(&stats->time);
|
|
|
|
bfq_stat_reset(&stats->avg_queue_size_sum);
|
|
|
|
bfq_stat_reset(&stats->avg_queue_size_samples);
|
|
|
|
bfq_stat_reset(&stats->dequeue);
|
|
|
|
bfq_stat_reset(&stats->group_wait_time);
|
|
|
|
bfq_stat_reset(&stats->idle_time);
|
|
|
|
bfq_stat_reset(&stats->empty_time);
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
#endif
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* @to += @from */
|
|
|
|
static void bfqg_stats_add_aux(struct bfqg_stats *to, struct bfqg_stats *from)
|
|
|
|
{
|
|
|
|
if (!to || !from)
|
|
|
|
return;
|
|
|
|
|
2019-06-06 10:26:24 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
2017-04-19 14:48:24 +00:00
|
|
|
/* queued stats shouldn't be cleared */
|
|
|
|
blkg_rwstat_add_aux(&to->merged, &from->merged);
|
|
|
|
blkg_rwstat_add_aux(&to->service_time, &from->service_time);
|
|
|
|
blkg_rwstat_add_aux(&to->wait_time, &from->wait_time);
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add_aux(&from->time, &from->time);
|
|
|
|
bfq_stat_add_aux(&to->avg_queue_size_sum, &from->avg_queue_size_sum);
|
|
|
|
bfq_stat_add_aux(&to->avg_queue_size_samples,
|
2017-04-19 14:48:24 +00:00
|
|
|
&from->avg_queue_size_samples);
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_add_aux(&to->dequeue, &from->dequeue);
|
|
|
|
bfq_stat_add_aux(&to->group_wait_time, &from->group_wait_time);
|
|
|
|
bfq_stat_add_aux(&to->idle_time, &from->idle_time);
|
|
|
|
bfq_stat_add_aux(&to->empty_time, &from->empty_time);
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
#endif
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer @bfqg's stats to its parent's aux counts so that the ancestors'
|
|
|
|
* recursive stats can still account for the amount used by this bfqg after
|
|
|
|
* it's gone.
|
|
|
|
*/
|
|
|
|
static void bfqg_stats_xfer_dead(struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfq_group *parent;
|
|
|
|
|
|
|
|
if (!bfqg) /* root_group */
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent = bfqg_parent(bfqg);
|
|
|
|
|
2018-11-15 19:17:28 +00:00
|
|
|
lockdep_assert_held(&bfqg_to_blkg(bfqg)->q->queue_lock);
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
if (unlikely(!parent))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bfqg_stats_add_aux(&parent->stats, &bfqg->stats);
|
|
|
|
bfqg_stats_reset(&bfqg->stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
|
|
|
|
|
|
|
|
entity->weight = entity->new_weight;
|
|
|
|
entity->orig_weight = entity->new_weight;
|
|
|
|
if (bfqq) {
|
|
|
|
bfqq->ioprio = bfqq->new_ioprio;
|
|
|
|
bfqq->ioprio_class = bfqq->new_ioprio_class;
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
/*
|
|
|
|
* Make sure that bfqg and its associated blkg do not
|
|
|
|
* disappear before entity.
|
|
|
|
*/
|
|
|
|
bfqg_and_blkg_get(bfqg);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
entity->parent = bfqg->my_entity; /* NULL for root group */
|
|
|
|
entity->sched_data = &bfqg->sched_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfqg_stats_exit(struct bfqg_stats *stats)
|
|
|
|
{
|
2019-11-07 19:18:00 +00:00
|
|
|
blkg_rwstat_exit(&stats->bytes);
|
|
|
|
blkg_rwstat_exit(&stats->ios);
|
2019-06-06 10:26:24 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
2017-04-19 14:48:24 +00:00
|
|
|
blkg_rwstat_exit(&stats->merged);
|
|
|
|
blkg_rwstat_exit(&stats->service_time);
|
|
|
|
blkg_rwstat_exit(&stats->wait_time);
|
|
|
|
blkg_rwstat_exit(&stats->queued);
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_exit(&stats->time);
|
|
|
|
bfq_stat_exit(&stats->avg_queue_size_sum);
|
|
|
|
bfq_stat_exit(&stats->avg_queue_size_samples);
|
|
|
|
bfq_stat_exit(&stats->dequeue);
|
|
|
|
bfq_stat_exit(&stats->group_wait_time);
|
|
|
|
bfq_stat_exit(&stats->idle_time);
|
|
|
|
bfq_stat_exit(&stats->empty_time);
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
#endif
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bfqg_stats_init(struct bfqg_stats *stats, gfp_t gfp)
|
|
|
|
{
|
2019-11-07 19:18:00 +00:00
|
|
|
if (blkg_rwstat_init(&stats->bytes, gfp) ||
|
|
|
|
blkg_rwstat_init(&stats->ios, gfp))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-06-06 10:26:24 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
2017-04-19 14:48:24 +00:00
|
|
|
if (blkg_rwstat_init(&stats->merged, gfp) ||
|
|
|
|
blkg_rwstat_init(&stats->service_time, gfp) ||
|
|
|
|
blkg_rwstat_init(&stats->wait_time, gfp) ||
|
|
|
|
blkg_rwstat_init(&stats->queued, gfp) ||
|
2019-06-06 10:26:22 +00:00
|
|
|
bfq_stat_init(&stats->time, gfp) ||
|
|
|
|
bfq_stat_init(&stats->avg_queue_size_sum, gfp) ||
|
|
|
|
bfq_stat_init(&stats->avg_queue_size_samples, gfp) ||
|
|
|
|
bfq_stat_init(&stats->dequeue, gfp) ||
|
|
|
|
bfq_stat_init(&stats->group_wait_time, gfp) ||
|
|
|
|
bfq_stat_init(&stats->idle_time, gfp) ||
|
|
|
|
bfq_stat_init(&stats->empty_time, gfp)) {
|
2017-04-19 14:48:24 +00:00
|
|
|
bfqg_stats_exit(stats);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
#endif
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bfq_group_data *cpd_to_bfqgd(struct blkcg_policy_data *cpd)
|
|
|
|
{
|
|
|
|
return cpd ? container_of(cpd, struct bfq_group_data, pd) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bfq_group_data *blkcg_to_bfqgd(struct blkcg *blkcg)
|
|
|
|
{
|
|
|
|
return cpd_to_bfqgd(blkcg_to_cpd(blkcg, &blkcg_policy_bfq));
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:42:08 +00:00
|
|
|
static struct blkcg_policy_data *bfq_cpd_alloc(gfp_t gfp)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct bfq_group_data *bgd;
|
|
|
|
|
|
|
|
bgd = kzalloc(sizeof(*bgd), gfp);
|
|
|
|
if (!bgd)
|
|
|
|
return NULL;
|
|
|
|
return &bgd->pd;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:42:08 +00:00
|
|
|
static void bfq_cpd_init(struct blkcg_policy_data *cpd)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct bfq_group_data *d = cpd_to_bfqgd(cpd);
|
|
|
|
|
|
|
|
d->weight = cgroup_subsys_on_dfl(io_cgrp_subsys) ?
|
|
|
|
CGROUP_WEIGHT_DFL : BFQ_WEIGHT_LEGACY_DFL;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:42:08 +00:00
|
|
|
static void bfq_cpd_free(struct blkcg_policy_data *cpd)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
kfree(cpd_to_bfqgd(cpd));
|
|
|
|
}
|
|
|
|
|
2019-08-28 22:05:51 +00:00
|
|
|
static struct blkg_policy_data *bfq_pd_alloc(gfp_t gfp, struct request_queue *q,
|
|
|
|
struct blkcg *blkcg)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct bfq_group *bfqg;
|
|
|
|
|
2019-08-28 22:05:51 +00:00
|
|
|
bfqg = kzalloc_node(sizeof(*bfqg), gfp, q->node);
|
2017-04-19 14:48:24 +00:00
|
|
|
if (!bfqg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (bfqg_stats_init(&bfqg->stats, gfp)) {
|
|
|
|
kfree(bfqg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
/* see comments in bfq_bic_update_cgroup for why refcounting */
|
|
|
|
bfqg_get(bfqg);
|
2017-04-19 14:48:24 +00:00
|
|
|
return &bfqg->pd;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:42:08 +00:00
|
|
|
static void bfq_pd_init(struct blkg_policy_data *pd)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct blkcg_gq *blkg = pd_to_blkg(pd);
|
|
|
|
struct bfq_group *bfqg = blkg_to_bfqg(blkg);
|
|
|
|
struct bfq_data *bfqd = blkg->q->elevator->elevator_data;
|
|
|
|
struct bfq_entity *entity = &bfqg->entity;
|
|
|
|
struct bfq_group_data *d = blkcg_to_bfqgd(blkg->blkcg);
|
|
|
|
|
|
|
|
entity->orig_weight = entity->weight = entity->new_weight = d->weight;
|
|
|
|
entity->my_sched_data = &bfqg->sched_data;
|
block, bfq: merge bursts of newly-created queues
Many throughput-sensitive workloads are made of several parallel I/O
flows, with all flows generated by the same application, or more
generically by the same task (e.g., system boot). The most
counterproductive action with these workloads is plugging I/O dispatch
when one of the bfq_queues associated with these flows remains
temporarily empty.
To avoid this plugging, BFQ has been using a burst-handling mechanism
for years now. This mechanism has proven effective for throughput, and
not detrimental for service guarantees. This commit pushes this
mechanism a little bit further, basing on the following two facts.
First, all the I/O flows of a the same application or task contribute
to the execution/completion of that common application or task. So the
performance figures that matter are total throughput of the flows and
task-wide I/O latency. In particular, these flows do not need to be
protected from each other, in terms of individual bandwidth or
latency.
Second, the above fact holds regardless of the number of flows.
Putting these two facts together, this commits merges stably the
bfq_queues associated with these I/O flows, i.e., with the processes
that generate these IO/ flows, regardless of how many the involved
processes are.
To decide whether a set of bfq_queues is actually associated with the
I/O flows of a common application or task, and to merge these queues
stably, this commit operates as follows: given a bfq_queue, say Q2,
currently being created, and the last bfq_queue, say Q1, created
before Q2, Q2 is merged stably with Q1 if
- very little time has elapsed since when Q1 was created
- Q2 has the same ioprio as Q1
- Q2 belongs to the same group as Q1
Merging bfq_queues also reduces scheduling overhead. A fio test with
ten random readers on /dev/nullb shows a throughput boost of 40%, with
a quadcore. Since BFQ's execution time amounts to ~50% of the total
per-request processing time, the above throughput boost implies that
BFQ's overhead is reduced by more than 50%.
Tested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Link: https://lore.kernel.org/r/20210304174627.161-7-paolo.valente@linaro.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-03-04 17:46:27 +00:00
|
|
|
entity->last_bfqq_created = NULL;
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
bfqg->my_entity = entity; /*
|
|
|
|
* the root_group's will be set to NULL
|
|
|
|
* in bfq_init_queue()
|
|
|
|
*/
|
|
|
|
bfqg->bfqd = bfqd;
|
|
|
|
bfqg->active_entities = 0;
|
|
|
|
bfqg->rq_pos_tree = RB_ROOT;
|
|
|
|
}
|
|
|
|
|
2017-08-30 18:42:08 +00:00
|
|
|
static void bfq_pd_free(struct blkg_policy_data *pd)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct bfq_group *bfqg = pd_to_bfqg(pd);
|
|
|
|
|
|
|
|
bfqg_stats_exit(&bfqg->stats);
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
bfqg_put(bfqg);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
2017-08-30 18:42:08 +00:00
|
|
|
static void bfq_pd_reset_stats(struct blkg_policy_data *pd)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct bfq_group *bfqg = pd_to_bfqg(pd);
|
|
|
|
|
|
|
|
bfqg_stats_reset(&bfqg->stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfq_group_set_parent(struct bfq_group *bfqg,
|
|
|
|
struct bfq_group *parent)
|
|
|
|
{
|
|
|
|
struct bfq_entity *entity;
|
|
|
|
|
|
|
|
entity = &bfqg->entity;
|
|
|
|
entity->parent = parent->my_entity;
|
|
|
|
entity->sched_data = &parent->sched_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bfq_group *bfq_lookup_bfqg(struct bfq_data *bfqd,
|
|
|
|
struct blkcg *blkcg)
|
|
|
|
{
|
|
|
|
struct blkcg_gq *blkg;
|
|
|
|
|
|
|
|
blkg = blkg_lookup(blkcg, bfqd->queue);
|
|
|
|
if (likely(blkg))
|
|
|
|
return blkg_to_bfqg(blkg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd,
|
|
|
|
struct blkcg *blkcg)
|
|
|
|
{
|
|
|
|
struct bfq_group *bfqg, *parent;
|
|
|
|
struct bfq_entity *entity;
|
|
|
|
|
|
|
|
bfqg = bfq_lookup_bfqg(bfqd, blkcg);
|
|
|
|
|
|
|
|
if (unlikely(!bfqg))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update chain of bfq_groups as we might be handling a leaf group
|
|
|
|
* which, along with some of its relatives, has not been hooked yet
|
|
|
|
* to the private hierarchy of BFQ.
|
|
|
|
*/
|
|
|
|
entity = &bfqg->entity;
|
|
|
|
for_each_entity(entity) {
|
2020-03-06 12:27:31 +00:00
|
|
|
struct bfq_group *curr_bfqg = container_of(entity,
|
|
|
|
struct bfq_group, entity);
|
|
|
|
if (curr_bfqg != bfqd->root_group) {
|
|
|
|
parent = bfqg_parent(curr_bfqg);
|
2017-04-19 14:48:24 +00:00
|
|
|
if (!parent)
|
|
|
|
parent = bfqd->root_group;
|
2020-03-06 12:27:31 +00:00
|
|
|
bfq_group_set_parent(curr_bfqg, parent);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfqg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_bfqq_move - migrate @bfqq to @bfqg.
|
|
|
|
* @bfqd: queue descriptor.
|
|
|
|
* @bfqq: the queue to move.
|
|
|
|
* @bfqg: the group to move to.
|
|
|
|
*
|
|
|
|
* Move @bfqq to @bfqg, deactivating it from its old group and reactivating
|
|
|
|
* it on the new one. Avoid putting the entity on the old group idle tree.
|
|
|
|
*
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
* Must be called under the scheduler lock, to make sure that the blkg
|
|
|
|
* owning @bfqg does not disappear (see comments in
|
|
|
|
* bfq_bic_update_cgroup on guaranteeing the consistency of blkg
|
|
|
|
* objects).
|
2017-04-19 14:48:24 +00:00
|
|
|
*/
|
|
|
|
void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
|
|
|
|
struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfq_entity *entity = &bfqq->entity;
|
|
|
|
|
2020-03-21 09:45:18 +00:00
|
|
|
/*
|
|
|
|
* Get extra reference to prevent bfqq from being freed in
|
|
|
|
* next possible expire or deactivate.
|
|
|
|
*/
|
|
|
|
bfqq->ref++;
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
/* If bfqq is empty, then bfq_bfqq_expire also invokes
|
|
|
|
* bfq_del_bfqq_busy, thereby removing bfqq and its entity
|
|
|
|
* from data structures related to current group. Otherwise we
|
|
|
|
* need to remove bfqq explicitly with bfq_deactivate_bfqq, as
|
|
|
|
* we do below.
|
|
|
|
*/
|
|
|
|
if (bfqq == bfqd->in_service_queue)
|
|
|
|
bfq_bfqq_expire(bfqd, bfqd->in_service_queue,
|
|
|
|
false, BFQQE_PREEMPTED);
|
|
|
|
|
|
|
|
if (bfq_bfqq_busy(bfqq))
|
|
|
|
bfq_deactivate_bfqq(bfqd, bfqq, false, false);
|
2020-02-03 10:40:57 +00:00
|
|
|
else if (entity->on_st_or_in_serv)
|
2017-04-19 14:48:24 +00:00
|
|
|
bfq_put_idle_entity(bfq_entity_service_tree(entity), entity);
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
bfqg_and_blkg_put(bfqq_group(bfqq));
|
2017-04-19 14:48:24 +00:00
|
|
|
|
block, bfq: reset last_bfqq_created on group change
Since commit 430a67f9d616 ("block, bfq: merge bursts of newly-created
queues"), BFQ maintains a per-group pointer to the last bfq_queue
created. If such a queue, say bfqq, happens to move to a different
group, then bfqq is no more a valid last bfq_queue created for its
previous group. That pointer must then be cleared. Not resetting such
a pointer may also cause UAF, if bfqq happens to also be freed after
being moved to a different group. This commit performs this missing
reset. As such it fixes commit 430a67f9d616 ("block, bfq: merge bursts
of newly-created queues").
Such a missing reset is most likely the cause of the crash reported in [1].
With some analysis, we found that this crash was due to the
above UAF. And such UAF did go away with this commit applied [1].
Anyway, before this commit, that crash happened to be triggered in
conjunction with commit 2d52c58b9c9b ("block, bfq: honor already-setup
queue merges"). The latter was then reverted by commit ebc69e897e17
("Revert "block, bfq: honor already-setup queue merges""). Yet commit
2d52c58b9c9b ("block, bfq: honor already-setup queue merges") contains
no error related with the above UAF, and can then be restored.
[1] https://bugzilla.kernel.org/show_bug.cgi?id=214503
Fixes: 430a67f9d616 ("block, bfq: merge bursts of newly-created queues")
Tested-by: Grzegorz Kowal <custos.mentis@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Link: https://lore.kernel.org/r/20211015144336.45894-2-paolo.valente@linaro.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-10-15 14:43:36 +00:00
|
|
|
if (entity->parent &&
|
|
|
|
entity->parent->last_bfqq_created == bfqq)
|
|
|
|
entity->parent->last_bfqq_created = NULL;
|
|
|
|
else if (bfqd->last_bfqq_created == bfqq)
|
|
|
|
bfqd->last_bfqq_created = NULL;
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
entity->parent = bfqg->my_entity;
|
|
|
|
entity->sched_data = &bfqg->sched_data;
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
/* pin down bfqg and its associated blkg */
|
|
|
|
bfqg_and_blkg_get(bfqg);
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
if (bfq_bfqq_busy(bfqq)) {
|
block, bfq: do not merge queues on flash storage with queueing
To boost throughput with a set of processes doing interleaved I/O
(i.e., a set of processes whose individual I/O is random, but whose
merged cumulative I/O is sequential), BFQ merges the queues associated
with these processes, i.e., redirects the I/O of these processes into a
common, shared queue. In the shared queue, I/O requests are ordered by
their position on the medium, thus sequential I/O gets dispatched to
the device when the shared queue is served.
Queue merging costs execution time, because, to detect which queues to
merge, BFQ must maintain a list of the head I/O requests of active
queues, ordered by request positions. Measurements showed that this
costs about 10% of BFQ's total per-request processing time.
Request processing time becomes more and more critical as the speed of
the underlying storage device grows. Yet, fortunately, queue merging
is basically useless on the very devices that are so fast to make
request processing time critical. To reach a high throughput, these
devices must have many requests queued at the same time. But, in this
configuration, the internal scheduling algorithms of these devices do
also the job of queue merging: they reorder requests so as to obtain
as much as possible a sequential I/O pattern. As a consequence, with
processes doing interleaved I/O, the throughput reached by one such
device is likely to be the same, with and without queue merging.
In view of this fact, this commit disables queue merging, and all
related housekeeping, for non-rotational devices with internal
queueing. The total, single-lock-protected, per-request processing
time of BFQ drops to, e.g., 1.9 us on an Intel Core i7-2760QM@2.40GHz
(time measured with simple code instrumentation, and using the
throughput-sync.sh script of the S suite [1], in performance-profiling
mode). To put this result into context, the total,
single-lock-protected, per-request execution time of the lightest I/O
scheduler available in blk-mq, mq-deadline, is 0.7 us (mq-deadline is
~800 LOC, against ~10500 LOC for BFQ).
Disabling merging provides a further, remarkable benefit in terms of
throughput. Merging tends to make many workloads artificially more
uneven, mainly because of shared queues remaining non empty for
incomparably more time than normal queues. So, if, e.g., one of the
queues in a set of merged queues has a higher weight than a normal
queue, then the shared queue may inherit such a high weight and, by
staying almost always active, may force BFQ to perform I/O plugging
most of the time. This evidently makes it harder for BFQ to let the
device reach a high throughput.
As a practical example of this problem, and of the benefits of this
commit, we measured again the throughput in the nasty scenario
considered in previous commit messages: dbench test (in the Phoronix
suite), with 6 clients, on a filesystem with journaling, and with the
journaling daemon enjoying a higher weight than normal processes. With
this commit, the throughput grows from ~150 MB/s to ~200 MB/s on a
PLEXTOR PX-256M5 SSD. This is the same peak throughput reached by any
of the other I/O schedulers. As such, this is also likely to be the
maximum possible throughput reachable with this workload on this
device, because I/O is mostly random, and the other schedulers
basically just pass I/O requests to the drive as fast as possible.
[1] https://github.com/Algodev-github/S
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Tested-by: Francesco Pollicino <fra.fra.800@gmail.com>
Signed-off-by: Alessio Masola <alessio.masola@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-03-12 08:59:30 +00:00
|
|
|
if (unlikely(!bfqd->nonrot_with_queueing))
|
|
|
|
bfq_pos_tree_add_move(bfqd, bfqq);
|
2017-04-19 14:48:24 +00:00
|
|
|
bfq_activate_bfqq(bfqd, bfqq);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bfqd->in_service_queue && !bfqd->rq_in_driver)
|
|
|
|
bfq_schedule_dispatch(bfqd);
|
2020-03-21 09:45:18 +00:00
|
|
|
/* release extra ref taken above, bfqq may happen to be freed now */
|
2020-02-03 10:40:56 +00:00
|
|
|
bfq_put_queue(bfqq);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __bfq_bic_change_cgroup - move @bic to @cgroup.
|
|
|
|
* @bfqd: the queue descriptor.
|
|
|
|
* @bic: the bic to move.
|
|
|
|
* @blkcg: the blk-cgroup to move to.
|
|
|
|
*
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
* Move bic to blkcg, assuming that bfqd->lock is held; which makes
|
|
|
|
* sure that the reference to cgroup is valid across the call (see
|
|
|
|
* comments in bfq_bic_update_cgroup on this issue)
|
2017-04-19 14:48:24 +00:00
|
|
|
*
|
|
|
|
* NOTE: an alternative approach might have been to store the current
|
|
|
|
* cgroup in bfqq and getting a reference to it, reducing the lookup
|
|
|
|
* time here, at the price of slightly more complex code.
|
|
|
|
*/
|
|
|
|
static struct bfq_group *__bfq_bic_change_cgroup(struct bfq_data *bfqd,
|
|
|
|
struct bfq_io_cq *bic,
|
|
|
|
struct blkcg *blkcg)
|
|
|
|
{
|
|
|
|
struct bfq_queue *async_bfqq = bic_to_bfqq(bic, 0);
|
|
|
|
struct bfq_queue *sync_bfqq = bic_to_bfqq(bic, 1);
|
|
|
|
struct bfq_group *bfqg;
|
|
|
|
struct bfq_entity *entity;
|
|
|
|
|
|
|
|
bfqg = bfq_find_set_group(bfqd, blkcg);
|
|
|
|
|
|
|
|
if (unlikely(!bfqg))
|
|
|
|
bfqg = bfqd->root_group;
|
|
|
|
|
|
|
|
if (async_bfqq) {
|
|
|
|
entity = &async_bfqq->entity;
|
|
|
|
|
|
|
|
if (entity->sched_data != &bfqg->sched_data) {
|
|
|
|
bic_set_bfqq(bic, NULL, 0);
|
2020-03-21 09:45:19 +00:00
|
|
|
bfq_release_process_ref(bfqd, async_bfqq);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sync_bfqq) {
|
|
|
|
entity = &sync_bfqq->entity;
|
|
|
|
if (entity->sched_data != &bfqg->sched_data)
|
|
|
|
bfq_bfqq_move(bfqd, sync_bfqq, bfqg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfqg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio)
|
|
|
|
{
|
|
|
|
struct bfq_data *bfqd = bic_to_bfqd(bic);
|
|
|
|
struct bfq_group *bfqg = NULL;
|
|
|
|
uint64_t serial_nr;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2018-12-05 17:10:26 +00:00
|
|
|
serial_nr = __bio_blkcg(bio)->css.serial_nr;
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether blkcg has changed. The condition may trigger
|
|
|
|
* spuriously on a newly created cic but there's no harm.
|
|
|
|
*/
|
|
|
|
if (unlikely(!bfqd) || likely(bic->blkcg_serial_nr == serial_nr))
|
|
|
|
goto out;
|
|
|
|
|
2018-12-05 17:10:26 +00:00
|
|
|
bfqg = __bfq_bic_change_cgroup(bfqd, bic, __bio_blkcg(bio));
|
block, bfq: access and cache blkg data only when safe
In blk-cgroup, operations on blkg objects are protected with the
request_queue lock. This is no more the lock that protects
I/O-scheduler operations in blk-mq. In fact, the latter are now
protected with a finer-grained per-scheduler-instance lock. As a
consequence, although blkg lookups are also rcu-protected, blk-mq I/O
schedulers may see inconsistent data when they access blkg and
blkg-related objects. BFQ does access these objects, and does incur
this problem, in the following case.
The blkg_lookup performed in bfq_get_queue, being protected (only)
through rcu, may happen to return the address of a copy of the
original blkg. If this is the case, then the blkg_get performed in
bfq_get_queue, to pin down the blkg, is useless: it does not prevent
blk-cgroup code from destroying both the original blkg and all objects
directly or indirectly referred by the copy of the blkg. BFQ accesses
these objects, which typically causes a crash for NULL-pointer
dereference of memory-protection violation.
Some additional protection mechanism should be added to blk-cgroup to
address this issue. In the meantime, this commit provides a quick
temporary fix for BFQ: cache (when safe) blkg data that might
disappear right after a blkg_lookup.
In particular, this commit exploits the following facts to achieve its
goal without introducing further locks. Destroy operations on a blkg
invoke, as a first step, hooks of the scheduler associated with the
blkg. And these hooks are executed with bfqd->lock held for BFQ. As a
consequence, for any blkg associated with the request queue an
instance of BFQ is attached to, we are guaranteed that such a blkg is
not destroyed, and that all the pointers it contains are consistent,
while that instance is holding its bfqd->lock. A blkg_lookup performed
with bfqd->lock held then returns a fully consistent blkg, which
remains consistent until this lock is held. In more detail, this holds
even if the returned blkg is a copy of the original one.
Finally, also the object describing a group inside BFQ needs to be
protected from destruction on the blkg_free of the original blkg
(which invokes bfq_pd_free). This commit adds private refcounting for
this object, to let it disappear only after no bfq_queue refers to it
any longer.
This commit also removes or updates some stale comments on locking
issues related to blk-cgroup operations.
Reported-by: Tomas Konir <tomas.konir@gmail.com>
Reported-by: Lee Tibbert <lee.tibbert@gmail.com>
Reported-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Tested-by: Tomas Konir <tomas.konir@gmail.com>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Marco Piazza <mpiazza@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2017-06-05 08:11:15 +00:00
|
|
|
/*
|
|
|
|
* Update blkg_path for bfq_log_* functions. We cache this
|
|
|
|
* path, and update it here, for the following
|
|
|
|
* reasons. Operations on blkg objects in blk-cgroup are
|
|
|
|
* protected with the request_queue lock, and not with the
|
|
|
|
* lock that protects the instances of this scheduler
|
|
|
|
* (bfqd->lock). This exposes BFQ to the following sort of
|
|
|
|
* race.
|
|
|
|
*
|
|
|
|
* The blkg_lookup performed in bfq_get_queue, protected
|
|
|
|
* through rcu, may happen to return the address of a copy of
|
|
|
|
* the original blkg. If this is the case, then the
|
|
|
|
* bfqg_and_blkg_get performed in bfq_get_queue, to pin down
|
|
|
|
* the blkg, is useless: it does not prevent blk-cgroup code
|
|
|
|
* from destroying both the original blkg and all objects
|
|
|
|
* directly or indirectly referred by the copy of the
|
|
|
|
* blkg.
|
|
|
|
*
|
|
|
|
* On the bright side, destroy operations on a blkg invoke, as
|
|
|
|
* a first step, hooks of the scheduler associated with the
|
|
|
|
* blkg. And these hooks are executed with bfqd->lock held for
|
|
|
|
* BFQ. As a consequence, for any blkg associated with the
|
|
|
|
* request queue this instance of the scheduler is attached
|
|
|
|
* to, we are guaranteed that such a blkg is not destroyed, and
|
|
|
|
* that all the pointers it contains are consistent, while we
|
|
|
|
* are holding bfqd->lock. A blkg_lookup performed with
|
|
|
|
* bfqd->lock held then returns a fully consistent blkg, which
|
|
|
|
* remains consistent until this lock is held.
|
|
|
|
*
|
|
|
|
* Thanks to the last fact, and to the fact that: (1) bfqg has
|
|
|
|
* been obtained through a blkg_lookup in the above
|
|
|
|
* assignment, and (2) bfqd->lock is being held, here we can
|
|
|
|
* safely use the policy data for the involved blkg (i.e., the
|
|
|
|
* field bfqg->pd) to get to the blkg associated with bfqg,
|
|
|
|
* and then we can safely use any field of blkg. After we
|
|
|
|
* release bfqd->lock, even just getting blkg through this
|
|
|
|
* bfqg may cause dangling references to be traversed, as
|
|
|
|
* bfqg->pd may not exist any more.
|
|
|
|
*
|
|
|
|
* In view of the above facts, here we cache, in the bfqg, any
|
|
|
|
* blkg data we may need for this bic, and for its associated
|
|
|
|
* bfq_queue. As of now, we need to cache only the path of the
|
|
|
|
* blkg, which is used in the bfq_log_* functions.
|
|
|
|
*
|
|
|
|
* Finally, note that bfqg itself needs to be protected from
|
|
|
|
* destruction on the blkg_free of the original blkg (which
|
|
|
|
* invokes bfq_pd_free). We use an additional private
|
|
|
|
* refcounter for bfqg, to let it disappear only after no
|
|
|
|
* bfq_queue refers to it any longer.
|
|
|
|
*/
|
|
|
|
blkg_path(bfqg_to_blkg(bfqg), bfqg->blkg_path, sizeof(bfqg->blkg_path));
|
2017-04-19 14:48:24 +00:00
|
|
|
bic->blkcg_serial_nr = serial_nr;
|
|
|
|
out:
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_flush_idle_tree - deactivate any entity on the idle tree of @st.
|
|
|
|
* @st: the service tree being flushed.
|
|
|
|
*/
|
|
|
|
static void bfq_flush_idle_tree(struct bfq_service_tree *st)
|
|
|
|
{
|
|
|
|
struct bfq_entity *entity = st->first_idle;
|
|
|
|
|
|
|
|
for (; entity ; entity = st->first_idle)
|
|
|
|
__bfq_deactivate_entity(entity, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_reparent_leaf_entity - move leaf entity to the root_group.
|
|
|
|
* @bfqd: the device data structure with the root group.
|
2020-03-21 09:45:20 +00:00
|
|
|
* @entity: the entity to move, if entity is a leaf; or the parent entity
|
|
|
|
* of an active leaf entity to move, if entity is not a leaf.
|
2017-04-19 14:48:24 +00:00
|
|
|
*/
|
|
|
|
static void bfq_reparent_leaf_entity(struct bfq_data *bfqd,
|
2020-03-21 09:45:20 +00:00
|
|
|
struct bfq_entity *entity,
|
|
|
|
int ioprio_class)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
2020-03-21 09:45:20 +00:00
|
|
|
struct bfq_queue *bfqq;
|
|
|
|
struct bfq_entity *child_entity = entity;
|
|
|
|
|
|
|
|
while (child_entity->my_sched_data) { /* leaf not reached yet */
|
|
|
|
struct bfq_sched_data *child_sd = child_entity->my_sched_data;
|
|
|
|
struct bfq_service_tree *child_st = child_sd->service_tree +
|
|
|
|
ioprio_class;
|
|
|
|
struct rb_root *child_active = &child_st->active;
|
2017-04-19 14:48:24 +00:00
|
|
|
|
2020-03-21 09:45:20 +00:00
|
|
|
child_entity = bfq_entity_of(rb_first(child_active));
|
|
|
|
|
|
|
|
if (!child_entity)
|
|
|
|
child_entity = child_sd->in_service_entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
bfqq = bfq_entity_to_bfqq(child_entity);
|
2017-04-19 14:48:24 +00:00
|
|
|
bfq_bfqq_move(bfqd, bfqq, bfqd->root_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-21 09:45:20 +00:00
|
|
|
* bfq_reparent_active_queues - move to the root group all active queues.
|
2017-04-19 14:48:24 +00:00
|
|
|
* @bfqd: the device data structure with the root group.
|
|
|
|
* @bfqg: the group to move from.
|
2020-03-21 09:45:20 +00:00
|
|
|
* @st: the service tree to start the search from.
|
2017-04-19 14:48:24 +00:00
|
|
|
*/
|
2020-03-21 09:45:20 +00:00
|
|
|
static void bfq_reparent_active_queues(struct bfq_data *bfqd,
|
|
|
|
struct bfq_group *bfqg,
|
|
|
|
struct bfq_service_tree *st,
|
|
|
|
int ioprio_class)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct rb_root *active = &st->active;
|
2020-03-21 09:45:20 +00:00
|
|
|
struct bfq_entity *entity;
|
2017-04-19 14:48:24 +00:00
|
|
|
|
2020-03-21 09:45:20 +00:00
|
|
|
while ((entity = bfq_entity_of(rb_first(active))))
|
|
|
|
bfq_reparent_leaf_entity(bfqd, entity, ioprio_class);
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
if (bfqg->sched_data.in_service_entity)
|
|
|
|
bfq_reparent_leaf_entity(bfqd,
|
2020-03-21 09:45:20 +00:00
|
|
|
bfqg->sched_data.in_service_entity,
|
|
|
|
ioprio_class);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* bfq_pd_offline - deactivate the entity associated with @pd,
|
|
|
|
* and reparent its children entities.
|
|
|
|
* @pd: descriptor of the policy going offline.
|
|
|
|
*
|
|
|
|
* blkio already grabs the queue_lock for us, so no need to use
|
|
|
|
* RCU-based magic
|
|
|
|
*/
|
2017-08-30 18:42:08 +00:00
|
|
|
static void bfq_pd_offline(struct blkg_policy_data *pd)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct bfq_service_tree *st;
|
|
|
|
struct bfq_group *bfqg = pd_to_bfqg(pd);
|
|
|
|
struct bfq_data *bfqd = bfqg->bfqd;
|
|
|
|
struct bfq_entity *entity = bfqg->my_entity;
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
block, bfq: put async queues for root bfq groups too
For each pair [device for which bfq is selected as I/O scheduler,
group in blkio/io], bfq maintains a corresponding bfq group. Each such
bfq group contains a set of async queues, with each async queue
created on demand, i.e., when some I/O request arrives for it. On
creation, an async queue gets an extra reference, to make sure that
the queue is not freed as long as its bfq group exists. Accordingly,
to allow the queue to be freed after the group exited, this extra
reference must released on group exit.
The above holds also for a bfq root group, i.e., for the bfq group
corresponding to the root blkio/io root for a given device. Yet, by
mistake, the references to the existing async queues of a root group
are not released when the latter exits. This causes a memory leak when
the instance of bfq for a given device exits. In a similar vein,
bfqg_stats_xfer_dead is not executed for a root group.
This commit fixes bfq_pd_offline so that the latter executes the above
missing operations for a root group too.
Reported-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reported-by: Guoqing Jiang <gqjiang@suse.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: Davide Ferrari <davideferrari8@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-01-09 09:27:58 +00:00
|
|
|
spin_lock_irqsave(&bfqd->lock, flags);
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
if (!entity) /* root group */
|
block, bfq: put async queues for root bfq groups too
For each pair [device for which bfq is selected as I/O scheduler,
group in blkio/io], bfq maintains a corresponding bfq group. Each such
bfq group contains a set of async queues, with each async queue
created on demand, i.e., when some I/O request arrives for it. On
creation, an async queue gets an extra reference, to make sure that
the queue is not freed as long as its bfq group exists. Accordingly,
to allow the queue to be freed after the group exited, this extra
reference must released on group exit.
The above holds also for a bfq root group, i.e., for the bfq group
corresponding to the root blkio/io root for a given device. Yet, by
mistake, the references to the existing async queues of a root group
are not released when the latter exits. This causes a memory leak when
the instance of bfq for a given device exits. In a similar vein,
bfqg_stats_xfer_dead is not executed for a root group.
This commit fixes bfq_pd_offline so that the latter executes the above
missing operations for a root group too.
Reported-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reported-by: Guoqing Jiang <gqjiang@suse.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: Davide Ferrari <davideferrari8@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-01-09 09:27:58 +00:00
|
|
|
goto put_async_queues;
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Empty all service_trees belonging to this group before
|
|
|
|
* deactivating the group itself.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < BFQ_IOPRIO_CLASSES; i++) {
|
|
|
|
st = bfqg->sched_data.service_tree + i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It may happen that some queues are still active
|
|
|
|
* (busy) upon group destruction (if the corresponding
|
|
|
|
* processes have been forced to terminate). We move
|
|
|
|
* all the leaf entities corresponding to these queues
|
|
|
|
* to the root_group.
|
|
|
|
* Also, it may happen that the group has an entity
|
|
|
|
* in service, which is disconnected from the active
|
|
|
|
* tree: it must be moved, too.
|
|
|
|
* There is no need to put the sync queues, as the
|
|
|
|
* scheduler has taken no reference.
|
|
|
|
*/
|
2020-03-21 09:45:20 +00:00
|
|
|
bfq_reparent_active_queues(bfqd, bfqg, st, i);
|
2020-03-21 09:45:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The idle tree may still contain bfq_queues
|
|
|
|
* belonging to exited task because they never
|
|
|
|
* migrated to a different cgroup from the one being
|
|
|
|
* destroyed now. In addition, even
|
|
|
|
* bfq_reparent_active_queues() may happen to add some
|
|
|
|
* entities to the idle tree. It happens if, in some
|
|
|
|
* of the calls to bfq_bfqq_move() performed by
|
|
|
|
* bfq_reparent_active_queues(), the queue to move is
|
|
|
|
* empty and gets expired.
|
|
|
|
*/
|
|
|
|
bfq_flush_idle_tree(st);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__bfq_deactivate_entity(entity, false);
|
block, bfq: put async queues for root bfq groups too
For each pair [device for which bfq is selected as I/O scheduler,
group in blkio/io], bfq maintains a corresponding bfq group. Each such
bfq group contains a set of async queues, with each async queue
created on demand, i.e., when some I/O request arrives for it. On
creation, an async queue gets an extra reference, to make sure that
the queue is not freed as long as its bfq group exists. Accordingly,
to allow the queue to be freed after the group exited, this extra
reference must released on group exit.
The above holds also for a bfq root group, i.e., for the bfq group
corresponding to the root blkio/io root for a given device. Yet, by
mistake, the references to the existing async queues of a root group
are not released when the latter exits. This causes a memory leak when
the instance of bfq for a given device exits. In a similar vein,
bfqg_stats_xfer_dead is not executed for a root group.
This commit fixes bfq_pd_offline so that the latter executes the above
missing operations for a root group too.
Reported-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Reported-by: Guoqing Jiang <gqjiang@suse.com>
Tested-by: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: Davide Ferrari <davideferrari8@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-01-09 09:27:58 +00:00
|
|
|
|
|
|
|
put_async_queues:
|
2017-04-19 14:48:24 +00:00
|
|
|
bfq_put_async_queues(bfqd, bfqg);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&bfqd->lock, flags);
|
|
|
|
/*
|
|
|
|
* @blkg is going offline and will be ignored by
|
|
|
|
* blkg_[rw]stat_recursive_sum(). Transfer stats to the parent so
|
|
|
|
* that they don't get lost. If IOs complete after this point, the
|
|
|
|
* stats for them will be lost. Oh well...
|
|
|
|
*/
|
|
|
|
bfqg_stats_xfer_dead(bfqg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfq_end_wr_async(struct bfq_data *bfqd)
|
|
|
|
{
|
|
|
|
struct blkcg_gq *blkg;
|
|
|
|
|
|
|
|
list_for_each_entry(blkg, &bfqd->queue->blkg_list, q_node) {
|
|
|
|
struct bfq_group *bfqg = blkg_to_bfqg(blkg);
|
|
|
|
|
|
|
|
bfq_end_wr_async_queues(bfqd, bfqg);
|
|
|
|
}
|
|
|
|
bfq_end_wr_async_queues(bfqd, bfqd->root_group);
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:54:53 +00:00
|
|
|
static int bfq_io_show_weight_legacy(struct seq_file *sf, void *v)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
|
|
|
|
struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
|
|
|
|
unsigned int val = 0;
|
|
|
|
|
|
|
|
if (bfqgd)
|
|
|
|
val = bfqgd->weight;
|
|
|
|
|
|
|
|
seq_printf(sf, "%u\n", val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:54:53 +00:00
|
|
|
static u64 bfqg_prfill_weight_device(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
2019-08-28 03:54:52 +00:00
|
|
|
{
|
2019-08-28 03:54:53 +00:00
|
|
|
struct bfq_group *bfqg = pd_to_bfqg(pd);
|
|
|
|
|
|
|
|
if (!bfqg->entity.dev_weight)
|
|
|
|
return 0;
|
|
|
|
return __blkg_prfill_u64(sf, pd, bfqg->entity.dev_weight);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfq_io_show_weight(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
|
|
|
|
struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
|
|
|
|
|
|
|
|
seq_printf(sf, "default %u\n", bfqgd->weight);
|
|
|
|
blkcg_print_blkgs(sf, blkcg, bfqg_prfill_weight_device,
|
|
|
|
&blkcg_policy_bfq, 0, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bfq_group_set_weight(struct bfq_group *bfqg, u64 weight, u64 dev_weight)
|
|
|
|
{
|
|
|
|
weight = dev_weight ?: weight;
|
|
|
|
|
|
|
|
bfqg->entity.dev_weight = dev_weight;
|
2019-08-28 03:54:52 +00:00
|
|
|
/*
|
|
|
|
* Setting the prio_changed flag of the entity
|
|
|
|
* to 1 with new_weight == weight would re-set
|
|
|
|
* the value of the weight to its ioprio mapping.
|
|
|
|
* Set the flag only if necessary.
|
|
|
|
*/
|
|
|
|
if ((unsigned short)weight != bfqg->entity.new_weight) {
|
|
|
|
bfqg->entity.new_weight = (unsigned short)weight;
|
|
|
|
/*
|
|
|
|
* Make sure that the above new value has been
|
|
|
|
* stored in bfqg->entity.new_weight before
|
|
|
|
* setting the prio_changed flag. In fact,
|
|
|
|
* this flag may be read asynchronously (in
|
|
|
|
* critical sections protected by a different
|
|
|
|
* lock than that held here), and finding this
|
|
|
|
* flag set may cause the execution of the code
|
|
|
|
* for updating parameters whose value may
|
|
|
|
* depend also on bfqg->entity.new_weight (in
|
|
|
|
* __bfq_entity_update_weight_prio).
|
|
|
|
* This barrier makes sure that the new value
|
|
|
|
* of bfqg->entity.new_weight is correctly
|
|
|
|
* seen in that code.
|
|
|
|
*/
|
|
|
|
smp_wmb();
|
|
|
|
bfqg->entity.prio_changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
static int bfq_io_set_weight_legacy(struct cgroup_subsys_state *css,
|
|
|
|
struct cftype *cftype,
|
|
|
|
u64 val)
|
|
|
|
{
|
|
|
|
struct blkcg *blkcg = css_to_blkcg(css);
|
|
|
|
struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
|
|
|
|
struct blkcg_gq *blkg;
|
|
|
|
int ret = -ERANGE;
|
|
|
|
|
|
|
|
if (val < BFQ_MIN_WEIGHT || val > BFQ_MAX_WEIGHT)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
spin_lock_irq(&blkcg->lock);
|
|
|
|
bfqgd->weight = (unsigned short)val;
|
|
|
|
hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node) {
|
|
|
|
struct bfq_group *bfqg = blkg_to_bfqg(blkg);
|
|
|
|
|
2019-08-28 03:54:52 +00:00
|
|
|
if (bfqg)
|
2019-08-28 03:54:53 +00:00
|
|
|
bfq_group_set_weight(bfqg, val, 0);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irq(&blkcg->lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-08-28 03:54:53 +00:00
|
|
|
static ssize_t bfq_io_set_device_weight(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes,
|
|
|
|
loff_t off)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
2019-08-28 03:54:53 +00:00
|
|
|
int ret;
|
|
|
|
struct blkg_conf_ctx ctx;
|
|
|
|
struct blkcg *blkcg = css_to_blkcg(of_css(of));
|
|
|
|
struct bfq_group *bfqg;
|
|
|
|
u64 v;
|
2017-04-19 14:48:24 +00:00
|
|
|
|
2019-08-28 03:54:53 +00:00
|
|
|
ret = blkg_conf_prep(blkcg, &blkcg_policy_bfq, buf, &ctx);
|
2017-04-19 14:48:24 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-08-28 03:54:53 +00:00
|
|
|
if (sscanf(ctx.body, "%llu", &v) == 1) {
|
|
|
|
/* require "default" on dfl */
|
|
|
|
ret = -ERANGE;
|
|
|
|
if (!v)
|
|
|
|
goto out;
|
|
|
|
} else if (!strcmp(strim(ctx.body), "default")) {
|
|
|
|
v = 0;
|
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
bfqg = blkg_to_bfqg(ctx.blkg);
|
|
|
|
|
|
|
|
ret = -ERANGE;
|
|
|
|
if (!v || (v >= BFQ_MIN_WEIGHT && v <= BFQ_MAX_WEIGHT)) {
|
|
|
|
bfq_group_set_weight(bfqg, bfqg->entity.weight, v);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
blkg_conf_finish(&ctx);
|
2018-08-15 21:56:45 +00:00
|
|
|
return ret ?: nbytes;
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 03:54:53 +00:00
|
|
|
static ssize_t bfq_io_set_weight(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes,
|
|
|
|
loff_t off)
|
|
|
|
{
|
|
|
|
char *endp;
|
|
|
|
int ret;
|
|
|
|
u64 v;
|
|
|
|
|
|
|
|
buf = strim(buf);
|
|
|
|
|
|
|
|
/* "WEIGHT" or "default WEIGHT" sets the default weight */
|
|
|
|
v = simple_strtoull(buf, &endp, 0);
|
|
|
|
if (*endp == '\0' || sscanf(buf, "default %llu", &v) == 1) {
|
|
|
|
ret = bfq_io_set_weight_legacy(of_css(of), NULL, v);
|
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfq_io_set_device_weight(of, buf, nbytes, off);
|
|
|
|
}
|
|
|
|
|
2019-11-07 19:17:59 +00:00
|
|
|
static int bfqg_print_rwstat(struct seq_file *sf, void *v)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
2019-11-07 19:17:59 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_rwstat,
|
|
|
|
&blkcg_policy_bfq, seq_cft(sf)->private, true);
|
2017-04-19 14:48:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-07 19:17:59 +00:00
|
|
|
static u64 bfqg_prfill_rwstat_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
2019-11-07 19:17:59 +00:00
|
|
|
struct blkg_rwstat_sample sum;
|
|
|
|
|
|
|
|
blkg_rwstat_recursive_sum(pd_to_blkg(pd), &blkcg_policy_bfq, off, &sum);
|
|
|
|
return __blkg_prfill_rwstat(sf, pd, &sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfqg_print_rwstat_recursive(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
bfqg_prfill_rwstat_recursive, &blkcg_policy_bfq,
|
|
|
|
seq_cft(sf)->private, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-07 19:18:00 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
2019-11-07 19:17:59 +00:00
|
|
|
static int bfqg_print_stat(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_stat,
|
|
|
|
&blkcg_policy_bfq, seq_cft(sf)->private, false);
|
2017-04-19 14:48:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 bfqg_prfill_stat_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
2019-06-06 10:26:23 +00:00
|
|
|
struct blkcg_gq *blkg = pd_to_blkg(pd);
|
|
|
|
struct blkcg_gq *pos_blkg;
|
|
|
|
struct cgroup_subsys_state *pos_css;
|
|
|
|
u64 sum = 0;
|
|
|
|
|
|
|
|
lockdep_assert_held(&blkg->q->queue_lock);
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
blkg_for_each_descendant_pre(pos_blkg, pos_css, blkg) {
|
|
|
|
struct bfq_stat *stat;
|
|
|
|
|
|
|
|
if (!pos_blkg->online)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stat = (void *)blkg_to_pd(pos_blkg, &blkcg_policy_bfq) + off;
|
|
|
|
sum += bfq_stat_read(stat) + atomic64_read(&stat->aux_cnt);
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
return __blkg_prfill_u64(sf, pd, sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfqg_print_stat_recursive(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
bfqg_prfill_stat_recursive, &blkcg_policy_bfq,
|
|
|
|
seq_cft(sf)->private, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 bfqg_prfill_sectors(struct seq_file *sf, struct blkg_policy_data *pd,
|
|
|
|
int off)
|
|
|
|
{
|
2019-11-07 19:18:00 +00:00
|
|
|
struct bfq_group *bfqg = blkg_to_bfqg(pd->blkg);
|
|
|
|
u64 sum = blkg_rwstat_total(&bfqg->stats.bytes);
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
return __blkg_prfill_u64(sf, pd, sum >> 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bfqg_print_stat_sectors(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
bfqg_prfill_sectors, &blkcg_policy_bfq, 0, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 bfqg_prfill_sectors_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
2019-06-06 10:26:21 +00:00
|
|
|
struct blkg_rwstat_sample tmp;
|
2019-06-06 10:26:20 +00:00
|
|
|
|
2019-11-07 19:18:00 +00:00
|
|
|
blkg_rwstat_recursive_sum(pd->blkg, &blkcg_policy_bfq,
|
|
|
|
offsetof(struct bfq_group, stats.bytes), &tmp);
|
2017-04-19 14:48:24 +00:00
|
|
|
|
2019-06-06 10:26:21 +00:00
|
|
|
return __blkg_prfill_u64(sf, pd,
|
|
|
|
(tmp.cnt[BLKG_RWSTAT_READ] + tmp.cnt[BLKG_RWSTAT_WRITE]) >> 9);
|
2017-04-19 14:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int bfqg_print_stat_sectors_recursive(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
bfqg_prfill_sectors_recursive, &blkcg_policy_bfq, 0,
|
|
|
|
false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 bfqg_prfill_avg_queue_size(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
|
|
|
struct bfq_group *bfqg = pd_to_bfqg(pd);
|
2019-06-06 10:26:22 +00:00
|
|
|
u64 samples = bfq_stat_read(&bfqg->stats.avg_queue_size_samples);
|
2017-04-19 14:48:24 +00:00
|
|
|
u64 v = 0;
|
|
|
|
|
|
|
|
if (samples) {
|
2019-06-06 10:26:22 +00:00
|
|
|
v = bfq_stat_read(&bfqg->stats.avg_queue_size_sum);
|
2017-04-19 14:48:24 +00:00
|
|
|
v = div64_u64(v, samples);
|
|
|
|
}
|
|
|
|
__blkg_prfill_u64(sf, pd, v);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print avg_queue_size */
|
|
|
|
static int bfqg_print_avg_queue_size(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
bfqg_prfill_avg_queue_size, &blkcg_policy_bfq,
|
|
|
|
0, false);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-06-06 10:26:24 +00:00
|
|
|
#endif /* CONFIG_BFQ_CGROUP_DEBUG */
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = blkcg_activate_policy(bfqd->queue, &blkcg_policy_bfq);
|
|
|
|
if (ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return blkg_to_bfqg(bfqd->queue->root_blkg);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct blkcg_policy blkcg_policy_bfq = {
|
|
|
|
.dfl_cftypes = bfq_blkg_files,
|
|
|
|
.legacy_cftypes = bfq_blkcg_legacy_files,
|
|
|
|
|
|
|
|
.cpd_alloc_fn = bfq_cpd_alloc,
|
|
|
|
.cpd_init_fn = bfq_cpd_init,
|
|
|
|
.cpd_bind_fn = bfq_cpd_init,
|
|
|
|
.cpd_free_fn = bfq_cpd_free,
|
|
|
|
|
|
|
|
.pd_alloc_fn = bfq_pd_alloc,
|
|
|
|
.pd_init_fn = bfq_pd_init,
|
|
|
|
.pd_offline_fn = bfq_pd_offline,
|
|
|
|
.pd_free_fn = bfq_pd_free,
|
|
|
|
.pd_reset_stats_fn = bfq_pd_reset_stats,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cftype bfq_blkcg_legacy_files[] = {
|
|
|
|
{
|
|
|
|
.name = "bfq.weight",
|
2019-06-10 09:35:41 +00:00
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
2019-08-28 03:54:53 +00:00
|
|
|
.seq_show = bfq_io_show_weight_legacy,
|
2017-04-19 14:48:24 +00:00
|
|
|
.write_u64 = bfq_io_set_weight_legacy,
|
|
|
|
},
|
2019-08-28 03:54:53 +00:00
|
|
|
{
|
|
|
|
.name = "bfq.weight_device",
|
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
|
|
|
.seq_show = bfq_io_show_weight,
|
|
|
|
.write = bfq_io_set_weight,
|
|
|
|
},
|
2017-04-19 14:48:24 +00:00
|
|
|
|
|
|
|
/* statistics, covers only the tasks in the bfqg */
|
|
|
|
{
|
|
|
|
.name = "bfq.io_service_bytes",
|
2019-11-07 19:18:00 +00:00
|
|
|
.private = offsetof(struct bfq_group, stats.bytes),
|
|
|
|
.seq_show = bfqg_print_rwstat,
|
2017-04-19 14:48:24 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_serviced",
|
2019-11-07 19:18:00 +00:00
|
|
|
.private = offsetof(struct bfq_group, stats.ios),
|
|
|
|
.seq_show = bfqg_print_rwstat,
|
2017-04-19 14:48:24 +00:00
|
|
|
},
|
2019-06-06 10:26:24 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
{
|
|
|
|
.name = "bfq.time",
|
|
|
|
.private = offsetof(struct bfq_group, stats.time),
|
|
|
|
.seq_show = bfqg_print_stat,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.sectors",
|
|
|
|
.seq_show = bfqg_print_stat_sectors,
|
|
|
|
},
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
.name = "bfq.io_service_time",
|
|
|
|
.private = offsetof(struct bfq_group, stats.service_time),
|
|
|
|
.seq_show = bfqg_print_rwstat,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_wait_time",
|
|
|
|
.private = offsetof(struct bfq_group, stats.wait_time),
|
|
|
|
.seq_show = bfqg_print_rwstat,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_merged",
|
|
|
|
.private = offsetof(struct bfq_group, stats.merged),
|
|
|
|
.seq_show = bfqg_print_rwstat,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_queued",
|
|
|
|
.private = offsetof(struct bfq_group, stats.queued),
|
|
|
|
.seq_show = bfqg_print_rwstat,
|
|
|
|
},
|
2019-06-06 10:26:24 +00:00
|
|
|
#endif /* CONFIG_BFQ_CGROUP_DEBUG */
|
2017-04-19 14:48:24 +00:00
|
|
|
|
2019-04-08 15:35:34 +00:00
|
|
|
/* the same statistics which cover the bfqg and its descendants */
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
.name = "bfq.io_service_bytes_recursive",
|
2019-11-07 19:18:00 +00:00
|
|
|
.private = offsetof(struct bfq_group, stats.bytes),
|
|
|
|
.seq_show = bfqg_print_rwstat_recursive,
|
2017-04-19 14:48:24 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_serviced_recursive",
|
2019-11-07 19:18:00 +00:00
|
|
|
.private = offsetof(struct bfq_group, stats.ios),
|
|
|
|
.seq_show = bfqg_print_rwstat_recursive,
|
2017-04-19 14:48:24 +00:00
|
|
|
},
|
2019-06-06 10:26:24 +00:00
|
|
|
#ifdef CONFIG_BFQ_CGROUP_DEBUG
|
block, bfq: move debug blkio stats behind CONFIG_DEBUG_BLK_CGROUP
BFQ currently creates, and updates, its own instance of the whole
set of blkio statistics that cfq creates. Yet, from the comments
of Tejun Heo in [1], it turned out that most of these statistics
are meant/useful only for debugging. This commit makes BFQ create
the latter, debugging statistics only if the option
CONFIG_DEBUG_BLK_CGROUP is set.
By doing so, this commit also enables BFQ to enjoy a high perfomance
boost. The reason is that, if CONFIG_DEBUG_BLK_CGROUP is not set, then
BFQ has to update far fewer statistics, and, in particular, not the
heaviest to update. To give an idea of the benefits, if
CONFIG_DEBUG_BLK_CGROUP is not set, then, on an Intel i7-4850HQ, and
with 8 threads doing random I/O in parallel on null_blk (configured
with 0 latency), the throughput of BFQ grows from 310 to 400 KIOPS
(+30%). We have measured similar or even much higher boosts with other
CPUs: e.g., +45% with an ARM CortexTM-A53 Octa-core. Our results have
been obtained and can be reproduced very easily with the script in [1].
[1] https://www.spinics.net/lists/linux-block/msg18943.html
Suggested-by: Tejun Heo <tj@kernel.org>
Suggested-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Lee Tibbert <lee.tibbert@gmail.com>
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Luca Miccio <lucmiccio@gmail.com>
Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-11-13 06:34:10 +00:00
|
|
|
{
|
|
|
|
.name = "bfq.time_recursive",
|
|
|
|
.private = offsetof(struct bfq_group, stats.time),
|
|
|
|
.seq_show = bfqg_print_stat_recursive,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.sectors_recursive",
|
|
|
|
.seq_show = bfqg_print_stat_sectors_recursive,
|
|
|
|
},
|
2017-04-19 14:48:24 +00:00
|
|
|
{
|
|
|
|
.name = "bfq.io_service_time_recursive",
|
|
|
|
.private = offsetof(struct bfq_group, stats.service_time),
|
|
|
|
.seq_show = bfqg_print_rwstat_recursive,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_wait_time_recursive",
|
|
|
|
.private = offsetof(struct bfq_group, stats.wait_time),
|
|
|
|
.seq_show = bfqg_print_rwstat_recursive,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_merged_recursive",
|
|
|
|
.private = offsetof(struct bfq_group, stats.merged),
|
|
|
|
.seq_show = bfqg_print_rwstat_recursive,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.io_queued_recursive",
|
|
|
|
.private = offsetof(struct bfq_group, stats.queued),
|
|
|
|
.seq_show = bfqg_print_rwstat_recursive,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.avg_queue_size",
|
|
|
|
.seq_show = bfqg_print_avg_queue_size,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.group_wait_time",
|
|
|
|
.private = offsetof(struct bfq_group, stats.group_wait_time),
|
|
|
|
.seq_show = bfqg_print_stat,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.idle_time",
|
|
|
|
.private = offsetof(struct bfq_group, stats.idle_time),
|
|
|
|
.seq_show = bfqg_print_stat,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.empty_time",
|
|
|
|
.private = offsetof(struct bfq_group, stats.empty_time),
|
|
|
|
.seq_show = bfqg_print_stat,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "bfq.dequeue",
|
|
|
|
.private = offsetof(struct bfq_group, stats.dequeue),
|
|
|
|
.seq_show = bfqg_print_stat,
|
|
|
|
},
|
2019-06-06 10:26:24 +00:00
|
|
|
#endif /* CONFIG_BFQ_CGROUP_DEBUG */
|
2017-04-19 14:48:24 +00:00
|
|
|
{ } /* terminate */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cftype bfq_blkg_files[] = {
|
|
|
|
{
|
|
|
|
.name = "bfq.weight",
|
2019-06-10 09:35:41 +00:00
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
2017-04-19 14:48:24 +00:00
|
|
|
.seq_show = bfq_io_show_weight,
|
|
|
|
.write = bfq_io_set_weight,
|
|
|
|
},
|
|
|
|
{} /* terminate */
|
|
|
|
};
|
|
|
|
|
|
|
|
#else /* CONFIG_BFQ_GROUP_IOSCHED */
|
|
|
|
|
|
|
|
void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
|
|
|
|
struct bfq_group *bfqg) {}
|
|
|
|
|
|
|
|
void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg)
|
|
|
|
{
|
|
|
|
struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
|
|
|
|
|
|
|
|
entity->weight = entity->new_weight;
|
|
|
|
entity->orig_weight = entity->new_weight;
|
|
|
|
if (bfqq) {
|
|
|
|
bfqq->ioprio = bfqq->new_ioprio;
|
|
|
|
bfqq->ioprio_class = bfqq->new_ioprio_class;
|
|
|
|
}
|
|
|
|
entity->sched_data = &bfqg->sched_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio) {}
|
|
|
|
|
|
|
|
void bfq_end_wr_async(struct bfq_data *bfqd)
|
|
|
|
{
|
|
|
|
bfq_end_wr_async_queues(bfqd, bfqd->root_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd, struct blkcg *blkcg)
|
|
|
|
{
|
|
|
|
return bfqd->root_group;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bfq_group *bfqq_group(struct bfq_queue *bfqq)
|
|
|
|
{
|
|
|
|
return bfqq->bfqd->root_group;
|
|
|
|
}
|
|
|
|
|
2020-02-03 10:40:58 +00:00
|
|
|
void bfqg_and_blkg_get(struct bfq_group *bfqg) {}
|
|
|
|
|
|
|
|
void bfqg_and_blkg_put(struct bfq_group *bfqg) {}
|
|
|
|
|
2017-04-19 14:48:24 +00:00
|
|
|
struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
|
|
|
|
{
|
|
|
|
struct bfq_group *bfqg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
bfqg = kmalloc_node(sizeof(*bfqg), GFP_KERNEL | __GFP_ZERO, node);
|
|
|
|
if (!bfqg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < BFQ_IOPRIO_CLASSES; i++)
|
|
|
|
bfqg->sched_data.service_tree[i] = BFQ_SERVICE_TREE_INIT;
|
|
|
|
|
|
|
|
return bfqg;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BFQ_GROUP_IOSCHED */
|