2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* CFQ, or complete fairness queueing, disk scheduler.
|
|
|
|
*
|
|
|
|
* Based on ideas from a previously unfinished io
|
|
|
|
* scheduler (round robin per-process disk scheduling) and Andrea Arcangeli.
|
|
|
|
*
|
2006-09-04 13:41:16 +00:00
|
|
|
* Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2006-03-18 17:29:52 +00:00
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/elevator.h>
|
2016-06-08 14:55:34 +00:00
|
|
|
#include <linux/ktime.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/rbtree.h>
|
2005-06-27 08:55:12 +00:00
|
|
|
#include <linux/ioprio.h>
|
2008-05-30 10:23:07 +00:00
|
|
|
#include <linux/blktrace_api.h>
|
2015-05-22 21:13:17 +00:00
|
|
|
#include <linux/blk-cgroup.h>
|
block: make ioc get/put interface more conventional and fix race on alloction
Ignoring copy_io() during fork, io_context can be allocated from two
places - current_io_context() and set_task_ioprio(). The former is
always called from local task while the latter can be called from
different task. The synchornization between them are peculiar and
dubious.
* current_io_context() doesn't grab task_lock() and assumes that if it
saw %NULL ->io_context, it would stay that way until allocation and
assignment is complete. It has smp_wmb() between alloc/init and
assignment.
* set_task_ioprio() grabs task_lock() for assignment and does
smp_read_barrier_depends() between "ioc = task->io_context" and "if
(ioc)". Unfortunately, this doesn't achieve anything - the latter
is not a dependent load of the former. ie, if ioc itself were being
dereferenced "ioc->xxx", it would mean something (not sure what tho)
but as the code currently stands, the dependent read barrier is
noop.
As only one of the the two test-assignment sequences is task_lock()
protected, the task_lock() can't do much about race between the two.
Nothing prevents current_io_context() and set_task_ioprio() allocating
its own ioc for the same task and overwriting the other's.
Also, set_task_ioprio() can race with exiting task and create a new
ioc after exit_io_context() is finished.
ioc get/put doesn't have any reason to be complex. The only hot path
is accessing the existing ioc of %current, which is simple to achieve
given that ->io_context is never destroyed as long as the task is
alive. All other paths can happily go through task_lock() like all
other task sub structures without impacting anything.
This patch updates ioc get/put so that it becomes more conventional.
* alloc_io_context() is replaced with get_task_io_context(). This is
the only interface which can acquire access to ioc of another task.
On return, the caller has an explicit reference to the object which
should be put using put_io_context() afterwards.
* The functionality of current_io_context() remains the same but when
creating a new ioc, it shares the code path with
get_task_io_context() and always goes through task_lock().
* get_io_context() now means incrementing ref on an ioc which the
caller already has access to (be that an explicit refcnt or implicit
%current one).
* PF_EXITING inhibits creation of new io_context and once
exit_io_context() is finished, it's guaranteed that both ioc
acquisition functions return %NULL.
* All users are updated. Most are trivial but
smp_read_barrier_depends() removal from cfq_get_io_context() needs a
bit of explanation. I suppose the original intention was to ensure
ioc->ioprio is visible when set_task_ioprio() allocates new
io_context and installs it; however, this wouldn't have worked
because set_task_ioprio() doesn't have wmb between init and install.
There are other problems with this which will be fixed in another
patch.
* While at it, use NUMA_NO_NODE instead of -1 for wildcard node
specification.
-v2: Vivek spotted contamination from debug patch. Removed.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2011-12-13 23:33:38 +00:00
|
|
|
#include "blk.h"
|
block: hook up writeback throttling
Enable throttling of buffered writeback to make it a lot
more smooth, and has way less impact on other system activity.
Background writeback should be, by definition, background
activity. The fact that we flush huge bundles of it at the time
means that it potentially has heavy impacts on foreground workloads,
which isn't ideal. We can't easily limit the sizes of writes that
we do, since that would impact file system layout in the presence
of delayed allocation. So just throttle back buffered writeback,
unless someone is waiting for it.
The algorithm for when to throttle takes its inspiration in the
CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors
the minimum latencies of requests over a window of time. In that
window of time, if the minimum latency of any request exceeds a
given target, then a scale count is incremented and the queue depth
is shrunk. The next monitoring window is shrunk accordingly. Unlike
CoDel, if we hit a window that exhibits good behavior, then we
simply increment the scale count and re-calculate the limits for that
scale value. This prevents us from oscillating between a
close-to-ideal value and max all the time, instead remaining in the
windows where we get good behavior.
Unlike CoDel, blk-wb allows the scale count to to negative. This
happens if we primarily have writes going on. Unlike positive
scale counts, this doesn't change the size of the monitoring window.
When the heavy writers finish, blk-bw quickly snaps back to it's
stable state of a zero scale count.
The patch registers a sysfs entry, 'wb_lat_usec'. This sets the latency
target to me met. It defaults to 2 msec for non-rotational storage, and
75 msec for rotational storage. Setting this value to '0' disables
blk-wb. Generally, a user would not have to touch this setting.
We don't enable WBT on devices that are managed with CFQ, and have
a non-root block cgroup attached. If we have a proportional share setup
on this particular disk, then the wbt throttling will interfere with
that. We don't have a strong need for wbt for that case, since we will
rely on CFQ doing that for us.
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-11-09 19:38:14 +00:00
|
|
|
#include "blk-wbt.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* tunables
|
|
|
|
*/
|
2008-01-31 12:08:54 +00:00
|
|
|
/* max queue in one round of service */
|
2010-03-01 08:20:54 +00:00
|
|
|
static const int cfq_quantum = 8;
|
2016-06-08 14:55:34 +00:00
|
|
|
static const u64 cfq_fifo_expire[2] = { NSEC_PER_SEC / 4, NSEC_PER_SEC / 8 };
|
2008-01-31 12:08:54 +00:00
|
|
|
/* maximum backwards seek, in KiB */
|
|
|
|
static const int cfq_back_max = 16 * 1024;
|
|
|
|
/* penalty of a backwards seek */
|
|
|
|
static const int cfq_back_penalty = 2;
|
2016-06-08 14:55:34 +00:00
|
|
|
static const u64 cfq_slice_sync = NSEC_PER_SEC / 10;
|
|
|
|
static u64 cfq_slice_async = NSEC_PER_SEC / 25;
|
2006-01-06 08:46:02 +00:00
|
|
|
static const int cfq_slice_async_rq = 2;
|
2016-06-08 14:55:34 +00:00
|
|
|
static u64 cfq_slice_idle = NSEC_PER_SEC / 125;
|
|
|
|
static u64 cfq_group_idle = NSEC_PER_SEC / 125;
|
|
|
|
static const u64 cfq_target_latency = (u64)NSEC_PER_SEC * 3/10; /* 300 ms */
|
2009-10-26 21:44:04 +00:00
|
|
|
static const int cfq_hist_divisor = 4;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2007-04-20 12:27:50 +00:00
|
|
|
/*
|
2008-01-28 10:38:15 +00:00
|
|
|
* offset from end of service tree
|
2007-04-20 12:27:50 +00:00
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
#define CFQ_IDLE_DELAY (NSEC_PER_SEC / 5)
|
2007-04-20 12:27:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* below this threshold, we consider thinktime immediate
|
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
#define CFQ_MIN_TT (2 * NSEC_PER_SEC / HZ)
|
2007-04-20 12:27:50 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
#define CFQ_SLICE_SCALE (5)
|
2008-08-26 13:52:36 +00:00
|
|
|
#define CFQ_HW_QUEUE_MIN (5)
|
2009-12-03 17:59:43 +00:00
|
|
|
#define CFQ_SERVICE_SHIFT 12
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2010-02-27 18:45:39 +00:00
|
|
|
#define CFQQ_SEEK_THR (sector_t)(8 * 100)
|
2010-03-19 07:03:04 +00:00
|
|
|
#define CFQQ_CLOSE_THR (sector_t)(8 * 1024)
|
2010-02-27 18:45:40 +00:00
|
|
|
#define CFQQ_SECT_THR_NONROT (sector_t)(2 * 32)
|
2010-02-27 18:45:39 +00:00
|
|
|
#define CFQQ_SEEKY(cfqq) (hweight32(cfqq->seek_history) > 32/8)
|
2010-02-05 12:11:45 +00:00
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
#define RQ_CIC(rq) icq_to_cic((rq)->elv.icq)
|
|
|
|
#define RQ_CFQQ(rq) (struct cfq_queue *) ((rq)->elv.priv[0])
|
|
|
|
#define RQ_CFQG(rq) (struct cfq_group *) ((rq)->elv.priv[1])
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-12-07 04:33:20 +00:00
|
|
|
static struct kmem_cache *cfq_pool;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
#define CFQ_PRIO_LISTS IOPRIO_BE_NR
|
|
|
|
#define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE)
|
|
|
|
#define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT)
|
|
|
|
|
2006-03-28 11:03:44 +00:00
|
|
|
#define sample_valid(samples) ((samples) > 80)
|
2009-12-03 17:59:41 +00:00
|
|
|
#define rb_entry_cfqg(node) rb_entry((node), struct cfq_group, rb_node)
|
2006-03-28 11:03:44 +00:00
|
|
|
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
/* blkio-related constants */
|
2015-08-18 21:55:35 +00:00
|
|
|
#define CFQ_WEIGHT_LEGACY_MIN 10
|
|
|
|
#define CFQ_WEIGHT_LEGACY_DFL 500
|
|
|
|
#define CFQ_WEIGHT_LEGACY_MAX 1000
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_ttime {
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 last_end_request;
|
2011-12-13 23:33:41 +00:00
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 ttime_total;
|
|
|
|
u64 ttime_mean;
|
2011-12-13 23:33:41 +00:00
|
|
|
unsigned long ttime_samples;
|
|
|
|
};
|
|
|
|
|
2007-04-26 10:53:50 +00:00
|
|
|
/*
|
|
|
|
* Most of our rbtree usage is for sorting with min extraction, so
|
|
|
|
* if we cache the leftmost node we don't have to walk down the tree
|
|
|
|
* to find it. Idea borrowed from Ingo Molnars CFS scheduler. We should
|
|
|
|
* move this into the elevator for the rq sorting as well.
|
|
|
|
*/
|
|
|
|
struct cfq_rb_root {
|
|
|
|
struct rb_root rb;
|
|
|
|
struct rb_node *left;
|
2009-10-26 21:44:33 +00:00
|
|
|
unsigned count;
|
2009-12-03 17:59:41 +00:00
|
|
|
u64 min_vdisktime;
|
2011-07-12 12:24:55 +00:00
|
|
|
struct cfq_ttime ttime;
|
2007-04-26 10:53:50 +00:00
|
|
|
};
|
2011-07-12 12:24:55 +00:00
|
|
|
#define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT, \
|
2016-06-08 14:55:34 +00:00
|
|
|
.ttime = {.last_end_request = ktime_get_ns(),},}
|
2007-04-26 10:53:50 +00:00
|
|
|
|
2009-06-30 07:34:12 +00:00
|
|
|
/*
|
|
|
|
* Per process-grouping structure
|
|
|
|
*/
|
|
|
|
struct cfq_queue {
|
|
|
|
/* reference count */
|
2011-01-07 07:46:59 +00:00
|
|
|
int ref;
|
2009-06-30 07:34:12 +00:00
|
|
|
/* various state flags, see below */
|
|
|
|
unsigned int flags;
|
|
|
|
/* parent cfq_data */
|
|
|
|
struct cfq_data *cfqd;
|
|
|
|
/* service_tree member */
|
|
|
|
struct rb_node rb_node;
|
|
|
|
/* service_tree key */
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 rb_key;
|
2009-06-30 07:34:12 +00:00
|
|
|
/* prio tree member */
|
|
|
|
struct rb_node p_node;
|
|
|
|
/* prio tree root we belong to, if any */
|
|
|
|
struct rb_root *p_root;
|
|
|
|
/* sorted list of pending requests */
|
|
|
|
struct rb_root sort_list;
|
|
|
|
/* if fifo isn't expired, next request to serve */
|
|
|
|
struct request *next_rq;
|
|
|
|
/* requests queued in sort_list */
|
|
|
|
int queued[2];
|
|
|
|
/* currently allocated requests */
|
|
|
|
int allocated[2];
|
|
|
|
/* fifo list of requests in sort_list */
|
|
|
|
struct list_head fifo;
|
|
|
|
|
2009-12-03 17:59:45 +00:00
|
|
|
/* time when queue got scheduled in to dispatch first request. */
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 dispatch_start;
|
|
|
|
u64 allocated_slice;
|
|
|
|
u64 slice_dispatch;
|
2009-12-03 17:59:45 +00:00
|
|
|
/* time when first request from queue completed and slice started. */
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 slice_start;
|
|
|
|
u64 slice_end;
|
2016-06-28 07:04:00 +00:00
|
|
|
s64 slice_resid;
|
2009-06-30 07:34:12 +00:00
|
|
|
|
2011-08-23 12:50:29 +00:00
|
|
|
/* pending priority requests */
|
|
|
|
int prio_pending;
|
2009-06-30 07:34:12 +00:00
|
|
|
/* number of requests that are on the dispatch list or inside driver */
|
|
|
|
int dispatched;
|
|
|
|
|
|
|
|
/* io prio of this group */
|
|
|
|
unsigned short ioprio, org_ioprio;
|
2016-06-09 21:47:29 +00:00
|
|
|
unsigned short ioprio_class, org_ioprio_class;
|
2009-06-30 07:34:12 +00:00
|
|
|
|
2010-02-22 12:49:24 +00:00
|
|
|
pid_t pid;
|
|
|
|
|
2010-02-27 18:45:39 +00:00
|
|
|
u32 seek_history;
|
2009-10-23 21:14:49 +00:00
|
|
|
sector_t last_request_pos;
|
|
|
|
|
2009-10-26 21:44:33 +00:00
|
|
|
struct cfq_rb_root *service_tree;
|
2009-10-23 21:14:50 +00:00
|
|
|
struct cfq_queue *new_cfqq;
|
2009-12-03 17:59:38 +00:00
|
|
|
struct cfq_group *cfqg;
|
2010-08-23 10:25:03 +00:00
|
|
|
/* Number of sectors dispatched from queue in single dispatch round */
|
|
|
|
unsigned long nr_sectors;
|
2009-06-30 07:34:12 +00:00
|
|
|
};
|
|
|
|
|
2009-10-27 18:16:03 +00:00
|
|
|
/*
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
* First index in the service_trees.
|
2009-10-27 18:16:03 +00:00
|
|
|
* IDLE is handled separately, so it has negative index
|
|
|
|
*/
|
2012-10-03 20:56:56 +00:00
|
|
|
enum wl_class_t {
|
2009-10-27 18:16:03 +00:00
|
|
|
BE_WORKLOAD = 0,
|
2009-12-03 17:59:39 +00:00
|
|
|
RT_WORKLOAD = 1,
|
|
|
|
IDLE_WORKLOAD = 2,
|
2010-10-22 07:48:43 +00:00
|
|
|
CFQ_PRIO_NR,
|
2009-10-27 18:16:03 +00:00
|
|
|
};
|
|
|
|
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
/*
|
|
|
|
* Second index in the service_trees.
|
|
|
|
*/
|
|
|
|
enum wl_type_t {
|
|
|
|
ASYNC_WORKLOAD = 0,
|
|
|
|
SYNC_NOIDLE_WORKLOAD = 1,
|
|
|
|
SYNC_WORKLOAD = 2
|
|
|
|
};
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfqg_stats {
|
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
/* number of ios merged */
|
|
|
|
struct blkg_rwstat merged;
|
|
|
|
/* total time spent on device in ns, may not be accurate w/ queueing */
|
|
|
|
struct blkg_rwstat service_time;
|
|
|
|
/* total time spent waiting in scheduler queue in ns */
|
|
|
|
struct blkg_rwstat wait_time;
|
|
|
|
/* number of IOs queued up */
|
|
|
|
struct blkg_rwstat queued;
|
|
|
|
/* total disk time and nr sectors dispatched by this group */
|
|
|
|
struct blkg_stat time;
|
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
|
|
|
/* time not charged to this cgroup */
|
|
|
|
struct blkg_stat unaccounted_time;
|
|
|
|
/* sum of number of ios queued across all samples */
|
|
|
|
struct blkg_stat avg_queue_size_sum;
|
|
|
|
/* count of samples taken for average */
|
|
|
|
struct blkg_stat avg_queue_size_samples;
|
|
|
|
/* how many times this group has been removed from service tree */
|
|
|
|
struct blkg_stat dequeue;
|
|
|
|
/* total time spent waiting for it to be assigned a timeslice. */
|
|
|
|
struct blkg_stat group_wait_time;
|
2012-04-16 20:57:25 +00:00
|
|
|
/* time spent idling for this blkcg_gq */
|
2012-04-01 21:38:44 +00:00
|
|
|
struct blkg_stat idle_time;
|
|
|
|
/* total time with empty current active q with other requests queued */
|
|
|
|
struct blkg_stat empty_time;
|
|
|
|
/* fields after this shouldn't be cleared on stat reset */
|
|
|
|
uint64_t start_group_wait_time;
|
|
|
|
uint64_t start_idle_time;
|
|
|
|
uint64_t start_empty_time;
|
|
|
|
uint16_t flags;
|
|
|
|
#endif /* CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
#endif /* CONFIG_CFQ_GROUP_IOSCHED */
|
|
|
|
};
|
|
|
|
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
/* Per-cgroup data */
|
|
|
|
struct cfq_group_data {
|
|
|
|
/* must be the first member */
|
2015-08-18 21:55:15 +00:00
|
|
|
struct blkcg_policy_data cpd;
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
|
|
|
|
unsigned int weight;
|
|
|
|
unsigned int leaf_weight;
|
|
|
|
};
|
|
|
|
|
2009-12-03 17:59:38 +00:00
|
|
|
/* This is per cgroup per device grouping structure */
|
|
|
|
struct cfq_group {
|
2012-04-16 20:57:26 +00:00
|
|
|
/* must be the first member */
|
|
|
|
struct blkg_policy_data pd;
|
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
/* group service_tree member */
|
|
|
|
struct rb_node rb_node;
|
|
|
|
|
|
|
|
/* group service_tree key */
|
|
|
|
u64 vdisktime;
|
2013-01-09 16:05:10 +00:00
|
|
|
|
2013-01-09 16:05:11 +00:00
|
|
|
/*
|
|
|
|
* The number of active cfqgs and sum of their weights under this
|
|
|
|
* cfqg. This covers this cfqg's leaf_weight and all children's
|
|
|
|
* weights, but does not cover weights of further descendants.
|
|
|
|
*
|
|
|
|
* If a cfqg is on the service tree, it's active. An active cfqg
|
|
|
|
* also activates its parent and contributes to the children_weight
|
|
|
|
* of the parent.
|
|
|
|
*/
|
|
|
|
int nr_active;
|
|
|
|
unsigned int children_weight;
|
|
|
|
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
/*
|
|
|
|
* vfraction is the fraction of vdisktime that the tasks in this
|
|
|
|
* cfqg are entitled to. This is determined by compounding the
|
|
|
|
* ratios walking up from this cfqg to the root.
|
|
|
|
*
|
|
|
|
* It is in fixed point w/ CFQ_SERVICE_SHIFT and the sum of all
|
|
|
|
* vfractions on a service tree is approximately 1. The sum may
|
|
|
|
* deviate a bit due to rounding errors and fluctuations caused by
|
|
|
|
* cfqgs entering and leaving the service tree.
|
|
|
|
*/
|
|
|
|
unsigned int vfraction;
|
|
|
|
|
2013-01-09 16:05:10 +00:00
|
|
|
/*
|
|
|
|
* There are two weights - (internal) weight is the weight of this
|
|
|
|
* cfqg against the sibling cfqgs. leaf_weight is the wight of
|
|
|
|
* this cfqg against the child cfqgs. For the root cfqg, both
|
|
|
|
* weights are kept in sync for backward compatibility.
|
|
|
|
*/
|
2009-12-03 17:59:43 +00:00
|
|
|
unsigned int weight;
|
2011-03-17 15:12:36 +00:00
|
|
|
unsigned int new_weight;
|
2012-04-01 21:38:44 +00:00
|
|
|
unsigned int dev_weight;
|
2009-12-03 17:59:41 +00:00
|
|
|
|
2013-01-09 16:05:10 +00:00
|
|
|
unsigned int leaf_weight;
|
|
|
|
unsigned int new_leaf_weight;
|
|
|
|
unsigned int dev_leaf_weight;
|
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
/* number of cfqq currently on this group */
|
|
|
|
int nr_cfqq;
|
|
|
|
|
2009-12-03 17:59:38 +00:00
|
|
|
/*
|
2011-05-31 08:04:09 +00:00
|
|
|
* Per group busy queues average. Useful for workload slice calc. We
|
2010-10-22 07:48:43 +00:00
|
|
|
* create the array for each prio class but at run time it is used
|
|
|
|
* only for RT and BE class and slot for IDLE class remains unused.
|
|
|
|
* This is primarily done to avoid confusion and a gcc warning.
|
|
|
|
*/
|
|
|
|
unsigned int busy_queues_avg[CFQ_PRIO_NR];
|
|
|
|
/*
|
|
|
|
* rr lists of queues with requests. We maintain service trees for
|
|
|
|
* RT and BE classes. These trees are subdivided in subclasses
|
|
|
|
* of SYNC, SYNC_NOIDLE and ASYNC based on workload type. For IDLE
|
|
|
|
* class there is no subclassification and all the cfq queues go on
|
|
|
|
* a single tree service_tree_idle.
|
2009-12-03 17:59:38 +00:00
|
|
|
* Counts are embedded in the cfq_rb_root
|
|
|
|
*/
|
|
|
|
struct cfq_rb_root service_trees[2][3];
|
|
|
|
struct cfq_rb_root service_tree_idle;
|
2009-12-03 17:59:45 +00:00
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 saved_wl_slice;
|
2012-10-03 20:56:57 +00:00
|
|
|
enum wl_type_t saved_wl_type;
|
|
|
|
enum wl_class_t saved_wl_class;
|
2012-03-05 21:15:18 +00:00
|
|
|
|
2010-08-23 10:24:26 +00:00
|
|
|
/* number of requests that are on the dispatch list or inside driver */
|
|
|
|
int dispatched;
|
2011-07-12 12:24:56 +00:00
|
|
|
struct cfq_ttime ttime;
|
2013-01-09 16:05:13 +00:00
|
|
|
struct cfqg_stats stats; /* stats for this cfqg */
|
2015-08-18 21:55:05 +00:00
|
|
|
|
|
|
|
/* async queue for each priority case */
|
|
|
|
struct cfq_queue *async_cfqq[2][IOPRIO_BE_NR];
|
|
|
|
struct cfq_queue *async_idle_cfqq;
|
|
|
|
|
2009-12-03 17:59:38 +00:00
|
|
|
};
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq {
|
|
|
|
struct io_cq icq; /* must be the first member */
|
|
|
|
struct cfq_queue *cfqq[2];
|
|
|
|
struct cfq_ttime ttime;
|
2012-03-19 22:10:58 +00:00
|
|
|
int ioprio; /* the current ioprio */
|
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2014-09-07 23:15:20 +00:00
|
|
|
uint64_t blkcg_serial_nr; /* the current blkcg serial */
|
2012-03-19 22:10:58 +00:00
|
|
|
#endif
|
2011-12-13 23:33:41 +00:00
|
|
|
};
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* Per block device queue structure
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cfq_data {
|
2007-07-24 07:28:11 +00:00
|
|
|
struct request_queue *queue;
|
2009-12-03 17:59:41 +00:00
|
|
|
/* Root service tree for cfq_groups */
|
|
|
|
struct cfq_rb_root grp_service_tree;
|
2012-03-05 21:15:05 +00:00
|
|
|
struct cfq_group *root_group;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2009-10-27 18:16:03 +00:00
|
|
|
/*
|
|
|
|
* The priority currently being served
|
2005-06-27 08:55:12 +00:00
|
|
|
*/
|
2012-10-03 20:56:57 +00:00
|
|
|
enum wl_class_t serving_wl_class;
|
|
|
|
enum wl_type_t serving_wl_type;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 workload_expires;
|
2009-12-03 17:59:38 +00:00
|
|
|
struct cfq_group *serving_group;
|
2009-04-15 10:15:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Each priority tree is sorted by next_request position. These
|
|
|
|
* trees are used when determining if two or more queues are
|
|
|
|
* interleaving requests (see cfq_close_cooperator).
|
|
|
|
*/
|
|
|
|
struct rb_root prio_trees[CFQ_PRIO_LISTS];
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
unsigned int busy_queues;
|
2011-03-07 08:26:29 +00:00
|
|
|
unsigned int busy_sync_queues;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
int rq_in_driver;
|
|
|
|
int rq_in_flight[2];
|
2008-08-26 13:52:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* queue-depth detection
|
|
|
|
*/
|
|
|
|
int rq_queued;
|
2006-06-01 08:12:26 +00:00
|
|
|
int hw_tag;
|
cfq-iosched: fix ncq detection code
CFQ's detection of queueing devices initially assumes a queuing device
and detects if the queue depth reaches a certain threshold.
However, it will reconsider this choice periodically.
Unfortunately, if device is considered not queuing, CFQ will force a
unit queue depth for some workloads, thus defeating the detection logic.
This leads to poor performance on queuing hardware,
since the idle window remains enabled.
Given this premise, switching to hw_tag = 0 after we have proved at
least once that the device is NCQ capable is not a good choice.
The new detection code starts in an indeterminate state, in which CFQ behaves
as if hw_tag = 1, and then, if for a long observation period we never saw
large depth, we switch to hw_tag = 0, otherwise we stick to hw_tag = 1,
without reconsidering it again.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-26 09:02:57 +00:00
|
|
|
/*
|
|
|
|
* hw_tag can be
|
|
|
|
* -1 => indeterminate, (cfq will behave as if NCQ is present, to allow better detection)
|
|
|
|
* 1 => NCQ is present (hw_tag_est_depth is the estimated max depth)
|
|
|
|
* 0 => no NCQ
|
|
|
|
*/
|
|
|
|
int hw_tag_est_depth;
|
|
|
|
unsigned int hw_tag_samples;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* idle window management
|
|
|
|
*/
|
2016-06-08 13:11:39 +00:00
|
|
|
struct hrtimer idle_slice_timer;
|
2009-10-05 06:52:35 +00:00
|
|
|
struct work_struct unplug_work;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
struct cfq_queue *active_queue;
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *active_cic;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2007-04-25 10:44:27 +00:00
|
|
|
sector_t last_position;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* tunables, see top of file
|
|
|
|
*/
|
|
|
|
unsigned int cfq_quantum;
|
|
|
|
unsigned int cfq_back_penalty;
|
|
|
|
unsigned int cfq_back_max;
|
2005-06-27 08:55:12 +00:00
|
|
|
unsigned int cfq_slice_async_rq;
|
2009-10-03 17:42:18 +00:00
|
|
|
unsigned int cfq_latency;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 cfq_fifo_expire[2];
|
|
|
|
u64 cfq_slice[2];
|
|
|
|
u64 cfq_slice_idle;
|
|
|
|
u64 cfq_group_idle;
|
|
|
|
u64 cfq_target_latency;
|
2006-03-18 18:51:22 +00:00
|
|
|
|
2009-06-30 07:34:12 +00:00
|
|
|
/*
|
|
|
|
* Fallback dummy cfqq for extreme OOM conditions
|
|
|
|
*/
|
|
|
|
struct cfq_queue oom_cfqq;
|
2009-10-03 13:21:27 +00:00
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 last_delayed_sync;
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2009-12-03 17:59:46 +00:00
|
|
|
static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd);
|
2015-08-18 21:55:05 +00:00
|
|
|
static void cfq_put_queue(struct cfq_queue *cfqq);
|
2009-12-03 17:59:46 +00:00
|
|
|
|
2012-10-03 20:56:58 +00:00
|
|
|
static struct cfq_rb_root *st_for(struct cfq_group *cfqg,
|
2012-10-03 20:56:56 +00:00
|
|
|
enum wl_class_t class,
|
2009-12-16 22:52:59 +00:00
|
|
|
enum wl_type_t type)
|
2009-10-27 18:16:03 +00:00
|
|
|
{
|
2009-12-03 17:59:41 +00:00
|
|
|
if (!cfqg)
|
|
|
|
return NULL;
|
|
|
|
|
2012-10-03 20:56:56 +00:00
|
|
|
if (class == IDLE_WORKLOAD)
|
2009-12-03 17:59:38 +00:00
|
|
|
return &cfqg->service_tree_idle;
|
2009-10-27 18:16:03 +00:00
|
|
|
|
2012-10-03 20:56:56 +00:00
|
|
|
return &cfqg->service_trees[class][type];
|
2009-10-27 18:16:03 +00:00
|
|
|
}
|
|
|
|
|
2005-06-27 08:56:24 +00:00
|
|
|
enum cfqq_state_flags {
|
2007-01-19 00:35:30 +00:00
|
|
|
CFQ_CFQQ_FLAG_on_rr = 0, /* on round-robin busy list */
|
|
|
|
CFQ_CFQQ_FLAG_wait_request, /* waiting for a request */
|
2009-04-07 09:38:31 +00:00
|
|
|
CFQ_CFQQ_FLAG_must_dispatch, /* must be allowed a dispatch */
|
2007-01-19 00:35:30 +00:00
|
|
|
CFQ_CFQQ_FLAG_must_alloc_slice, /* per-slice must_alloc flag */
|
|
|
|
CFQ_CFQQ_FLAG_fifo_expire, /* FIFO checked in this slice */
|
|
|
|
CFQ_CFQQ_FLAG_idle_window, /* slice idling enabled */
|
|
|
|
CFQ_CFQQ_FLAG_prio_changed, /* task priority has changed */
|
2007-01-19 00:51:58 +00:00
|
|
|
CFQ_CFQQ_FLAG_slice_new, /* no requests dispatched in slice */
|
2007-04-25 10:29:51 +00:00
|
|
|
CFQ_CFQQ_FLAG_sync, /* synchronous queue */
|
2009-10-23 21:14:51 +00:00
|
|
|
CFQ_CFQQ_FLAG_coop, /* cfqq is shared */
|
2010-02-05 12:11:45 +00:00
|
|
|
CFQ_CFQQ_FLAG_split_coop, /* shared cfqq will be splitted */
|
2009-11-26 09:02:58 +00:00
|
|
|
CFQ_CFQQ_FLAG_deep, /* sync cfqq experienced large depth */
|
2009-12-03 17:59:53 +00:00
|
|
|
CFQ_CFQQ_FLAG_wait_busy, /* Waiting for next request */
|
2005-06-27 08:56:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CFQ_CFQQ_FNS(name) \
|
|
|
|
static inline void cfq_mark_cfqq_##name(struct cfq_queue *cfqq) \
|
|
|
|
{ \
|
2008-01-31 12:08:54 +00:00
|
|
|
(cfqq)->flags |= (1 << CFQ_CFQQ_FLAG_##name); \
|
2005-06-27 08:56:24 +00:00
|
|
|
} \
|
|
|
|
static inline void cfq_clear_cfqq_##name(struct cfq_queue *cfqq) \
|
|
|
|
{ \
|
2008-01-31 12:08:54 +00:00
|
|
|
(cfqq)->flags &= ~(1 << CFQ_CFQQ_FLAG_##name); \
|
2005-06-27 08:56:24 +00:00
|
|
|
} \
|
|
|
|
static inline int cfq_cfqq_##name(const struct cfq_queue *cfqq) \
|
|
|
|
{ \
|
2008-01-31 12:08:54 +00:00
|
|
|
return ((cfqq)->flags & (1 << CFQ_CFQQ_FLAG_##name)) != 0; \
|
2005-06-27 08:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CFQ_CFQQ_FNS(on_rr);
|
|
|
|
CFQ_CFQQ_FNS(wait_request);
|
2009-04-07 09:38:31 +00:00
|
|
|
CFQ_CFQQ_FNS(must_dispatch);
|
2005-06-27 08:56:24 +00:00
|
|
|
CFQ_CFQQ_FNS(must_alloc_slice);
|
|
|
|
CFQ_CFQQ_FNS(fifo_expire);
|
|
|
|
CFQ_CFQQ_FNS(idle_window);
|
|
|
|
CFQ_CFQQ_FNS(prio_changed);
|
2007-01-19 00:51:58 +00:00
|
|
|
CFQ_CFQQ_FNS(slice_new);
|
2007-04-25 10:29:51 +00:00
|
|
|
CFQ_CFQQ_FNS(sync);
|
2009-04-15 10:15:11 +00:00
|
|
|
CFQ_CFQQ_FNS(coop);
|
2010-02-05 12:11:45 +00:00
|
|
|
CFQ_CFQQ_FNS(split_coop);
|
2009-11-26 09:02:58 +00:00
|
|
|
CFQ_CFQQ_FNS(deep);
|
2009-12-03 17:59:53 +00:00
|
|
|
CFQ_CFQQ_FNS(wait_busy);
|
2005-06-27 08:56:24 +00:00
|
|
|
#undef CFQ_CFQQ_FNS
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
#if defined(CONFIG_CFQ_GROUP_IOSCHED) && defined(CONFIG_DEBUG_BLK_CGROUP)
|
2012-04-01 21:38:43 +00:00
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
/* cfqg stats flags */
|
|
|
|
enum cfqg_stats_flags {
|
|
|
|
CFQG_stats_waiting = 0,
|
|
|
|
CFQG_stats_idling,
|
|
|
|
CFQG_stats_empty,
|
2012-04-01 21:38:44 +00:00
|
|
|
};
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
#define CFQG_FLAG_FNS(name) \
|
|
|
|
static inline void cfqg_stats_mark_##name(struct cfqg_stats *stats) \
|
2012-04-01 21:38:44 +00:00
|
|
|
{ \
|
2012-04-01 21:38:44 +00:00
|
|
|
stats->flags |= (1 << CFQG_stats_##name); \
|
2012-04-01 21:38:44 +00:00
|
|
|
} \
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline void cfqg_stats_clear_##name(struct cfqg_stats *stats) \
|
2012-04-01 21:38:44 +00:00
|
|
|
{ \
|
2012-04-01 21:38:44 +00:00
|
|
|
stats->flags &= ~(1 << CFQG_stats_##name); \
|
2012-04-01 21:38:44 +00:00
|
|
|
} \
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline int cfqg_stats_##name(struct cfqg_stats *stats) \
|
2012-04-01 21:38:44 +00:00
|
|
|
{ \
|
2012-04-01 21:38:44 +00:00
|
|
|
return (stats->flags & (1 << CFQG_stats_##name)) != 0; \
|
2012-04-01 21:38:44 +00:00
|
|
|
} \
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
CFQG_FLAG_FNS(waiting)
|
|
|
|
CFQG_FLAG_FNS(idling)
|
|
|
|
CFQG_FLAG_FNS(empty)
|
|
|
|
#undef CFQG_FLAG_FNS
|
2012-04-01 21:38:44 +00:00
|
|
|
|
|
|
|
/* This should be called with the queue_lock held. */
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_update_group_wait_time(struct cfqg_stats *stats)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
|
|
|
unsigned long long now;
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
if (!cfqg_stats_waiting(stats))
|
2012-04-01 21:38:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
now = sched_clock();
|
|
|
|
if (time_after64(now, stats->start_group_wait_time))
|
|
|
|
blkg_stat_add(&stats->group_wait_time,
|
|
|
|
now - stats->start_group_wait_time);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_clear_waiting(stats);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be called with the queue_lock held. */
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_set_start_group_wait_time(struct cfq_group *cfqg,
|
|
|
|
struct cfq_group *curr_cfqg)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 21:38:44 +00:00
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
if (cfqg_stats_waiting(stats))
|
2012-04-01 21:38:44 +00:00
|
|
|
return;
|
2012-04-01 21:38:44 +00:00
|
|
|
if (cfqg == curr_cfqg)
|
2012-04-01 21:38:44 +00:00
|
|
|
return;
|
2012-04-01 21:38:44 +00:00
|
|
|
stats->start_group_wait_time = sched_clock();
|
|
|
|
cfqg_stats_mark_waiting(stats);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be called with the queue_lock held. */
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_end_empty_time(struct cfqg_stats *stats)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
|
|
|
unsigned long long now;
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
if (!cfqg_stats_empty(stats))
|
2012-04-01 21:38:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
now = sched_clock();
|
|
|
|
if (time_after64(now, stats->start_empty_time))
|
|
|
|
blkg_stat_add(&stats->empty_time,
|
|
|
|
now - stats->start_empty_time);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_clear_empty(stats);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_update_dequeue(struct cfq_group *cfqg)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
blkg_stat_add(&cfqg->stats.dequeue, 1);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_set_start_empty_time(struct cfq_group *cfqg)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 21:38:44 +00:00
|
|
|
|
2013-01-09 16:05:12 +00:00
|
|
|
if (blkg_rwstat_total(&stats->queued))
|
2012-04-01 21:38:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* group is already marked empty. This can happen if cfqq got new
|
|
|
|
* request in parent group and moved to this group while being added
|
|
|
|
* to service tree. Just ignore the event and move on.
|
|
|
|
*/
|
2012-04-01 21:38:44 +00:00
|
|
|
if (cfqg_stats_empty(stats))
|
2012-04-01 21:38:44 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
stats->start_empty_time = sched_clock();
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_mark_empty(stats);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_update_idle_time(struct cfq_group *cfqg)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 21:38:44 +00:00
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
if (cfqg_stats_idling(stats)) {
|
2012-04-01 21:38:44 +00:00
|
|
|
unsigned long long now = sched_clock();
|
|
|
|
|
|
|
|
if (time_after64(now, stats->start_idle_time))
|
|
|
|
blkg_stat_add(&stats->idle_time,
|
|
|
|
now - stats->start_idle_time);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_clear_idling(stats);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_set_start_idle_time(struct cfq_group *cfqg)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 21:38:44 +00:00
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
BUG_ON(cfqg_stats_idling(stats));
|
2012-04-01 21:38:44 +00:00
|
|
|
|
|
|
|
stats->start_idle_time = sched_clock();
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_mark_idling(stats);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static void cfqg_stats_update_avg_queue_size(struct cfq_group *cfqg)
|
2012-04-01 21:38:44 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 21:38:44 +00:00
|
|
|
|
|
|
|
blkg_stat_add(&stats->avg_queue_size_sum,
|
2013-01-09 16:05:12 +00:00
|
|
|
blkg_rwstat_total(&stats->queued));
|
2012-04-01 21:38:44 +00:00
|
|
|
blkg_stat_add(&stats->avg_queue_size_samples, 1);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_group_wait_time(stats);
|
2012-04-01 21:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_CFQ_GROUP_IOSCHED && CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
|
2012-04-13 20:11:25 +00:00
|
|
|
static inline void cfqg_stats_set_start_group_wait_time(struct cfq_group *cfqg, struct cfq_group *curr_cfqg) { }
|
|
|
|
static inline void cfqg_stats_end_empty_time(struct cfqg_stats *stats) { }
|
|
|
|
static inline void cfqg_stats_update_dequeue(struct cfq_group *cfqg) { }
|
|
|
|
static inline void cfqg_stats_set_start_empty_time(struct cfq_group *cfqg) { }
|
|
|
|
static inline void cfqg_stats_update_idle_time(struct cfq_group *cfqg) { }
|
|
|
|
static inline void cfqg_stats_set_start_idle_time(struct cfq_group *cfqg) { }
|
|
|
|
static inline void cfqg_stats_update_avg_queue_size(struct cfq_group *cfqg) { }
|
2012-04-01 21:38:44 +00:00
|
|
|
|
|
|
|
#endif /* CONFIG_CFQ_GROUP_IOSCHED && CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-01 21:38:43 +00:00
|
|
|
|
2015-06-19 16:13:01 +00:00
|
|
|
static inline struct cfq_group *pd_to_cfqg(struct blkg_policy_data *pd)
|
|
|
|
{
|
|
|
|
return pd ? container_of(pd, struct cfq_group, pd) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cfq_group_data
|
|
|
|
*cpd_to_cfqgd(struct blkcg_policy_data *cpd)
|
|
|
|
{
|
2015-08-18 21:55:15 +00:00
|
|
|
return cpd ? container_of(cpd, struct cfq_group_data, cpd) : NULL;
|
2015-06-19 16:13:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct blkcg_gq *cfqg_to_blkg(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
return pd_to_blkg(&cfqg->pd);
|
|
|
|
}
|
|
|
|
|
block: blkcg_policy_cfq shouldn't be used if !CONFIG_CFQ_GROUP_IOSCHED
cfq may be built w/ or w/o blkcg support depending on
CONFIG_CFQ_CGROUP_IOSCHED. If blkcg support is disabled, most of
related code is ifdef'd out but some part is left dangling -
blkcg_policy_cfq is left zero-filled and blkcg_policy_[un]register()
calls are made on it.
Feeding zero filled policy to blkcg_policy_register() is incorrect and
triggers the following WARN_ON() if CONFIG_BLK_CGROUP &&
!CONFIG_CFQ_GROUP_IOSCHED.
------------[ cut here ]------------
WARNING: at block/blk-cgroup.c:867
Modules linked in:
Modules linked in:
CPU: 3 Not tainted 3.4.0-09547-gfb21aff #1
Process swapper/0 (pid: 1, task: 000000003ff80000, ksp: 000000003ff7f8b8)
Krnl PSW : 0704100180000000 00000000003d76ca (blkcg_policy_register+0xca/0xe0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0 EA:3
Krnl GPRS: 0000000000000000 00000000014b85ec 00000000014b85b0 0000000000000000
000000000096fb60 0000000000000000 00000000009a8e78 0000000000000048
000000000099c070 0000000000b6f000 0000000000000000 000000000099c0b8
00000000014b85b0 0000000000667580 000000003ff7fd98 000000003ff7fd70
Krnl Code: 00000000003d76be: a7280001 lhi %r2,1
00000000003d76c2: a7f4ffdf brc 15,3d7680
#00000000003d76c6: a7f40001 brc 15,3d76c8
>00000000003d76ca: a7c8ffea lhi %r12,-22
00000000003d76ce: a7f4ffce brc 15,3d766a
00000000003d76d2: a7f40001 brc 15,3d76d4
00000000003d76d6: a7c80000 lhi %r12,0
00000000003d76da: a7f4ffc2 brc 15,3d765e
Call Trace:
([<0000000000b6f000>] initcall_debug+0x0/0x4)
[<0000000000989e8a>] cfq_init+0x62/0xd4
[<00000000001000ba>] do_one_initcall+0x3a/0x170
[<000000000096fb60>] kernel_init+0x214/0x2bc
[<0000000000623202>] kernel_thread_starter+0x6/0xc
[<00000000006231fc>] kernel_thread_starter+0x0/0xc
no locks held by swapper/0/1.
Last Breaking-Event-Address:
[<00000000003d76c6>] blkcg_policy_register+0xc6/0xe0
---[ end trace b8ef4903fcbf9dd3 ]---
This patch fixes the problem by ensuring all blkcg support code is
inside CONFIG_CFQ_GROUP_IOSCHED.
* blkcg_policy_cfq declaration and blkg_to_cfqg() definition are moved
inside the first CONFIG_CFQ_GROUP_IOSCHED block. __maybe_unused is
dropped from blkcg_policy_cfq decl.
* blkcg_deactivate_poilcy() invocation is moved inside ifdef. This
also makes the activation logic match cfq_init_queue().
* All blkcg_policy_[un]register() invocations are moved inside ifdef.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
LKML-Reference: <20120601112954.GC3535@osiris.boeblingen.de.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-06-04 08:02:29 +00:00
|
|
|
static struct blkcg_policy blkcg_policy_cfq;
|
|
|
|
|
|
|
|
static inline struct cfq_group *blkg_to_cfqg(struct blkcg_gq *blkg)
|
|
|
|
{
|
|
|
|
return pd_to_cfqg(blkg_to_pd(blkg, &blkcg_policy_cfq));
|
|
|
|
}
|
|
|
|
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
static struct cfq_group_data *blkcg_to_cfqgd(struct blkcg *blkcg)
|
|
|
|
{
|
|
|
|
return cpd_to_cfqgd(blkcg_to_cpd(blkcg, &blkcg_policy_cfq));
|
|
|
|
}
|
|
|
|
|
2013-01-09 16:05:11 +00:00
|
|
|
static inline struct cfq_group *cfqg_parent(struct cfq_group *cfqg)
|
2013-01-09 16:05:11 +00:00
|
|
|
{
|
2013-01-09 16:05:11 +00:00
|
|
|
struct blkcg_gq *pblkg = cfqg_to_blkg(cfqg)->parent;
|
2013-01-09 16:05:11 +00:00
|
|
|
|
2013-01-09 16:05:11 +00:00
|
|
|
return pblkg ? blkg_to_cfqg(pblkg) : NULL;
|
2013-01-09 16:05:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 15:24:19 +00:00
|
|
|
static inline bool cfqg_is_descendant(struct cfq_group *cfqg,
|
|
|
|
struct cfq_group *ancestor)
|
|
|
|
{
|
|
|
|
return cgroup_is_descendant(cfqg_to_blkg(cfqg)->blkcg->css.cgroup,
|
|
|
|
cfqg_to_blkg(ancestor)->blkcg->css.cgroup);
|
|
|
|
}
|
|
|
|
|
2012-03-23 13:02:53 +00:00
|
|
|
static inline void cfqg_get(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
return blkg_get(cfqg_to_blkg(cfqg));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void cfqg_put(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
return blkg_put(cfqg_to_blkg(cfqg));
|
|
|
|
}
|
|
|
|
|
2012-04-16 20:57:23 +00:00
|
|
|
#define cfq_log_cfqq(cfqd, cfqq, fmt, args...) do { \
|
|
|
|
char __pbuf[128]; \
|
|
|
|
\
|
|
|
|
blkg_path(cfqg_to_blkg((cfqq)->cfqg), __pbuf, sizeof(__pbuf)); \
|
2012-10-03 20:57:01 +00:00
|
|
|
blk_add_trace_msg((cfqd)->queue, "cfq%d%c%c %s " fmt, (cfqq)->pid, \
|
|
|
|
cfq_cfqq_sync((cfqq)) ? 'S' : 'A', \
|
|
|
|
cfqq_type((cfqq)) == SYNC_NOIDLE_WORKLOAD ? 'N' : ' ',\
|
2012-04-16 20:57:23 +00:00
|
|
|
__pbuf, ##args); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define cfq_log_cfqg(cfqd, cfqg, fmt, args...) do { \
|
|
|
|
char __pbuf[128]; \
|
|
|
|
\
|
|
|
|
blkg_path(cfqg_to_blkg(cfqg), __pbuf, sizeof(__pbuf)); \
|
|
|
|
blk_add_trace_msg((cfqd)->queue, "%s " fmt, __pbuf, ##args); \
|
|
|
|
} while (0)
|
2009-12-03 17:59:48 +00:00
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg,
|
2016-10-28 14:48:16 +00:00
|
|
|
struct cfq_group *curr_cfqg,
|
|
|
|
unsigned int op)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2016-10-28 14:48:16 +00:00
|
|
|
blkg_rwstat_add(&cfqg->stats.queued, op, 1);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_end_empty_time(&cfqg->stats);
|
|
|
|
cfqg_stats_set_start_group_wait_time(cfqg, curr_cfqg);
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg,
|
2016-06-08 14:55:34 +00:00
|
|
|
uint64_t time, unsigned long unaccounted_time)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
blkg_stat_add(&cfqg->stats.time, time);
|
2012-04-01 21:38:44 +00:00
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
2012-04-01 21:38:44 +00:00
|
|
|
blkg_stat_add(&cfqg->stats.unaccounted_time, unaccounted_time);
|
2012-04-01 21:38:44 +00:00
|
|
|
#endif
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 14:48:16 +00:00
|
|
|
static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg,
|
|
|
|
unsigned int op)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2016-10-28 14:48:16 +00:00
|
|
|
blkg_rwstat_add(&cfqg->stats.queued, op, -1);
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 14:48:16 +00:00
|
|
|
static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg,
|
|
|
|
unsigned int op)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2016-10-28 14:48:16 +00:00
|
|
|
blkg_rwstat_add(&cfqg->stats.merged, op, 1);
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
|
2016-10-28 14:48:16 +00:00
|
|
|
uint64_t start_time, uint64_t io_start_time,
|
|
|
|
unsigned int op)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 21:38:44 +00:00
|
|
|
unsigned long long now = sched_clock();
|
|
|
|
|
|
|
|
if (time_after64(now, io_start_time))
|
2016-10-28 14:48:16 +00:00
|
|
|
blkg_rwstat_add(&stats->service_time, op, now - io_start_time);
|
2012-04-01 21:38:44 +00:00
|
|
|
if (time_after64(io_start_time, start_time))
|
2016-10-28 14:48:16 +00:00
|
|
|
blkg_rwstat_add(&stats->wait_time, op,
|
2012-04-01 21:38:44 +00:00
|
|
|
io_start_time - start_time);
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 16:05:13 +00:00
|
|
|
/* @stats = 0 */
|
|
|
|
static void cfqg_stats_reset(struct cfqg_stats *stats)
|
2012-04-01 21:38:44 +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);
|
|
|
|
blkg_stat_reset(&stats->time);
|
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
|
|
|
blkg_stat_reset(&stats->unaccounted_time);
|
|
|
|
blkg_stat_reset(&stats->avg_queue_size_sum);
|
|
|
|
blkg_stat_reset(&stats->avg_queue_size_samples);
|
|
|
|
blkg_stat_reset(&stats->dequeue);
|
|
|
|
blkg_stat_reset(&stats->group_wait_time);
|
|
|
|
blkg_stat_reset(&stats->idle_time);
|
|
|
|
blkg_stat_reset(&stats->empty_time);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-09 16:05:13 +00:00
|
|
|
/* @to += @from */
|
2015-08-18 21:55:21 +00:00
|
|
|
static void cfqg_stats_add_aux(struct cfqg_stats *to, struct cfqg_stats *from)
|
2013-01-09 16:05:13 +00:00
|
|
|
{
|
|
|
|
/* queued stats shouldn't be cleared */
|
2015-08-18 21:55:21 +00:00
|
|
|
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);
|
|
|
|
blkg_stat_add_aux(&from->time, &from->time);
|
2013-01-09 16:05:13 +00:00
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
2015-08-18 21:55:21 +00:00
|
|
|
blkg_stat_add_aux(&to->unaccounted_time, &from->unaccounted_time);
|
|
|
|
blkg_stat_add_aux(&to->avg_queue_size_sum, &from->avg_queue_size_sum);
|
|
|
|
blkg_stat_add_aux(&to->avg_queue_size_samples, &from->avg_queue_size_samples);
|
|
|
|
blkg_stat_add_aux(&to->dequeue, &from->dequeue);
|
|
|
|
blkg_stat_add_aux(&to->group_wait_time, &from->group_wait_time);
|
|
|
|
blkg_stat_add_aux(&to->idle_time, &from->idle_time);
|
|
|
|
blkg_stat_add_aux(&to->empty_time, &from->empty_time);
|
2013-01-09 16:05:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-08-18 21:55:21 +00:00
|
|
|
* Transfer @cfqg's stats to its parent's aux counts so that the ancestors'
|
2013-01-09 16:05:13 +00:00
|
|
|
* recursive stats can still account for the amount used by this cfqg after
|
|
|
|
* it's gone.
|
|
|
|
*/
|
|
|
|
static void cfqg_stats_xfer_dead(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
struct cfq_group *parent = cfqg_parent(cfqg);
|
|
|
|
|
|
|
|
lockdep_assert_held(cfqg_to_blkg(cfqg)->q->queue_lock);
|
|
|
|
|
|
|
|
if (unlikely(!parent))
|
|
|
|
return;
|
|
|
|
|
2015-08-18 21:55:21 +00:00
|
|
|
cfqg_stats_add_aux(&parent->stats, &cfqg->stats);
|
2013-01-09 16:05:13 +00:00
|
|
|
cfqg_stats_reset(&cfqg->stats);
|
|
|
|
}
|
|
|
|
|
2012-03-23 13:02:53 +00:00
|
|
|
#else /* CONFIG_CFQ_GROUP_IOSCHED */
|
|
|
|
|
2013-01-09 16:05:11 +00:00
|
|
|
static inline struct cfq_group *cfqg_parent(struct cfq_group *cfqg) { return NULL; }
|
2016-01-12 15:24:19 +00:00
|
|
|
static inline bool cfqg_is_descendant(struct cfq_group *cfqg,
|
|
|
|
struct cfq_group *ancestor)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-23 13:02:53 +00:00
|
|
|
static inline void cfqg_get(struct cfq_group *cfqg) { }
|
|
|
|
static inline void cfqg_put(struct cfq_group *cfqg) { }
|
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
#define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \
|
2012-10-03 20:57:01 +00:00
|
|
|
blk_add_trace_msg((cfqd)->queue, "cfq%d%c%c " fmt, (cfqq)->pid, \
|
|
|
|
cfq_cfqq_sync((cfqq)) ? 'S' : 'A', \
|
|
|
|
cfqq_type((cfqq)) == SYNC_NOIDLE_WORKLOAD ? 'N' : ' ',\
|
|
|
|
##args)
|
2011-05-31 08:04:09 +00:00
|
|
|
#define cfq_log_cfqg(cfqd, cfqg, fmt, args...) do {} while (0)
|
2012-03-23 13:02:53 +00:00
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg,
|
2016-10-28 14:48:16 +00:00
|
|
|
struct cfq_group *curr_cfqg, unsigned int op) { }
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg,
|
2016-06-08 14:55:34 +00:00
|
|
|
uint64_t time, unsigned long unaccounted_time) { }
|
2016-10-28 14:48:16 +00:00
|
|
|
static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg,
|
|
|
|
unsigned int op) { }
|
|
|
|
static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg,
|
|
|
|
unsigned int op) { }
|
2012-04-01 21:38:44 +00:00
|
|
|
static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
|
2016-10-28 14:48:16 +00:00
|
|
|
uint64_t start_time, uint64_t io_start_time,
|
|
|
|
unsigned int op) { }
|
2012-04-01 21:38:43 +00:00
|
|
|
|
2012-03-23 13:02:53 +00:00
|
|
|
#endif /* CONFIG_CFQ_GROUP_IOSCHED */
|
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
#define cfq_log(cfqd, fmt, args...) \
|
|
|
|
blk_add_trace_msg((cfqd)->queue, "cfq " fmt, ##args)
|
|
|
|
|
2009-12-03 17:59:39 +00:00
|
|
|
/* Traverses through cfq group service trees */
|
|
|
|
#define for_each_cfqg_st(cfqg, i, j, st) \
|
|
|
|
for (i = 0; i <= IDLE_WORKLOAD; i++) \
|
|
|
|
for (j = 0, st = i < IDLE_WORKLOAD ? &cfqg->service_trees[i][j]\
|
|
|
|
: &cfqg->service_tree_idle; \
|
|
|
|
(i < IDLE_WORKLOAD && j <= SYNC_WORKLOAD) || \
|
|
|
|
(i == IDLE_WORKLOAD && j == 0); \
|
|
|
|
j++, st = i < IDLE_WORKLOAD ? \
|
|
|
|
&cfqg->service_trees[i][j]: NULL) \
|
|
|
|
|
2011-07-12 12:24:55 +00:00
|
|
|
static inline bool cfq_io_thinktime_big(struct cfq_data *cfqd,
|
|
|
|
struct cfq_ttime *ttime, bool group_idle)
|
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 slice;
|
2011-07-12 12:24:55 +00:00
|
|
|
if (!sample_valid(ttime->ttime_samples))
|
|
|
|
return false;
|
|
|
|
if (group_idle)
|
|
|
|
slice = cfqd->cfq_group_idle;
|
|
|
|
else
|
|
|
|
slice = cfqd->cfq_slice_idle;
|
|
|
|
return ttime->ttime_mean > slice;
|
|
|
|
}
|
2009-12-03 17:59:39 +00:00
|
|
|
|
2010-08-23 10:23:53 +00:00
|
|
|
static inline bool iops_mode(struct cfq_data *cfqd)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If we are not idling on queues and it is a NCQ drive, parallel
|
|
|
|
* execution of requests is on and measuring time is not possible
|
|
|
|
* in most of the cases until and unless we drive shallower queue
|
|
|
|
* depths and that becomes a performance bottleneck. In such cases
|
|
|
|
* switch to start providing fairness in terms of number of IOs.
|
|
|
|
*/
|
|
|
|
if (!cfqd->cfq_slice_idle && cfqd->hw_tag)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-03 20:56:56 +00:00
|
|
|
static inline enum wl_class_t cfqq_class(struct cfq_queue *cfqq)
|
2009-10-27 18:16:03 +00:00
|
|
|
{
|
|
|
|
if (cfq_class_idle(cfqq))
|
|
|
|
return IDLE_WORKLOAD;
|
|
|
|
if (cfq_class_rt(cfqq))
|
|
|
|
return RT_WORKLOAD;
|
|
|
|
return BE_WORKLOAD;
|
|
|
|
}
|
|
|
|
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
|
|
|
|
static enum wl_type_t cfqq_type(struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
if (!cfq_cfqq_sync(cfqq))
|
|
|
|
return ASYNC_WORKLOAD;
|
|
|
|
if (!cfq_cfqq_idle_window(cfqq))
|
|
|
|
return SYNC_NOIDLE_WORKLOAD;
|
|
|
|
return SYNC_WORKLOAD;
|
|
|
|
}
|
|
|
|
|
2012-10-03 20:56:56 +00:00
|
|
|
static inline int cfq_group_busy_queues_wl(enum wl_class_t wl_class,
|
2009-12-03 17:59:44 +00:00
|
|
|
struct cfq_data *cfqd,
|
|
|
|
struct cfq_group *cfqg)
|
2009-10-27 18:16:03 +00:00
|
|
|
{
|
2012-10-03 20:56:56 +00:00
|
|
|
if (wl_class == IDLE_WORKLOAD)
|
2009-12-03 17:59:38 +00:00
|
|
|
return cfqg->service_tree_idle.count;
|
2009-10-27 18:16:03 +00:00
|
|
|
|
2012-10-03 20:56:58 +00:00
|
|
|
return cfqg->service_trees[wl_class][ASYNC_WORKLOAD].count +
|
|
|
|
cfqg->service_trees[wl_class][SYNC_NOIDLE_WORKLOAD].count +
|
|
|
|
cfqg->service_trees[wl_class][SYNC_WORKLOAD].count;
|
2009-10-27 18:16:03 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:54 +00:00
|
|
|
static inline int cfqg_busy_async_queues(struct cfq_data *cfqd,
|
|
|
|
struct cfq_group *cfqg)
|
|
|
|
{
|
2012-10-03 20:56:58 +00:00
|
|
|
return cfqg->service_trees[RT_WORKLOAD][ASYNC_WORKLOAD].count +
|
|
|
|
cfqg->service_trees[BE_WORKLOAD][ASYNC_WORKLOAD].count;
|
2009-12-03 17:59:54 +00:00
|
|
|
}
|
|
|
|
|
2007-07-24 07:28:11 +00:00
|
|
|
static void cfq_dispatch_insert(struct request_queue *, struct request *);
|
2012-03-05 21:15:28 +00:00
|
|
|
static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, bool is_sync,
|
2015-08-18 21:55:02 +00:00
|
|
|
struct cfq_io_cq *cic, struct bio *bio);
|
2007-04-25 10:29:51 +00:00
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
static inline struct cfq_io_cq *icq_to_cic(struct io_cq *icq)
|
|
|
|
{
|
|
|
|
/* cic->icq is the first member, %NULL will convert to %NULL */
|
|
|
|
return container_of(icq, struct cfq_io_cq, icq);
|
|
|
|
}
|
|
|
|
|
2011-12-13 23:33:42 +00:00
|
|
|
static inline struct cfq_io_cq *cfq_cic_lookup(struct cfq_data *cfqd,
|
|
|
|
struct io_context *ioc)
|
|
|
|
{
|
|
|
|
if (ioc)
|
|
|
|
return icq_to_cic(ioc_lookup_icq(ioc, cfqd->queue));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
static inline struct cfq_queue *cic_to_cfqq(struct cfq_io_cq *cic, bool is_sync)
|
2007-04-25 10:29:51 +00:00
|
|
|
{
|
2009-10-07 18:02:57 +00:00
|
|
|
return cic->cfqq[is_sync];
|
2007-04-25 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
static inline void cic_set_cfqq(struct cfq_io_cq *cic, struct cfq_queue *cfqq,
|
|
|
|
bool is_sync)
|
2007-04-25 10:29:51 +00:00
|
|
|
{
|
2009-10-07 18:02:57 +00:00
|
|
|
cic->cfqq[is_sync] = cfqq;
|
2007-04-25 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic)
|
2010-05-20 19:21:34 +00:00
|
|
|
{
|
2011-12-13 23:33:41 +00:00
|
|
|
return cic->icq.q->elevator->elevator_data;
|
2010-05-20 19:21:34 +00:00
|
|
|
}
|
|
|
|
|
2005-06-28 03:14:05 +00:00
|
|
|
/*
|
|
|
|
* scheduler run of queue, if there are requests pending and no one in the
|
|
|
|
* driver that will restart queueing
|
|
|
|
*/
|
2009-10-05 06:52:35 +00:00
|
|
|
static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
|
2005-06-28 03:14:05 +00:00
|
|
|
{
|
2008-05-30 10:23:07 +00:00
|
|
|
if (cfqd->busy_queues) {
|
|
|
|
cfq_log(cfqd, "schedule dispatch");
|
2014-04-08 15:15:35 +00:00
|
|
|
kblockd_schedule_work(&cfqd->unplug_work);
|
2008-05-30 10:23:07 +00:00
|
|
|
}
|
2005-06-28 03:14:05 +00:00
|
|
|
}
|
|
|
|
|
2007-01-19 00:51:58 +00:00
|
|
|
/*
|
|
|
|
* Scale schedule slice based on io priority. Use the sync time slice only
|
|
|
|
* if a queue is marked sync and has sync io queued. A sync queue with async
|
|
|
|
* io only, should not get full sync slice length.
|
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
static inline u64 cfq_prio_slice(struct cfq_data *cfqd, bool sync,
|
2007-04-20 12:27:50 +00:00
|
|
|
unsigned short prio)
|
2007-01-19 00:51:58 +00:00
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 base_slice = cfqd->cfq_slice[sync];
|
|
|
|
u64 slice = div_u64(base_slice, CFQ_SLICE_SCALE);
|
2007-01-19 00:51:58 +00:00
|
|
|
|
2007-04-20 12:27:50 +00:00
|
|
|
WARN_ON(prio >= IOPRIO_BE_NR);
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
return base_slice + (slice * (4 - prio));
|
2007-04-20 12:27:50 +00:00
|
|
|
}
|
2007-01-19 00:51:58 +00:00
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
static inline u64
|
2007-04-20 12:27:50 +00:00
|
|
|
cfq_prio_to_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
return cfq_prio_slice(cfqd, cfq_cfqq_sync(cfqq), cfqq->ioprio);
|
2007-01-19 00:51:58 +00:00
|
|
|
}
|
|
|
|
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
/**
|
|
|
|
* cfqg_scale_charge - scale disk time charge according to cfqg weight
|
|
|
|
* @charge: disk time being charged
|
|
|
|
* @vfraction: vfraction of the cfqg, fixed point w/ CFQ_SERVICE_SHIFT
|
|
|
|
*
|
|
|
|
* Scale @charge according to @vfraction, which is in range (0, 1]. The
|
|
|
|
* scaling is inversely proportional.
|
|
|
|
*
|
|
|
|
* scaled = charge / vfraction
|
|
|
|
*
|
|
|
|
* The result is also in fixed point w/ CFQ_SERVICE_SHIFT.
|
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
static inline u64 cfqg_scale_charge(u64 charge,
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
unsigned int vfraction)
|
2009-12-03 17:59:43 +00:00
|
|
|
{
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
u64 c = charge << CFQ_SERVICE_SHIFT; /* make it fixed point */
|
2009-12-03 17:59:43 +00:00
|
|
|
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
/* charge / vfraction */
|
|
|
|
c <<= CFQ_SERVICE_SHIFT;
|
2016-06-08 14:55:34 +00:00
|
|
|
return div_u64(c, vfraction);
|
2009-12-03 17:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 max_vdisktime(u64 min_vdisktime, u64 vdisktime)
|
|
|
|
{
|
|
|
|
s64 delta = (s64)(vdisktime - min_vdisktime);
|
|
|
|
if (delta > 0)
|
|
|
|
min_vdisktime = vdisktime;
|
|
|
|
|
|
|
|
return min_vdisktime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 min_vdisktime(u64 min_vdisktime, u64 vdisktime)
|
|
|
|
{
|
|
|
|
s64 delta = (s64)(vdisktime - min_vdisktime);
|
|
|
|
if (delta < 0)
|
|
|
|
min_vdisktime = vdisktime;
|
|
|
|
|
|
|
|
return min_vdisktime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_min_vdisktime(struct cfq_rb_root *st)
|
|
|
|
{
|
|
|
|
struct cfq_group *cfqg;
|
|
|
|
|
|
|
|
if (st->left) {
|
|
|
|
cfqg = rb_entry_cfqg(st->left);
|
2011-03-07 08:28:09 +00:00
|
|
|
st->min_vdisktime = max_vdisktime(st->min_vdisktime,
|
|
|
|
cfqg->vdisktime);
|
2009-12-03 17:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-26 21:44:04 +00:00
|
|
|
/*
|
|
|
|
* get averaged number of queues of RT/BE priority.
|
|
|
|
* average is updated, with a formula that gives more weight to higher numbers,
|
|
|
|
* to quickly follows sudden increases and decrease slowly
|
|
|
|
*/
|
|
|
|
|
2009-12-03 17:59:44 +00:00
|
|
|
static inline unsigned cfq_group_get_avg_queues(struct cfq_data *cfqd,
|
|
|
|
struct cfq_group *cfqg, bool rt)
|
2009-10-28 08:27:07 +00:00
|
|
|
{
|
2009-10-26 21:44:04 +00:00
|
|
|
unsigned min_q, max_q;
|
|
|
|
unsigned mult = cfq_hist_divisor - 1;
|
|
|
|
unsigned round = cfq_hist_divisor / 2;
|
2009-12-03 17:59:44 +00:00
|
|
|
unsigned busy = cfq_group_busy_queues_wl(rt, cfqd, cfqg);
|
2009-10-26 21:44:04 +00:00
|
|
|
|
2009-12-03 17:59:44 +00:00
|
|
|
min_q = min(cfqg->busy_queues_avg[rt], busy);
|
|
|
|
max_q = max(cfqg->busy_queues_avg[rt], busy);
|
|
|
|
cfqg->busy_queues_avg[rt] = (mult * max_q + min_q + round) /
|
2009-10-26 21:44:04 +00:00
|
|
|
cfq_hist_divisor;
|
2009-12-03 17:59:44 +00:00
|
|
|
return cfqg->busy_queues_avg[rt];
|
|
|
|
}
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
static inline u64
|
2009-12-03 17:59:44 +00:00
|
|
|
cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg)
|
|
|
|
{
|
2013-01-09 16:05:11 +00:00
|
|
|
return cfqd->cfq_target_latency * cfqg->vfraction >> CFQ_SERVICE_SHIFT;
|
2009-10-26 21:44:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
static inline u64
|
2011-01-19 15:25:02 +00:00
|
|
|
cfq_scaled_cfqq_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2007-01-19 00:51:58 +00:00
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 slice = cfq_prio_to_slice(cfqd, cfqq);
|
2009-10-26 21:44:04 +00:00
|
|
|
if (cfqd->cfq_latency) {
|
2009-12-03 17:59:44 +00:00
|
|
|
/*
|
|
|
|
* interested queues (we consider only the ones with the same
|
|
|
|
* priority class in the cfq group)
|
|
|
|
*/
|
|
|
|
unsigned iq = cfq_group_get_avg_queues(cfqd, cfqq->cfqg,
|
|
|
|
cfq_class_rt(cfqq));
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 sync_slice = cfqd->cfq_slice[1];
|
|
|
|
u64 expect_latency = sync_slice * iq;
|
|
|
|
u64 group_slice = cfq_group_slice(cfqd, cfqq->cfqg);
|
2009-12-03 17:59:44 +00:00
|
|
|
|
|
|
|
if (expect_latency > group_slice) {
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 base_low_slice = 2 * cfqd->cfq_slice_idle;
|
|
|
|
u64 low_slice;
|
|
|
|
|
2009-10-26 21:44:04 +00:00
|
|
|
/* scale low_slice according to IO priority
|
|
|
|
* and sync vs async */
|
2016-06-08 14:55:34 +00:00
|
|
|
low_slice = div64_u64(base_low_slice*slice, sync_slice);
|
|
|
|
low_slice = min(slice, low_slice);
|
2009-10-26 21:44:04 +00:00
|
|
|
/* the adapted slice value is scaled to fit all iqs
|
|
|
|
* into the target latency */
|
2016-06-08 14:55:34 +00:00
|
|
|
slice = div64_u64(slice*group_slice, expect_latency);
|
|
|
|
slice = max(slice, low_slice);
|
2009-10-26 21:44:04 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-14 07:41:03 +00:00
|
|
|
return slice;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 slice = cfq_scaled_cfqq_slice(cfqd, cfqq);
|
|
|
|
u64 now = ktime_get_ns();
|
2011-01-14 07:41:03 +00:00
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqq->slice_start = now;
|
|
|
|
cfqq->slice_end = now + slice;
|
2009-12-03 17:59:53 +00:00
|
|
|
cfqq->allocated_slice = slice;
|
2016-06-08 14:55:34 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "set_slice=%llu", cfqq->slice_end - now);
|
2007-01-19 00:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to wrap this check in cfq_cfqq_slice_new(), since ->slice_end
|
|
|
|
* isn't valid until the first request from the dispatch is activated
|
|
|
|
* and the slice time set.
|
|
|
|
*/
|
2009-10-07 18:02:57 +00:00
|
|
|
static inline bool cfq_slice_used(struct cfq_queue *cfqq)
|
2007-01-19 00:51:58 +00:00
|
|
|
{
|
|
|
|
if (cfq_cfqq_slice_new(cfqq))
|
2010-11-08 14:01:02 +00:00
|
|
|
return false;
|
2016-06-08 14:55:34 +00:00
|
|
|
if (ktime_get_ns() < cfqq->slice_end)
|
2010-11-08 14:01:02 +00:00
|
|
|
return false;
|
2007-01-19 00:51:58 +00:00
|
|
|
|
2010-11-08 14:01:02 +00:00
|
|
|
return true;
|
2007-01-19 00:51:58 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2006-07-13 10:39:25 +00:00
|
|
|
* Lifted from AS - choose which of rq1 and rq2 that is best served now.
|
2005-04-16 22:20:36 +00:00
|
|
|
* We choose the request that is closest to the head right now. Distance
|
2006-03-28 06:59:49 +00:00
|
|
|
* behind the head is penalized and only allowed to a certain extent.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2006-07-13 10:39:25 +00:00
|
|
|
static struct request *
|
cfq-iosched: fix next_rq computation
Cfq has a bug in computation of next_rq, that affects transition
between multiple sequential request streams in a single queue
(e.g.: two sequential buffered writers of the same priority),
causing the alternation between the two streams for a transient period.
8,0 1 18737 0.260400660 5312 D W 141653311 + 256
8,0 1 20839 0.273239461 5400 D W 141653567 + 256
8,0 1 20841 0.276343885 5394 D W 142803919 + 256
8,0 1 20843 0.279490878 5394 D W 141668927 + 256
8,0 1 20845 0.292459993 5400 D W 142804175 + 256
8,0 1 20847 0.295537247 5400 D W 141668671 + 256
8,0 1 20849 0.298656337 5400 D W 142804431 + 256
8,0 1 20851 0.311481148 5394 D W 141668415 + 256
8,0 1 20853 0.314421305 5394 D W 142804687 + 256
8,0 1 20855 0.318960112 5400 D W 142804943 + 256
The fix makes sure that the next_rq is computed from the last
dispatched request, and not affected by merging.
8,0 1 37776 4.305161306 0 D W 141738087 + 256
8,0 1 37778 4.308298091 0 D W 141738343 + 256
8,0 1 37780 4.312885190 0 D W 141738599 + 256
8,0 1 37782 4.315933291 0 D W 141738855 + 256
8,0 1 37784 4.319064459 0 D W 141739111 + 256
8,0 1 37786 4.331918431 5672 D W 142803007 + 256
8,0 1 37788 4.334930332 5672 D W 142803263 + 256
8,0 1 37790 4.337902723 5672 D W 142803519 + 256
8,0 1 37792 4.342359774 5672 D W 142803775 + 256
8,0 1 37794 4.345318286 0 D W 142804031 + 256
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-08 16:16:46 +00:00
|
|
|
cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2, sector_t last)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
cfq-iosched: fix next_rq computation
Cfq has a bug in computation of next_rq, that affects transition
between multiple sequential request streams in a single queue
(e.g.: two sequential buffered writers of the same priority),
causing the alternation between the two streams for a transient period.
8,0 1 18737 0.260400660 5312 D W 141653311 + 256
8,0 1 20839 0.273239461 5400 D W 141653567 + 256
8,0 1 20841 0.276343885 5394 D W 142803919 + 256
8,0 1 20843 0.279490878 5394 D W 141668927 + 256
8,0 1 20845 0.292459993 5400 D W 142804175 + 256
8,0 1 20847 0.295537247 5400 D W 141668671 + 256
8,0 1 20849 0.298656337 5400 D W 142804431 + 256
8,0 1 20851 0.311481148 5394 D W 141668415 + 256
8,0 1 20853 0.314421305 5394 D W 142804687 + 256
8,0 1 20855 0.318960112 5400 D W 142804943 + 256
The fix makes sure that the next_rq is computed from the last
dispatched request, and not affected by merging.
8,0 1 37776 4.305161306 0 D W 141738087 + 256
8,0 1 37778 4.308298091 0 D W 141738343 + 256
8,0 1 37780 4.312885190 0 D W 141738599 + 256
8,0 1 37782 4.315933291 0 D W 141738855 + 256
8,0 1 37784 4.319064459 0 D W 141739111 + 256
8,0 1 37786 4.331918431 5672 D W 142803007 + 256
8,0 1 37788 4.334930332 5672 D W 142803263 + 256
8,0 1 37790 4.337902723 5672 D W 142803519 + 256
8,0 1 37792 4.342359774 5672 D W 142803775 + 256
8,0 1 37794 4.345318286 0 D W 142804031 + 256
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-08 16:16:46 +00:00
|
|
|
sector_t s1, s2, d1 = 0, d2 = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long back_max;
|
2006-03-28 06:59:49 +00:00
|
|
|
#define CFQ_RQ1_WRAP 0x01 /* request 1 wraps */
|
|
|
|
#define CFQ_RQ2_WRAP 0x02 /* request 2 wraps */
|
|
|
|
unsigned wrap = 0; /* bit mask: requests behind the disk head? */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-13 10:39:25 +00:00
|
|
|
if (rq1 == NULL || rq1 == rq2)
|
|
|
|
return rq2;
|
|
|
|
if (rq2 == NULL)
|
|
|
|
return rq1;
|
2005-08-24 12:57:54 +00:00
|
|
|
|
2011-05-24 08:23:21 +00:00
|
|
|
if (rq_is_sync(rq1) != rq_is_sync(rq2))
|
|
|
|
return rq_is_sync(rq1) ? rq1 : rq2;
|
|
|
|
|
2011-08-23 12:50:29 +00:00
|
|
|
if ((rq1->cmd_flags ^ rq2->cmd_flags) & REQ_PRIO)
|
|
|
|
return rq1->cmd_flags & REQ_PRIO ? rq1 : rq2;
|
2011-08-19 06:34:48 +00:00
|
|
|
|
2009-05-07 13:24:39 +00:00
|
|
|
s1 = blk_rq_pos(rq1);
|
|
|
|
s2 = blk_rq_pos(rq2);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* by definition, 1KiB is 2 sectors
|
|
|
|
*/
|
|
|
|
back_max = cfqd->cfq_back_max * 2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strict one way elevator _except_ in the case where we allow
|
|
|
|
* short backward seeks which are biased as twice the cost of a
|
|
|
|
* similar forward seek.
|
|
|
|
*/
|
|
|
|
if (s1 >= last)
|
|
|
|
d1 = s1 - last;
|
|
|
|
else if (s1 + back_max >= last)
|
|
|
|
d1 = (last - s1) * cfqd->cfq_back_penalty;
|
|
|
|
else
|
2006-03-28 06:59:49 +00:00
|
|
|
wrap |= CFQ_RQ1_WRAP;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (s2 >= last)
|
|
|
|
d2 = s2 - last;
|
|
|
|
else if (s2 + back_max >= last)
|
|
|
|
d2 = (last - s2) * cfqd->cfq_back_penalty;
|
|
|
|
else
|
2006-03-28 06:59:49 +00:00
|
|
|
wrap |= CFQ_RQ2_WRAP;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Found required data */
|
2006-03-28 06:59:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* By doing switch() on the bit mask "wrap" we avoid having to
|
|
|
|
* check two variables for all permutations: --> faster!
|
|
|
|
*/
|
|
|
|
switch (wrap) {
|
2006-07-13 10:39:25 +00:00
|
|
|
case 0: /* common case for CFQ: rq1 and rq2 not wrapped */
|
2006-03-28 06:59:49 +00:00
|
|
|
if (d1 < d2)
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq1;
|
2006-03-28 06:59:49 +00:00
|
|
|
else if (d2 < d1)
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq2;
|
2006-03-28 06:59:49 +00:00
|
|
|
else {
|
|
|
|
if (s1 >= s2)
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq1;
|
2006-03-28 06:59:49 +00:00
|
|
|
else
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq2;
|
2006-03-28 06:59:49 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-28 06:59:49 +00:00
|
|
|
case CFQ_RQ2_WRAP:
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq1;
|
2006-03-28 06:59:49 +00:00
|
|
|
case CFQ_RQ1_WRAP:
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq2;
|
|
|
|
case (CFQ_RQ1_WRAP|CFQ_RQ2_WRAP): /* both rqs wrapped */
|
2006-03-28 06:59:49 +00:00
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Since both rqs are wrapped,
|
|
|
|
* start with the one that's further behind head
|
|
|
|
* (--> only *one* back seek required),
|
|
|
|
* since back seek takes more time than forward.
|
|
|
|
*/
|
|
|
|
if (s1 <= s2)
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq1;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2006-07-13 10:39:25 +00:00
|
|
|
return rq2;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
|
|
|
* The below is leftmost cache rbtree addon
|
|
|
|
*/
|
2008-01-28 10:38:15 +00:00
|
|
|
static struct cfq_queue *cfq_rb_first(struct cfq_rb_root *root)
|
2007-04-26 10:53:50 +00:00
|
|
|
{
|
2009-12-03 17:59:39 +00:00
|
|
|
/* Service tree is empty */
|
|
|
|
if (!root->count)
|
|
|
|
return NULL;
|
|
|
|
|
2007-04-26 10:53:50 +00:00
|
|
|
if (!root->left)
|
|
|
|
root->left = rb_first(&root->rb);
|
|
|
|
|
2008-01-28 10:38:15 +00:00
|
|
|
if (root->left)
|
|
|
|
return rb_entry(root->left, struct cfq_queue, rb_node);
|
|
|
|
|
|
|
|
return NULL;
|
2007-04-26 10:53:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
static struct cfq_group *cfq_rb_first_group(struct cfq_rb_root *root)
|
|
|
|
{
|
|
|
|
if (!root->left)
|
|
|
|
root->left = rb_first(&root->rb);
|
|
|
|
|
|
|
|
if (root->left)
|
|
|
|
return rb_entry_cfqg(root->left);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-04-15 10:15:11 +00:00
|
|
|
static void rb_erase_init(struct rb_node *n, struct rb_root *root)
|
|
|
|
{
|
|
|
|
rb_erase(n, root);
|
|
|
|
RB_CLEAR_NODE(n);
|
|
|
|
}
|
|
|
|
|
2007-04-26 10:53:50 +00:00
|
|
|
static void cfq_rb_erase(struct rb_node *n, struct cfq_rb_root *root)
|
|
|
|
{
|
|
|
|
if (root->left == n)
|
|
|
|
root->left = NULL;
|
2009-04-15 10:15:11 +00:00
|
|
|
rb_erase_init(n, &root->rb);
|
2009-10-26 21:44:33 +00:00
|
|
|
--root->count;
|
2007-04-26 10:53:50 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* would be nice to take fifo expire time into account as well
|
|
|
|
*/
|
2006-07-13 10:39:25 +00:00
|
|
|
static struct request *
|
|
|
|
cfq_find_next_rq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
|
|
|
struct request *last)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:33:14 +00:00
|
|
|
struct rb_node *rbnext = rb_next(&last->rb_node);
|
|
|
|
struct rb_node *rbprev = rb_prev(&last->rb_node);
|
2006-07-13 10:39:25 +00:00
|
|
|
struct request *next = NULL, *prev = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-13 10:33:14 +00:00
|
|
|
BUG_ON(RB_EMPTY_NODE(&last->rb_node));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (rbprev)
|
2006-07-13 10:39:25 +00:00
|
|
|
prev = rb_entry_rq(rbprev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-13 10:33:14 +00:00
|
|
|
if (rbnext)
|
2006-07-13 10:39:25 +00:00
|
|
|
next = rb_entry_rq(rbnext);
|
2006-07-13 10:33:14 +00:00
|
|
|
else {
|
|
|
|
rbnext = rb_first(&cfqq->sort_list);
|
|
|
|
if (rbnext && rbnext != &last->rb_node)
|
2006-07-13 10:39:25 +00:00
|
|
|
next = rb_entry_rq(rbnext);
|
2006-07-13 10:33:14 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
cfq-iosched: fix next_rq computation
Cfq has a bug in computation of next_rq, that affects transition
between multiple sequential request streams in a single queue
(e.g.: two sequential buffered writers of the same priority),
causing the alternation between the two streams for a transient period.
8,0 1 18737 0.260400660 5312 D W 141653311 + 256
8,0 1 20839 0.273239461 5400 D W 141653567 + 256
8,0 1 20841 0.276343885 5394 D W 142803919 + 256
8,0 1 20843 0.279490878 5394 D W 141668927 + 256
8,0 1 20845 0.292459993 5400 D W 142804175 + 256
8,0 1 20847 0.295537247 5400 D W 141668671 + 256
8,0 1 20849 0.298656337 5400 D W 142804431 + 256
8,0 1 20851 0.311481148 5394 D W 141668415 + 256
8,0 1 20853 0.314421305 5394 D W 142804687 + 256
8,0 1 20855 0.318960112 5400 D W 142804943 + 256
The fix makes sure that the next_rq is computed from the last
dispatched request, and not affected by merging.
8,0 1 37776 4.305161306 0 D W 141738087 + 256
8,0 1 37778 4.308298091 0 D W 141738343 + 256
8,0 1 37780 4.312885190 0 D W 141738599 + 256
8,0 1 37782 4.315933291 0 D W 141738855 + 256
8,0 1 37784 4.319064459 0 D W 141739111 + 256
8,0 1 37786 4.331918431 5672 D W 142803007 + 256
8,0 1 37788 4.334930332 5672 D W 142803263 + 256
8,0 1 37790 4.337902723 5672 D W 142803519 + 256
8,0 1 37792 4.342359774 5672 D W 142803775 + 256
8,0 1 37794 4.345318286 0 D W 142804031 + 256
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-08 16:16:46 +00:00
|
|
|
return cfq_choose_req(cfqd, next, prev, blk_rq_pos(last));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
static u64 cfq_slice_offset(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-04-20 12:27:50 +00:00
|
|
|
/*
|
|
|
|
* just an approximation, should be ok.
|
|
|
|
*/
|
2009-12-03 17:59:38 +00:00
|
|
|
return (cfqq->cfqg->nr_cfqq - 1) * (cfq_prio_slice(cfqd, 1, 0) -
|
2009-11-30 08:38:13 +00:00
|
|
|
cfq_prio_slice(cfqd, cfq_cfqq_sync(cfqq), cfqq->ioprio));
|
2007-04-20 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
static inline s64
|
|
|
|
cfqg_key(struct cfq_rb_root *st, struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
return cfqg->vdisktime - st->min_vdisktime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
struct rb_node **node = &st->rb.rb_node;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct cfq_group *__cfqg;
|
|
|
|
s64 key = cfqg_key(st, cfqg);
|
|
|
|
int left = 1;
|
|
|
|
|
|
|
|
while (*node != NULL) {
|
|
|
|
parent = *node;
|
|
|
|
__cfqg = rb_entry_cfqg(parent);
|
|
|
|
|
|
|
|
if (key < cfqg_key(st, __cfqg))
|
|
|
|
node = &parent->rb_left;
|
|
|
|
else {
|
|
|
|
node = &parent->rb_right;
|
|
|
|
left = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left)
|
|
|
|
st->left = &cfqg->rb_node;
|
|
|
|
|
|
|
|
rb_link_node(&cfqg->rb_node, parent, node);
|
|
|
|
rb_insert_color(&cfqg->rb_node, &st->rb);
|
|
|
|
}
|
|
|
|
|
2014-08-28 08:14:58 +00:00
|
|
|
/*
|
|
|
|
* This has to be called only on activation of cfqg
|
|
|
|
*/
|
2009-12-03 17:59:41 +00:00
|
|
|
static void
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_update_group_weight(struct cfq_group *cfqg)
|
|
|
|
{
|
2012-04-01 21:38:44 +00:00
|
|
|
if (cfqg->new_weight) {
|
2011-03-17 15:12:36 +00:00
|
|
|
cfqg->weight = cfqg->new_weight;
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg->new_weight = 0;
|
2011-03-17 15:12:36 +00:00
|
|
|
}
|
2014-08-26 11:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cfq_update_group_leaf_weight(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node));
|
2013-01-09 16:05:10 +00:00
|
|
|
|
|
|
|
if (cfqg->new_leaf_weight) {
|
|
|
|
cfqg->leaf_weight = cfqg->new_leaf_weight;
|
|
|
|
cfqg->new_leaf_weight = 0;
|
|
|
|
}
|
2011-03-17 15:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg)
|
|
|
|
{
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
unsigned int vfr = 1 << CFQ_SERVICE_SHIFT; /* start with 1 */
|
2013-01-09 16:05:11 +00:00
|
|
|
struct cfq_group *pos = cfqg;
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
struct cfq_group *parent;
|
2013-01-09 16:05:11 +00:00
|
|
|
bool propagate;
|
|
|
|
|
|
|
|
/* add to the service tree */
|
2011-03-17 15:12:36 +00:00
|
|
|
BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node));
|
|
|
|
|
2014-08-28 08:14:58 +00:00
|
|
|
/*
|
|
|
|
* Update leaf_weight. We cannot update weight at this point
|
|
|
|
* because cfqg might already have been activated and is
|
|
|
|
* contributing its current weight to the parent's child_weight.
|
|
|
|
*/
|
2014-08-26 11:56:36 +00:00
|
|
|
cfq_update_group_leaf_weight(cfqg);
|
2011-03-17 15:12:36 +00:00
|
|
|
__cfq_group_service_tree_add(st, cfqg);
|
2013-01-09 16:05:11 +00:00
|
|
|
|
|
|
|
/*
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
* Activate @cfqg and calculate the portion of vfraction @cfqg is
|
|
|
|
* entitled to. vfraction is calculated by walking the tree
|
|
|
|
* towards the root calculating the fraction it has at each level.
|
|
|
|
* The compounded ratio is how much vfraction @cfqg owns.
|
|
|
|
*
|
|
|
|
* Start with the proportion tasks in this cfqg has against active
|
|
|
|
* children cfqgs - its leaf_weight against children_weight.
|
2013-01-09 16:05:11 +00:00
|
|
|
*/
|
|
|
|
propagate = !pos->nr_active++;
|
|
|
|
pos->children_weight += pos->leaf_weight;
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
vfr = vfr * pos->leaf_weight / pos->children_weight;
|
2013-01-09 16:05:11 +00:00
|
|
|
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
/*
|
|
|
|
* Compound ->weight walking up the tree. Both activation and
|
|
|
|
* vfraction calculation are done in the same loop. Propagation
|
|
|
|
* stops once an already activated node is met. vfraction
|
|
|
|
* calculation should always continue to the root.
|
|
|
|
*/
|
2013-01-09 16:05:11 +00:00
|
|
|
while ((parent = cfqg_parent(pos))) {
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
if (propagate) {
|
2014-08-26 11:56:36 +00:00
|
|
|
cfq_update_group_weight(pos);
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
propagate = !parent->nr_active++;
|
|
|
|
parent->children_weight += pos->weight;
|
|
|
|
}
|
|
|
|
vfr = vfr * pos->weight / parent->children_weight;
|
2013-01-09 16:05:11 +00:00
|
|
|
pos = parent;
|
|
|
|
}
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
|
|
|
|
cfqg->vfraction = max_t(unsigned, vfr, 1);
|
2011-03-17 15:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
|
2009-12-03 17:59:41 +00:00
|
|
|
{
|
|
|
|
struct cfq_rb_root *st = &cfqd->grp_service_tree;
|
|
|
|
struct cfq_group *__cfqg;
|
|
|
|
struct rb_node *n;
|
|
|
|
|
|
|
|
cfqg->nr_cfqq++;
|
2010-11-30 19:52:47 +00:00
|
|
|
if (!RB_EMPTY_NODE(&cfqg->rb_node))
|
2009-12-03 17:59:41 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently put the group at the end. Later implement something
|
|
|
|
* so that groups get lesser vtime based on their weights, so that
|
2011-03-31 01:57:33 +00:00
|
|
|
* if group does not loose all if it was not continuously backlogged.
|
2009-12-03 17:59:41 +00:00
|
|
|
*/
|
|
|
|
n = rb_last(&st->rb);
|
|
|
|
if (n) {
|
|
|
|
__cfqg = rb_entry_cfqg(n);
|
|
|
|
cfqg->vdisktime = __cfqg->vdisktime + CFQ_IDLE_DELAY;
|
|
|
|
} else
|
|
|
|
cfqg->vdisktime = st->min_vdisktime;
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_group_service_tree_add(st, cfqg);
|
|
|
|
}
|
2009-12-03 17:59:41 +00:00
|
|
|
|
2011-03-17 15:12:36 +00:00
|
|
|
static void
|
|
|
|
cfq_group_service_tree_del(struct cfq_rb_root *st, struct cfq_group *cfqg)
|
|
|
|
{
|
2013-01-09 16:05:11 +00:00
|
|
|
struct cfq_group *pos = cfqg;
|
|
|
|
bool propagate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Undo activation from cfq_group_service_tree_add(). Deactivate
|
|
|
|
* @cfqg and propagate deactivation upwards.
|
|
|
|
*/
|
|
|
|
propagate = !--pos->nr_active;
|
|
|
|
pos->children_weight -= pos->leaf_weight;
|
|
|
|
|
|
|
|
while (propagate) {
|
2013-01-09 16:05:11 +00:00
|
|
|
struct cfq_group *parent = cfqg_parent(pos);
|
2013-01-09 16:05:11 +00:00
|
|
|
|
|
|
|
/* @pos has 0 nr_active at this point */
|
|
|
|
WARN_ON_ONCE(pos->children_weight);
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
pos->vfraction = 0;
|
2013-01-09 16:05:11 +00:00
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
propagate = !--parent->nr_active;
|
|
|
|
parent->children_weight -= pos->weight;
|
|
|
|
pos = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove from the service tree */
|
2011-03-17 15:12:36 +00:00
|
|
|
if (!RB_EMPTY_NODE(&cfqg->rb_node))
|
|
|
|
cfq_rb_erase(&cfqg->rb_node, st);
|
2009-12-03 17:59:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_group_notify_queue_del(struct cfq_data *cfqd, struct cfq_group *cfqg)
|
2009-12-03 17:59:41 +00:00
|
|
|
{
|
|
|
|
struct cfq_rb_root *st = &cfqd->grp_service_tree;
|
|
|
|
|
|
|
|
BUG_ON(cfqg->nr_cfqq < 1);
|
|
|
|
cfqg->nr_cfqq--;
|
2009-12-03 17:59:43 +00:00
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
/* If there are other cfq queues under this group, don't delete it */
|
|
|
|
if (cfqg->nr_cfqq)
|
|
|
|
return;
|
|
|
|
|
2009-12-03 17:59:48 +00:00
|
|
|
cfq_log_cfqg(cfqd, cfqg, "del_from_rr group");
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_group_service_tree_del(st, cfqg);
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqg->saved_wl_slice = 0;
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_dequeue(cfqg);
|
2009-12-03 17:59:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
static inline u64 cfq_cfqq_slice_usage(struct cfq_queue *cfqq,
|
|
|
|
u64 *unaccounted_time)
|
2009-12-03 17:59:45 +00:00
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 slice_used;
|
|
|
|
u64 now = ktime_get_ns();
|
2009-12-03 17:59:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue got expired before even a single request completed or
|
|
|
|
* got expired immediately after first request completion.
|
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
if (!cfqq->slice_start || cfqq->slice_start == now) {
|
2009-12-03 17:59:45 +00:00
|
|
|
/*
|
|
|
|
* Also charge the seek time incurred to the group, otherwise
|
|
|
|
* if there are mutiple queues in the group, each can dispatch
|
|
|
|
* a single request on seeky media and cause lots of seek time
|
|
|
|
* and group will never know it.
|
|
|
|
*/
|
2016-06-28 07:04:02 +00:00
|
|
|
slice_used = max_t(u64, (now - cfqq->dispatch_start),
|
|
|
|
jiffies_to_nsecs(1));
|
2009-12-03 17:59:45 +00:00
|
|
|
} else {
|
2016-06-08 14:55:34 +00:00
|
|
|
slice_used = now - cfqq->slice_start;
|
2011-03-12 15:54:00 +00:00
|
|
|
if (slice_used > cfqq->allocated_slice) {
|
|
|
|
*unaccounted_time = slice_used - cfqq->allocated_slice;
|
2009-12-03 17:59:53 +00:00
|
|
|
slice_used = cfqq->allocated_slice;
|
2011-03-12 15:54:00 +00:00
|
|
|
}
|
2016-06-08 14:55:34 +00:00
|
|
|
if (cfqq->slice_start > cfqq->dispatch_start)
|
2011-03-12 15:54:00 +00:00
|
|
|
*unaccounted_time += cfqq->slice_start -
|
|
|
|
cfqq->dispatch_start;
|
2009-12-03 17:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return slice_used;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,
|
2010-04-26 17:25:11 +00:00
|
|
|
struct cfq_queue *cfqq)
|
2009-12-03 17:59:45 +00:00
|
|
|
{
|
|
|
|
struct cfq_rb_root *st = &cfqd->grp_service_tree;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 used_sl, charge, unaccounted_sl = 0;
|
2009-12-03 17:59:54 +00:00
|
|
|
int nr_sync = cfqg->nr_cfqq - cfqg_busy_async_queues(cfqd, cfqg)
|
|
|
|
- cfqg->service_tree_idle.count;
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
unsigned int vfr;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2009-12-03 17:59:54 +00:00
|
|
|
|
|
|
|
BUG_ON(nr_sync < 0);
|
2011-03-12 15:54:00 +00:00
|
|
|
used_sl = charge = cfq_cfqq_slice_usage(cfqq, &unaccounted_sl);
|
2009-12-03 17:59:45 +00:00
|
|
|
|
2010-08-23 10:23:53 +00:00
|
|
|
if (iops_mode(cfqd))
|
|
|
|
charge = cfqq->slice_dispatch;
|
|
|
|
else if (!cfq_cfqq_sync(cfqq) && !nr_sync)
|
|
|
|
charge = cfqq->allocated_slice;
|
2009-12-03 17:59:45 +00:00
|
|
|
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
/*
|
|
|
|
* Can't update vdisktime while on service tree and cfqg->vfraction
|
|
|
|
* is valid only while on it. Cache vfr, leave the service tree,
|
|
|
|
* update vdisktime and go back on. The re-addition to the tree
|
|
|
|
* will also update the weights as necessary.
|
|
|
|
*/
|
|
|
|
vfr = cfqg->vfraction;
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_group_service_tree_del(st, cfqg);
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
cfqg->vdisktime += cfqg_scale_charge(charge, vfr);
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_group_service_tree_add(st, cfqg);
|
2009-12-03 17:59:45 +00:00
|
|
|
|
|
|
|
/* This group is being expired. Save the context */
|
2016-06-08 14:55:34 +00:00
|
|
|
if (cfqd->workload_expires > now) {
|
|
|
|
cfqg->saved_wl_slice = cfqd->workload_expires - now;
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqg->saved_wl_type = cfqd->serving_wl_type;
|
|
|
|
cfqg->saved_wl_class = cfqd->serving_wl_class;
|
2009-12-03 17:59:45 +00:00
|
|
|
} else
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqg->saved_wl_slice = 0;
|
2009-12-03 17:59:48 +00:00
|
|
|
|
|
|
|
cfq_log_cfqg(cfqd, cfqg, "served: vt=%llu min_vt=%llu", cfqg->vdisktime,
|
|
|
|
st->min_vdisktime);
|
2011-06-13 08:42:49 +00:00
|
|
|
cfq_log_cfqq(cfqq->cfqd, cfqq,
|
2016-06-08 14:55:34 +00:00
|
|
|
"sl_used=%llu disp=%llu charge=%llu iops=%u sect=%lu",
|
2011-06-13 08:42:49 +00:00
|
|
|
used_sl, cfqq->slice_dispatch, charge,
|
|
|
|
iops_mode(cfqd), cfqq->nr_sectors);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_timeslice_used(cfqg, used_sl, unaccounted_sl);
|
|
|
|
cfqg_stats_set_start_empty_time(cfqg);
|
2009-12-03 17:59:41 +00:00
|
|
|
}
|
|
|
|
|
2012-03-05 21:15:05 +00:00
|
|
|
/**
|
|
|
|
* cfq_init_cfqg_base - initialize base part of a cfq_group
|
|
|
|
* @cfqg: cfq_group to initialize
|
|
|
|
*
|
|
|
|
* Initialize the base part which is used whether %CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
* is enabled or not.
|
|
|
|
*/
|
|
|
|
static void cfq_init_cfqg_base(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
struct cfq_rb_root *st;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for_each_cfqg_st(cfqg, i, j, st)
|
|
|
|
*st = CFQ_RB_ROOT;
|
|
|
|
RB_CLEAR_NODE(&cfqg->rb_node);
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqg->ttime.last_end_request = ktime_get_ns();
|
2012-03-05 21:15:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:46 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2015-08-18 21:55:36 +00:00
|
|
|
static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
|
|
|
|
bool on_dfl, bool reset_dev, bool is_leaf_weight);
|
|
|
|
|
2015-08-18 21:55:22 +00:00
|
|
|
static void cfqg_stats_exit(struct cfqg_stats *stats)
|
2013-11-13 03:42:14 +00:00
|
|
|
{
|
2015-08-18 21:55:22 +00:00
|
|
|
blkg_rwstat_exit(&stats->merged);
|
|
|
|
blkg_rwstat_exit(&stats->service_time);
|
|
|
|
blkg_rwstat_exit(&stats->wait_time);
|
|
|
|
blkg_rwstat_exit(&stats->queued);
|
|
|
|
blkg_stat_exit(&stats->time);
|
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
|
|
|
blkg_stat_exit(&stats->unaccounted_time);
|
|
|
|
blkg_stat_exit(&stats->avg_queue_size_sum);
|
|
|
|
blkg_stat_exit(&stats->avg_queue_size_samples);
|
|
|
|
blkg_stat_exit(&stats->dequeue);
|
|
|
|
blkg_stat_exit(&stats->group_wait_time);
|
|
|
|
blkg_stat_exit(&stats->idle_time);
|
|
|
|
blkg_stat_exit(&stats->empty_time);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cfqg_stats_init(struct cfqg_stats *stats, gfp_t gfp)
|
|
|
|
{
|
2015-08-18 21:55:24 +00:00
|
|
|
if (blkg_rwstat_init(&stats->merged, gfp) ||
|
2015-08-18 21:55:22 +00:00
|
|
|
blkg_rwstat_init(&stats->service_time, gfp) ||
|
|
|
|
blkg_rwstat_init(&stats->wait_time, gfp) ||
|
|
|
|
blkg_rwstat_init(&stats->queued, gfp) ||
|
|
|
|
blkg_stat_init(&stats->time, gfp))
|
|
|
|
goto err;
|
2013-11-13 03:42:14 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
2015-08-18 21:55:22 +00:00
|
|
|
if (blkg_stat_init(&stats->unaccounted_time, gfp) ||
|
|
|
|
blkg_stat_init(&stats->avg_queue_size_sum, gfp) ||
|
|
|
|
blkg_stat_init(&stats->avg_queue_size_samples, gfp) ||
|
|
|
|
blkg_stat_init(&stats->dequeue, gfp) ||
|
|
|
|
blkg_stat_init(&stats->group_wait_time, gfp) ||
|
|
|
|
blkg_stat_init(&stats->idle_time, gfp) ||
|
|
|
|
blkg_stat_init(&stats->empty_time, gfp))
|
|
|
|
goto err;
|
2013-11-13 03:42:14 +00:00
|
|
|
#endif
|
2015-08-18 21:55:22 +00:00
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
cfqg_stats_exit(stats);
|
|
|
|
return -ENOMEM;
|
2013-11-13 03:42:14 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:16 +00:00
|
|
|
static struct blkcg_policy_data *cfq_cpd_alloc(gfp_t gfp)
|
|
|
|
{
|
|
|
|
struct cfq_group_data *cgd;
|
|
|
|
|
2016-11-10 16:16:37 +00:00
|
|
|
cgd = kzalloc(sizeof(*cgd), gfp);
|
2015-08-18 21:55:16 +00:00
|
|
|
if (!cgd)
|
|
|
|
return NULL;
|
|
|
|
return &cgd->cpd;
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:15 +00:00
|
|
|
static void cfq_cpd_init(struct blkcg_policy_data *cpd)
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
{
|
2015-08-18 21:55:15 +00:00
|
|
|
struct cfq_group_data *cgd = cpd_to_cfqgd(cpd);
|
2015-09-18 15:56:28 +00:00
|
|
|
unsigned int weight = cgroup_subsys_on_dfl(io_cgrp_subsys) ?
|
2015-08-18 21:55:36 +00:00
|
|
|
CGROUP_WEIGHT_DFL : CFQ_WEIGHT_LEGACY_DFL;
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
|
2015-08-18 21:55:36 +00:00
|
|
|
if (cpd_to_blkcg(cpd) == &blkcg_root)
|
|
|
|
weight *= 2;
|
|
|
|
|
|
|
|
cgd->weight = weight;
|
|
|
|
cgd->leaf_weight = weight;
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:16 +00:00
|
|
|
static void cfq_cpd_free(struct blkcg_policy_data *cpd)
|
|
|
|
{
|
|
|
|
kfree(cpd_to_cfqgd(cpd));
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:36 +00:00
|
|
|
static void cfq_cpd_bind(struct blkcg_policy_data *cpd)
|
|
|
|
{
|
|
|
|
struct blkcg *blkcg = cpd_to_blkcg(cpd);
|
2015-09-18 15:56:28 +00:00
|
|
|
bool on_dfl = cgroup_subsys_on_dfl(io_cgrp_subsys);
|
2015-08-18 21:55:36 +00:00
|
|
|
unsigned int weight = on_dfl ? CGROUP_WEIGHT_DFL : CFQ_WEIGHT_LEGACY_DFL;
|
|
|
|
|
|
|
|
if (blkcg == &blkcg_root)
|
|
|
|
weight *= 2;
|
|
|
|
|
|
|
|
WARN_ON_ONCE(__cfq_set_weight(&blkcg->css, weight, on_dfl, true, false));
|
|
|
|
WARN_ON_ONCE(__cfq_set_weight(&blkcg->css, weight, on_dfl, true, true));
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:11 +00:00
|
|
|
static struct blkg_policy_data *cfq_pd_alloc(gfp_t gfp, int node)
|
|
|
|
{
|
2015-08-18 21:55:13 +00:00
|
|
|
struct cfq_group *cfqg;
|
|
|
|
|
|
|
|
cfqg = kzalloc_node(sizeof(*cfqg), gfp, node);
|
|
|
|
if (!cfqg)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cfq_init_cfqg_base(cfqg);
|
2015-08-18 21:55:22 +00:00
|
|
|
if (cfqg_stats_init(&cfqg->stats, gfp)) {
|
|
|
|
kfree(cfqg);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-18 21:55:13 +00:00
|
|
|
|
|
|
|
return &cfqg->pd;
|
2015-08-18 21:55:11 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:14 +00:00
|
|
|
static void cfq_pd_init(struct blkg_policy_data *pd)
|
2011-05-19 19:38:23 +00:00
|
|
|
{
|
2015-08-18 21:55:14 +00:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
|
|
|
struct cfq_group_data *cgd = blkcg_to_cfqgd(pd->blkg->blkcg);
|
2009-12-03 17:59:46 +00:00
|
|
|
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
cfqg->weight = cgd->weight;
|
|
|
|
cfqg->leaf_weight = cgd->leaf_weight;
|
2009-12-03 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:14 +00:00
|
|
|
static void cfq_pd_offline(struct blkg_policy_data *pd)
|
2013-01-09 16:05:13 +00:00
|
|
|
{
|
2015-08-18 21:55:14 +00:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
2015-08-18 21:55:05 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < IOPRIO_BE_NR; i++) {
|
|
|
|
if (cfqg->async_cfqq[0][i])
|
|
|
|
cfq_put_queue(cfqg->async_cfqq[0][i]);
|
|
|
|
if (cfqg->async_cfqq[1][i])
|
|
|
|
cfq_put_queue(cfqg->async_cfqq[1][i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfqg->async_idle_cfqq)
|
|
|
|
cfq_put_queue(cfqg->async_idle_cfqq);
|
|
|
|
|
2013-01-09 16:05:13 +00:00
|
|
|
/*
|
|
|
|
* @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...
|
|
|
|
*/
|
2015-08-18 21:55:05 +00:00
|
|
|
cfqg_stats_xfer_dead(cfqg);
|
2013-01-09 16:05:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:11 +00:00
|
|
|
static void cfq_pd_free(struct blkg_policy_data *pd)
|
|
|
|
{
|
2015-08-18 21:55:22 +00:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
|
|
|
|
|
|
|
cfqg_stats_exit(&cfqg->stats);
|
|
|
|
return kfree(cfqg);
|
2015-08-18 21:55:11 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:14 +00:00
|
|
|
static void cfq_pd_reset_stats(struct blkg_policy_data *pd)
|
2013-01-09 16:05:13 +00:00
|
|
|
{
|
2015-08-18 21:55:14 +00:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
2013-01-09 16:05:13 +00:00
|
|
|
|
|
|
|
cfqg_stats_reset(&cfqg->stats);
|
2009-12-03 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:20 +00:00
|
|
|
static struct cfq_group *cfq_lookup_cfqg(struct cfq_data *cfqd,
|
|
|
|
struct blkcg *blkcg)
|
2009-12-03 17:59:46 +00:00
|
|
|
{
|
2015-08-18 21:55:20 +00:00
|
|
|
struct blkcg_gq *blkg;
|
2011-05-19 19:38:23 +00:00
|
|
|
|
2015-08-18 21:55:20 +00:00
|
|
|
blkg = blkg_lookup(blkcg, cfqd->queue);
|
|
|
|
if (likely(blkg))
|
|
|
|
return blkg_to_cfqg(blkg);
|
|
|
|
return NULL;
|
2009-12-03 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
cfqq->cfqg = cfqg;
|
2009-12-03 17:59:47 +00:00
|
|
|
/* cfqq reference on cfqg */
|
2012-03-23 13:02:53 +00:00
|
|
|
cfqg_get(cfqg);
|
2009-12-03 17:59:47 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 20:57:26 +00:00
|
|
|
static u64 cfqg_prfill_weight_device(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2012-04-16 20:57:26 +00:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
2012-04-01 21:38:44 +00:00
|
|
|
|
|
|
|
if (!cfqg->dev_weight)
|
2012-04-01 21:38:43 +00:00
|
|
|
return 0;
|
2012-04-16 20:57:26 +00:00
|
|
|
return __blkg_prfill_u64(sf, pd, cfqg->dev_weight);
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfqg_print_weight_device(struct seq_file *sf, void *v)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2013-12-05 17:28:04 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_weight_device, &blkcg_policy_cfq,
|
|
|
|
0, false);
|
2012-04-01 21:38:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-09 16:05:10 +00:00
|
|
|
static u64 cfqg_prfill_leaf_weight_device(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
|
|
|
|
|
|
|
if (!cfqg->dev_leaf_weight)
|
|
|
|
return 0;
|
|
|
|
return __blkg_prfill_u64(sf, pd, cfqg->dev_leaf_weight);
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfqg_print_leaf_weight_device(struct seq_file *sf, void *v)
|
2013-01-09 16:05:10 +00:00
|
|
|
{
|
2013-12-05 17:28:04 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_leaf_weight_device, &blkcg_policy_cfq,
|
|
|
|
0, false);
|
2013-01-09 16:05:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfq_print_weight(struct seq_file *sf, void *v)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
|
2015-06-19 16:19:36 +00:00
|
|
|
struct cfq_group_data *cgd = blkcg_to_cfqgd(blkcg);
|
|
|
|
unsigned int val = 0;
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
|
2015-06-19 16:19:36 +00:00
|
|
|
if (cgd)
|
|
|
|
val = cgd->weight;
|
|
|
|
|
|
|
|
seq_printf(sf, "%u\n", val);
|
2012-04-01 21:38:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfq_print_leaf_weight(struct seq_file *sf, void *v)
|
2013-01-09 16:05:10 +00:00
|
|
|
{
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
|
2015-06-19 16:19:36 +00:00
|
|
|
struct cfq_group_data *cgd = blkcg_to_cfqgd(blkcg);
|
|
|
|
unsigned int val = 0;
|
|
|
|
|
|
|
|
if (cgd)
|
|
|
|
val = cgd->leaf_weight;
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
|
2015-06-19 16:19:36 +00:00
|
|
|
seq_printf(sf, "%u\n", val);
|
2013-01-09 16:05:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:16:21 +00:00
|
|
|
static ssize_t __cfqg_set_weight_device(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off,
|
2015-08-18 21:55:34 +00:00
|
|
|
bool on_dfl, bool is_leaf_weight)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2015-08-18 21:55:36 +00:00
|
|
|
unsigned int min = on_dfl ? CGROUP_WEIGHT_MIN : CFQ_WEIGHT_LEGACY_MIN;
|
|
|
|
unsigned int max = on_dfl ? CGROUP_WEIGHT_MAX : CFQ_WEIGHT_LEGACY_MAX;
|
2014-05-13 16:16:21 +00:00
|
|
|
struct blkcg *blkcg = css_to_blkcg(of_css(of));
|
2012-04-01 21:38:43 +00:00
|
|
|
struct blkg_conf_ctx ctx;
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfq_group *cfqg;
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
struct cfq_group_data *cfqgd;
|
2012-04-01 21:38:43 +00:00
|
|
|
int ret;
|
2015-08-18 21:55:31 +00:00
|
|
|
u64 v;
|
2012-04-01 21:38:43 +00:00
|
|
|
|
2012-04-16 20:57:25 +00:00
|
|
|
ret = blkg_conf_prep(blkcg, &blkcg_policy_cfq, buf, &ctx);
|
2012-04-01 21:38:43 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-08-18 21:55:34 +00:00
|
|
|
if (sscanf(ctx.body, "%llu", &v) == 1) {
|
|
|
|
/* require "default" on dfl */
|
|
|
|
ret = -ERANGE;
|
|
|
|
if (!v && on_dfl)
|
|
|
|
goto out_finish;
|
|
|
|
} else if (!strcmp(strim(ctx.body), "default")) {
|
|
|
|
v = 0;
|
|
|
|
} else {
|
|
|
|
ret = -EINVAL;
|
2015-08-18 21:55:31 +00:00
|
|
|
goto out_finish;
|
2015-08-18 21:55:34 +00:00
|
|
|
}
|
2015-08-18 21:55:31 +00:00
|
|
|
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg = blkg_to_cfqg(ctx.blkg);
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
cfqgd = blkcg_to_cfqgd(blkcg);
|
2015-06-20 16:26:50 +00:00
|
|
|
|
2015-08-18 21:55:28 +00:00
|
|
|
ret = -ERANGE;
|
2015-08-18 21:55:36 +00:00
|
|
|
if (!v || (v >= min && v <= max)) {
|
2013-01-09 16:05:10 +00:00
|
|
|
if (!is_leaf_weight) {
|
2015-08-18 21:55:31 +00:00
|
|
|
cfqg->dev_weight = v;
|
|
|
|
cfqg->new_weight = v ?: cfqgd->weight;
|
2013-01-09 16:05:10 +00:00
|
|
|
} else {
|
2015-08-18 21:55:31 +00:00
|
|
|
cfqg->dev_leaf_weight = v;
|
|
|
|
cfqg->new_leaf_weight = v ?: cfqgd->leaf_weight;
|
2013-01-09 16:05:10 +00:00
|
|
|
}
|
2012-04-01 21:38:43 +00:00
|
|
|
ret = 0;
|
|
|
|
}
|
2015-08-18 21:55:31 +00:00
|
|
|
out_finish:
|
2012-04-01 21:38:43 +00:00
|
|
|
blkg_conf_finish(&ctx);
|
2014-05-13 16:16:21 +00:00
|
|
|
return ret ?: nbytes;
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 16:16:21 +00:00
|
|
|
static ssize_t cfqg_set_weight_device(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off)
|
2013-01-09 16:05:10 +00:00
|
|
|
{
|
2015-08-18 21:55:34 +00:00
|
|
|
return __cfqg_set_weight_device(of, buf, nbytes, off, false, false);
|
2013-01-09 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 16:16:21 +00:00
|
|
|
static ssize_t cfqg_set_leaf_weight_device(struct kernfs_open_file *of,
|
|
|
|
char *buf, size_t nbytes, loff_t off)
|
2013-01-09 16:05:10 +00:00
|
|
|
{
|
2015-08-18 21:55:34 +00:00
|
|
|
return __cfqg_set_weight_device(of, buf, nbytes, off, false, true);
|
2013-01-09 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:33 +00:00
|
|
|
static int __cfq_set_weight(struct cgroup_subsys_state *css, u64 val,
|
2015-08-18 21:55:36 +00:00
|
|
|
bool on_dfl, bool reset_dev, bool is_leaf_weight)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2015-08-18 21:55:36 +00:00
|
|
|
unsigned int min = on_dfl ? CGROUP_WEIGHT_MIN : CFQ_WEIGHT_LEGACY_MIN;
|
|
|
|
unsigned int max = on_dfl ? CGROUP_WEIGHT_MAX : CFQ_WEIGHT_LEGACY_MAX;
|
2013-08-09 00:11:24 +00:00
|
|
|
struct blkcg *blkcg = css_to_blkcg(css);
|
2012-04-16 20:57:25 +00:00
|
|
|
struct blkcg_gq *blkg;
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
struct cfq_group_data *cfqgd;
|
2015-06-20 16:26:50 +00:00
|
|
|
int ret = 0;
|
2012-04-01 21:38:43 +00:00
|
|
|
|
2015-08-18 21:55:36 +00:00
|
|
|
if (val < min || val > max)
|
|
|
|
return -ERANGE;
|
2012-04-01 21:38:43 +00:00
|
|
|
|
|
|
|
spin_lock_irq(&blkcg->lock);
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
cfqgd = blkcg_to_cfqgd(blkcg);
|
2015-06-20 16:26:50 +00:00
|
|
|
if (!cfqgd) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2013-01-09 16:05:10 +00:00
|
|
|
|
|
|
|
if (!is_leaf_weight)
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
cfqgd->weight = val;
|
2013-01-09 16:05:10 +00:00
|
|
|
else
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
cfqgd->leaf_weight = val;
|
2012-04-01 21:38:43 +00:00
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 01:06:00 +00:00
|
|
|
hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node) {
|
2012-04-01 21:38:44 +00:00
|
|
|
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
|
2012-04-01 21:38:43 +00:00
|
|
|
|
2013-01-09 16:05:10 +00:00
|
|
|
if (!cfqg)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!is_leaf_weight) {
|
2015-08-18 21:55:36 +00:00
|
|
|
if (reset_dev)
|
|
|
|
cfqg->dev_weight = 0;
|
2013-01-09 16:05:10 +00:00
|
|
|
if (!cfqg->dev_weight)
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
cfqg->new_weight = cfqgd->weight;
|
2013-01-09 16:05:10 +00:00
|
|
|
} else {
|
2015-08-18 21:55:36 +00:00
|
|
|
if (reset_dev)
|
|
|
|
cfqg->dev_leaf_weight = 0;
|
2013-01-09 16:05:10 +00:00
|
|
|
if (!cfqg->dev_leaf_weight)
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
cfqg->new_leaf_weight = cfqgd->leaf_weight;
|
2013-01-09 16:05:10 +00:00
|
|
|
}
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2015-06-20 16:26:50 +00:00
|
|
|
out:
|
2012-04-01 21:38:43 +00:00
|
|
|
spin_unlock_irq(&blkcg->lock);
|
2015-06-20 16:26:50 +00:00
|
|
|
return ret;
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 00:11:24 +00:00
|
|
|
static int cfq_set_weight(struct cgroup_subsys_state *css, struct cftype *cft,
|
|
|
|
u64 val)
|
2013-01-09 16:05:10 +00:00
|
|
|
{
|
2015-08-18 21:55:36 +00:00
|
|
|
return __cfq_set_weight(css, val, false, false, false);
|
2013-01-09 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 00:11:24 +00:00
|
|
|
static int cfq_set_leaf_weight(struct cgroup_subsys_state *css,
|
|
|
|
struct cftype *cft, u64 val)
|
2013-01-09 16:05:10 +00:00
|
|
|
{
|
2015-08-18 21:55:36 +00:00
|
|
|
return __cfq_set_weight(css, val, false, false, true);
|
2013-01-09 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfqg_print_stat(struct seq_file *sf, void *v)
|
2012-04-01 21:38:45 +00:00
|
|
|
{
|
2013-12-05 17:28:04 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_stat,
|
|
|
|
&blkcg_policy_cfq, seq_cft(sf)->private, false);
|
2012-04-01 21:38:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfqg_print_rwstat(struct seq_file *sf, void *v)
|
2012-04-01 21:38:45 +00:00
|
|
|
{
|
2013-12-05 17:28:04 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_rwstat,
|
|
|
|
&blkcg_policy_cfq, seq_cft(sf)->private, true);
|
2012-04-01 21:38:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-09 16:05:13 +00:00
|
|
|
static u64 cfqg_prfill_stat_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
2015-08-18 21:55:23 +00:00
|
|
|
u64 sum = blkg_stat_recursive_sum(pd_to_blkg(pd),
|
|
|
|
&blkcg_policy_cfq, off);
|
2013-01-09 16:05:13 +00:00
|
|
|
return __blkg_prfill_u64(sf, pd, sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 cfqg_prfill_rwstat_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
2015-08-18 21:55:23 +00:00
|
|
|
struct blkg_rwstat sum = blkg_rwstat_recursive_sum(pd_to_blkg(pd),
|
|
|
|
&blkcg_policy_cfq, off);
|
2013-01-09 16:05:13 +00:00
|
|
|
return __blkg_prfill_rwstat(sf, pd, &sum);
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfqg_print_stat_recursive(struct seq_file *sf, void *v)
|
2013-01-09 16:05:13 +00:00
|
|
|
{
|
2013-12-05 17:28:04 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_stat_recursive, &blkcg_policy_cfq,
|
|
|
|
seq_cft(sf)->private, false);
|
2013-01-09 16:05:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfqg_print_rwstat_recursive(struct seq_file *sf, void *v)
|
2013-01-09 16:05:13 +00:00
|
|
|
{
|
2013-12-05 17:28:04 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_rwstat_recursive, &blkcg_policy_cfq,
|
|
|
|
seq_cft(sf)->private, true);
|
2013-01-09 16:05:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:25 +00:00
|
|
|
static u64 cfqg_prfill_sectors(struct seq_file *sf, struct blkg_policy_data *pd,
|
|
|
|
int off)
|
|
|
|
{
|
|
|
|
u64 sum = blkg_rwstat_total(&pd->blkg->stat_bytes);
|
|
|
|
|
|
|
|
return __blkg_prfill_u64(sf, pd, sum >> 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cfqg_print_stat_sectors(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_sectors, &blkcg_policy_cfq, 0, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 cfqg_prfill_sectors_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
|
|
|
struct blkg_rwstat tmp = blkg_rwstat_recursive_sum(pd->blkg, NULL,
|
|
|
|
offsetof(struct blkcg_gq, stat_bytes));
|
|
|
|
u64 sum = atomic64_read(&tmp.aux_cnt[BLKG_RWSTAT_READ]) +
|
|
|
|
atomic64_read(&tmp.aux_cnt[BLKG_RWSTAT_WRITE]);
|
|
|
|
|
|
|
|
return __blkg_prfill_u64(sf, pd, sum >> 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cfqg_print_stat_sectors_recursive(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_sectors_recursive, &blkcg_policy_cfq, 0,
|
|
|
|
false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-01 21:38:43 +00:00
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
2012-04-16 20:57:26 +00:00
|
|
|
static u64 cfqg_prfill_avg_queue_size(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2012-04-16 20:57:26 +00:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
2012-04-01 21:38:44 +00:00
|
|
|
u64 samples = blkg_stat_read(&cfqg->stats.avg_queue_size_samples);
|
2012-04-01 21:38:43 +00:00
|
|
|
u64 v = 0;
|
|
|
|
|
|
|
|
if (samples) {
|
2012-04-01 21:38:44 +00:00
|
|
|
v = blkg_stat_read(&cfqg->stats.avg_queue_size_sum);
|
2013-09-22 18:43:47 +00:00
|
|
|
v = div64_u64(v, samples);
|
2012-04-01 21:38:43 +00:00
|
|
|
}
|
2012-04-16 20:57:26 +00:00
|
|
|
__blkg_prfill_u64(sf, pd, v);
|
2012-04-01 21:38:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print avg_queue_size */
|
2013-12-05 17:28:04 +00:00
|
|
|
static int cfqg_print_avg_queue_size(struct seq_file *sf, void *v)
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
2013-12-05 17:28:04 +00:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_avg_queue_size, &blkcg_policy_cfq,
|
|
|
|
0, false);
|
2012-04-01 21:38:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
|
2015-08-18 21:55:30 +00:00
|
|
|
static struct cftype cfq_blkcg_legacy_files[] = {
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
/* on root, weight is mapped to leaf_weight */
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
|
|
|
.name = "weight_device",
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
.flags = CFTYPE_ONLY_ON_ROOT,
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_leaf_weight_device,
|
2014-05-13 16:16:21 +00:00
|
|
|
.write = cfqg_set_leaf_weight_device,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "weight",
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
.flags = CFTYPE_ONLY_ON_ROOT,
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfq_print_leaf_weight,
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
.write_u64 = cfq_set_leaf_weight,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
2013-01-09 16:05:10 +00:00
|
|
|
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
/* no such mapping necessary for !roots */
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
|
|
|
.name = "weight_device",
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_weight_device,
|
2014-05-13 16:16:21 +00:00
|
|
|
.write = cfqg_set_weight_device,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "weight",
|
cfq-iosched: implement hierarchy-ready cfq_group charge scaling
Currently, cfqg charges are scaled directly according to cfqg->weight.
Regardless of the number of active cfqgs or the amount of active
weights, a given weight value always scales charge the same way. This
works fine as long as all cfqgs are treated equally regardless of
their positions in the hierarchy, which is what cfq currently
implements. It can't work in hierarchical settings because the
interpretation of a given weight value depends on where the weight is
located in the hierarchy.
This patch reimplements cfqg charge scaling so that it can be used to
support hierarchy properly. The scheme is fairly simple and
light-weight.
* When a cfqg is added to the service tree, v(disktime)weight is
calculated. It walks up the tree to root calculating the fraction
it has in the hierarchy. At each level, the fraction can be
calculated as
cfqg->weight / parent->level_weight
By compounding these, the global fraction of vdisktime the cfqg has
claim to - vfraction - can be determined.
* When the cfqg needs to be charged, the charge is scaled inversely
proportionally to the vfraction.
The new scaling scheme uses the same CFQ_SERVICE_SHIFT for fixed point
representation as before; however, the smallest scaling factor is now
1 (ie. 1 << CFQ_SERVICE_SHIFT). This is different from before where 1
was for CFQ_WEIGHT_DEFAULT and higher weight would result in smaller
scaling factor.
While this shifts the global scale of vdisktime a bit, it doesn't
change the relative relationships among cfqgs and the scheduling
result isn't different.
cfq_group_notify_queue_add uses fixed CFQ_IDLE_DELAY when appending
new cfqg to the service tree. The specific value of CFQ_IDLE_DELAY
didn't have any relevance to vdisktime before and is unlikely to cause
any visible behavior difference now especially as the scale shift
isn't that large.
As the new scheme now makes proper distinction between cfqg->weight
and ->leaf_weight, reverse the weight aliasing for root cfqgs. For
root, both weights are now mapped to ->leaf_weight instead of the
other way around.
Because we're still using cfqg_flat_parent(), this patch shouldn't
change the scheduling behavior in any noticeable way.
v2: Beefed up comments on vfraction as requested by Vivek.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
2013-01-09 16:05:11 +00:00
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfq_print_weight,
|
2012-04-01 21:38:44 +00:00
|
|
|
.write_u64 = cfq_set_weight,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
2013-01-09 16:05:10 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
.name = "leaf_weight_device",
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_leaf_weight_device,
|
2014-05-13 16:16:21 +00:00
|
|
|
.write = cfqg_set_leaf_weight_device,
|
2013-01-09 16:05:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "leaf_weight",
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfq_print_leaf_weight,
|
2013-01-09 16:05:10 +00:00
|
|
|
.write_u64 = cfq_set_leaf_weight,
|
|
|
|
},
|
|
|
|
|
2013-01-09 16:05:13 +00:00
|
|
|
/* statistics, covers only the tasks in the cfqg */
|
2012-04-01 21:38:43 +00:00
|
|
|
{
|
|
|
|
.name = "time",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "sectors",
|
2015-08-18 21:55:25 +00:00
|
|
|
.seq_show = cfqg_print_stat_sectors,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_bytes",
|
2015-08-18 21:55:24 +00:00
|
|
|
.private = (unsigned long)&blkcg_policy_cfq,
|
|
|
|
.seq_show = blkg_print_stat_bytes,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_serviced",
|
2015-08-18 21:55:24 +00:00
|
|
|
.private = (unsigned long)&blkcg_policy_cfq,
|
|
|
|
.seq_show = blkg_print_stat_ios,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_time",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.service_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_wait_time",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.wait_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_merged",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.merged),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_queued",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.queued),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
2013-01-09 16:05:13 +00:00
|
|
|
|
|
|
|
/* the same statictics which cover the cfqg and its descendants */
|
|
|
|
{
|
|
|
|
.name = "time_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_stat_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "sectors_recursive",
|
2015-08-18 21:55:25 +00:00
|
|
|
.seq_show = cfqg_print_stat_sectors_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_bytes_recursive",
|
2015-08-18 21:55:24 +00:00
|
|
|
.private = (unsigned long)&blkcg_policy_cfq,
|
|
|
|
.seq_show = blkg_print_stat_bytes_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_serviced_recursive",
|
2015-08-18 21:55:24 +00:00
|
|
|
.private = (unsigned long)&blkcg_policy_cfq,
|
|
|
|
.seq_show = blkg_print_stat_ios_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_time_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.service_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_wait_time_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.wait_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_merged_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.merged),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_queued_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.queued),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 16:05:13 +00:00
|
|
|
},
|
2012-04-01 21:38:43 +00:00
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
|
|
|
{
|
|
|
|
.name = "avg_queue_size",
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_avg_queue_size,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "group_wait_time",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.group_wait_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "idle_time",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.idle_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "empty_time",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.empty_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "dequeue",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.dequeue),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "unaccounted_time",
|
2012-04-01 21:38:45 +00:00
|
|
|
.private = offsetof(struct cfq_group, stats.unaccounted_time),
|
2013-12-05 17:28:04 +00:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 21:38:43 +00:00
|
|
|
},
|
|
|
|
#endif /* CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
{ } /* terminate */
|
|
|
|
};
|
2015-08-18 21:55:34 +00:00
|
|
|
|
|
|
|
static int cfq_print_weight_on_dfl(struct seq_file *sf, void *v)
|
|
|
|
{
|
|
|
|
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
|
|
|
|
struct cfq_group_data *cgd = blkcg_to_cfqgd(blkcg);
|
|
|
|
|
|
|
|
seq_printf(sf, "default %u\n", cgd->weight);
|
|
|
|
blkcg_print_blkgs(sf, blkcg, cfqg_prfill_weight_device,
|
|
|
|
&blkcg_policy_cfq, 0, false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t cfq_set_weight_on_dfl(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) {
|
2015-08-18 21:55:36 +00:00
|
|
|
ret = __cfq_set_weight(of_css(of), v, true, false, false);
|
2015-08-18 21:55:34 +00:00
|
|
|
return ret ?: nbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "MAJ:MIN WEIGHT" */
|
|
|
|
return __cfqg_set_weight_device(of, buf, nbytes, off, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cftype cfq_blkcg_files[] = {
|
|
|
|
{
|
|
|
|
.name = "weight",
|
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
|
|
|
.seq_show = cfq_print_weight_on_dfl,
|
|
|
|
.write = cfq_set_weight_on_dfl,
|
|
|
|
},
|
|
|
|
{ } /* terminate */
|
|
|
|
};
|
|
|
|
|
2009-12-03 17:59:46 +00:00
|
|
|
#else /* GROUP_IOSCHED */
|
2015-08-18 21:55:20 +00:00
|
|
|
static struct cfq_group *cfq_lookup_cfqg(struct cfq_data *cfqd,
|
|
|
|
struct blkcg *blkcg)
|
2009-12-03 17:59:46 +00:00
|
|
|
{
|
2012-03-05 21:15:05 +00:00
|
|
|
return cfqd->root_group;
|
2009-12-03 17:59:46 +00:00
|
|
|
}
|
2010-04-21 15:44:16 +00:00
|
|
|
|
2009-12-03 17:59:46 +00:00
|
|
|
static inline void
|
|
|
|
cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg) {
|
|
|
|
cfqq->cfqg = cfqg;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* GROUP_IOSCHED */
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
2009-10-27 18:16:03 +00:00
|
|
|
* The cfqd->service_trees holds all pending cfq_queue's that have
|
2007-04-26 10:54:48 +00:00
|
|
|
* requests waiting to be processed. It is sorted in the order that
|
|
|
|
* we will service the queues.
|
|
|
|
*/
|
2009-04-15 10:15:11 +00:00
|
|
|
static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2009-10-07 18:02:57 +00:00
|
|
|
bool add_front)
|
2007-04-20 12:27:50 +00:00
|
|
|
{
|
2008-01-28 10:38:15 +00:00
|
|
|
struct rb_node **p, *parent;
|
|
|
|
struct cfq_queue *__cfqq;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 rb_key;
|
2012-10-03 20:56:58 +00:00
|
|
|
struct cfq_rb_root *st;
|
2007-04-26 10:54:48 +00:00
|
|
|
int left;
|
2009-12-03 17:59:45 +00:00
|
|
|
int new_cfqq = 1;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2009-12-03 17:59:55 +00:00
|
|
|
|
2012-10-03 20:56:58 +00:00
|
|
|
st = st_for(cfqq->cfqg, cfqq_class(cfqq), cfqq_type(cfqq));
|
2008-01-28 10:38:15 +00:00
|
|
|
if (cfq_class_idle(cfqq)) {
|
|
|
|
rb_key = CFQ_IDLE_DELAY;
|
2012-10-03 20:56:58 +00:00
|
|
|
parent = rb_last(&st->rb);
|
2008-01-28 10:38:15 +00:00
|
|
|
if (parent && parent != &cfqq->rb_node) {
|
|
|
|
__cfqq = rb_entry(parent, struct cfq_queue, rb_node);
|
|
|
|
rb_key += __cfqq->rb_key;
|
|
|
|
} else
|
2016-06-08 14:55:34 +00:00
|
|
|
rb_key += now;
|
2008-01-28 10:38:15 +00:00
|
|
|
} else if (!add_front) {
|
2009-10-06 18:53:44 +00:00
|
|
|
/*
|
|
|
|
* Get our rb key offset. Subtract any residual slice
|
|
|
|
* value carried from last service. A negative resid
|
|
|
|
* count indicates slice overrun, and this should position
|
|
|
|
* the next service time further away in the tree.
|
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
rb_key = cfq_slice_offset(cfqd, cfqq) + now;
|
2009-10-06 18:53:44 +00:00
|
|
|
rb_key -= cfqq->slice_resid;
|
2007-04-19 10:03:34 +00:00
|
|
|
cfqq->slice_resid = 0;
|
2009-10-05 06:49:23 +00:00
|
|
|
} else {
|
2016-06-08 14:55:34 +00:00
|
|
|
rb_key = -NSEC_PER_SEC;
|
2012-10-03 20:56:58 +00:00
|
|
|
__cfqq = cfq_rb_first(st);
|
2016-06-08 14:55:34 +00:00
|
|
|
rb_key += __cfqq ? __cfqq->rb_key : now;
|
2009-10-05 06:49:23 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-20 12:27:50 +00:00
|
|
|
if (!RB_EMPTY_NODE(&cfqq->rb_node)) {
|
2009-12-03 17:59:45 +00:00
|
|
|
new_cfqq = 0;
|
2007-02-05 10:56:25 +00:00
|
|
|
/*
|
2007-04-20 12:27:50 +00:00
|
|
|
* same position, nothing more to do
|
2007-02-05 10:56:25 +00:00
|
|
|
*/
|
2012-10-03 20:56:58 +00:00
|
|
|
if (rb_key == cfqq->rb_key && cfqq->service_tree == st)
|
2007-04-20 12:27:50 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-10-26 21:44:33 +00:00
|
|
|
cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree);
|
|
|
|
cfqq->service_tree = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-04-20 12:27:50 +00:00
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
left = 1;
|
2008-01-28 10:38:15 +00:00
|
|
|
parent = NULL;
|
2012-10-03 20:56:58 +00:00
|
|
|
cfqq->service_tree = st;
|
|
|
|
p = &st->rb.rb_node;
|
2007-04-20 12:27:50 +00:00
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
__cfqq = rb_entry(parent, struct cfq_queue, rb_node);
|
|
|
|
|
2007-04-18 18:01:57 +00:00
|
|
|
/*
|
2009-10-27 18:16:03 +00:00
|
|
|
* sort by key, that represents service time.
|
2007-04-18 18:01:57 +00:00
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
if (rb_key < __cfqq->rb_key)
|
2012-10-03 20:57:00 +00:00
|
|
|
p = &parent->rb_left;
|
2009-10-27 18:16:03 +00:00
|
|
|
else {
|
2012-10-03 20:57:00 +00:00
|
|
|
p = &parent->rb_right;
|
2007-04-26 10:53:50 +00:00
|
|
|
left = 0;
|
2009-10-27 18:16:03 +00:00
|
|
|
}
|
2007-04-20 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 10:53:50 +00:00
|
|
|
if (left)
|
2012-10-03 20:56:58 +00:00
|
|
|
st->left = &cfqq->rb_node;
|
2007-04-26 10:53:50 +00:00
|
|
|
|
2007-04-20 12:27:50 +00:00
|
|
|
cfqq->rb_key = rb_key;
|
|
|
|
rb_link_node(&cfqq->rb_node, parent, p);
|
2012-10-03 20:56:58 +00:00
|
|
|
rb_insert_color(&cfqq->rb_node, &st->rb);
|
|
|
|
st->count++;
|
2011-05-24 08:23:22 +00:00
|
|
|
if (add_front || !new_cfqq)
|
2009-12-03 17:59:45 +00:00
|
|
|
return;
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_group_notify_queue_add(cfqd, cfqq->cfqg);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 10:15:11 +00:00
|
|
|
static struct cfq_queue *
|
2009-04-23 10:19:38 +00:00
|
|
|
cfq_prio_tree_lookup(struct cfq_data *cfqd, struct rb_root *root,
|
|
|
|
sector_t sector, struct rb_node **ret_parent,
|
|
|
|
struct rb_node ***rb_link)
|
2009-04-15 10:15:11 +00:00
|
|
|
{
|
|
|
|
struct rb_node **p, *parent;
|
|
|
|
struct cfq_queue *cfqq = NULL;
|
|
|
|
|
|
|
|
parent = NULL;
|
|
|
|
p = &root->rb_node;
|
|
|
|
while (*p) {
|
|
|
|
struct rb_node **n;
|
|
|
|
|
|
|
|
parent = *p;
|
|
|
|
cfqq = rb_entry(parent, struct cfq_queue, p_node);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort strictly based on sector. Smallest to the left,
|
|
|
|
* largest to the right.
|
|
|
|
*/
|
2009-05-07 13:24:41 +00:00
|
|
|
if (sector > blk_rq_pos(cfqq->next_rq))
|
2009-04-15 10:15:11 +00:00
|
|
|
n = &(*p)->rb_right;
|
2009-05-07 13:24:41 +00:00
|
|
|
else if (sector < blk_rq_pos(cfqq->next_rq))
|
2009-04-15 10:15:11 +00:00
|
|
|
n = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
p = n;
|
2009-04-23 10:14:56 +00:00
|
|
|
cfqq = NULL;
|
2009-04-15 10:15:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*ret_parent = parent;
|
|
|
|
if (rb_link)
|
|
|
|
*rb_link = p;
|
2009-04-23 10:14:56 +00:00
|
|
|
return cfqq;
|
2009-04-15 10:15:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cfq_prio_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
struct rb_node **p, *parent;
|
|
|
|
struct cfq_queue *__cfqq;
|
|
|
|
|
2009-04-23 10:19:38 +00:00
|
|
|
if (cfqq->p_root) {
|
|
|
|
rb_erase(&cfqq->p_node, cfqq->p_root);
|
|
|
|
cfqq->p_root = NULL;
|
|
|
|
}
|
2009-04-15 10:15:11 +00:00
|
|
|
|
|
|
|
if (cfq_class_idle(cfqq))
|
|
|
|
return;
|
|
|
|
if (!cfqq->next_rq)
|
|
|
|
return;
|
|
|
|
|
2009-04-23 10:19:38 +00:00
|
|
|
cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio];
|
2009-05-07 13:24:41 +00:00
|
|
|
__cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root,
|
|
|
|
blk_rq_pos(cfqq->next_rq), &parent, &p);
|
2009-04-23 10:14:56 +00:00
|
|
|
if (!__cfqq) {
|
|
|
|
rb_link_node(&cfqq->p_node, parent, p);
|
2009-04-23 10:19:38 +00:00
|
|
|
rb_insert_color(&cfqq->p_node, cfqq->p_root);
|
|
|
|
} else
|
|
|
|
cfqq->p_root = NULL;
|
2009-04-15 10:15:11 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
|
|
|
* Update cfqq's position in the service tree.
|
|
|
|
*/
|
2007-04-19 10:03:34 +00:00
|
|
|
static void cfq_resort_rr_list(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2007-04-25 10:44:27 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Resorting requires the cfqq to be on the RR list already.
|
|
|
|
*/
|
2009-04-15 10:15:11 +00:00
|
|
|
if (cfq_cfqq_on_rr(cfqq)) {
|
2007-04-19 10:03:34 +00:00
|
|
|
cfq_service_tree_add(cfqd, cfqq, 0);
|
2009-04-15 10:15:11 +00:00
|
|
|
cfq_prio_tree_add(cfqd, cfqq);
|
|
|
|
}
|
2007-04-25 10:44:27 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* add to busy list of queues for service, trying to be fair in ordering
|
2005-06-27 08:55:12 +00:00
|
|
|
* the pending list according to last request service
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2008-01-28 12:19:43 +00:00
|
|
|
static void cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "add_to_rr");
|
2005-06-27 08:56:24 +00:00
|
|
|
BUG_ON(cfq_cfqq_on_rr(cfqq));
|
|
|
|
cfq_mark_cfqq_on_rr(cfqq);
|
2005-04-16 22:20:36 +00:00
|
|
|
cfqd->busy_queues++;
|
2011-03-07 08:26:29 +00:00
|
|
|
if (cfq_cfqq_sync(cfqq))
|
|
|
|
cfqd->busy_sync_queues++;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-19 10:03:34 +00:00
|
|
|
cfq_resort_rr_list(cfqd, cfqq);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
|
|
|
* Called when the cfqq no longer has requests pending, remove it from
|
|
|
|
* the service tree.
|
|
|
|
*/
|
2008-01-28 12:19:43 +00:00
|
|
|
static void cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "del_from_rr");
|
2005-06-27 08:56:24 +00:00
|
|
|
BUG_ON(!cfq_cfqq_on_rr(cfqq));
|
|
|
|
cfq_clear_cfqq_on_rr(cfqq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-10-26 21:44:33 +00:00
|
|
|
if (!RB_EMPTY_NODE(&cfqq->rb_node)) {
|
|
|
|
cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree);
|
|
|
|
cfqq->service_tree = NULL;
|
|
|
|
}
|
2009-04-23 10:19:38 +00:00
|
|
|
if (cfqq->p_root) {
|
|
|
|
rb_erase(&cfqq->p_node, cfqq->p_root);
|
|
|
|
cfqq->p_root = NULL;
|
|
|
|
}
|
2007-04-20 12:27:50 +00:00
|
|
|
|
2011-03-17 15:12:36 +00:00
|
|
|
cfq_group_notify_queue_del(cfqd, cfqq->cfqg);
|
2005-04-16 22:20:36 +00:00
|
|
|
BUG_ON(!cfqd->busy_queues);
|
|
|
|
cfqd->busy_queues--;
|
2011-03-07 08:26:29 +00:00
|
|
|
if (cfq_cfqq_sync(cfqq))
|
|
|
|
cfqd->busy_sync_queues--;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rb tree support functions
|
|
|
|
*/
|
2008-01-28 12:19:43 +00:00
|
|
|
static void cfq_del_rq_rb(struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
|
|
|
const int sync = rq_is_sync(rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-20 14:42:29 +00:00
|
|
|
BUG_ON(!cfqq->queued[sync]);
|
|
|
|
cfqq->queued[sync]--;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-13 10:39:25 +00:00
|
|
|
elv_rb_del(&cfqq->sort_list, rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-12-03 17:59:40 +00:00
|
|
|
if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list)) {
|
|
|
|
/*
|
|
|
|
* Queue will be deleted from service tree when we actually
|
|
|
|
* expire it later. Right now just remove it from prio tree
|
|
|
|
* as it is empty.
|
|
|
|
*/
|
|
|
|
if (cfqq->p_root) {
|
|
|
|
rb_erase(&cfqq->p_node, cfqq->p_root);
|
|
|
|
cfqq->p_root = NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-07-13 10:39:25 +00:00
|
|
|
static void cfq_add_rq_rb(struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cfq_data *cfqd = cfqq->cfqd;
|
iosched: prevent aliased requests from starving other I/O
Hi, Jens,
If you recall, I posted an RFC patch for this back in July of last year:
http://lkml.org/lkml/2010/7/13/279
The basic problem is that a process can issue a never-ending stream of
async direct I/Os to the same sector on a device, thus starving out
other I/O in the system (due to the way the alias handling works in both
cfq and deadline). The solution I proposed back then was to start
dispatching from the fifo after a certain number of aliases had been
dispatched. Vivek asked why we had to treat aliases differently at all,
and I never had a good answer. So, I put together a simple patch which
allows aliases to be added to the rb tree (it adds them to the right,
though that doesn't matter as the order isn't guaranteed anyway). I
think this is the preferred solution, as it doesn't break up time slices
in CFQ or batches in deadline. I've tested it, and it does solve the
starvation issue. Let me know what you think.
Cheers,
Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-06-02 19:19:05 +00:00
|
|
|
struct request *prev;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-13 10:37:56 +00:00
|
|
|
cfqq->queued[rq_is_sync(rq)]++;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
iosched: prevent aliased requests from starving other I/O
Hi, Jens,
If you recall, I posted an RFC patch for this back in July of last year:
http://lkml.org/lkml/2010/7/13/279
The basic problem is that a process can issue a never-ending stream of
async direct I/Os to the same sector on a device, thus starving out
other I/O in the system (due to the way the alias handling works in both
cfq and deadline). The solution I proposed back then was to start
dispatching from the fifo after a certain number of aliases had been
dispatched. Vivek asked why we had to treat aliases differently at all,
and I never had a good answer. So, I put together a simple patch which
allows aliases to be added to the rb tree (it adds them to the right,
though that doesn't matter as the order isn't guaranteed anyway). I
think this is the preferred solution, as it doesn't break up time slices
in CFQ or batches in deadline. I've tested it, and it does solve the
starvation issue. Let me know what you think.
Cheers,
Jeff
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2011-06-02 19:19:05 +00:00
|
|
|
elv_rb_add(&cfqq->sort_list, rq);
|
2006-10-31 13:21:55 +00:00
|
|
|
|
|
|
|
if (!cfq_cfqq_on_rr(cfqq))
|
|
|
|
cfq_add_cfqq_rr(cfqd, cfqq);
|
2007-04-25 09:53:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check if this request is a better next-serve candidate
|
|
|
|
*/
|
2009-04-15 10:15:11 +00:00
|
|
|
prev = cfqq->next_rq;
|
cfq-iosched: fix next_rq computation
Cfq has a bug in computation of next_rq, that affects transition
between multiple sequential request streams in a single queue
(e.g.: two sequential buffered writers of the same priority),
causing the alternation between the two streams for a transient period.
8,0 1 18737 0.260400660 5312 D W 141653311 + 256
8,0 1 20839 0.273239461 5400 D W 141653567 + 256
8,0 1 20841 0.276343885 5394 D W 142803919 + 256
8,0 1 20843 0.279490878 5394 D W 141668927 + 256
8,0 1 20845 0.292459993 5400 D W 142804175 + 256
8,0 1 20847 0.295537247 5400 D W 141668671 + 256
8,0 1 20849 0.298656337 5400 D W 142804431 + 256
8,0 1 20851 0.311481148 5394 D W 141668415 + 256
8,0 1 20853 0.314421305 5394 D W 142804687 + 256
8,0 1 20855 0.318960112 5400 D W 142804943 + 256
The fix makes sure that the next_rq is computed from the last
dispatched request, and not affected by merging.
8,0 1 37776 4.305161306 0 D W 141738087 + 256
8,0 1 37778 4.308298091 0 D W 141738343 + 256
8,0 1 37780 4.312885190 0 D W 141738599 + 256
8,0 1 37782 4.315933291 0 D W 141738855 + 256
8,0 1 37784 4.319064459 0 D W 141739111 + 256
8,0 1 37786 4.331918431 5672 D W 142803007 + 256
8,0 1 37788 4.334930332 5672 D W 142803263 + 256
8,0 1 37790 4.337902723 5672 D W 142803519 + 256
8,0 1 37792 4.342359774 5672 D W 142803775 + 256
8,0 1 37794 4.345318286 0 D W 142804031 + 256
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-08 16:16:46 +00:00
|
|
|
cfqq->next_rq = cfq_choose_req(cfqd, cfqq->next_rq, rq, cfqd->last_position);
|
2009-04-15 10:15:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* adjust priority tree position, if ->next_rq changes
|
|
|
|
*/
|
|
|
|
if (prev != cfqq->next_rq)
|
|
|
|
cfq_prio_tree_add(cfqd, cfqq);
|
|
|
|
|
2007-04-25 09:53:48 +00:00
|
|
|
BUG_ON(!cfqq->next_rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 12:19:43 +00:00
|
|
|
static void cfq_reposition_rq_rb(struct cfq_queue *cfqq, struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:37:56 +00:00
|
|
|
elv_rb_del(&cfqq->sort_list, rq);
|
|
|
|
cfqq->queued[rq_is_sync(rq)]--;
|
2016-10-28 14:48:16 +00:00
|
|
|
cfqg_stats_update_io_remove(RQ_CFQG(rq), rq->cmd_flags);
|
2006-07-13 10:39:25 +00:00
|
|
|
cfq_add_rq_rb(rq);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_io_add(RQ_CFQG(rq), cfqq->cfqd->serving_group,
|
2016-10-28 14:48:16 +00:00
|
|
|
rq->cmd_flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-03-28 11:03:44 +00:00
|
|
|
static struct request *
|
|
|
|
cfq_find_rq_fmerge(struct cfq_data *cfqd, struct bio *bio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-03-28 11:03:44 +00:00
|
|
|
struct task_struct *tsk = current;
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic;
|
2006-03-28 11:03:44 +00:00
|
|
|
struct cfq_queue *cfqq;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-24 07:44:49 +00:00
|
|
|
cic = cfq_cic_lookup(cfqd, tsk->io_context);
|
2007-04-25 10:29:51 +00:00
|
|
|
if (!cic)
|
|
|
|
return NULL;
|
|
|
|
|
2016-11-01 13:40:02 +00:00
|
|
|
cfqq = cic_to_cfqq(cic, op_is_sync(bio->bi_opf));
|
2012-09-25 22:05:12 +00:00
|
|
|
if (cfqq)
|
|
|
|
return elv_rb_find(&cfqq->sort_list, bio_end_sector(bio));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-24 07:28:11 +00:00
|
|
|
static void cfq_activate_request(struct request_queue *q, struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-06-27 08:55:12 +00:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2005-06-27 08:56:24 +00:00
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
cfqd->rq_in_driver++;
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d",
|
2010-02-28 18:45:05 +00:00
|
|
|
cfqd->rq_in_driver);
|
2006-06-01 08:12:26 +00:00
|
|
|
|
2009-05-07 13:24:38 +00:00
|
|
|
cfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-24 07:28:11 +00:00
|
|
|
static void cfq_deactivate_request(struct request_queue *q, struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-10-20 14:42:29 +00:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
WARN_ON(!cfqd->rq_in_driver);
|
|
|
|
cfqd->rq_in_driver--;
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "deactivate rq, drv=%d",
|
2010-02-28 18:45:05 +00:00
|
|
|
cfqd->rq_in_driver);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-10-20 14:42:29 +00:00
|
|
|
static void cfq_remove_request(struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2006-07-13 10:33:14 +00:00
|
|
|
|
2006-07-13 10:39:25 +00:00
|
|
|
if (cfqq->next_rq == rq)
|
|
|
|
cfqq->next_rq = cfq_find_next_rq(cfqq->cfqd, cfqq, rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-20 14:42:29 +00:00
|
|
|
list_del_init(&rq->queuelist);
|
2006-07-13 10:39:25 +00:00
|
|
|
cfq_del_rq_rb(rq);
|
2006-07-22 23:42:19 +00:00
|
|
|
|
2008-08-26 13:52:36 +00:00
|
|
|
cfqq->cfqd->rq_queued--;
|
2016-10-28 14:48:16 +00:00
|
|
|
cfqg_stats_update_io_remove(RQ_CFQG(rq), rq->cmd_flags);
|
2011-08-23 12:50:29 +00:00
|
|
|
if (rq->cmd_flags & REQ_PRIO) {
|
|
|
|
WARN_ON(!cfqq->prio_pending);
|
|
|
|
cfqq->prio_pending--;
|
2011-08-19 06:34:48 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-24 07:28:11 +00:00
|
|
|
static int cfq_merge(struct request_queue *q, struct request **req,
|
|
|
|
struct bio *bio)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
struct request *__rq;
|
|
|
|
|
2006-03-28 11:03:44 +00:00
|
|
|
__rq = cfq_find_rq_fmerge(cfqd, bio);
|
2016-07-07 18:48:22 +00:00
|
|
|
if (__rq && elv_bio_merge_ok(__rq, bio)) {
|
2006-07-28 07:23:08 +00:00
|
|
|
*req = __rq;
|
|
|
|
return ELEVATOR_FRONT_MERGE;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ELEVATOR_NO_MERGE;
|
|
|
|
}
|
|
|
|
|
2007-07-24 07:28:11 +00:00
|
|
|
static void cfq_merged_request(struct request_queue *q, struct request *req,
|
2006-07-13 10:33:14 +00:00
|
|
|
int type)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:33:14 +00:00
|
|
|
if (type == ELEVATOR_FRONT_MERGE) {
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(req);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-13 10:39:25 +00:00
|
|
|
cfq_reposition_rq_rb(cfqq, req);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 04:14:23 +00:00
|
|
|
static void cfq_bio_merged(struct request_queue *q, struct request *req,
|
|
|
|
struct bio *bio)
|
|
|
|
{
|
2016-10-28 14:48:16 +00:00
|
|
|
cfqg_stats_update_io_merged(RQ_CFQG(req), bio->bi_opf);
|
2010-04-09 04:14:23 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static void
|
2007-07-24 07:28:11 +00:00
|
|
|
cfq_merged_requests(struct request_queue *q, struct request *rq,
|
2005-04-16 22:20:36 +00:00
|
|
|
struct request *next)
|
|
|
|
{
|
cfq-iosched: fix next_rq computation
Cfq has a bug in computation of next_rq, that affects transition
between multiple sequential request streams in a single queue
(e.g.: two sequential buffered writers of the same priority),
causing the alternation between the two streams for a transient period.
8,0 1 18737 0.260400660 5312 D W 141653311 + 256
8,0 1 20839 0.273239461 5400 D W 141653567 + 256
8,0 1 20841 0.276343885 5394 D W 142803919 + 256
8,0 1 20843 0.279490878 5394 D W 141668927 + 256
8,0 1 20845 0.292459993 5400 D W 142804175 + 256
8,0 1 20847 0.295537247 5400 D W 141668671 + 256
8,0 1 20849 0.298656337 5400 D W 142804431 + 256
8,0 1 20851 0.311481148 5394 D W 141668415 + 256
8,0 1 20853 0.314421305 5394 D W 142804687 + 256
8,0 1 20855 0.318960112 5400 D W 142804943 + 256
The fix makes sure that the next_rq is computed from the last
dispatched request, and not affected by merging.
8,0 1 37776 4.305161306 0 D W 141738087 + 256
8,0 1 37778 4.308298091 0 D W 141738343 + 256
8,0 1 37780 4.312885190 0 D W 141738599 + 256
8,0 1 37782 4.315933291 0 D W 141738855 + 256
8,0 1 37784 4.319064459 0 D W 141739111 + 256
8,0 1 37786 4.331918431 5672 D W 142803007 + 256
8,0 1 37788 4.334930332 5672 D W 142803263 + 256
8,0 1 37790 4.337902723 5672 D W 142803519 + 256
8,0 1 37792 4.342359774 5672 D W 142803775 + 256
8,0 1 37794 4.345318286 0 D W 142804031 + 256
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-08 16:16:46 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2011-12-16 13:00:22 +00:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* reposition in fifo if next is older than rq
|
|
|
|
*/
|
|
|
|
if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist) &&
|
2016-06-08 14:55:34 +00:00
|
|
|
next->fifo_time < rq->fifo_time &&
|
2012-11-06 11:39:51 +00:00
|
|
|
cfqq == RQ_CFQQ(next)) {
|
2005-06-27 08:55:12 +00:00
|
|
|
list_move(&rq->queuelist, &next->queuelist);
|
2014-02-24 15:39:52 +00:00
|
|
|
rq->fifo_time = next->fifo_time;
|
2009-10-05 09:03:39 +00:00
|
|
|
}
|
2005-06-27 08:55:12 +00:00
|
|
|
|
cfq-iosched: fix next_rq computation
Cfq has a bug in computation of next_rq, that affects transition
between multiple sequential request streams in a single queue
(e.g.: two sequential buffered writers of the same priority),
causing the alternation between the two streams for a transient period.
8,0 1 18737 0.260400660 5312 D W 141653311 + 256
8,0 1 20839 0.273239461 5400 D W 141653567 + 256
8,0 1 20841 0.276343885 5394 D W 142803919 + 256
8,0 1 20843 0.279490878 5394 D W 141668927 + 256
8,0 1 20845 0.292459993 5400 D W 142804175 + 256
8,0 1 20847 0.295537247 5400 D W 141668671 + 256
8,0 1 20849 0.298656337 5400 D W 142804431 + 256
8,0 1 20851 0.311481148 5394 D W 141668415 + 256
8,0 1 20853 0.314421305 5394 D W 142804687 + 256
8,0 1 20855 0.318960112 5400 D W 142804943 + 256
The fix makes sure that the next_rq is computed from the last
dispatched request, and not affected by merging.
8,0 1 37776 4.305161306 0 D W 141738087 + 256
8,0 1 37778 4.308298091 0 D W 141738343 + 256
8,0 1 37780 4.312885190 0 D W 141738599 + 256
8,0 1 37782 4.315933291 0 D W 141738855 + 256
8,0 1 37784 4.319064459 0 D W 141739111 + 256
8,0 1 37786 4.331918431 5672 D W 142803007 + 256
8,0 1 37788 4.334930332 5672 D W 142803263 + 256
8,0 1 37790 4.337902723 5672 D W 142803519 + 256
8,0 1 37792 4.342359774 5672 D W 142803775 + 256
8,0 1 37794 4.345318286 0 D W 142804031 + 256
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-08 16:16:46 +00:00
|
|
|
if (cfqq->next_rq == next)
|
|
|
|
cfqq->next_rq = rq;
|
2005-10-20 14:42:29 +00:00
|
|
|
cfq_remove_request(next);
|
2016-10-28 14:48:16 +00:00
|
|
|
cfqg_stats_update_io_merged(RQ_CFQG(rq), next->cmd_flags);
|
2011-12-16 13:00:22 +00:00
|
|
|
|
|
|
|
cfqq = RQ_CFQQ(next);
|
|
|
|
/*
|
|
|
|
* all requests of this queue are merged to other queues, delete it
|
|
|
|
* from the service tree. If it's the active_queue,
|
|
|
|
* cfq_dispatch_requests() will choose to expire it or do idle
|
|
|
|
*/
|
|
|
|
if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list) &&
|
|
|
|
cfqq != cfqd->active_queue)
|
|
|
|
cfq_del_cfqq_rr(cfqd, cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 18:48:22 +00:00
|
|
|
static int cfq_allow_bio_merge(struct request_queue *q, struct request *rq,
|
|
|
|
struct bio *bio)
|
2006-12-20 10:04:12 +00:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2016-11-01 13:40:02 +00:00
|
|
|
bool is_sync = op_is_sync(bio->bi_opf);
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic;
|
2006-12-20 10:04:12 +00:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
|
|
|
|
/*
|
2007-01-02 17:32:11 +00:00
|
|
|
* Disallow merge of a sync bio into an async request.
|
2006-12-20 10:04:12 +00:00
|
|
|
*/
|
2016-11-01 13:40:02 +00:00
|
|
|
if (is_sync && !rq_is_sync(rq))
|
2009-10-07 18:02:57 +00:00
|
|
|
return false;
|
2006-12-20 10:04:12 +00:00
|
|
|
|
|
|
|
/*
|
2011-12-13 23:33:39 +00:00
|
|
|
* Lookup the cfqq that this bio will be queued with and allow
|
block: don't call elevator callbacks for plug merges
Plug merge calls two elevator callbacks outside queue lock -
elevator_allow_merge_fn() and elevator_bio_merged_fn(). Although
attempt_plug_merge() suggests that elevator is guaranteed to be there
through the existing request on the plug list, nothing prevents plug
merge from calling into dying or initializing elevator.
For regular merges, bypass ensures elvpriv count to reach zero, which
in turn prevents merges as all !ELVPRIV requests get REQ_SOFTBARRIER
from forced back insertion. Plug merge doesn't check ELVPRIV, and, as
the requests haven't gone through elevator insertion yet, it doesn't
have SOFTBARRIER set allowing merges on a bypassed queue.
This, for example, leads to the following crash during elevator
switch.
BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
IP: [<ffffffff813b34e9>] cfq_allow_merge+0x49/0xa0
PGD 112cbc067 PUD 115d5c067 PMD 0
Oops: 0000 [#1] PREEMPT SMP
CPU 1
Modules linked in: deadline_iosched
Pid: 819, comm: dd Not tainted 3.3.0-rc2-work+ #76 Bochs Bochs
RIP: 0010:[<ffffffff813b34e9>] [<ffffffff813b34e9>] cfq_allow_merge+0x49/0xa0
RSP: 0018:ffff8801143a38f8 EFLAGS: 00010297
RAX: 0000000000000000 RBX: ffff88011817ce28 RCX: ffff880116eb6cc0
RDX: 0000000000000000 RSI: ffff880118056e20 RDI: ffff8801199512f8
RBP: ffff8801143a3908 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffff880118195708
R13: ffff880118052aa0 R14: ffff8801143a3d50 R15: ffff880118195708
FS: 00007f19f82cb700(0000) GS:ffff88011fc80000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 0000000000000008 CR3: 0000000112c6a000 CR4: 00000000000006e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process dd (pid: 819, threadinfo ffff8801143a2000, task ffff880116eb6cc0)
Stack:
ffff88011817ce28 ffff880118195708 ffff8801143a3928 ffffffff81391bba
ffff88011817ce28 ffff880118195708 ffff8801143a3948 ffffffff81391bf1
ffff88011817ce28 0000000000000000 ffff8801143a39a8 ffffffff81398e3e
Call Trace:
[<ffffffff81391bba>] elv_rq_merge_ok+0x4a/0x60
[<ffffffff81391bf1>] elv_try_merge+0x21/0x40
[<ffffffff81398e3e>] blk_queue_bio+0x8e/0x390
[<ffffffff81396a5a>] generic_make_request+0xca/0x100
[<ffffffff81396b04>] submit_bio+0x74/0x100
[<ffffffff811d45c2>] __blockdev_direct_IO+0x1ce2/0x3450
[<ffffffff811d0dc7>] blkdev_direct_IO+0x57/0x60
[<ffffffff811460b5>] generic_file_aio_read+0x6d5/0x760
[<ffffffff811986b2>] do_sync_read+0xe2/0x120
[<ffffffff81199345>] vfs_read+0xc5/0x180
[<ffffffff81199501>] sys_read+0x51/0x90
[<ffffffff81aeac12>] system_call_fastpath+0x16/0x1b
There are multiple ways to fix this including making plug merge check
ELVPRIV; however,
* Calling into elevator outside queue lock is confusing and
error-prone.
* Requests on plug list aren't known to the elevator. They aren't on
the elevator yet, so there's no elevator specific state to update.
* Given the nature of plug merges - collecting bio's for the same
purpose from the same issuer - elevator specific restrictions aren't
applicable.
So, simply don't call into elevator methods from plug merge by moving
elv_bio_merged() from bio_attempt_*_merge() to blk_queue_bio(), and
using blk_try_merge() in attempt_plug_merge().
This is based on Jens' patch to skip elevator_allow_merge_fn() from
plug merge.
Note that this makes per-cgroup merged stats skip plug merging.
Signed-off-by: Tejun Heo <tj@kernel.org>
LKML-Reference: <4F16F3CA.90904@kernel.dk>
Original-patch-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-02-08 08:19:42 +00:00
|
|
|
* merge only if rq is queued there.
|
2011-12-13 23:33:39 +00:00
|
|
|
*/
|
block: don't call elevator callbacks for plug merges
Plug merge calls two elevator callbacks outside queue lock -
elevator_allow_merge_fn() and elevator_bio_merged_fn(). Although
attempt_plug_merge() suggests that elevator is guaranteed to be there
through the existing request on the plug list, nothing prevents plug
merge from calling into dying or initializing elevator.
For regular merges, bypass ensures elvpriv count to reach zero, which
in turn prevents merges as all !ELVPRIV requests get REQ_SOFTBARRIER
from forced back insertion. Plug merge doesn't check ELVPRIV, and, as
the requests haven't gone through elevator insertion yet, it doesn't
have SOFTBARRIER set allowing merges on a bypassed queue.
This, for example, leads to the following crash during elevator
switch.
BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
IP: [<ffffffff813b34e9>] cfq_allow_merge+0x49/0xa0
PGD 112cbc067 PUD 115d5c067 PMD 0
Oops: 0000 [#1] PREEMPT SMP
CPU 1
Modules linked in: deadline_iosched
Pid: 819, comm: dd Not tainted 3.3.0-rc2-work+ #76 Bochs Bochs
RIP: 0010:[<ffffffff813b34e9>] [<ffffffff813b34e9>] cfq_allow_merge+0x49/0xa0
RSP: 0018:ffff8801143a38f8 EFLAGS: 00010297
RAX: 0000000000000000 RBX: ffff88011817ce28 RCX: ffff880116eb6cc0
RDX: 0000000000000000 RSI: ffff880118056e20 RDI: ffff8801199512f8
RBP: ffff8801143a3908 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffff880118195708
R13: ffff880118052aa0 R14: ffff8801143a3d50 R15: ffff880118195708
FS: 00007f19f82cb700(0000) GS:ffff88011fc80000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 0000000000000008 CR3: 0000000112c6a000 CR4: 00000000000006e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process dd (pid: 819, threadinfo ffff8801143a2000, task ffff880116eb6cc0)
Stack:
ffff88011817ce28 ffff880118195708 ffff8801143a3928 ffffffff81391bba
ffff88011817ce28 ffff880118195708 ffff8801143a3948 ffffffff81391bf1
ffff88011817ce28 0000000000000000 ffff8801143a39a8 ffffffff81398e3e
Call Trace:
[<ffffffff81391bba>] elv_rq_merge_ok+0x4a/0x60
[<ffffffff81391bf1>] elv_try_merge+0x21/0x40
[<ffffffff81398e3e>] blk_queue_bio+0x8e/0x390
[<ffffffff81396a5a>] generic_make_request+0xca/0x100
[<ffffffff81396b04>] submit_bio+0x74/0x100
[<ffffffff811d45c2>] __blockdev_direct_IO+0x1ce2/0x3450
[<ffffffff811d0dc7>] blkdev_direct_IO+0x57/0x60
[<ffffffff811460b5>] generic_file_aio_read+0x6d5/0x760
[<ffffffff811986b2>] do_sync_read+0xe2/0x120
[<ffffffff81199345>] vfs_read+0xc5/0x180
[<ffffffff81199501>] sys_read+0x51/0x90
[<ffffffff81aeac12>] system_call_fastpath+0x16/0x1b
There are multiple ways to fix this including making plug merge check
ELVPRIV; however,
* Calling into elevator outside queue lock is confusing and
error-prone.
* Requests on plug list aren't known to the elevator. They aren't on
the elevator yet, so there's no elevator specific state to update.
* Given the nature of plug merges - collecting bio's for the same
purpose from the same issuer - elevator specific restrictions aren't
applicable.
So, simply don't call into elevator methods from plug merge by moving
elv_bio_merged() from bio_attempt_*_merge() to blk_queue_bio(), and
using blk_try_merge() in attempt_plug_merge().
This is based on Jens' patch to skip elevator_allow_merge_fn() from
plug merge.
Note that this makes per-cgroup merged stats skip plug merging.
Signed-off-by: Tejun Heo <tj@kernel.org>
LKML-Reference: <4F16F3CA.90904@kernel.dk>
Original-patch-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-02-08 08:19:42 +00:00
|
|
|
cic = cfq_cic_lookup(cfqd, current->io_context);
|
|
|
|
if (!cic)
|
|
|
|
return false;
|
2006-12-22 08:38:53 +00:00
|
|
|
|
2016-11-01 13:40:02 +00:00
|
|
|
cfqq = cic_to_cfqq(cic, is_sync);
|
2009-10-07 18:02:57 +00:00
|
|
|
return cfqq == RQ_CFQQ(rq);
|
2006-12-20 10:04:12 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 18:48:22 +00:00
|
|
|
static int cfq_allow_rq_merge(struct request_queue *q, struct request *rq,
|
|
|
|
struct request *next)
|
|
|
|
{
|
|
|
|
return RQ_CFQQ(rq) == RQ_CFQQ(next);
|
|
|
|
}
|
|
|
|
|
2010-04-09 04:15:35 +00:00
|
|
|
static inline void cfq_del_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
2016-06-08 13:11:39 +00:00
|
|
|
hrtimer_try_to_cancel(&cfqd->idle_slice_timer);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_idle_time(cfqq->cfqg);
|
2010-04-09 04:15:35 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 12:19:43 +00:00
|
|
|
static void __cfq_set_active_queue(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
|
|
|
if (cfqq) {
|
2012-10-03 20:56:56 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "set_active wl_class:%d wl_type:%d",
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_avg_queue_size(cfqq->cfqg);
|
2011-03-23 07:25:44 +00:00
|
|
|
cfqq->slice_start = 0;
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqq->dispatch_start = ktime_get_ns();
|
2011-03-23 07:25:44 +00:00
|
|
|
cfqq->allocated_slice = 0;
|
|
|
|
cfqq->slice_end = 0;
|
|
|
|
cfqq->slice_dispatch = 0;
|
|
|
|
cfqq->nr_sectors = 0;
|
|
|
|
|
|
|
|
cfq_clear_cfqq_wait_request(cfqq);
|
|
|
|
cfq_clear_cfqq_must_dispatch(cfqq);
|
|
|
|
cfq_clear_cfqq_must_alloc_slice(cfqq);
|
|
|
|
cfq_clear_cfqq_fifo_expire(cfqq);
|
|
|
|
cfq_mark_cfqq_slice_new(cfqq);
|
|
|
|
|
|
|
|
cfq_del_timer(cfqd, cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cfqd->active_queue = cfqq;
|
|
|
|
}
|
|
|
|
|
2006-02-28 08:35:11 +00:00
|
|
|
/*
|
|
|
|
* current cfqq expired its slice (or was too idle), select new one
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
__cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2010-04-26 17:25:11 +00:00
|
|
|
bool timed_out)
|
2006-02-28 08:35:11 +00:00
|
|
|
{
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "slice expired t=%d", timed_out);
|
|
|
|
|
2006-02-28 08:35:11 +00:00
|
|
|
if (cfq_cfqq_wait_request(cfqq))
|
2010-04-09 04:15:35 +00:00
|
|
|
cfq_del_timer(cfqd, cfqq);
|
2006-02-28 08:35:11 +00:00
|
|
|
|
|
|
|
cfq_clear_cfqq_wait_request(cfqq);
|
2009-12-03 17:59:53 +00:00
|
|
|
cfq_clear_cfqq_wait_busy(cfqq);
|
2006-02-28 08:35:11 +00:00
|
|
|
|
2010-02-05 12:11:45 +00:00
|
|
|
/*
|
|
|
|
* If this cfqq is shared between multiple processes, check to
|
|
|
|
* make sure that those processes are still issuing I/Os within
|
|
|
|
* the mean seek distance. If not, it may be time to break the
|
|
|
|
* queues apart again.
|
|
|
|
*/
|
|
|
|
if (cfq_cfqq_coop(cfqq) && CFQQ_SEEKY(cfqq))
|
|
|
|
cfq_mark_cfqq_split_coop(cfqq);
|
|
|
|
|
2006-02-28 08:35:11 +00:00
|
|
|
/*
|
2007-04-23 06:25:00 +00:00
|
|
|
* store what was left of this slice, if the queue idled/timed out
|
2006-02-28 08:35:11 +00:00
|
|
|
*/
|
2011-01-14 07:41:03 +00:00
|
|
|
if (timed_out) {
|
|
|
|
if (cfq_cfqq_slice_new(cfqq))
|
2011-01-19 15:25:02 +00:00
|
|
|
cfqq->slice_resid = cfq_scaled_cfqq_slice(cfqd, cfqq);
|
2011-01-14 07:41:03 +00:00
|
|
|
else
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqq->slice_resid = cfqq->slice_end - ktime_get_ns();
|
2016-06-28 07:04:00 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "resid=%lld", cfqq->slice_resid);
|
2008-05-30 10:23:07 +00:00
|
|
|
}
|
2006-02-28 08:35:11 +00:00
|
|
|
|
2010-04-26 17:25:11 +00:00
|
|
|
cfq_group_served(cfqd, cfqq->cfqg, cfqq);
|
2009-12-03 17:59:45 +00:00
|
|
|
|
2009-12-03 17:59:40 +00:00
|
|
|
if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list))
|
|
|
|
cfq_del_cfqq_rr(cfqd, cfqq);
|
|
|
|
|
2007-04-19 10:03:34 +00:00
|
|
|
cfq_resort_rr_list(cfqd, cfqq);
|
2006-02-28 08:35:11 +00:00
|
|
|
|
|
|
|
if (cfqq == cfqd->active_queue)
|
|
|
|
cfqd->active_queue = NULL;
|
|
|
|
|
|
|
|
if (cfqd->active_cic) {
|
2012-02-07 06:51:30 +00:00
|
|
|
put_io_context(cfqd->active_cic->icq.ioc);
|
2006-02-28 08:35:11 +00:00
|
|
|
cfqd->active_cic = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-26 17:25:11 +00:00
|
|
|
static inline void cfq_slice_expired(struct cfq_data *cfqd, bool timed_out)
|
2006-02-28 08:35:11 +00:00
|
|
|
{
|
|
|
|
struct cfq_queue *cfqq = cfqd->active_queue;
|
|
|
|
|
|
|
|
if (cfqq)
|
2010-04-26 17:25:11 +00:00
|
|
|
__cfq_slice_expired(cfqd, cfqq, timed_out);
|
2006-02-28 08:35:11 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
|
|
|
* Get next queue for service. Unless we have a queue preemption,
|
|
|
|
* we'll simply select the first cfqq in the service tree.
|
|
|
|
*/
|
2007-04-25 10:44:27 +00:00
|
|
|
static struct cfq_queue *cfq_get_next_queue(struct cfq_data *cfqd)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2012-10-03 20:56:58 +00:00
|
|
|
struct cfq_rb_root *st = st_for(cfqd->serving_group,
|
|
|
|
cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2007-04-20 12:27:50 +00:00
|
|
|
|
2009-12-03 17:59:40 +00:00
|
|
|
if (!cfqd->rq_queued)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
/* There is nothing to dispatch */
|
2012-10-03 20:56:58 +00:00
|
|
|
if (!st)
|
2009-12-03 17:59:41 +00:00
|
|
|
return NULL;
|
2012-10-03 20:56:58 +00:00
|
|
|
if (RB_EMPTY_ROOT(&st->rb))
|
2009-10-27 18:16:03 +00:00
|
|
|
return NULL;
|
2012-10-03 20:56:58 +00:00
|
|
|
return cfq_rb_first(st);
|
2007-04-25 10:44:27 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:40 +00:00
|
|
|
static struct cfq_queue *cfq_get_next_queue_forced(struct cfq_data *cfqd)
|
|
|
|
{
|
2009-12-03 17:59:46 +00:00
|
|
|
struct cfq_group *cfqg;
|
2009-12-03 17:59:40 +00:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
int i, j;
|
|
|
|
struct cfq_rb_root *st;
|
|
|
|
|
|
|
|
if (!cfqd->rq_queued)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 17:59:46 +00:00
|
|
|
cfqg = cfq_get_next_cfqg(cfqd);
|
|
|
|
if (!cfqg)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 17:59:40 +00:00
|
|
|
for_each_cfqg_st(cfqg, i, j, st)
|
|
|
|
if ((cfqq = cfq_rb_first(st)) != NULL)
|
|
|
|
return cfqq;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
|
|
|
* Get and set a new active queue for service.
|
|
|
|
*/
|
2009-04-15 10:15:11 +00:00
|
|
|
static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
2007-04-25 10:44:27 +00:00
|
|
|
{
|
2009-11-04 07:54:55 +00:00
|
|
|
if (!cfqq)
|
2009-04-15 10:15:11 +00:00
|
|
|
cfqq = cfq_get_next_queue(cfqd);
|
2007-04-25 10:44:27 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
__cfq_set_active_queue(cfqd, cfqq);
|
2005-06-27 08:56:24 +00:00
|
|
|
return cfqq;
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
2007-04-20 12:27:50 +00:00
|
|
|
static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd,
|
|
|
|
struct request *rq)
|
|
|
|
{
|
2009-05-07 13:24:39 +00:00
|
|
|
if (blk_rq_pos(rq) >= cfqd->last_position)
|
|
|
|
return blk_rq_pos(rq) - cfqd->last_position;
|
2007-04-20 12:27:50 +00:00
|
|
|
else
|
2009-05-07 13:24:39 +00:00
|
|
|
return cfqd->last_position - blk_rq_pos(rq);
|
2007-04-20 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
2009-10-23 21:14:49 +00:00
|
|
|
static inline int cfq_rq_close(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2010-03-19 07:03:04 +00:00
|
|
|
struct request *rq)
|
2007-04-25 10:44:27 +00:00
|
|
|
{
|
2010-03-19 07:03:04 +00:00
|
|
|
return cfq_dist_from_last(cfqd, rq) <= CFQQ_CLOSE_THR;
|
2007-04-25 10:44:27 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 10:15:11 +00:00
|
|
|
static struct cfq_queue *cfqq_close(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cur_cfqq)
|
|
|
|
{
|
2009-04-23 10:19:38 +00:00
|
|
|
struct rb_root *root = &cfqd->prio_trees[cur_cfqq->org_ioprio];
|
2009-04-15 10:15:11 +00:00
|
|
|
struct rb_node *parent, *node;
|
|
|
|
struct cfq_queue *__cfqq;
|
|
|
|
sector_t sector = cfqd->last_position;
|
|
|
|
|
|
|
|
if (RB_EMPTY_ROOT(root))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, if we find a request starting at the end of the last
|
|
|
|
* request, choose it.
|
|
|
|
*/
|
2009-04-23 10:19:38 +00:00
|
|
|
__cfqq = cfq_prio_tree_lookup(cfqd, root, sector, &parent, NULL);
|
2009-04-15 10:15:11 +00:00
|
|
|
if (__cfqq)
|
|
|
|
return __cfqq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the exact sector wasn't found, the parent of the NULL leaf
|
|
|
|
* will contain the closest sector.
|
|
|
|
*/
|
|
|
|
__cfqq = rb_entry(parent, struct cfq_queue, p_node);
|
2010-03-19 07:03:04 +00:00
|
|
|
if (cfq_rq_close(cfqd, cur_cfqq, __cfqq->next_rq))
|
2009-04-15 10:15:11 +00:00
|
|
|
return __cfqq;
|
|
|
|
|
2009-05-07 13:24:41 +00:00
|
|
|
if (blk_rq_pos(__cfqq->next_rq) < sector)
|
2009-04-15 10:15:11 +00:00
|
|
|
node = rb_next(&__cfqq->p_node);
|
|
|
|
else
|
|
|
|
node = rb_prev(&__cfqq->p_node);
|
|
|
|
if (!node)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
__cfqq = rb_entry(node, struct cfq_queue, p_node);
|
2010-03-19 07:03:04 +00:00
|
|
|
if (cfq_rq_close(cfqd, cur_cfqq, __cfqq->next_rq))
|
2009-04-15 10:15:11 +00:00
|
|
|
return __cfqq;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cfqd - obvious
|
|
|
|
* cur_cfqq - passed in so that we don't decide that the current queue is
|
|
|
|
* closely cooperating with itself.
|
|
|
|
*
|
|
|
|
* So, basically we're assuming that that cur_cfqq has dispatched at least
|
|
|
|
* one request, and that cfqd->last_position reflects a position on the disk
|
|
|
|
* associated with the I/O issued by cur_cfqq. I'm not sure this is a valid
|
|
|
|
* assumption.
|
|
|
|
*/
|
|
|
|
static struct cfq_queue *cfq_close_cooperator(struct cfq_data *cfqd,
|
2009-10-23 21:14:51 +00:00
|
|
|
struct cfq_queue *cur_cfqq)
|
2007-04-25 10:44:27 +00:00
|
|
|
{
|
2009-04-15 10:15:11 +00:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
|
2010-03-25 14:45:57 +00:00
|
|
|
if (cfq_class_idle(cur_cfqq))
|
|
|
|
return NULL;
|
2009-10-23 21:14:52 +00:00
|
|
|
if (!cfq_cfqq_sync(cur_cfqq))
|
|
|
|
return NULL;
|
|
|
|
if (CFQQ_SEEKY(cur_cfqq))
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-08 07:54:17 +00:00
|
|
|
/*
|
|
|
|
* Don't search priority tree if it's the only queue in the group.
|
|
|
|
*/
|
|
|
|
if (cur_cfqq->cfqg->nr_cfqq == 1)
|
|
|
|
return NULL;
|
|
|
|
|
2007-04-25 10:44:27 +00:00
|
|
|
/*
|
2007-04-20 12:27:50 +00:00
|
|
|
* We should notice if some of the queues are cooperating, eg
|
|
|
|
* working closely on the same area of the disk. In that case,
|
|
|
|
* we can group them together and don't waste time idling.
|
2007-04-25 10:44:27 +00:00
|
|
|
*/
|
2009-04-15 10:15:11 +00:00
|
|
|
cfqq = cfqq_close(cfqd, cur_cfqq);
|
|
|
|
if (!cfqq)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 17:59:50 +00:00
|
|
|
/* If new queue belongs to different cfq_group, don't choose it */
|
|
|
|
if (cur_cfqq->cfqg != cfqq->cfqg)
|
|
|
|
return NULL;
|
|
|
|
|
2009-10-23 21:14:50 +00:00
|
|
|
/*
|
|
|
|
* It only makes sense to merge sync queues.
|
|
|
|
*/
|
|
|
|
if (!cfq_cfqq_sync(cfqq))
|
|
|
|
return NULL;
|
2009-10-23 21:14:52 +00:00
|
|
|
if (CFQQ_SEEKY(cfqq))
|
|
|
|
return NULL;
|
2009-10-23 21:14:50 +00:00
|
|
|
|
2009-10-27 18:16:03 +00:00
|
|
|
/*
|
|
|
|
* Do not merge queues of different priority classes
|
|
|
|
*/
|
|
|
|
if (cfq_class_rt(cfqq) != cfq_class_rt(cur_cfqq))
|
|
|
|
return NULL;
|
|
|
|
|
2009-04-15 10:15:11 +00:00
|
|
|
return cfqq;
|
2007-04-25 10:44:27 +00:00
|
|
|
}
|
|
|
|
|
cfq-iosched: enable idling for last queue on priority class
cfq can disable idling for queues in various circumstances.
When workloads of different priorities are competing, if the higher
priority queue has idling disabled, lower priority queues may steal
its disk share. For example, in a scenario with an RT process
performing seeky reads vs a BE process performing sequential reads,
on an NCQ enabled hardware, with low_latency unset,
the RT process will dispatch only the few pending requests every full
slice of service for the BE process.
The patch solves this issue by always performing idle on the last
queue at a given priority class > idle. If the same process, or one
that can pre-empt it (so at the same priority or higher), submits a
new request within the idle window, the lower priority queue won't
dispatch, saving the disk bandwidth for higher priority ones.
Note: this doesn't touch the non_rotational + NCQ case (no hardware
to test if this is a benefit in that case).
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:11 +00:00
|
|
|
/*
|
|
|
|
* Determine whether we should enforce idle window for this queue.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static bool cfq_should_idle(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
2012-10-03 20:56:56 +00:00
|
|
|
enum wl_class_t wl_class = cfqq_class(cfqq);
|
2012-10-03 20:56:58 +00:00
|
|
|
struct cfq_rb_root *st = cfqq->service_tree;
|
cfq-iosched: enable idling for last queue on priority class
cfq can disable idling for queues in various circumstances.
When workloads of different priorities are competing, if the higher
priority queue has idling disabled, lower priority queues may steal
its disk share. For example, in a scenario with an RT process
performing seeky reads vs a BE process performing sequential reads,
on an NCQ enabled hardware, with low_latency unset,
the RT process will dispatch only the few pending requests every full
slice of service for the BE process.
The patch solves this issue by always performing idle on the last
queue at a given priority class > idle. If the same process, or one
that can pre-empt it (so at the same priority or higher), submits a
new request within the idle window, the lower priority queue won't
dispatch, saving the disk bandwidth for higher priority ones.
Note: this doesn't touch the non_rotational + NCQ case (no hardware
to test if this is a benefit in that case).
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:11 +00:00
|
|
|
|
2012-10-03 20:56:58 +00:00
|
|
|
BUG_ON(!st);
|
|
|
|
BUG_ON(!st->count);
|
2009-12-03 17:59:40 +00:00
|
|
|
|
2010-08-23 10:23:33 +00:00
|
|
|
if (!cfqd->cfq_slice_idle)
|
|
|
|
return false;
|
|
|
|
|
cfq-iosched: enable idling for last queue on priority class
cfq can disable idling for queues in various circumstances.
When workloads of different priorities are competing, if the higher
priority queue has idling disabled, lower priority queues may steal
its disk share. For example, in a scenario with an RT process
performing seeky reads vs a BE process performing sequential reads,
on an NCQ enabled hardware, with low_latency unset,
the RT process will dispatch only the few pending requests every full
slice of service for the BE process.
The patch solves this issue by always performing idle on the last
queue at a given priority class > idle. If the same process, or one
that can pre-empt it (so at the same priority or higher), submits a
new request within the idle window, the lower priority queue won't
dispatch, saving the disk bandwidth for higher priority ones.
Note: this doesn't touch the non_rotational + NCQ case (no hardware
to test if this is a benefit in that case).
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:11 +00:00
|
|
|
/* We never do for idle class queues. */
|
2012-10-03 20:56:56 +00:00
|
|
|
if (wl_class == IDLE_WORKLOAD)
|
cfq-iosched: enable idling for last queue on priority class
cfq can disable idling for queues in various circumstances.
When workloads of different priorities are competing, if the higher
priority queue has idling disabled, lower priority queues may steal
its disk share. For example, in a scenario with an RT process
performing seeky reads vs a BE process performing sequential reads,
on an NCQ enabled hardware, with low_latency unset,
the RT process will dispatch only the few pending requests every full
slice of service for the BE process.
The patch solves this issue by always performing idle on the last
queue at a given priority class > idle. If the same process, or one
that can pre-empt it (so at the same priority or higher), submits a
new request within the idle window, the lower priority queue won't
dispatch, saving the disk bandwidth for higher priority ones.
Note: this doesn't touch the non_rotational + NCQ case (no hardware
to test if this is a benefit in that case).
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:11 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* We do for queues that were marked with idle window flag. */
|
2009-12-04 12:12:06 +00:00
|
|
|
if (cfq_cfqq_idle_window(cfqq) &&
|
|
|
|
!(blk_queue_nonrot(cfqd->queue) && cfqd->hw_tag))
|
cfq-iosched: enable idling for last queue on priority class
cfq can disable idling for queues in various circumstances.
When workloads of different priorities are competing, if the higher
priority queue has idling disabled, lower priority queues may steal
its disk share. For example, in a scenario with an RT process
performing seeky reads vs a BE process performing sequential reads,
on an NCQ enabled hardware, with low_latency unset,
the RT process will dispatch only the few pending requests every full
slice of service for the BE process.
The patch solves this issue by always performing idle on the last
queue at a given priority class > idle. If the same process, or one
that can pre-empt it (so at the same priority or higher), submits a
new request within the idle window, the lower priority queue won't
dispatch, saving the disk bandwidth for higher priority ones.
Note: this doesn't touch the non_rotational + NCQ case (no hardware
to test if this is a benefit in that case).
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:11 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise, we do only if they are the last ones
|
|
|
|
* in their service tree.
|
|
|
|
*/
|
2012-10-03 20:56:58 +00:00
|
|
|
if (st->count == 1 && cfq_cfqq_sync(cfqq) &&
|
|
|
|
!cfq_io_thinktime_big(cfqd, &st->ttime, false))
|
2010-11-08 14:01:02 +00:00
|
|
|
return true;
|
2012-10-03 20:56:58 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "Not idling. st->count:%d", st->count);
|
2010-11-08 14:01:02 +00:00
|
|
|
return false;
|
cfq-iosched: enable idling for last queue on priority class
cfq can disable idling for queues in various circumstances.
When workloads of different priorities are competing, if the higher
priority queue has idling disabled, lower priority queues may steal
its disk share. For example, in a scenario with an RT process
performing seeky reads vs a BE process performing sequential reads,
on an NCQ enabled hardware, with low_latency unset,
the RT process will dispatch only the few pending requests every full
slice of service for the BE process.
The patch solves this issue by always performing idle on the last
queue at a given priority class > idle. If the same process, or one
that can pre-empt it (so at the same priority or higher), submits a
new request within the idle window, the lower priority queue won't
dispatch, saving the disk bandwidth for higher priority ones.
Note: this doesn't touch the non_rotational + NCQ case (no hardware
to test if this is a benefit in that case).
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:11 +00:00
|
|
|
}
|
|
|
|
|
2007-04-25 10:44:27 +00:00
|
|
|
static void cfq_arm_slice_timer(struct cfq_data *cfqd)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2007-01-19 00:59:30 +00:00
|
|
|
struct cfq_queue *cfqq = cfqd->active_queue;
|
2016-01-12 15:24:15 +00:00
|
|
|
struct cfq_rb_root *st = cfqq->service_tree;
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 sl, group_idle = 0;
|
|
|
|
u64 now = ktime_get_ns();
|
2006-02-28 08:35:11 +00:00
|
|
|
|
2008-09-24 11:03:33 +00:00
|
|
|
/*
|
2008-09-25 09:37:50 +00:00
|
|
|
* SSD device without seek penalty, disable idling. But only do so
|
|
|
|
* for devices that support queuing, otherwise we still have a problem
|
|
|
|
* with sync vs async workloads.
|
2008-09-24 11:03:33 +00:00
|
|
|
*/
|
2008-09-25 09:37:50 +00:00
|
|
|
if (blk_queue_nonrot(cfqd->queue) && cfqd->hw_tag)
|
2008-09-24 11:03:33 +00:00
|
|
|
return;
|
|
|
|
|
2006-06-21 07:36:18 +00:00
|
|
|
WARN_ON(!RB_EMPTY_ROOT(&cfqq->sort_list));
|
2007-04-25 10:44:27 +00:00
|
|
|
WARN_ON(cfq_cfqq_slice_new(cfqq));
|
2005-06-27 08:55:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* idle is disabled, either manually or by past process history
|
|
|
|
*/
|
2010-08-23 10:24:26 +00:00
|
|
|
if (!cfq_should_idle(cfqd, cfqq)) {
|
|
|
|
/* no queue idling. Check for group idling */
|
|
|
|
if (cfqd->cfq_group_idle)
|
|
|
|
group_idle = cfqd->cfq_group_idle;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2007-04-25 10:44:27 +00:00
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
/*
|
2009-11-26 09:02:58 +00:00
|
|
|
* still active requests from this queue, don't idle
|
2008-05-30 10:23:07 +00:00
|
|
|
*/
|
2009-11-26 09:02:58 +00:00
|
|
|
if (cfqq->dispatched)
|
2008-05-30 10:23:07 +00:00
|
|
|
return;
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* task has exited, don't wait
|
|
|
|
*/
|
2006-03-28 11:03:44 +00:00
|
|
|
cic = cfqd->active_cic;
|
2012-03-05 21:15:26 +00:00
|
|
|
if (!cic || !atomic_read(&cic->icq.ioc->active_ref))
|
2007-04-25 10:44:27 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-08 06:43:32 +00:00
|
|
|
/*
|
|
|
|
* If our average think time is larger than the remaining time
|
|
|
|
* slice, then don't idle. This avoids overrunning the allotted
|
|
|
|
* time slice.
|
|
|
|
*/
|
2011-07-12 12:24:35 +00:00
|
|
|
if (sample_valid(cic->ttime.ttime_samples) &&
|
2016-06-08 14:55:34 +00:00
|
|
|
(cfqq->slice_end - now < cic->ttime.ttime_mean)) {
|
|
|
|
cfq_log_cfqq(cfqd, cfqq, "Not idling. think_time:%llu",
|
2011-07-12 12:24:35 +00:00
|
|
|
cic->ttime.ttime_mean);
|
2009-10-08 06:43:32 +00:00
|
|
|
return;
|
2010-03-25 14:45:03 +00:00
|
|
|
}
|
2009-10-08 06:43:32 +00:00
|
|
|
|
2016-01-12 15:24:15 +00:00
|
|
|
/*
|
|
|
|
* There are other queues in the group or this is the only group and
|
|
|
|
* it has too big thinktime, don't do group idle.
|
|
|
|
*/
|
|
|
|
if (group_idle &&
|
|
|
|
(cfqq->cfqg->nr_cfqq > 1 ||
|
|
|
|
cfq_io_thinktime_big(cfqd, &st->ttime, true)))
|
2010-08-23 10:24:26 +00:00
|
|
|
return;
|
|
|
|
|
2005-06-27 08:56:24 +00:00
|
|
|
cfq_mark_cfqq_wait_request(cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2010-08-23 10:24:26 +00:00
|
|
|
if (group_idle)
|
|
|
|
sl = cfqd->cfq_group_idle;
|
|
|
|
else
|
|
|
|
sl = cfqd->cfq_slice_idle;
|
2006-03-28 11:03:44 +00:00
|
|
|
|
2016-06-08 13:11:39 +00:00
|
|
|
hrtimer_start(&cfqd->idle_slice_timer, ns_to_ktime(sl),
|
|
|
|
HRTIMER_MODE_REL);
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_set_start_idle_time(cfqq->cfqg);
|
2016-06-08 14:55:34 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "arm_idle: %llu group_idle: %d", sl,
|
2010-08-23 10:24:26 +00:00
|
|
|
group_idle ? 1 : 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
|
|
|
* Move request from internal lists to the request queue dispatch list.
|
|
|
|
*/
|
2007-07-24 07:28:11 +00:00
|
|
|
static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-04-23 06:33:33 +00:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "dispatch_insert");
|
|
|
|
|
2009-09-11 15:08:59 +00:00
|
|
|
cfqq->next_rq = cfq_find_next_rq(cfqd, cfqq, rq);
|
2006-07-13 10:37:56 +00:00
|
|
|
cfq_remove_request(rq);
|
2007-04-25 10:44:27 +00:00
|
|
|
cfqq->dispatched++;
|
2010-08-23 10:24:26 +00:00
|
|
|
(RQ_CFQG(rq))->dispatched++;
|
2006-07-13 10:37:56 +00:00
|
|
|
elv_dispatch_sort(q, rq);
|
2007-04-23 06:33:33 +00:00
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]++;
|
2010-08-23 10:25:03 +00:00
|
|
|
cfqq->nr_sectors += blk_rq_sectors(rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return expired entry, or NULL to just start from scratch in rbtree
|
|
|
|
*/
|
2008-01-28 12:19:43 +00:00
|
|
|
static struct request *cfq_check_fifo(struct cfq_queue *cfqq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-10-05 09:03:39 +00:00
|
|
|
struct request *rq = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:56:24 +00:00
|
|
|
if (cfq_cfqq_fifo_expire(cfqq))
|
2005-04-16 22:20:36 +00:00
|
|
|
return NULL;
|
2007-01-19 01:01:16 +00:00
|
|
|
|
|
|
|
cfq_mark_cfqq_fifo_expire(cfqq);
|
|
|
|
|
2006-07-22 14:48:31 +00:00
|
|
|
if (list_empty(&cfqq->fifo))
|
|
|
|
return NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-22 14:48:31 +00:00
|
|
|
rq = rq_entry_fifo(cfqq->fifo.next);
|
2016-06-08 14:55:34 +00:00
|
|
|
if (ktime_get_ns() < rq->fifo_time)
|
2008-05-30 10:23:07 +00:00
|
|
|
rq = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-25 10:44:27 +00:00
|
|
|
return rq;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
static inline int
|
|
|
|
cfq_prio_to_maxrq(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
const int base_rq = cfqd->cfq_slice_async_rq;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-05-24 08:23:21 +00:00
|
|
|
return 2 * base_rq * (IOPRIO_BE_NR - cfqq->ioprio);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-10-23 21:14:50 +00:00
|
|
|
/*
|
|
|
|
* Must be called with the queue_lock held.
|
|
|
|
*/
|
|
|
|
static int cfqq_process_refs(struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
int process_refs, io_refs;
|
|
|
|
|
|
|
|
io_refs = cfqq->allocated[READ] + cfqq->allocated[WRITE];
|
2011-01-07 07:46:59 +00:00
|
|
|
process_refs = cfqq->ref - io_refs;
|
2009-10-23 21:14:50 +00:00
|
|
|
BUG_ON(process_refs < 0);
|
|
|
|
return process_refs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cfq_setup_merge(struct cfq_queue *cfqq, struct cfq_queue *new_cfqq)
|
|
|
|
{
|
2009-10-23 21:14:52 +00:00
|
|
|
int process_refs, new_process_refs;
|
2009-10-23 21:14:50 +00:00
|
|
|
struct cfq_queue *__cfqq;
|
|
|
|
|
cfq: Don't allow queue merges for queues that have no process references
Hi,
A user reported a kernel bug when running a particular program that did
the following:
created 32 threads
- each thread took a mutex, grabbed a global offset, added a buffer size
to that offset, released the lock
- read from the given offset in the file
- created a new thread to do the same
- exited
The result is that cfq's close cooperator logic would trigger, as the
threads were issuing I/O within the mean seek distance of one another.
This workload managed to routinely trigger a use after free bug when
walking the list of merge candidates for a particular cfqq
(cfqq->new_cfqq). The logic used for merging queues looks like this:
static void cfq_setup_merge(struct cfq_queue *cfqq, struct cfq_queue *new_cfqq)
{
int process_refs, new_process_refs;
struct cfq_queue *__cfqq;
/* Avoid a circular list and skip interim queue merges */
while ((__cfqq = new_cfqq->new_cfqq)) {
if (__cfqq == cfqq)
return;
new_cfqq = __cfqq;
}
process_refs = cfqq_process_refs(cfqq);
/*
* If the process for the cfqq has gone away, there is no
* sense in merging the queues.
*/
if (process_refs == 0)
return;
/*
* Merge in the direction of the lesser amount of work.
*/
new_process_refs = cfqq_process_refs(new_cfqq);
if (new_process_refs >= process_refs) {
cfqq->new_cfqq = new_cfqq;
atomic_add(process_refs, &new_cfqq->ref);
} else {
new_cfqq->new_cfqq = cfqq;
atomic_add(new_process_refs, &cfqq->ref);
}
}
When a merge candidate is found, we add the process references for the
queue with less references to the queue with more. The actual merging
of queues happens when a new request is issued for a given cfqq. In the
case of the test program, it only does a single pread call to read in
1MB, so the actual merge never happens.
Normally, this is fine, as when the queue exits, we simply drop the
references we took on the other cfqqs in the merge chain:
/*
* If this queue was scheduled to merge with another queue, be
* sure to drop the reference taken on that queue (and others in
* the merge chain). See cfq_setup_merge and cfq_merge_cfqqs.
*/
__cfqq = cfqq->new_cfqq;
while (__cfqq) {
if (__cfqq == cfqq) {
WARN(1, "cfqq->new_cfqq loop detected\n");
break;
}
next = __cfqq->new_cfqq;
cfq_put_queue(__cfqq);
__cfqq = next;
}
However, there is a hole in this logic. Consider the following (and
keep in mind that each I/O keeps a reference to the cfqq):
q1->new_cfqq = q2 // q2 now has 2 process references
q3->new_cfqq = q2 // q2 now has 3 process references
// the process associated with q2 exits
// q2 now has 2 process references
// queue 1 exits, drops its reference on q2
// q2 now has 1 process reference
// q3 exits, so has 0 process references, and hence drops its references
// to q2, which leaves q2 also with 0 process references
q4 comes along and wants to merge with q3
q3->new_cfqq still points at q2! We follow that link and end up at an
already freed cfqq.
So, the fix is to not follow a merge chain if the top-most queue does
not have a process reference, otherwise any queue in the chain could be
already freed. I also changed the logic to disallow merging with a
queue that does not have any process references. Previously, we did
this check for one of the merge candidates, but not the other. That
doesn't really make sense.
Without the attached patch, my system would BUG within a couple of
seconds of running the reproducer program. With the patch applied, my
system ran the program for over an hour without issues.
This addresses the following bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=16217
Thanks a ton to Phil Carns for providing the bug report and an excellent
reproducer.
[ Note for stable: this applies to 2.6.32/33/34 ].
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Reported-by: Phil Carns <carns@mcs.anl.gov>
Cc: stable@kernel.org
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2010-06-17 14:19:11 +00:00
|
|
|
/*
|
|
|
|
* If there are no process references on the new_cfqq, then it is
|
|
|
|
* unsafe to follow the ->new_cfqq chain as other cfqq's in the
|
|
|
|
* chain may have dropped their last reference (not just their
|
|
|
|
* last process reference).
|
|
|
|
*/
|
|
|
|
if (!cfqq_process_refs(new_cfqq))
|
|
|
|
return;
|
|
|
|
|
2009-10-23 21:14:50 +00:00
|
|
|
/* Avoid a circular list and skip interim queue merges */
|
|
|
|
while ((__cfqq = new_cfqq->new_cfqq)) {
|
|
|
|
if (__cfqq == cfqq)
|
|
|
|
return;
|
|
|
|
new_cfqq = __cfqq;
|
|
|
|
}
|
|
|
|
|
|
|
|
process_refs = cfqq_process_refs(cfqq);
|
cfq: Don't allow queue merges for queues that have no process references
Hi,
A user reported a kernel bug when running a particular program that did
the following:
created 32 threads
- each thread took a mutex, grabbed a global offset, added a buffer size
to that offset, released the lock
- read from the given offset in the file
- created a new thread to do the same
- exited
The result is that cfq's close cooperator logic would trigger, as the
threads were issuing I/O within the mean seek distance of one another.
This workload managed to routinely trigger a use after free bug when
walking the list of merge candidates for a particular cfqq
(cfqq->new_cfqq). The logic used for merging queues looks like this:
static void cfq_setup_merge(struct cfq_queue *cfqq, struct cfq_queue *new_cfqq)
{
int process_refs, new_process_refs;
struct cfq_queue *__cfqq;
/* Avoid a circular list and skip interim queue merges */
while ((__cfqq = new_cfqq->new_cfqq)) {
if (__cfqq == cfqq)
return;
new_cfqq = __cfqq;
}
process_refs = cfqq_process_refs(cfqq);
/*
* If the process for the cfqq has gone away, there is no
* sense in merging the queues.
*/
if (process_refs == 0)
return;
/*
* Merge in the direction of the lesser amount of work.
*/
new_process_refs = cfqq_process_refs(new_cfqq);
if (new_process_refs >= process_refs) {
cfqq->new_cfqq = new_cfqq;
atomic_add(process_refs, &new_cfqq->ref);
} else {
new_cfqq->new_cfqq = cfqq;
atomic_add(new_process_refs, &cfqq->ref);
}
}
When a merge candidate is found, we add the process references for the
queue with less references to the queue with more. The actual merging
of queues happens when a new request is issued for a given cfqq. In the
case of the test program, it only does a single pread call to read in
1MB, so the actual merge never happens.
Normally, this is fine, as when the queue exits, we simply drop the
references we took on the other cfqqs in the merge chain:
/*
* If this queue was scheduled to merge with another queue, be
* sure to drop the reference taken on that queue (and others in
* the merge chain). See cfq_setup_merge and cfq_merge_cfqqs.
*/
__cfqq = cfqq->new_cfqq;
while (__cfqq) {
if (__cfqq == cfqq) {
WARN(1, "cfqq->new_cfqq loop detected\n");
break;
}
next = __cfqq->new_cfqq;
cfq_put_queue(__cfqq);
__cfqq = next;
}
However, there is a hole in this logic. Consider the following (and
keep in mind that each I/O keeps a reference to the cfqq):
q1->new_cfqq = q2 // q2 now has 2 process references
q3->new_cfqq = q2 // q2 now has 3 process references
// the process associated with q2 exits
// q2 now has 2 process references
// queue 1 exits, drops its reference on q2
// q2 now has 1 process reference
// q3 exits, so has 0 process references, and hence drops its references
// to q2, which leaves q2 also with 0 process references
q4 comes along and wants to merge with q3
q3->new_cfqq still points at q2! We follow that link and end up at an
already freed cfqq.
So, the fix is to not follow a merge chain if the top-most queue does
not have a process reference, otherwise any queue in the chain could be
already freed. I also changed the logic to disallow merging with a
queue that does not have any process references. Previously, we did
this check for one of the merge candidates, but not the other. That
doesn't really make sense.
Without the attached patch, my system would BUG within a couple of
seconds of running the reproducer program. With the patch applied, my
system ran the program for over an hour without issues.
This addresses the following bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=16217
Thanks a ton to Phil Carns for providing the bug report and an excellent
reproducer.
[ Note for stable: this applies to 2.6.32/33/34 ].
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Reported-by: Phil Carns <carns@mcs.anl.gov>
Cc: stable@kernel.org
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2010-06-17 14:19:11 +00:00
|
|
|
new_process_refs = cfqq_process_refs(new_cfqq);
|
2009-10-23 21:14:50 +00:00
|
|
|
/*
|
|
|
|
* If the process for the cfqq has gone away, there is no
|
|
|
|
* sense in merging the queues.
|
|
|
|
*/
|
cfq: Don't allow queue merges for queues that have no process references
Hi,
A user reported a kernel bug when running a particular program that did
the following:
created 32 threads
- each thread took a mutex, grabbed a global offset, added a buffer size
to that offset, released the lock
- read from the given offset in the file
- created a new thread to do the same
- exited
The result is that cfq's close cooperator logic would trigger, as the
threads were issuing I/O within the mean seek distance of one another.
This workload managed to routinely trigger a use after free bug when
walking the list of merge candidates for a particular cfqq
(cfqq->new_cfqq). The logic used for merging queues looks like this:
static void cfq_setup_merge(struct cfq_queue *cfqq, struct cfq_queue *new_cfqq)
{
int process_refs, new_process_refs;
struct cfq_queue *__cfqq;
/* Avoid a circular list and skip interim queue merges */
while ((__cfqq = new_cfqq->new_cfqq)) {
if (__cfqq == cfqq)
return;
new_cfqq = __cfqq;
}
process_refs = cfqq_process_refs(cfqq);
/*
* If the process for the cfqq has gone away, there is no
* sense in merging the queues.
*/
if (process_refs == 0)
return;
/*
* Merge in the direction of the lesser amount of work.
*/
new_process_refs = cfqq_process_refs(new_cfqq);
if (new_process_refs >= process_refs) {
cfqq->new_cfqq = new_cfqq;
atomic_add(process_refs, &new_cfqq->ref);
} else {
new_cfqq->new_cfqq = cfqq;
atomic_add(new_process_refs, &cfqq->ref);
}
}
When a merge candidate is found, we add the process references for the
queue with less references to the queue with more. The actual merging
of queues happens when a new request is issued for a given cfqq. In the
case of the test program, it only does a single pread call to read in
1MB, so the actual merge never happens.
Normally, this is fine, as when the queue exits, we simply drop the
references we took on the other cfqqs in the merge chain:
/*
* If this queue was scheduled to merge with another queue, be
* sure to drop the reference taken on that queue (and others in
* the merge chain). See cfq_setup_merge and cfq_merge_cfqqs.
*/
__cfqq = cfqq->new_cfqq;
while (__cfqq) {
if (__cfqq == cfqq) {
WARN(1, "cfqq->new_cfqq loop detected\n");
break;
}
next = __cfqq->new_cfqq;
cfq_put_queue(__cfqq);
__cfqq = next;
}
However, there is a hole in this logic. Consider the following (and
keep in mind that each I/O keeps a reference to the cfqq):
q1->new_cfqq = q2 // q2 now has 2 process references
q3->new_cfqq = q2 // q2 now has 3 process references
// the process associated with q2 exits
// q2 now has 2 process references
// queue 1 exits, drops its reference on q2
// q2 now has 1 process reference
// q3 exits, so has 0 process references, and hence drops its references
// to q2, which leaves q2 also with 0 process references
q4 comes along and wants to merge with q3
q3->new_cfqq still points at q2! We follow that link and end up at an
already freed cfqq.
So, the fix is to not follow a merge chain if the top-most queue does
not have a process reference, otherwise any queue in the chain could be
already freed. I also changed the logic to disallow merging with a
queue that does not have any process references. Previously, we did
this check for one of the merge candidates, but not the other. That
doesn't really make sense.
Without the attached patch, my system would BUG within a couple of
seconds of running the reproducer program. With the patch applied, my
system ran the program for over an hour without issues.
This addresses the following bugzilla:
https://bugzilla.kernel.org/show_bug.cgi?id=16217
Thanks a ton to Phil Carns for providing the bug report and an excellent
reproducer.
[ Note for stable: this applies to 2.6.32/33/34 ].
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Reported-by: Phil Carns <carns@mcs.anl.gov>
Cc: stable@kernel.org
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2010-06-17 14:19:11 +00:00
|
|
|
if (process_refs == 0 || new_process_refs == 0)
|
2009-10-23 21:14:50 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-23 21:14:52 +00:00
|
|
|
/*
|
|
|
|
* Merge in the direction of the lesser amount of work.
|
|
|
|
*/
|
|
|
|
if (new_process_refs >= process_refs) {
|
|
|
|
cfqq->new_cfqq = new_cfqq;
|
2011-01-07 07:46:59 +00:00
|
|
|
new_cfqq->ref += process_refs;
|
2009-10-23 21:14:52 +00:00
|
|
|
} else {
|
|
|
|
new_cfqq->new_cfqq = cfqq;
|
2011-01-07 07:46:59 +00:00
|
|
|
cfqq->ref += new_process_refs;
|
2009-10-23 21:14:52 +00:00
|
|
|
}
|
2009-10-23 21:14:50 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 20:56:59 +00:00
|
|
|
static enum wl_type_t cfq_choose_wl_type(struct cfq_data *cfqd,
|
2012-10-03 20:56:56 +00:00
|
|
|
struct cfq_group *cfqg, enum wl_class_t wl_class)
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
{
|
|
|
|
struct cfq_queue *queue;
|
|
|
|
int i;
|
|
|
|
bool key_valid = false;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 lowest_key = 0;
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
enum wl_type_t cur_best = SYNC_NOIDLE_WORKLOAD;
|
|
|
|
|
2009-12-16 22:52:59 +00:00
|
|
|
for (i = 0; i <= SYNC_WORKLOAD; ++i) {
|
|
|
|
/* select the one with lowest rb_key */
|
2012-10-03 20:56:58 +00:00
|
|
|
queue = cfq_rb_first(st_for(cfqg, wl_class, i));
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
if (queue &&
|
2016-06-08 14:55:34 +00:00
|
|
|
(!key_valid || queue->rb_key < lowest_key)) {
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
lowest_key = queue->rb_key;
|
|
|
|
cur_best = i;
|
|
|
|
key_valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cur_best;
|
|
|
|
}
|
|
|
|
|
2012-10-03 20:56:59 +00:00
|
|
|
static void
|
|
|
|
choose_wl_class_and_type(struct cfq_data *cfqd, struct cfq_group *cfqg)
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 slice;
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
unsigned count;
|
2009-12-03 17:59:38 +00:00
|
|
|
struct cfq_rb_root *st;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 group_slice;
|
2012-10-03 20:56:57 +00:00
|
|
|
enum wl_class_t original_class = cfqd->serving_wl_class;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2009-12-03 17:59:41 +00:00
|
|
|
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
/* Choose next priority. RT > BE > IDLE */
|
2009-12-03 17:59:44 +00:00
|
|
|
if (cfq_group_busy_queues_wl(RT_WORKLOAD, cfqd, cfqg))
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqd->serving_wl_class = RT_WORKLOAD;
|
2009-12-03 17:59:44 +00:00
|
|
|
else if (cfq_group_busy_queues_wl(BE_WORKLOAD, cfqd, cfqg))
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqd->serving_wl_class = BE_WORKLOAD;
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
else {
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqd->serving_wl_class = IDLE_WORKLOAD;
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqd->workload_expires = now + jiffies_to_nsecs(1);
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-03 20:56:57 +00:00
|
|
|
if (original_class != cfqd->serving_wl_class)
|
2010-12-13 13:32:22 +00:00
|
|
|
goto new_workload;
|
|
|
|
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
/*
|
|
|
|
* For RT and BE, we have to choose also the type
|
|
|
|
* (SYNC, SYNC_NOIDLE, ASYNC), and to compute a workload
|
|
|
|
* expiration time
|
|
|
|
*/
|
2012-10-03 20:56:58 +00:00
|
|
|
st = st_for(cfqg, cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2009-12-03 17:59:38 +00:00
|
|
|
count = st->count;
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
|
|
|
|
/*
|
2009-12-16 22:52:59 +00:00
|
|
|
* check workload expiration, and that we still have other queues ready
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
if (count && !(now > cfqd->workload_expires))
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-13 13:32:22 +00:00
|
|
|
new_workload:
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
/* otherwise select new workload type */
|
2012-10-03 20:56:59 +00:00
|
|
|
cfqd->serving_wl_type = cfq_choose_wl_type(cfqd, cfqg,
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqd->serving_wl_class);
|
2012-10-03 20:56:58 +00:00
|
|
|
st = st_for(cfqg, cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2009-12-03 17:59:38 +00:00
|
|
|
count = st->count;
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the workload slice is computed as a fraction of target latency
|
|
|
|
* proportional to the number of queues in that workload, over
|
|
|
|
* all the queues in the same priority class
|
|
|
|
*/
|
2009-12-03 17:59:44 +00:00
|
|
|
group_slice = cfq_group_slice(cfqd, cfqg);
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
slice = div_u64(group_slice * count,
|
2012-10-03 20:56:57 +00:00
|
|
|
max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_wl_class],
|
|
|
|
cfq_group_busy_queues_wl(cfqd->serving_wl_class, cfqd,
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqg)));
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
|
2012-10-03 20:56:57 +00:00
|
|
|
if (cfqd->serving_wl_type == ASYNC_WORKLOAD) {
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 tmp;
|
2009-12-03 17:59:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Async queues are currently system wide. Just taking
|
|
|
|
* proportion of queues with-in same group will lead to higher
|
|
|
|
* async ratio system wide as generally root group is going
|
|
|
|
* to have higher weight. A more accurate thing would be to
|
|
|
|
* calculate system wide asnc/sync ratio.
|
|
|
|
*/
|
2012-04-01 21:33:39 +00:00
|
|
|
tmp = cfqd->cfq_target_latency *
|
|
|
|
cfqg_busy_async_queues(cfqd, cfqg);
|
2016-06-08 14:55:34 +00:00
|
|
|
tmp = div_u64(tmp, cfqd->busy_queues);
|
|
|
|
slice = min_t(u64, slice, tmp);
|
2009-12-03 17:59:54 +00:00
|
|
|
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
/* async workload slice is scaled down according to
|
|
|
|
* the sync/async slice ratio. */
|
2016-06-08 14:55:34 +00:00
|
|
|
slice = div64_u64(slice*cfqd->cfq_slice[0], cfqd->cfq_slice[1]);
|
2009-12-03 17:59:54 +00:00
|
|
|
} else
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
/* sync workload slice is at least 2 * cfq_slice_idle */
|
|
|
|
slice = max(slice, 2 * cfqd->cfq_slice_idle);
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
slice = max_t(u64, slice, CFQ_MIN_TT);
|
|
|
|
cfq_log(cfqd, "workload slice:%llu", slice);
|
|
|
|
cfqd->workload_expires = now + slice;
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd)
|
|
|
|
{
|
|
|
|
struct cfq_rb_root *st = &cfqd->grp_service_tree;
|
2009-12-03 17:59:43 +00:00
|
|
|
struct cfq_group *cfqg;
|
2009-12-03 17:59:41 +00:00
|
|
|
|
|
|
|
if (RB_EMPTY_ROOT(&st->rb))
|
|
|
|
return NULL;
|
2009-12-03 17:59:43 +00:00
|
|
|
cfqg = cfq_rb_first_group(st);
|
|
|
|
update_min_vdisktime(st);
|
|
|
|
return cfqg;
|
2009-12-03 17:59:41 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:38 +00:00
|
|
|
static void cfq_choose_cfqg(struct cfq_data *cfqd)
|
|
|
|
{
|
2009-12-03 17:59:41 +00:00
|
|
|
struct cfq_group *cfqg = cfq_get_next_cfqg(cfqd);
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2009-12-03 17:59:41 +00:00
|
|
|
|
|
|
|
cfqd->serving_group = cfqg;
|
2009-12-03 17:59:45 +00:00
|
|
|
|
|
|
|
/* Restore the workload type data */
|
2012-10-03 20:56:57 +00:00
|
|
|
if (cfqg->saved_wl_slice) {
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqd->workload_expires = now + cfqg->saved_wl_slice;
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqd->serving_wl_type = cfqg->saved_wl_type;
|
|
|
|
cfqd->serving_wl_class = cfqg->saved_wl_class;
|
2009-12-15 09:08:45 +00:00
|
|
|
} else
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqd->workload_expires = now - 1;
|
2009-12-15 09:08:45 +00:00
|
|
|
|
2012-10-03 20:56:59 +00:00
|
|
|
choose_wl_class_and_type(cfqd, cfqg);
|
2009-12-03 17:59:38 +00:00
|
|
|
}
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
2007-04-26 10:54:48 +00:00
|
|
|
* Select a queue for service. If we have a current active queue,
|
|
|
|
* check whether to continue servicing it, or retrieve and set a new one.
|
2005-06-27 08:55:12 +00:00
|
|
|
*/
|
2005-11-10 07:49:19 +00:00
|
|
|
static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-04-15 10:15:11 +00:00
|
|
|
struct cfq_queue *cfqq, *new_cfqq = NULL;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
cfqq = cfqd->active_queue;
|
|
|
|
if (!cfqq)
|
|
|
|
goto new_queue;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-12-03 17:59:40 +00:00
|
|
|
if (!cfqd->rq_queued)
|
|
|
|
return NULL;
|
2009-12-08 22:52:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We were waiting for group to get backlogged. Expire the queue
|
|
|
|
*/
|
|
|
|
if (cfq_cfqq_wait_busy(cfqq) && !RB_EMPTY_ROOT(&cfqq->sort_list))
|
|
|
|
goto expire;
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
2007-04-25 10:44:27 +00:00
|
|
|
* The active queue has run out of time, expire it and select new.
|
2005-06-27 08:55:12 +00:00
|
|
|
*/
|
2009-12-08 22:52:58 +00:00
|
|
|
if (cfq_slice_used(cfqq) && !cfq_cfqq_must_dispatch(cfqq)) {
|
|
|
|
/*
|
|
|
|
* If slice had not expired at the completion of last request
|
|
|
|
* we might not have turned on wait_busy flag. Don't expire
|
|
|
|
* the queue yet. Allow the group to get backlogged.
|
|
|
|
*
|
|
|
|
* The very fact that we have used the slice, that means we
|
|
|
|
* have been idling all along on this queue and it should be
|
|
|
|
* ok to wait for this request to complete.
|
|
|
|
*/
|
2009-12-10 18:25:41 +00:00
|
|
|
if (cfqq->cfqg->nr_cfqq == 1 && RB_EMPTY_ROOT(&cfqq->sort_list)
|
|
|
|
&& cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) {
|
|
|
|
cfqq = NULL;
|
2009-12-08 22:52:58 +00:00
|
|
|
goto keep_queue;
|
2009-12-10 18:25:41 +00:00
|
|
|
} else
|
2010-08-23 10:24:26 +00:00
|
|
|
goto check_group_idle;
|
2009-12-08 22:52:58 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
2007-04-25 10:44:27 +00:00
|
|
|
* The active queue has requests and isn't expired, allow it to
|
|
|
|
* dispatch.
|
2005-06-27 08:55:12 +00:00
|
|
|
*/
|
2006-06-21 07:36:18 +00:00
|
|
|
if (!RB_EMPTY_ROOT(&cfqq->sort_list))
|
2005-06-27 08:55:12 +00:00
|
|
|
goto keep_queue;
|
2007-04-25 10:44:27 +00:00
|
|
|
|
2009-04-15 10:15:11 +00:00
|
|
|
/*
|
|
|
|
* If another queue has a request waiting within our mean seek
|
|
|
|
* distance, let it run. The expire code will check for close
|
|
|
|
* cooperators and put the close queue at the front of the service
|
2009-10-23 21:14:50 +00:00
|
|
|
* tree. If possible, merge the expiring queue with the new cfqq.
|
2009-04-15 10:15:11 +00:00
|
|
|
*/
|
2009-10-23 21:14:51 +00:00
|
|
|
new_cfqq = cfq_close_cooperator(cfqd, cfqq);
|
2009-10-23 21:14:50 +00:00
|
|
|
if (new_cfqq) {
|
|
|
|
if (!cfqq->new_cfqq)
|
|
|
|
cfq_setup_merge(cfqq, new_cfqq);
|
2009-04-15 10:15:11 +00:00
|
|
|
goto expire;
|
2009-10-23 21:14:50 +00:00
|
|
|
}
|
2009-04-15 10:15:11 +00:00
|
|
|
|
2007-04-25 10:44:27 +00:00
|
|
|
/*
|
|
|
|
* No requests pending. If the active queue still has requests in
|
|
|
|
* flight or is idling for a new request, allow either of these
|
|
|
|
* conditions to happen (or time out) before selecting a new queue.
|
|
|
|
*/
|
2016-06-08 13:11:39 +00:00
|
|
|
if (hrtimer_active(&cfqd->idle_slice_timer)) {
|
2010-08-23 10:24:26 +00:00
|
|
|
cfqq = NULL;
|
|
|
|
goto keep_queue;
|
|
|
|
}
|
|
|
|
|
cfq-iosched: don't idle if a deep seek queue is slow
If a deep seek queue slowly deliver requests but disk is much faster, idle
for the queue just wastes disk throughput. If the queue delevers all requests
before half its slice is used, the patch disable idle for it.
In my test, application delivers 32 requests one time, the disk can accept
128 requests at maxium and disk is fast. without the patch, the throughput
is just around 30m/s, while with it, the speed is about 80m/s. The disk is
a SSD, but is detected as a rotational disk. I can configure it as SSD, but
I thought the deep seek queue logic should be fixed too, for example,
considering a fast raid.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2010-11-08 14:01:04 +00:00
|
|
|
/*
|
|
|
|
* This is a deep seek queue, but the device is much faster than
|
|
|
|
* the queue can deliver, don't idle
|
|
|
|
**/
|
|
|
|
if (CFQQ_SEEKY(cfqq) && cfq_cfqq_idle_window(cfqq) &&
|
|
|
|
(cfq_cfqq_slice_new(cfqq) ||
|
2016-06-08 14:55:34 +00:00
|
|
|
(cfqq->slice_end - now > now - cfqq->slice_start))) {
|
cfq-iosched: don't idle if a deep seek queue is slow
If a deep seek queue slowly deliver requests but disk is much faster, idle
for the queue just wastes disk throughput. If the queue delevers all requests
before half its slice is used, the patch disable idle for it.
In my test, application delivers 32 requests one time, the disk can accept
128 requests at maxium and disk is fast. without the patch, the throughput
is just around 30m/s, while with it, the speed is about 80m/s. The disk is
a SSD, but is detected as a rotational disk. I can configure it as SSD, but
I thought the deep seek queue logic should be fixed too, for example,
considering a fast raid.
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
2010-11-08 14:01:04 +00:00
|
|
|
cfq_clear_cfqq_deep(cfqq);
|
|
|
|
cfq_clear_cfqq_idle_window(cfqq);
|
|
|
|
}
|
|
|
|
|
2010-08-23 10:24:26 +00:00
|
|
|
if (cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) {
|
|
|
|
cfqq = NULL;
|
|
|
|
goto keep_queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If group idle is enabled and there are requests dispatched from
|
|
|
|
* this group, wait for requests to complete.
|
|
|
|
*/
|
|
|
|
check_group_idle:
|
2011-07-12 12:24:56 +00:00
|
|
|
if (cfqd->cfq_group_idle && cfqq->cfqg->nr_cfqq == 1 &&
|
|
|
|
cfqq->cfqg->dispatched &&
|
|
|
|
!cfq_io_thinktime_big(cfqd, &cfqq->cfqg->ttime, true)) {
|
2006-06-16 09:23:00 +00:00
|
|
|
cfqq = NULL;
|
|
|
|
goto keep_queue;
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
2005-06-27 08:56:24 +00:00
|
|
|
expire:
|
2010-04-26 17:25:11 +00:00
|
|
|
cfq_slice_expired(cfqd, 0);
|
2005-06-27 08:56:24 +00:00
|
|
|
new_queue:
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
/*
|
|
|
|
* Current queue expired. Check if we have to switch to a new
|
|
|
|
* service tree
|
|
|
|
*/
|
|
|
|
if (!new_cfqq)
|
2009-12-03 17:59:38 +00:00
|
|
|
cfq_choose_cfqg(cfqd);
|
cfq-iosched: fairness for sync no-idle queues
Currently no-idle queues in cfq are not serviced fairly:
even if they can only dispatch a small number of requests at a time,
they have to compete with idling queues to be serviced, experiencing
large latencies.
We should notice, instead, that no-idle queues are the ones that would
benefit most from having low latency, in fact they are any of:
* processes with large think times (e.g. interactive ones like file
managers)
* seeky (e.g. programs faulting in their code at startup)
* or marked as no-idle from upper levels, to improve latencies of those
requests.
This patch improves the fairness and latency for those queues, by:
* separating sync idle, sync no-idle and async queues in separate
service_trees, for each priority
* service all no-idle queues together
* and idling when the last no-idle queue has been serviced, to
anticipate for more no-idle work
* the timeslices allotted for idle and no-idle service_trees are
computed proportionally to the number of processes in each set.
Servicing all no-idle queues together should have a performance boost
for NCQ-capable drives, without compromising fairness.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-10-26 21:45:29 +00:00
|
|
|
|
2009-04-15 10:15:11 +00:00
|
|
|
cfqq = cfq_set_active_queue(cfqd, new_cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
keep_queue:
|
2005-06-27 08:56:24 +00:00
|
|
|
return cfqq;
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 12:19:43 +00:00
|
|
|
static int __cfq_forced_dispatch_cfqq(struct cfq_queue *cfqq)
|
2007-04-20 12:27:50 +00:00
|
|
|
{
|
|
|
|
int dispatched = 0;
|
|
|
|
|
|
|
|
while (cfqq->next_rq) {
|
|
|
|
cfq_dispatch_insert(cfqq->cfqd->queue, cfqq->next_rq);
|
|
|
|
dispatched++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BUG_ON(!list_empty(&cfqq->fifo));
|
2009-12-03 17:59:40 +00:00
|
|
|
|
|
|
|
/* By default cfqq is not expired if it is empty. Do it explicitly */
|
2010-04-26 17:25:11 +00:00
|
|
|
__cfq_slice_expired(cfqq->cfqd, cfqq, 0);
|
2007-04-20 12:27:50 +00:00
|
|
|
return dispatched;
|
|
|
|
}
|
|
|
|
|
2007-04-26 10:54:48 +00:00
|
|
|
/*
|
|
|
|
* Drain our current requests. Used for barriers and when switching
|
|
|
|
* io schedulers on-the-fly.
|
|
|
|
*/
|
2007-04-20 12:27:50 +00:00
|
|
|
static int cfq_forced_dispatch(struct cfq_data *cfqd)
|
2005-11-10 07:49:19 +00:00
|
|
|
{
|
2008-01-28 10:38:15 +00:00
|
|
|
struct cfq_queue *cfqq;
|
2007-04-20 12:27:50 +00:00
|
|
|
int dispatched = 0;
|
2009-12-03 17:59:38 +00:00
|
|
|
|
2010-04-09 07:29:57 +00:00
|
|
|
/* Expire the timeslice of the current active queue first */
|
2010-04-26 17:25:11 +00:00
|
|
|
cfq_slice_expired(cfqd, 0);
|
2010-04-09 07:29:57 +00:00
|
|
|
while ((cfqq = cfq_get_next_queue_forced(cfqd)) != NULL) {
|
|
|
|
__cfq_set_active_queue(cfqd, cfqq);
|
2009-12-03 17:59:40 +00:00
|
|
|
dispatched += __cfq_forced_dispatch_cfqq(cfqq);
|
2010-04-09 07:29:57 +00:00
|
|
|
}
|
2005-11-10 07:49:19 +00:00
|
|
|
|
|
|
|
BUG_ON(cfqd->busy_queues);
|
|
|
|
|
2009-06-12 13:29:30 +00:00
|
|
|
cfq_log(cfqd, "forced_dispatch=%d", dispatched);
|
2005-11-10 07:49:19 +00:00
|
|
|
return dispatched;
|
|
|
|
}
|
|
|
|
|
2010-03-01 08:20:54 +00:00
|
|
|
static inline bool cfq_slice_used_soon(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
|
|
|
|
2010-03-01 08:20:54 +00:00
|
|
|
/* the queue hasn't finished any request, can't estimate */
|
|
|
|
if (cfq_cfqq_slice_new(cfqq))
|
2010-11-08 14:01:02 +00:00
|
|
|
return true;
|
2016-06-08 14:55:34 +00:00
|
|
|
if (now + cfqd->cfq_slice_idle * cfqq->dispatched > cfqq->slice_end)
|
2010-11-08 14:01:02 +00:00
|
|
|
return true;
|
2010-03-01 08:20:54 +00:00
|
|
|
|
2010-11-08 14:01:02 +00:00
|
|
|
return false;
|
2010-03-01 08:20:54 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 18:49:37 +00:00
|
|
|
static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2009-04-07 06:51:19 +00:00
|
|
|
{
|
|
|
|
unsigned int max_dispatch;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
cfq: fix starvation of asynchronous writes
While debugging timeouts happening in my application workload (ScyllaDB), I have
observed calls to open() taking a long time, ranging everywhere from 2 seconds -
the first ones that are enough to time out my application - to more than 30
seconds.
The problem seems to happen because XFS may block on pending metadata updates
under certain circumnstances, and that's confirmed with the following backtrace
taken by the offcputime tool (iovisor/bcc):
ffffffffb90c57b1 finish_task_switch
ffffffffb97dffb5 schedule
ffffffffb97e310c schedule_timeout
ffffffffb97e1f12 __down
ffffffffb90ea821 down
ffffffffc046a9dc xfs_buf_lock
ffffffffc046abfb _xfs_buf_find
ffffffffc046ae4a xfs_buf_get_map
ffffffffc046babd xfs_buf_read_map
ffffffffc0499931 xfs_trans_read_buf_map
ffffffffc044a561 xfs_da_read_buf
ffffffffc0451390 xfs_dir3_leaf_read.constprop.16
ffffffffc0452b90 xfs_dir2_leaf_lookup_int
ffffffffc0452e0f xfs_dir2_leaf_lookup
ffffffffc044d9d3 xfs_dir_lookup
ffffffffc047d1d9 xfs_lookup
ffffffffc0479e53 xfs_vn_lookup
ffffffffb925347a path_openat
ffffffffb9254a71 do_filp_open
ffffffffb9242a94 do_sys_open
ffffffffb9242b9e sys_open
ffffffffb97e42b2 entry_SYSCALL_64_fastpath
00007fb0698162ed [unknown]
Inspecting my run with blktrace, I can see that the xfsaild kthread exhibit very
high "Dispatch wait" times, on the dozens of seconds range and consistent with
the open() times I have saw in that run.
Still from the blktrace output, we can after searching a bit, identify the
request that wasn't dispatched:
8,0 11 152 81.092472813 804 A WM 141698288 + 8 <- (8,1) 141696240
8,0 11 153 81.092472889 804 Q WM 141698288 + 8 [xfsaild/sda1]
8,0 11 154 81.092473207 804 G WM 141698288 + 8 [xfsaild/sda1]
8,0 11 206 81.092496118 804 I WM 141698288 + 8 ( 22911) [xfsaild/sda1]
<==== 'I' means Inserted (into the IO scheduler) ===================================>
8,0 0 289372 96.718761435 0 D WM 141698288 + 8 (15626265317) [swapper/0]
<==== Only 15s later the CFQ scheduler dispatches the request ======================>
As we can see above, in this particular example CFQ took 15 seconds to dispatch
this request. Going back to the full trace, we can see that the xfsaild queue
had plenty of opportunity to run, and it was selected as the active queue many
times. It would just always be preempted by something else (example):
8,0 1 0 81.117912979 0 m N cfq1618SN / insert_request
8,0 1 0 81.117913419 0 m N cfq1618SN / add_to_rr
8,0 1 0 81.117914044 0 m N cfq1618SN / preempt
8,0 1 0 81.117914398 0 m N cfq767A / slice expired t=1
8,0 1 0 81.117914755 0 m N cfq767A / resid=40
8,0 1 0 81.117915340 0 m N / served: vt=1948520448 min_vt=1948520448
8,0 1 0 81.117915858 0 m N cfq767A / sl_used=1 disp=0 charge=0 iops=1 sect=0
where cfq767 is the xfsaild queue and cfq1618 corresponds to one of the ScyllaDB
IO dispatchers.
The requests preempting the xfsaild queue are synchronous requests. That's a
characteristic of ScyllaDB workloads, as we only ever issue O_DIRECT requests.
While it can be argued that preempting ASYNC requests in favor of SYNC is part
of the CFQ logic, I don't believe that doing so for 15+ seconds is anyone's
goal.
Moreover, unless I am misunderstanding something, that breaks the expectation
set by the "fifo_expire_async" tunable, which in my system is set to the
default.
Looking at the code, it seems to me that the issue is that after we make
an async queue active, there is no guarantee that it will execute any request.
When the queue itself tests if it cfq_may_dispatch() it can bail if it sees SYNC
requests in flight. An incoming request from another queue can also preempt it
in such situation before we have the chance to execute anything (as seen in the
trace above).
This patch sets the must_dispatch flag if we notice that we have requests
that are already fifo_expired. This flag is always cleared after
cfq_dispatch_request() returns from cfq_dispatch_requests(), so it won't pin
the queue for subsequent requests (unless they are themselves expired)
Care is taken during preempt to still allow rt requests to preempt us
regardless.
Testing my workload with this patch applied produces much better results.
From the application side I see no timeouts, and the open() latency histogram
generated by systemtap looks much better, with the worst outlier at 131ms:
Latency histogram of xfs_buf_lock acquisition (microseconds):
value |-------------------------------------------------- count
0 | 11
1 |@@@@ 161
2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1966
4 |@ 54
8 | 36
16 | 7
32 | 0
64 | 0
~
1024 | 0
2048 | 0
4096 | 1
8192 | 1
16384 | 2
32768 | 0
65536 | 0
131072 | 1
262144 | 0
524288 | 0
Signed-off-by: Glauber Costa <glauber@scylladb.com>
CC: Jens Axboe <axboe@kernel.dk>
CC: linux-block@vger.kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Glauber Costa <glauber@scylladb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-09-23 00:59:59 +00:00
|
|
|
if (cfq_cfqq_must_dispatch(cfqq))
|
|
|
|
return true;
|
|
|
|
|
2009-07-03 10:57:48 +00:00
|
|
|
/*
|
|
|
|
* Drain async requests before we start sync IO
|
|
|
|
*/
|
2010-02-28 18:45:05 +00:00
|
|
|
if (cfq_should_idle(cfqd, cfqq) && cfqd->rq_in_flight[BLK_RW_ASYNC])
|
2009-10-06 18:49:37 +00:00
|
|
|
return false;
|
2009-07-03 10:57:48 +00:00
|
|
|
|
2009-04-07 06:51:19 +00:00
|
|
|
/*
|
|
|
|
* If this is an async queue and we have sync IO in flight, let it wait
|
|
|
|
*/
|
2010-02-28 18:45:05 +00:00
|
|
|
if (cfqd->rq_in_flight[BLK_RW_SYNC] && !cfq_cfqq_sync(cfqq))
|
2009-10-06 18:49:37 +00:00
|
|
|
return false;
|
2009-04-07 06:51:19 +00:00
|
|
|
|
2010-03-01 08:20:54 +00:00
|
|
|
max_dispatch = max_t(unsigned int, cfqd->cfq_quantum / 2, 1);
|
2009-04-07 06:51:19 +00:00
|
|
|
if (cfq_class_idle(cfqq))
|
|
|
|
max_dispatch = 1;
|
2005-10-20 14:42:29 +00:00
|
|
|
|
2009-04-07 06:51:19 +00:00
|
|
|
/*
|
|
|
|
* Does this cfqq already have too much IO in flight?
|
|
|
|
*/
|
|
|
|
if (cfqq->dispatched >= max_dispatch) {
|
2011-03-07 08:26:29 +00:00
|
|
|
bool promote_sync = false;
|
2009-04-07 06:51:19 +00:00
|
|
|
/*
|
|
|
|
* idle queue must always only have a single IO in flight
|
|
|
|
*/
|
2007-04-23 06:33:33 +00:00
|
|
|
if (cfq_class_idle(cfqq))
|
2009-10-06 18:49:37 +00:00
|
|
|
return false;
|
2007-04-23 06:33:33 +00:00
|
|
|
|
2011-03-07 08:26:29 +00:00
|
|
|
/*
|
2011-03-23 07:30:34 +00:00
|
|
|
* If there is only one sync queue
|
|
|
|
* we can ignore async queue here and give the sync
|
2011-03-07 08:26:29 +00:00
|
|
|
* queue no dispatch limit. The reason is a sync queue can
|
|
|
|
* preempt async queue, limiting the sync queue doesn't make
|
|
|
|
* sense. This is useful for aiostress test.
|
|
|
|
*/
|
2011-03-23 07:30:34 +00:00
|
|
|
if (cfq_cfqq_sync(cfqq) && cfqd->busy_sync_queues == 1)
|
|
|
|
promote_sync = true;
|
2011-03-07 08:26:29 +00:00
|
|
|
|
2009-04-07 06:51:19 +00:00
|
|
|
/*
|
|
|
|
* We have other queues, don't allow more IO from this one
|
|
|
|
*/
|
2011-03-07 08:26:29 +00:00
|
|
|
if (cfqd->busy_queues > 1 && cfq_slice_used_soon(cfqd, cfqq) &&
|
|
|
|
!promote_sync)
|
2009-10-06 18:49:37 +00:00
|
|
|
return false;
|
2007-01-19 01:11:44 +00:00
|
|
|
|
2009-10-03 13:21:27 +00:00
|
|
|
/*
|
2009-12-03 11:58:05 +00:00
|
|
|
* Sole queue user, no limit
|
2009-10-03 13:21:27 +00:00
|
|
|
*/
|
2011-03-07 08:26:29 +00:00
|
|
|
if (cfqd->busy_queues == 1 || promote_sync)
|
2010-03-01 08:20:54 +00:00
|
|
|
max_dispatch = -1;
|
|
|
|
else
|
|
|
|
/*
|
|
|
|
* Normally we start throttling cfqq when cfq_quantum/2
|
|
|
|
* requests have been dispatched. But we can drive
|
|
|
|
* deeper queue depths at the beginning of slice
|
|
|
|
* subjected to upper limit of cfq_quantum.
|
|
|
|
* */
|
|
|
|
max_dispatch = cfqd->cfq_quantum;
|
2009-10-03 14:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Async queues must wait a bit before being allowed dispatch.
|
|
|
|
* We also ramp up the dispatch depth gradually for async IO,
|
|
|
|
* based on the last sync IO we serviced
|
|
|
|
*/
|
2009-10-03 17:42:18 +00:00
|
|
|
if (!cfq_cfqq_sync(cfqq) && cfqd->cfq_latency) {
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 last_sync = ktime_get_ns() - cfqd->last_delayed_sync;
|
2009-10-03 14:26:03 +00:00
|
|
|
unsigned int depth;
|
2009-10-03 13:21:27 +00:00
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
depth = div64_u64(last_sync, cfqd->cfq_slice[1]);
|
2009-10-04 18:36:19 +00:00
|
|
|
if (!depth && !cfqq->dispatched)
|
|
|
|
depth = 1;
|
2009-10-03 14:26:03 +00:00
|
|
|
if (depth < max_dispatch)
|
|
|
|
max_dispatch = depth;
|
2009-04-07 06:51:19 +00:00
|
|
|
}
|
2007-04-23 06:33:33 +00:00
|
|
|
|
2009-10-06 18:49:37 +00:00
|
|
|
/*
|
|
|
|
* If we're below the current max, allow a dispatch
|
|
|
|
*/
|
|
|
|
return cfqq->dispatched < max_dispatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dispatch a request from cfqq, moving them to the request queue
|
|
|
|
* dispatch list.
|
|
|
|
*/
|
|
|
|
static bool cfq_dispatch_request(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
struct request *rq;
|
|
|
|
|
|
|
|
BUG_ON(RB_EMPTY_ROOT(&cfqq->sort_list));
|
|
|
|
|
cfq: fix starvation of asynchronous writes
While debugging timeouts happening in my application workload (ScyllaDB), I have
observed calls to open() taking a long time, ranging everywhere from 2 seconds -
the first ones that are enough to time out my application - to more than 30
seconds.
The problem seems to happen because XFS may block on pending metadata updates
under certain circumnstances, and that's confirmed with the following backtrace
taken by the offcputime tool (iovisor/bcc):
ffffffffb90c57b1 finish_task_switch
ffffffffb97dffb5 schedule
ffffffffb97e310c schedule_timeout
ffffffffb97e1f12 __down
ffffffffb90ea821 down
ffffffffc046a9dc xfs_buf_lock
ffffffffc046abfb _xfs_buf_find
ffffffffc046ae4a xfs_buf_get_map
ffffffffc046babd xfs_buf_read_map
ffffffffc0499931 xfs_trans_read_buf_map
ffffffffc044a561 xfs_da_read_buf
ffffffffc0451390 xfs_dir3_leaf_read.constprop.16
ffffffffc0452b90 xfs_dir2_leaf_lookup_int
ffffffffc0452e0f xfs_dir2_leaf_lookup
ffffffffc044d9d3 xfs_dir_lookup
ffffffffc047d1d9 xfs_lookup
ffffffffc0479e53 xfs_vn_lookup
ffffffffb925347a path_openat
ffffffffb9254a71 do_filp_open
ffffffffb9242a94 do_sys_open
ffffffffb9242b9e sys_open
ffffffffb97e42b2 entry_SYSCALL_64_fastpath
00007fb0698162ed [unknown]
Inspecting my run with blktrace, I can see that the xfsaild kthread exhibit very
high "Dispatch wait" times, on the dozens of seconds range and consistent with
the open() times I have saw in that run.
Still from the blktrace output, we can after searching a bit, identify the
request that wasn't dispatched:
8,0 11 152 81.092472813 804 A WM 141698288 + 8 <- (8,1) 141696240
8,0 11 153 81.092472889 804 Q WM 141698288 + 8 [xfsaild/sda1]
8,0 11 154 81.092473207 804 G WM 141698288 + 8 [xfsaild/sda1]
8,0 11 206 81.092496118 804 I WM 141698288 + 8 ( 22911) [xfsaild/sda1]
<==== 'I' means Inserted (into the IO scheduler) ===================================>
8,0 0 289372 96.718761435 0 D WM 141698288 + 8 (15626265317) [swapper/0]
<==== Only 15s later the CFQ scheduler dispatches the request ======================>
As we can see above, in this particular example CFQ took 15 seconds to dispatch
this request. Going back to the full trace, we can see that the xfsaild queue
had plenty of opportunity to run, and it was selected as the active queue many
times. It would just always be preempted by something else (example):
8,0 1 0 81.117912979 0 m N cfq1618SN / insert_request
8,0 1 0 81.117913419 0 m N cfq1618SN / add_to_rr
8,0 1 0 81.117914044 0 m N cfq1618SN / preempt
8,0 1 0 81.117914398 0 m N cfq767A / slice expired t=1
8,0 1 0 81.117914755 0 m N cfq767A / resid=40
8,0 1 0 81.117915340 0 m N / served: vt=1948520448 min_vt=1948520448
8,0 1 0 81.117915858 0 m N cfq767A / sl_used=1 disp=0 charge=0 iops=1 sect=0
where cfq767 is the xfsaild queue and cfq1618 corresponds to one of the ScyllaDB
IO dispatchers.
The requests preempting the xfsaild queue are synchronous requests. That's a
characteristic of ScyllaDB workloads, as we only ever issue O_DIRECT requests.
While it can be argued that preempting ASYNC requests in favor of SYNC is part
of the CFQ logic, I don't believe that doing so for 15+ seconds is anyone's
goal.
Moreover, unless I am misunderstanding something, that breaks the expectation
set by the "fifo_expire_async" tunable, which in my system is set to the
default.
Looking at the code, it seems to me that the issue is that after we make
an async queue active, there is no guarantee that it will execute any request.
When the queue itself tests if it cfq_may_dispatch() it can bail if it sees SYNC
requests in flight. An incoming request from another queue can also preempt it
in such situation before we have the chance to execute anything (as seen in the
trace above).
This patch sets the must_dispatch flag if we notice that we have requests
that are already fifo_expired. This flag is always cleared after
cfq_dispatch_request() returns from cfq_dispatch_requests(), so it won't pin
the queue for subsequent requests (unless they are themselves expired)
Care is taken during preempt to still allow rt requests to preempt us
regardless.
Testing my workload with this patch applied produces much better results.
From the application side I see no timeouts, and the open() latency histogram
generated by systemtap looks much better, with the worst outlier at 131ms:
Latency histogram of xfs_buf_lock acquisition (microseconds):
value |-------------------------------------------------- count
0 | 11
1 |@@@@ 161
2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1966
4 |@ 54
8 | 36
16 | 7
32 | 0
64 | 0
~
1024 | 0
2048 | 0
4096 | 1
8192 | 1
16384 | 2
32768 | 0
65536 | 0
131072 | 1
262144 | 0
524288 | 0
Signed-off-by: Glauber Costa <glauber@scylladb.com>
CC: Jens Axboe <axboe@kernel.dk>
CC: linux-block@vger.kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Glauber Costa <glauber@scylladb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-09-23 00:59:59 +00:00
|
|
|
rq = cfq_check_fifo(cfqq);
|
|
|
|
if (rq)
|
|
|
|
cfq_mark_cfqq_must_dispatch(cfqq);
|
|
|
|
|
2009-10-06 18:49:37 +00:00
|
|
|
if (!cfq_may_dispatch(cfqd, cfqq))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* follow expired path, else get first next available
|
|
|
|
*/
|
|
|
|
if (!rq)
|
|
|
|
rq = cfqq->next_rq;
|
cfq: fix starvation of asynchronous writes
While debugging timeouts happening in my application workload (ScyllaDB), I have
observed calls to open() taking a long time, ranging everywhere from 2 seconds -
the first ones that are enough to time out my application - to more than 30
seconds.
The problem seems to happen because XFS may block on pending metadata updates
under certain circumnstances, and that's confirmed with the following backtrace
taken by the offcputime tool (iovisor/bcc):
ffffffffb90c57b1 finish_task_switch
ffffffffb97dffb5 schedule
ffffffffb97e310c schedule_timeout
ffffffffb97e1f12 __down
ffffffffb90ea821 down
ffffffffc046a9dc xfs_buf_lock
ffffffffc046abfb _xfs_buf_find
ffffffffc046ae4a xfs_buf_get_map
ffffffffc046babd xfs_buf_read_map
ffffffffc0499931 xfs_trans_read_buf_map
ffffffffc044a561 xfs_da_read_buf
ffffffffc0451390 xfs_dir3_leaf_read.constprop.16
ffffffffc0452b90 xfs_dir2_leaf_lookup_int
ffffffffc0452e0f xfs_dir2_leaf_lookup
ffffffffc044d9d3 xfs_dir_lookup
ffffffffc047d1d9 xfs_lookup
ffffffffc0479e53 xfs_vn_lookup
ffffffffb925347a path_openat
ffffffffb9254a71 do_filp_open
ffffffffb9242a94 do_sys_open
ffffffffb9242b9e sys_open
ffffffffb97e42b2 entry_SYSCALL_64_fastpath
00007fb0698162ed [unknown]
Inspecting my run with blktrace, I can see that the xfsaild kthread exhibit very
high "Dispatch wait" times, on the dozens of seconds range and consistent with
the open() times I have saw in that run.
Still from the blktrace output, we can after searching a bit, identify the
request that wasn't dispatched:
8,0 11 152 81.092472813 804 A WM 141698288 + 8 <- (8,1) 141696240
8,0 11 153 81.092472889 804 Q WM 141698288 + 8 [xfsaild/sda1]
8,0 11 154 81.092473207 804 G WM 141698288 + 8 [xfsaild/sda1]
8,0 11 206 81.092496118 804 I WM 141698288 + 8 ( 22911) [xfsaild/sda1]
<==== 'I' means Inserted (into the IO scheduler) ===================================>
8,0 0 289372 96.718761435 0 D WM 141698288 + 8 (15626265317) [swapper/0]
<==== Only 15s later the CFQ scheduler dispatches the request ======================>
As we can see above, in this particular example CFQ took 15 seconds to dispatch
this request. Going back to the full trace, we can see that the xfsaild queue
had plenty of opportunity to run, and it was selected as the active queue many
times. It would just always be preempted by something else (example):
8,0 1 0 81.117912979 0 m N cfq1618SN / insert_request
8,0 1 0 81.117913419 0 m N cfq1618SN / add_to_rr
8,0 1 0 81.117914044 0 m N cfq1618SN / preempt
8,0 1 0 81.117914398 0 m N cfq767A / slice expired t=1
8,0 1 0 81.117914755 0 m N cfq767A / resid=40
8,0 1 0 81.117915340 0 m N / served: vt=1948520448 min_vt=1948520448
8,0 1 0 81.117915858 0 m N cfq767A / sl_used=1 disp=0 charge=0 iops=1 sect=0
where cfq767 is the xfsaild queue and cfq1618 corresponds to one of the ScyllaDB
IO dispatchers.
The requests preempting the xfsaild queue are synchronous requests. That's a
characteristic of ScyllaDB workloads, as we only ever issue O_DIRECT requests.
While it can be argued that preempting ASYNC requests in favor of SYNC is part
of the CFQ logic, I don't believe that doing so for 15+ seconds is anyone's
goal.
Moreover, unless I am misunderstanding something, that breaks the expectation
set by the "fifo_expire_async" tunable, which in my system is set to the
default.
Looking at the code, it seems to me that the issue is that after we make
an async queue active, there is no guarantee that it will execute any request.
When the queue itself tests if it cfq_may_dispatch() it can bail if it sees SYNC
requests in flight. An incoming request from another queue can also preempt it
in such situation before we have the chance to execute anything (as seen in the
trace above).
This patch sets the must_dispatch flag if we notice that we have requests
that are already fifo_expired. This flag is always cleared after
cfq_dispatch_request() returns from cfq_dispatch_requests(), so it won't pin
the queue for subsequent requests (unless they are themselves expired)
Care is taken during preempt to still allow rt requests to preempt us
regardless.
Testing my workload with this patch applied produces much better results.
From the application side I see no timeouts, and the open() latency histogram
generated by systemtap looks much better, with the worst outlier at 131ms:
Latency histogram of xfs_buf_lock acquisition (microseconds):
value |-------------------------------------------------- count
0 | 11
1 |@@@@ 161
2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1966
4 |@ 54
8 | 36
16 | 7
32 | 0
64 | 0
~
1024 | 0
2048 | 0
4096 | 1
8192 | 1
16384 | 2
32768 | 0
65536 | 0
131072 | 1
262144 | 0
524288 | 0
Signed-off-by: Glauber Costa <glauber@scylladb.com>
CC: Jens Axboe <axboe@kernel.dk>
CC: linux-block@vger.kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Glauber Costa <glauber@scylladb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-09-23 00:59:59 +00:00
|
|
|
else
|
|
|
|
cfq_log_cfqq(cfqq->cfqd, cfqq, "fifo=%p", rq);
|
2009-10-06 18:49:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* insert request into driver dispatch list
|
|
|
|
*/
|
|
|
|
cfq_dispatch_insert(cfqd->queue, rq);
|
|
|
|
|
|
|
|
if (!cfqd->active_cic) {
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic = RQ_CIC(rq);
|
2009-10-06 18:49:37 +00:00
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
atomic_long_inc(&cic->icq.ioc->refcount);
|
2009-10-06 18:49:37 +00:00
|
|
|
cfqd->active_cic = cic;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the cfqq that we need to service and move a request from that to the
|
|
|
|
* dispatch list
|
|
|
|
*/
|
|
|
|
static int cfq_dispatch_requests(struct request_queue *q, int force)
|
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
|
|
|
|
if (!cfqd->busy_queues)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (unlikely(force))
|
|
|
|
return cfq_forced_dispatch(cfqd);
|
|
|
|
|
|
|
|
cfqq = cfq_select_queue(cfqd);
|
|
|
|
if (!cfqq)
|
2009-10-03 14:26:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-04-07 06:51:19 +00:00
|
|
|
/*
|
2009-10-06 18:49:37 +00:00
|
|
|
* Dispatch a request from this cfqq, if it is allowed
|
2009-04-07 06:51:19 +00:00
|
|
|
*/
|
2009-10-06 18:49:37 +00:00
|
|
|
if (!cfq_dispatch_request(cfqd, cfqq))
|
|
|
|
return 0;
|
|
|
|
|
2009-04-07 06:51:19 +00:00
|
|
|
cfqq->slice_dispatch++;
|
2009-04-07 09:38:31 +00:00
|
|
|
cfq_clear_cfqq_must_dispatch(cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2009-04-07 06:51:19 +00:00
|
|
|
/*
|
|
|
|
* expire an async queue immediately if it has used up its slice. idle
|
|
|
|
* queue always expire after 1 dispatch round.
|
|
|
|
*/
|
|
|
|
if (cfqd->busy_queues > 1 && ((!cfq_cfqq_sync(cfqq) &&
|
|
|
|
cfqq->slice_dispatch >= cfq_prio_to_maxrq(cfqd, cfqq)) ||
|
|
|
|
cfq_class_idle(cfqq))) {
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqq->slice_end = ktime_get_ns() + 1;
|
2010-04-26 17:25:11 +00:00
|
|
|
cfq_slice_expired(cfqd, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-01 08:06:42 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "dispatched a request");
|
2009-04-07 06:51:19 +00:00
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-13 10:39:25 +00:00
|
|
|
* task holds one reference to the queue, dropped when task exits. each rq
|
|
|
|
* in-flight on this queue also holds a reference, dropped when rq is freed.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2009-12-03 17:59:47 +00:00
|
|
|
* Each cfq queue took a reference on the parent group. Drop it now.
|
2005-04-16 22:20:36 +00:00
|
|
|
* queue lock must be held here.
|
|
|
|
*/
|
|
|
|
static void cfq_put_queue(struct cfq_queue *cfqq)
|
|
|
|
{
|
2005-06-27 08:55:12 +00:00
|
|
|
struct cfq_data *cfqd = cfqq->cfqd;
|
2011-03-01 20:05:08 +00:00
|
|
|
struct cfq_group *cfqg;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2011-01-07 07:46:59 +00:00
|
|
|
BUG_ON(cfqq->ref <= 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-01-07 07:46:59 +00:00
|
|
|
cfqq->ref--;
|
|
|
|
if (cfqq->ref)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "put_queue");
|
2005-04-16 22:20:36 +00:00
|
|
|
BUG_ON(rb_first(&cfqq->sort_list));
|
2005-06-27 08:55:12 +00:00
|
|
|
BUG_ON(cfqq->allocated[READ] + cfqq->allocated[WRITE]);
|
2009-12-03 17:59:47 +00:00
|
|
|
cfqg = cfqq->cfqg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-01-19 01:09:53 +00:00
|
|
|
if (unlikely(cfqd->active_queue == cfqq)) {
|
2010-04-26 17:25:11 +00:00
|
|
|
__cfq_slice_expired(cfqd, cfqq, 0);
|
2009-10-05 06:52:35 +00:00
|
|
|
cfq_schedule_dispatch(cfqd);
|
2007-01-19 01:09:53 +00:00
|
|
|
}
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2009-12-03 17:59:40 +00:00
|
|
|
BUG_ON(cfq_cfqq_on_rr(cfqq));
|
2005-04-16 22:20:36 +00:00
|
|
|
kmem_cache_free(cfq_pool, cfqq);
|
2012-03-23 13:02:53 +00:00
|
|
|
cfqg_put(cfqg);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 08:16:53 +00:00
|
|
|
static void cfq_put_cooperator(struct cfq_queue *cfqq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-10-23 21:14:50 +00:00
|
|
|
struct cfq_queue *__cfqq, *next;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this queue was scheduled to merge with another queue, be
|
|
|
|
* sure to drop the reference taken on that queue (and others in
|
|
|
|
* the merge chain). See cfq_setup_merge and cfq_merge_cfqqs.
|
|
|
|
*/
|
|
|
|
__cfqq = cfqq->new_cfqq;
|
|
|
|
while (__cfqq) {
|
|
|
|
if (__cfqq == cfqq) {
|
|
|
|
WARN(1, "cfqq->new_cfqq loop detected\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
next = __cfqq->new_cfqq;
|
|
|
|
cfq_put_queue(__cfqq);
|
|
|
|
__cfqq = next;
|
|
|
|
}
|
2010-05-25 08:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cfq_exit_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
if (unlikely(cfqq == cfqd->active_queue)) {
|
|
|
|
__cfq_slice_expired(cfqd, cfqq, 0);
|
|
|
|
cfq_schedule_dispatch(cfqd);
|
|
|
|
}
|
|
|
|
|
|
|
|
cfq_put_cooperator(cfqq);
|
2009-10-23 21:14:50 +00:00
|
|
|
|
2006-07-22 14:48:31 +00:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
}
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2011-12-13 23:33:42 +00:00
|
|
|
static void cfq_init_icq(struct io_cq *icq)
|
|
|
|
{
|
|
|
|
struct cfq_io_cq *cic = icq_to_cic(icq);
|
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
cic->ttime.last_end_request = ktime_get_ns();
|
2011-12-13 23:33:42 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 23:33:41 +00:00
|
|
|
static void cfq_exit_icq(struct io_cq *icq)
|
2006-07-22 14:48:31 +00:00
|
|
|
{
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic = icq_to_cic(icq);
|
2011-12-13 23:33:38 +00:00
|
|
|
struct cfq_data *cfqd = cic_to_cfqd(cic);
|
2008-04-10 06:28:01 +00:00
|
|
|
|
2015-08-18 21:55:00 +00:00
|
|
|
if (cic_to_cfqq(cic, false)) {
|
|
|
|
cfq_exit_cfqq(cfqd, cic_to_cfqq(cic, false));
|
|
|
|
cic_set_cfqq(cic, NULL, false);
|
2006-03-18 18:38:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:00 +00:00
|
|
|
if (cic_to_cfqq(cic, true)) {
|
|
|
|
cfq_exit_cfqq(cfqd, cic_to_cfqq(cic, true));
|
|
|
|
cic_set_cfqq(cic, NULL, true);
|
2006-03-18 18:38:01 +00:00
|
|
|
}
|
2006-07-22 14:48:31 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 22:10:57 +00:00
|
|
|
static void cfq_init_prio_data(struct cfq_queue *cfqq, struct cfq_io_cq *cic)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
int ioprio_class;
|
|
|
|
|
2005-06-27 08:56:24 +00:00
|
|
|
if (!cfq_cfqq_prio_changed(cfqq))
|
2005-06-27 08:55:12 +00:00
|
|
|
return;
|
|
|
|
|
2012-03-19 22:10:58 +00:00
|
|
|
ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
|
2005-06-27 08:55:12 +00:00
|
|
|
switch (ioprio_class) {
|
2008-01-31 12:08:54 +00:00
|
|
|
default:
|
|
|
|
printk(KERN_ERR "cfq: bad prio %x\n", ioprio_class);
|
|
|
|
case IOPRIO_CLASS_NONE:
|
|
|
|
/*
|
2008-05-07 07:51:23 +00:00
|
|
|
* no prio set, inherit CPU scheduling settings
|
2008-01-31 12:08:54 +00:00
|
|
|
*/
|
|
|
|
cfqq->ioprio = task_nice_ioprio(tsk);
|
2008-05-07 07:51:23 +00:00
|
|
|
cfqq->ioprio_class = task_nice_ioclass(tsk);
|
2008-01-31 12:08:54 +00:00
|
|
|
break;
|
|
|
|
case IOPRIO_CLASS_RT:
|
2012-03-19 22:10:58 +00:00
|
|
|
cfqq->ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
|
2008-01-31 12:08:54 +00:00
|
|
|
cfqq->ioprio_class = IOPRIO_CLASS_RT;
|
|
|
|
break;
|
|
|
|
case IOPRIO_CLASS_BE:
|
2012-03-19 22:10:58 +00:00
|
|
|
cfqq->ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
|
2008-01-31 12:08:54 +00:00
|
|
|
cfqq->ioprio_class = IOPRIO_CLASS_BE;
|
|
|
|
break;
|
|
|
|
case IOPRIO_CLASS_IDLE:
|
|
|
|
cfqq->ioprio_class = IOPRIO_CLASS_IDLE;
|
|
|
|
cfqq->ioprio = 7;
|
|
|
|
cfq_clear_cfqq_idle_window(cfqq);
|
|
|
|
break;
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* keep track of original prio settings in case we have to temporarily
|
|
|
|
* elevate the priority of this queue
|
|
|
|
*/
|
|
|
|
cfqq->org_ioprio = cfqq->ioprio;
|
2016-06-09 21:47:29 +00:00
|
|
|
cfqq->org_ioprio_class = cfqq->ioprio_class;
|
2005-06-27 08:56:24 +00:00
|
|
|
cfq_clear_cfqq_prio_changed(cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-19 22:10:58 +00:00
|
|
|
static void check_ioprio_changed(struct cfq_io_cq *cic, struct bio *bio)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2012-03-19 22:10:58 +00:00
|
|
|
int ioprio = cic->icq.ioc->ioprio;
|
2010-05-20 19:21:34 +00:00
|
|
|
struct cfq_data *cfqd = cic_to_cfqd(cic);
|
2006-03-18 18:25:24 +00:00
|
|
|
struct cfq_queue *cfqq;
|
2006-06-14 07:10:45 +00:00
|
|
|
|
2012-03-19 22:10:58 +00:00
|
|
|
/*
|
|
|
|
* Check whether ioprio has changed. The condition may trigger
|
|
|
|
* spuriously on a newly created cic but there's no harm.
|
|
|
|
*/
|
|
|
|
if (unlikely(!cfqd) || likely(cic->ioprio == ioprio))
|
2006-06-16 09:23:00 +00:00
|
|
|
return;
|
|
|
|
|
2015-08-18 21:55:00 +00:00
|
|
|
cfqq = cic_to_cfqq(cic, false);
|
2006-06-16 09:23:00 +00:00
|
|
|
if (cfqq) {
|
2015-08-18 21:55:00 +00:00
|
|
|
cfq_put_queue(cfqq);
|
2015-08-18 21:55:02 +00:00
|
|
|
cfqq = cfq_get_queue(cfqd, BLK_RW_ASYNC, cic, bio);
|
2015-08-18 21:55:00 +00:00
|
|
|
cic_set_cfqq(cic, cfqq, false);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
2006-06-16 09:23:00 +00:00
|
|
|
|
2015-08-18 21:55:00 +00:00
|
|
|
cfqq = cic_to_cfqq(cic, true);
|
2006-06-16 09:23:00 +00:00
|
|
|
if (cfqq)
|
|
|
|
cfq_mark_cfqq_prio_changed(cfqq);
|
2012-03-19 22:10:58 +00:00
|
|
|
|
|
|
|
cic->ioprio = ioprio;
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
2009-06-26 08:44:34 +00:00
|
|
|
static void cfq_init_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2009-10-07 18:02:57 +00:00
|
|
|
pid_t pid, bool is_sync)
|
2009-06-26 08:44:34 +00:00
|
|
|
{
|
|
|
|
RB_CLEAR_NODE(&cfqq->rb_node);
|
|
|
|
RB_CLEAR_NODE(&cfqq->p_node);
|
|
|
|
INIT_LIST_HEAD(&cfqq->fifo);
|
|
|
|
|
2011-01-07 07:46:59 +00:00
|
|
|
cfqq->ref = 0;
|
2009-06-26 08:44:34 +00:00
|
|
|
cfqq->cfqd = cfqd;
|
|
|
|
|
|
|
|
cfq_mark_cfqq_prio_changed(cfqq);
|
|
|
|
|
|
|
|
if (is_sync) {
|
|
|
|
if (!cfq_class_idle(cfqq))
|
|
|
|
cfq_mark_cfqq_idle_window(cfqq);
|
|
|
|
cfq_mark_cfqq_sync(cfqq);
|
|
|
|
}
|
|
|
|
cfqq->pid = pid;
|
|
|
|
}
|
|
|
|
|
2009-12-03 17:59:51 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-03-19 22:10:58 +00:00
|
|
|
static void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio)
|
2009-12-03 17:59:51 +00:00
|
|
|
{
|
2010-05-20 19:21:34 +00:00
|
|
|
struct cfq_data *cfqd = cic_to_cfqd(cic);
|
2015-08-18 21:55:05 +00:00
|
|
|
struct cfq_queue *cfqq;
|
2014-09-07 23:15:20 +00:00
|
|
|
uint64_t serial_nr;
|
block: hook up writeback throttling
Enable throttling of buffered writeback to make it a lot
more smooth, and has way less impact on other system activity.
Background writeback should be, by definition, background
activity. The fact that we flush huge bundles of it at the time
means that it potentially has heavy impacts on foreground workloads,
which isn't ideal. We can't easily limit the sizes of writes that
we do, since that would impact file system layout in the presence
of delayed allocation. So just throttle back buffered writeback,
unless someone is waiting for it.
The algorithm for when to throttle takes its inspiration in the
CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors
the minimum latencies of requests over a window of time. In that
window of time, if the minimum latency of any request exceeds a
given target, then a scale count is incremented and the queue depth
is shrunk. The next monitoring window is shrunk accordingly. Unlike
CoDel, if we hit a window that exhibits good behavior, then we
simply increment the scale count and re-calculate the limits for that
scale value. This prevents us from oscillating between a
close-to-ideal value and max all the time, instead remaining in the
windows where we get good behavior.
Unlike CoDel, blk-wb allows the scale count to to negative. This
happens if we primarily have writes going on. Unlike positive
scale counts, this doesn't change the size of the monitoring window.
When the heavy writers finish, blk-bw quickly snaps back to it's
stable state of a zero scale count.
The patch registers a sysfs entry, 'wb_lat_usec'. This sets the latency
target to me met. It defaults to 2 msec for non-rotational storage, and
75 msec for rotational storage. Setting this value to '0' disables
blk-wb. Generally, a user would not have to touch this setting.
We don't enable WBT on devices that are managed with CFQ, and have
a non-root block cgroup attached. If we have a proportional share setup
on this particular disk, then the wbt throttling will interfere with
that. We don't have a strong need for wbt for that case, since we will
rely on CFQ doing that for us.
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-11-09 19:38:14 +00:00
|
|
|
bool nonroot_cg;
|
2009-12-03 17:59:51 +00:00
|
|
|
|
2012-03-19 22:10:58 +00:00
|
|
|
rcu_read_lock();
|
2014-09-07 23:15:20 +00:00
|
|
|
serial_nr = bio_blkcg(bio)->css.serial_nr;
|
block: hook up writeback throttling
Enable throttling of buffered writeback to make it a lot
more smooth, and has way less impact on other system activity.
Background writeback should be, by definition, background
activity. The fact that we flush huge bundles of it at the time
means that it potentially has heavy impacts on foreground workloads,
which isn't ideal. We can't easily limit the sizes of writes that
we do, since that would impact file system layout in the presence
of delayed allocation. So just throttle back buffered writeback,
unless someone is waiting for it.
The algorithm for when to throttle takes its inspiration in the
CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors
the minimum latencies of requests over a window of time. In that
window of time, if the minimum latency of any request exceeds a
given target, then a scale count is incremented and the queue depth
is shrunk. The next monitoring window is shrunk accordingly. Unlike
CoDel, if we hit a window that exhibits good behavior, then we
simply increment the scale count and re-calculate the limits for that
scale value. This prevents us from oscillating between a
close-to-ideal value and max all the time, instead remaining in the
windows where we get good behavior.
Unlike CoDel, blk-wb allows the scale count to to negative. This
happens if we primarily have writes going on. Unlike positive
scale counts, this doesn't change the size of the monitoring window.
When the heavy writers finish, blk-bw quickly snaps back to it's
stable state of a zero scale count.
The patch registers a sysfs entry, 'wb_lat_usec'. This sets the latency
target to me met. It defaults to 2 msec for non-rotational storage, and
75 msec for rotational storage. Setting this value to '0' disables
blk-wb. Generally, a user would not have to touch this setting.
We don't enable WBT on devices that are managed with CFQ, and have
a non-root block cgroup attached. If we have a proportional share setup
on this particular disk, then the wbt throttling will interfere with
that. We don't have a strong need for wbt for that case, since we will
rely on CFQ doing that for us.
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-11-09 19:38:14 +00:00
|
|
|
nonroot_cg = bio_blkcg(bio) != &blkcg_root;
|
2012-03-19 22:10:58 +00:00
|
|
|
rcu_read_unlock();
|
2009-12-03 17:59:51 +00:00
|
|
|
|
2012-03-19 22:10:58 +00:00
|
|
|
/*
|
|
|
|
* Check whether blkcg has changed. The condition may trigger
|
|
|
|
* spuriously on a newly created cic but there's no harm.
|
|
|
|
*/
|
2014-09-07 23:15:20 +00:00
|
|
|
if (unlikely(!cfqd) || likely(cic->blkcg_serial_nr == serial_nr))
|
2012-03-19 22:10:58 +00:00
|
|
|
return;
|
2009-12-03 17:59:51 +00:00
|
|
|
|
block: hook up writeback throttling
Enable throttling of buffered writeback to make it a lot
more smooth, and has way less impact on other system activity.
Background writeback should be, by definition, background
activity. The fact that we flush huge bundles of it at the time
means that it potentially has heavy impacts on foreground workloads,
which isn't ideal. We can't easily limit the sizes of writes that
we do, since that would impact file system layout in the presence
of delayed allocation. So just throttle back buffered writeback,
unless someone is waiting for it.
The algorithm for when to throttle takes its inspiration in the
CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors
the minimum latencies of requests over a window of time. In that
window of time, if the minimum latency of any request exceeds a
given target, then a scale count is incremented and the queue depth
is shrunk. The next monitoring window is shrunk accordingly. Unlike
CoDel, if we hit a window that exhibits good behavior, then we
simply increment the scale count and re-calculate the limits for that
scale value. This prevents us from oscillating between a
close-to-ideal value and max all the time, instead remaining in the
windows where we get good behavior.
Unlike CoDel, blk-wb allows the scale count to to negative. This
happens if we primarily have writes going on. Unlike positive
scale counts, this doesn't change the size of the monitoring window.
When the heavy writers finish, blk-bw quickly snaps back to it's
stable state of a zero scale count.
The patch registers a sysfs entry, 'wb_lat_usec'. This sets the latency
target to me met. It defaults to 2 msec for non-rotational storage, and
75 msec for rotational storage. Setting this value to '0' disables
blk-wb. Generally, a user would not have to touch this setting.
We don't enable WBT on devices that are managed with CFQ, and have
a non-root block cgroup attached. If we have a proportional share setup
on this particular disk, then the wbt throttling will interfere with
that. We don't have a strong need for wbt for that case, since we will
rely on CFQ doing that for us.
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-11-09 19:38:14 +00:00
|
|
|
/*
|
|
|
|
* If we have a non-root cgroup, we can depend on that to
|
|
|
|
* do proper throttling of writes. Turn off wbt for that
|
2016-11-28 16:25:50 +00:00
|
|
|
* case, if it was enabled by default.
|
block: hook up writeback throttling
Enable throttling of buffered writeback to make it a lot
more smooth, and has way less impact on other system activity.
Background writeback should be, by definition, background
activity. The fact that we flush huge bundles of it at the time
means that it potentially has heavy impacts on foreground workloads,
which isn't ideal. We can't easily limit the sizes of writes that
we do, since that would impact file system layout in the presence
of delayed allocation. So just throttle back buffered writeback,
unless someone is waiting for it.
The algorithm for when to throttle takes its inspiration in the
CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors
the minimum latencies of requests over a window of time. In that
window of time, if the minimum latency of any request exceeds a
given target, then a scale count is incremented and the queue depth
is shrunk. The next monitoring window is shrunk accordingly. Unlike
CoDel, if we hit a window that exhibits good behavior, then we
simply increment the scale count and re-calculate the limits for that
scale value. This prevents us from oscillating between a
close-to-ideal value and max all the time, instead remaining in the
windows where we get good behavior.
Unlike CoDel, blk-wb allows the scale count to to negative. This
happens if we primarily have writes going on. Unlike positive
scale counts, this doesn't change the size of the monitoring window.
When the heavy writers finish, blk-bw quickly snaps back to it's
stable state of a zero scale count.
The patch registers a sysfs entry, 'wb_lat_usec'. This sets the latency
target to me met. It defaults to 2 msec for non-rotational storage, and
75 msec for rotational storage. Setting this value to '0' disables
blk-wb. Generally, a user would not have to touch this setting.
We don't enable WBT on devices that are managed with CFQ, and have
a non-root block cgroup attached. If we have a proportional share setup
on this particular disk, then the wbt throttling will interfere with
that. We don't have a strong need for wbt for that case, since we will
rely on CFQ doing that for us.
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-11-09 19:38:14 +00:00
|
|
|
*/
|
2016-11-28 16:25:50 +00:00
|
|
|
if (nonroot_cg)
|
|
|
|
wbt_disable_default(cfqd->queue);
|
block: hook up writeback throttling
Enable throttling of buffered writeback to make it a lot
more smooth, and has way less impact on other system activity.
Background writeback should be, by definition, background
activity. The fact that we flush huge bundles of it at the time
means that it potentially has heavy impacts on foreground workloads,
which isn't ideal. We can't easily limit the sizes of writes that
we do, since that would impact file system layout in the presence
of delayed allocation. So just throttle back buffered writeback,
unless someone is waiting for it.
The algorithm for when to throttle takes its inspiration in the
CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors
the minimum latencies of requests over a window of time. In that
window of time, if the minimum latency of any request exceeds a
given target, then a scale count is incremented and the queue depth
is shrunk. The next monitoring window is shrunk accordingly. Unlike
CoDel, if we hit a window that exhibits good behavior, then we
simply increment the scale count and re-calculate the limits for that
scale value. This prevents us from oscillating between a
close-to-ideal value and max all the time, instead remaining in the
windows where we get good behavior.
Unlike CoDel, blk-wb allows the scale count to to negative. This
happens if we primarily have writes going on. Unlike positive
scale counts, this doesn't change the size of the monitoring window.
When the heavy writers finish, blk-bw quickly snaps back to it's
stable state of a zero scale count.
The patch registers a sysfs entry, 'wb_lat_usec'. This sets the latency
target to me met. It defaults to 2 msec for non-rotational storage, and
75 msec for rotational storage. Setting this value to '0' disables
blk-wb. Generally, a user would not have to touch this setting.
We don't enable WBT on devices that are managed with CFQ, and have
a non-root block cgroup attached. If we have a proportional share setup
on this particular disk, then the wbt throttling will interfere with
that. We don't have a strong need for wbt for that case, since we will
rely on CFQ doing that for us.
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-11-09 19:38:14 +00:00
|
|
|
|
2015-08-18 21:55:05 +00:00
|
|
|
/*
|
|
|
|
* Drop reference to queues. New queues will be assigned in new
|
|
|
|
* group upon arrival of fresh requests.
|
|
|
|
*/
|
|
|
|
cfqq = cic_to_cfqq(cic, false);
|
|
|
|
if (cfqq) {
|
|
|
|
cfq_log_cfqq(cfqd, cfqq, "changed cgroup");
|
|
|
|
cic_set_cfqq(cic, NULL, false);
|
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
}
|
|
|
|
|
|
|
|
cfqq = cic_to_cfqq(cic, true);
|
|
|
|
if (cfqq) {
|
|
|
|
cfq_log_cfqq(cfqd, cfqq, "changed cgroup");
|
|
|
|
cic_set_cfqq(cic, NULL, true);
|
|
|
|
cfq_put_queue(cfqq);
|
2009-12-03 17:59:51 +00:00
|
|
|
}
|
2012-03-19 22:10:58 +00:00
|
|
|
|
2014-09-07 23:15:20 +00:00
|
|
|
cic->blkcg_serial_nr = serial_nr;
|
2009-12-03 17:59:51 +00:00
|
|
|
}
|
2012-03-19 22:10:58 +00:00
|
|
|
#else
|
|
|
|
static inline void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio) { }
|
2009-12-03 17:59:51 +00:00
|
|
|
#endif /* CONFIG_CFQ_GROUP_IOSCHED */
|
|
|
|
|
2007-07-20 08:06:38 +00:00
|
|
|
static struct cfq_queue **
|
2015-08-18 21:55:05 +00:00
|
|
|
cfq_async_queue_prio(struct cfq_group *cfqg, int ioprio_class, int ioprio)
|
2007-07-20 08:06:38 +00:00
|
|
|
{
|
2008-01-31 12:08:54 +00:00
|
|
|
switch (ioprio_class) {
|
2007-07-20 08:06:38 +00:00
|
|
|
case IOPRIO_CLASS_RT:
|
2015-08-18 21:55:05 +00:00
|
|
|
return &cfqg->async_cfqq[0][ioprio];
|
2012-03-19 22:10:58 +00:00
|
|
|
case IOPRIO_CLASS_NONE:
|
|
|
|
ioprio = IOPRIO_NORM;
|
|
|
|
/* fall through */
|
2007-07-20 08:06:38 +00:00
|
|
|
case IOPRIO_CLASS_BE:
|
2015-08-18 21:55:05 +00:00
|
|
|
return &cfqg->async_cfqq[1][ioprio];
|
2007-07-20 08:06:38 +00:00
|
|
|
case IOPRIO_CLASS_IDLE:
|
2015-08-18 21:55:05 +00:00
|
|
|
return &cfqg->async_idle_cfqq;
|
2007-07-20 08:06:38 +00:00
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 11:43:25 +00:00
|
|
|
static struct cfq_queue *
|
2012-03-19 22:10:57 +00:00
|
|
|
cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct cfq_io_cq *cic,
|
2015-08-18 21:55:02 +00:00
|
|
|
struct bio *bio)
|
2007-07-10 11:43:25 +00:00
|
|
|
{
|
cfq-iosched: fix incorrect filing of rt async cfqq
Hi,
If you can manage to submit an async write as the first async I/O from
the context of a process with realtime scheduling priority, then a
cfq_queue is allocated, but filed into the wrong async_cfqq bucket. It
ends up in the best effort array, but actually has realtime I/O
scheduling priority set in cfqq->ioprio.
The reason is that cfq_get_queue assumes the default scheduling class and
priority when there is no information present (i.e. when the async cfqq
is created):
static struct cfq_queue *
cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct cfq_io_cq *cic,
struct bio *bio, gfp_t gfp_mask)
{
const int ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
const int ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
cic->ioprio starts out as 0, which is "invalid". So, class of 0
(IOPRIO_CLASS_NONE) is passed to cfq_async_queue_prio like so:
async_cfqq = cfq_async_queue_prio(cfqd, ioprio_class, ioprio);
static struct cfq_queue **
cfq_async_queue_prio(struct cfq_data *cfqd, int ioprio_class, int ioprio)
{
switch (ioprio_class) {
case IOPRIO_CLASS_RT:
return &cfqd->async_cfqq[0][ioprio];
case IOPRIO_CLASS_NONE:
ioprio = IOPRIO_NORM;
/* fall through */
case IOPRIO_CLASS_BE:
return &cfqd->async_cfqq[1][ioprio];
case IOPRIO_CLASS_IDLE:
return &cfqd->async_idle_cfqq;
default:
BUG();
}
}
Here, instead of returning a class mapped from the process' scheduling
priority, we get back the bucket associated with IOPRIO_CLASS_BE.
Now, there is no queue allocated there yet, so we create it:
cfqq = cfq_find_alloc_queue(cfqd, is_sync, cic, bio, gfp_mask);
That function ends up doing this:
cfq_init_cfqq(cfqd, cfqq, current->pid, is_sync);
cfq_init_prio_data(cfqq, cic);
cfq_init_cfqq marks the priority as having changed. Then, cfq_init_prio
data does this:
ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
switch (ioprio_class) {
default:
printk(KERN_ERR "cfq: bad prio %x\n", ioprio_class);
case IOPRIO_CLASS_NONE:
/*
* no prio set, inherit CPU scheduling settings
*/
cfqq->ioprio = task_nice_ioprio(tsk);
cfqq->ioprio_class = task_nice_ioclass(tsk);
break;
So we basically have two code paths that treat IOPRIO_CLASS_NONE
differently, which results in an RT async cfqq filed into a best effort
bucket.
Attached is a patch which fixes the problem. I'm not sure how to make
it cleaner. Suggestions would be welcome.
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Tested-by: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
Cc: stable@kernel.org
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-01-12 20:21:01 +00:00
|
|
|
int ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
|
|
|
|
int ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
|
2015-08-18 21:55:04 +00:00
|
|
|
struct cfq_queue **async_cfqq = NULL;
|
2015-08-18 21:54:57 +00:00
|
|
|
struct cfq_queue *cfqq;
|
2015-08-18 21:55:03 +00:00
|
|
|
struct cfq_group *cfqg;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
2015-08-18 21:55:20 +00:00
|
|
|
cfqg = cfq_lookup_cfqg(cfqd, bio_blkcg(bio));
|
2015-08-18 21:55:03 +00:00
|
|
|
if (!cfqg) {
|
|
|
|
cfqq = &cfqd->oom_cfqq;
|
|
|
|
goto out;
|
|
|
|
}
|
2007-07-10 11:43:25 +00:00
|
|
|
|
2007-07-20 08:06:38 +00:00
|
|
|
if (!is_sync) {
|
cfq-iosched: fix incorrect filing of rt async cfqq
Hi,
If you can manage to submit an async write as the first async I/O from
the context of a process with realtime scheduling priority, then a
cfq_queue is allocated, but filed into the wrong async_cfqq bucket. It
ends up in the best effort array, but actually has realtime I/O
scheduling priority set in cfqq->ioprio.
The reason is that cfq_get_queue assumes the default scheduling class and
priority when there is no information present (i.e. when the async cfqq
is created):
static struct cfq_queue *
cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct cfq_io_cq *cic,
struct bio *bio, gfp_t gfp_mask)
{
const int ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
const int ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
cic->ioprio starts out as 0, which is "invalid". So, class of 0
(IOPRIO_CLASS_NONE) is passed to cfq_async_queue_prio like so:
async_cfqq = cfq_async_queue_prio(cfqd, ioprio_class, ioprio);
static struct cfq_queue **
cfq_async_queue_prio(struct cfq_data *cfqd, int ioprio_class, int ioprio)
{
switch (ioprio_class) {
case IOPRIO_CLASS_RT:
return &cfqd->async_cfqq[0][ioprio];
case IOPRIO_CLASS_NONE:
ioprio = IOPRIO_NORM;
/* fall through */
case IOPRIO_CLASS_BE:
return &cfqd->async_cfqq[1][ioprio];
case IOPRIO_CLASS_IDLE:
return &cfqd->async_idle_cfqq;
default:
BUG();
}
}
Here, instead of returning a class mapped from the process' scheduling
priority, we get back the bucket associated with IOPRIO_CLASS_BE.
Now, there is no queue allocated there yet, so we create it:
cfqq = cfq_find_alloc_queue(cfqd, is_sync, cic, bio, gfp_mask);
That function ends up doing this:
cfq_init_cfqq(cfqd, cfqq, current->pid, is_sync);
cfq_init_prio_data(cfqq, cic);
cfq_init_cfqq marks the priority as having changed. Then, cfq_init_prio
data does this:
ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
switch (ioprio_class) {
default:
printk(KERN_ERR "cfq: bad prio %x\n", ioprio_class);
case IOPRIO_CLASS_NONE:
/*
* no prio set, inherit CPU scheduling settings
*/
cfqq->ioprio = task_nice_ioprio(tsk);
cfqq->ioprio_class = task_nice_ioclass(tsk);
break;
So we basically have two code paths that treat IOPRIO_CLASS_NONE
differently, which results in an RT async cfqq filed into a best effort
bucket.
Attached is a patch which fixes the problem. I'm not sure how to make
it cleaner. Suggestions would be welcome.
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Tested-by: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
Cc: stable@kernel.org
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-01-12 20:21:01 +00:00
|
|
|
if (!ioprio_valid(cic->ioprio)) {
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
ioprio = task_nice_ioprio(tsk);
|
|
|
|
ioprio_class = task_nice_ioclass(tsk);
|
|
|
|
}
|
2015-08-18 21:55:05 +00:00
|
|
|
async_cfqq = cfq_async_queue_prio(cfqg, ioprio_class, ioprio);
|
2007-07-20 08:06:38 +00:00
|
|
|
cfqq = *async_cfqq;
|
2015-08-18 21:54:57 +00:00
|
|
|
if (cfqq)
|
|
|
|
goto out;
|
2007-07-20 08:06:38 +00:00
|
|
|
}
|
|
|
|
|
2016-11-21 23:03:32 +00:00
|
|
|
cfqq = kmem_cache_alloc_node(cfq_pool,
|
|
|
|
GFP_NOWAIT | __GFP_ZERO | __GFP_NOWARN,
|
2015-08-18 21:55:04 +00:00
|
|
|
cfqd->queue->node);
|
|
|
|
if (!cfqq) {
|
|
|
|
cfqq = &cfqd->oom_cfqq;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-01-23 14:06:43 +00:00
|
|
|
/* cfq_init_cfqq() assumes cfqq->ioprio_class is initialized. */
|
|
|
|
cfqq->ioprio_class = IOPRIO_CLASS_NONE;
|
2015-08-18 21:55:04 +00:00
|
|
|
cfq_init_cfqq(cfqd, cfqq, current->pid, is_sync);
|
|
|
|
cfq_init_prio_data(cfqq, cic);
|
|
|
|
cfq_link_cfqq_cfqg(cfqq, cfqg);
|
|
|
|
cfq_log_cfqq(cfqd, cfqq, "alloced");
|
2007-07-10 11:43:25 +00:00
|
|
|
|
2015-08-18 21:55:04 +00:00
|
|
|
if (async_cfqq) {
|
|
|
|
/* a new async queue is created, pin and remember */
|
2011-01-07 07:46:59 +00:00
|
|
|
cfqq->ref++;
|
2007-07-20 08:06:38 +00:00
|
|
|
*async_cfqq = cfqq;
|
2007-07-10 11:43:25 +00:00
|
|
|
}
|
2015-08-18 21:54:57 +00:00
|
|
|
out:
|
2011-01-07 07:46:59 +00:00
|
|
|
cfqq->ref++;
|
2015-08-18 21:55:03 +00:00
|
|
|
rcu_read_unlock();
|
2007-07-10 11:43:25 +00:00
|
|
|
return cfqq;
|
|
|
|
}
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
static void
|
2016-06-08 14:55:34 +00:00
|
|
|
__cfq_update_io_thinktime(struct cfq_ttime *ttime, u64 slice_idle)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 elapsed = ktime_get_ns() - ttime->last_end_request;
|
2011-07-12 12:24:35 +00:00
|
|
|
elapsed = min(elapsed, 2UL * slice_idle);
|
2005-06-17 14:15:10 +00:00
|
|
|
|
2011-07-12 12:24:35 +00:00
|
|
|
ttime->ttime_samples = (7*ttime->ttime_samples + 256) / 8;
|
2016-06-08 14:55:34 +00:00
|
|
|
ttime->ttime_total = div_u64(7*ttime->ttime_total + 256*elapsed, 8);
|
|
|
|
ttime->ttime_mean = div64_ul(ttime->ttime_total + 128,
|
|
|
|
ttime->ttime_samples);
|
2011-07-12 12:24:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cfq_update_io_thinktime(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic)
|
2011-07-12 12:24:35 +00:00
|
|
|
{
|
2011-07-12 12:24:55 +00:00
|
|
|
if (cfq_cfqq_sync(cfqq)) {
|
2011-07-12 12:24:35 +00:00
|
|
|
__cfq_update_io_thinktime(&cic->ttime, cfqd->cfq_slice_idle);
|
2011-07-12 12:24:55 +00:00
|
|
|
__cfq_update_io_thinktime(&cfqq->service_tree->ttime,
|
|
|
|
cfqd->cfq_slice_idle);
|
|
|
|
}
|
2011-07-12 12:24:56 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
__cfq_update_io_thinktime(&cfqq->cfqg->ttime, cfqd->cfq_group_idle);
|
|
|
|
#endif
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-28 11:03:44 +00:00
|
|
|
static void
|
2009-10-23 21:14:49 +00:00
|
|
|
cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2007-04-25 10:44:27 +00:00
|
|
|
struct request *rq)
|
2006-03-28 11:03:44 +00:00
|
|
|
{
|
2010-02-27 18:45:39 +00:00
|
|
|
sector_t sdist = 0;
|
2010-02-27 18:45:40 +00:00
|
|
|
sector_t n_sec = blk_rq_sectors(rq);
|
2010-02-27 18:45:39 +00:00
|
|
|
if (cfqq->last_request_pos) {
|
|
|
|
if (cfqq->last_request_pos < blk_rq_pos(rq))
|
|
|
|
sdist = blk_rq_pos(rq) - cfqq->last_request_pos;
|
|
|
|
else
|
|
|
|
sdist = cfqq->last_request_pos - blk_rq_pos(rq);
|
|
|
|
}
|
2006-03-28 11:03:44 +00:00
|
|
|
|
2010-02-27 18:45:39 +00:00
|
|
|
cfqq->seek_history <<= 1;
|
2010-02-27 18:45:40 +00:00
|
|
|
if (blk_queue_nonrot(cfqd->queue))
|
|
|
|
cfqq->seek_history |= (n_sec < CFQQ_SECT_THR_NONROT);
|
|
|
|
else
|
|
|
|
cfqq->seek_history |= (sdist > CFQQ_SEEK_THR);
|
2006-03-28 11:03:44 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-11-01 13:40:09 +00:00
|
|
|
static inline bool req_noidle(struct request *req)
|
|
|
|
{
|
|
|
|
return req_op(req) == REQ_OP_WRITE &&
|
|
|
|
(req->cmd_flags & (REQ_SYNC | REQ_IDLE)) == REQ_SYNC;
|
|
|
|
}
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* Disable idle window if the process thinks too long or seeks so much that
|
|
|
|
* it doesn't matter
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2008-05-30 10:23:07 +00:00
|
|
|
int old_idle, enable_idle;
|
2007-04-19 12:32:26 +00:00
|
|
|
|
2008-01-28 10:38:15 +00:00
|
|
|
/*
|
|
|
|
* Don't idle for async or idle io prio class
|
|
|
|
*/
|
|
|
|
if (!cfq_cfqq_sync(cfqq) || cfq_class_idle(cfqq))
|
2007-04-19 12:32:26 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-26 11:49:33 +00:00
|
|
|
enable_idle = old_idle = cfq_cfqq_idle_window(cfqq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-11-26 09:02:58 +00:00
|
|
|
if (cfqq->queued[0] + cfqq->queued[1] >= 4)
|
|
|
|
cfq_mark_cfqq_deep(cfqq);
|
|
|
|
|
2016-11-01 13:40:09 +00:00
|
|
|
if (cfqq->next_rq && req_noidle(cfqq->next_rq))
|
2010-09-20 13:24:50 +00:00
|
|
|
enable_idle = 0;
|
2012-03-05 21:15:26 +00:00
|
|
|
else if (!atomic_read(&cic->icq.ioc->active_ref) ||
|
2011-12-13 23:33:41 +00:00
|
|
|
!cfqd->cfq_slice_idle ||
|
|
|
|
(!cfq_cfqq_deep(cfqq) && CFQQ_SEEKY(cfqq)))
|
2005-06-27 08:55:12 +00:00
|
|
|
enable_idle = 0;
|
2011-07-12 12:24:35 +00:00
|
|
|
else if (sample_valid(cic->ttime.ttime_samples)) {
|
|
|
|
if (cic->ttime.ttime_mean > cfqd->cfq_slice_idle)
|
2005-06-27 08:55:12 +00:00
|
|
|
enable_idle = 0;
|
|
|
|
else
|
|
|
|
enable_idle = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
if (old_idle != enable_idle) {
|
|
|
|
cfq_log_cfqq(cfqd, cfqq, "idle=%d", enable_idle);
|
|
|
|
if (enable_idle)
|
|
|
|
cfq_mark_cfqq_idle_window(cfqq);
|
|
|
|
else
|
|
|
|
cfq_clear_cfqq_idle_window(cfqq);
|
|
|
|
}
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* Check if new_cfqq should preempt the currently active queue. Return 0 for
|
|
|
|
* no or if we aren't sure, a 1 will cause a preempt.
|
|
|
|
*/
|
2009-10-07 18:02:57 +00:00
|
|
|
static bool
|
2005-06-27 08:55:12 +00:00
|
|
|
cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
|
2006-07-13 10:39:25 +00:00
|
|
|
struct request *rq)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2007-04-25 10:44:27 +00:00
|
|
|
struct cfq_queue *cfqq;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2007-04-25 10:44:27 +00:00
|
|
|
cfqq = cfqd->active_queue;
|
|
|
|
if (!cfqq)
|
2009-10-07 18:02:57 +00:00
|
|
|
return false;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2007-04-25 10:44:27 +00:00
|
|
|
if (cfq_class_idle(new_cfqq))
|
2009-10-07 18:02:57 +00:00
|
|
|
return false;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
|
|
|
if (cfq_class_idle(cfqq))
|
2009-10-07 18:02:57 +00:00
|
|
|
return true;
|
2007-02-14 18:59:49 +00:00
|
|
|
|
2010-01-07 02:58:20 +00:00
|
|
|
/*
|
|
|
|
* Don't allow a non-RT request to preempt an ongoing RT cfqq timeslice.
|
|
|
|
*/
|
|
|
|
if (cfq_class_rt(cfqq) && !cfq_class_rt(new_cfqq))
|
|
|
|
return false;
|
|
|
|
|
2006-07-22 23:42:19 +00:00
|
|
|
/*
|
|
|
|
* if the new request is sync, but the currently running queue is
|
|
|
|
* not, let the sync request have priority.
|
|
|
|
*/
|
cfq: fix starvation of asynchronous writes
While debugging timeouts happening in my application workload (ScyllaDB), I have
observed calls to open() taking a long time, ranging everywhere from 2 seconds -
the first ones that are enough to time out my application - to more than 30
seconds.
The problem seems to happen because XFS may block on pending metadata updates
under certain circumnstances, and that's confirmed with the following backtrace
taken by the offcputime tool (iovisor/bcc):
ffffffffb90c57b1 finish_task_switch
ffffffffb97dffb5 schedule
ffffffffb97e310c schedule_timeout
ffffffffb97e1f12 __down
ffffffffb90ea821 down
ffffffffc046a9dc xfs_buf_lock
ffffffffc046abfb _xfs_buf_find
ffffffffc046ae4a xfs_buf_get_map
ffffffffc046babd xfs_buf_read_map
ffffffffc0499931 xfs_trans_read_buf_map
ffffffffc044a561 xfs_da_read_buf
ffffffffc0451390 xfs_dir3_leaf_read.constprop.16
ffffffffc0452b90 xfs_dir2_leaf_lookup_int
ffffffffc0452e0f xfs_dir2_leaf_lookup
ffffffffc044d9d3 xfs_dir_lookup
ffffffffc047d1d9 xfs_lookup
ffffffffc0479e53 xfs_vn_lookup
ffffffffb925347a path_openat
ffffffffb9254a71 do_filp_open
ffffffffb9242a94 do_sys_open
ffffffffb9242b9e sys_open
ffffffffb97e42b2 entry_SYSCALL_64_fastpath
00007fb0698162ed [unknown]
Inspecting my run with blktrace, I can see that the xfsaild kthread exhibit very
high "Dispatch wait" times, on the dozens of seconds range and consistent with
the open() times I have saw in that run.
Still from the blktrace output, we can after searching a bit, identify the
request that wasn't dispatched:
8,0 11 152 81.092472813 804 A WM 141698288 + 8 <- (8,1) 141696240
8,0 11 153 81.092472889 804 Q WM 141698288 + 8 [xfsaild/sda1]
8,0 11 154 81.092473207 804 G WM 141698288 + 8 [xfsaild/sda1]
8,0 11 206 81.092496118 804 I WM 141698288 + 8 ( 22911) [xfsaild/sda1]
<==== 'I' means Inserted (into the IO scheduler) ===================================>
8,0 0 289372 96.718761435 0 D WM 141698288 + 8 (15626265317) [swapper/0]
<==== Only 15s later the CFQ scheduler dispatches the request ======================>
As we can see above, in this particular example CFQ took 15 seconds to dispatch
this request. Going back to the full trace, we can see that the xfsaild queue
had plenty of opportunity to run, and it was selected as the active queue many
times. It would just always be preempted by something else (example):
8,0 1 0 81.117912979 0 m N cfq1618SN / insert_request
8,0 1 0 81.117913419 0 m N cfq1618SN / add_to_rr
8,0 1 0 81.117914044 0 m N cfq1618SN / preempt
8,0 1 0 81.117914398 0 m N cfq767A / slice expired t=1
8,0 1 0 81.117914755 0 m N cfq767A / resid=40
8,0 1 0 81.117915340 0 m N / served: vt=1948520448 min_vt=1948520448
8,0 1 0 81.117915858 0 m N cfq767A / sl_used=1 disp=0 charge=0 iops=1 sect=0
where cfq767 is the xfsaild queue and cfq1618 corresponds to one of the ScyllaDB
IO dispatchers.
The requests preempting the xfsaild queue are synchronous requests. That's a
characteristic of ScyllaDB workloads, as we only ever issue O_DIRECT requests.
While it can be argued that preempting ASYNC requests in favor of SYNC is part
of the CFQ logic, I don't believe that doing so for 15+ seconds is anyone's
goal.
Moreover, unless I am misunderstanding something, that breaks the expectation
set by the "fifo_expire_async" tunable, which in my system is set to the
default.
Looking at the code, it seems to me that the issue is that after we make
an async queue active, there is no guarantee that it will execute any request.
When the queue itself tests if it cfq_may_dispatch() it can bail if it sees SYNC
requests in flight. An incoming request from another queue can also preempt it
in such situation before we have the chance to execute anything (as seen in the
trace above).
This patch sets the must_dispatch flag if we notice that we have requests
that are already fifo_expired. This flag is always cleared after
cfq_dispatch_request() returns from cfq_dispatch_requests(), so it won't pin
the queue for subsequent requests (unless they are themselves expired)
Care is taken during preempt to still allow rt requests to preempt us
regardless.
Testing my workload with this patch applied produces much better results.
From the application side I see no timeouts, and the open() latency histogram
generated by systemtap looks much better, with the worst outlier at 131ms:
Latency histogram of xfs_buf_lock acquisition (microseconds):
value |-------------------------------------------------- count
0 | 11
1 |@@@@ 161
2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1966
4 |@ 54
8 | 36
16 | 7
32 | 0
64 | 0
~
1024 | 0
2048 | 0
4096 | 1
8192 | 1
16384 | 2
32768 | 0
65536 | 0
131072 | 1
262144 | 0
524288 | 0
Signed-off-by: Glauber Costa <glauber@scylladb.com>
CC: Jens Axboe <axboe@kernel.dk>
CC: linux-block@vger.kernel.org
CC: linux-kernel@vger.kernel.org
Signed-off-by: Glauber Costa <glauber@scylladb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2016-09-23 00:59:59 +00:00
|
|
|
if (rq_is_sync(rq) && !cfq_cfqq_sync(cfqq) && !cfq_cfqq_must_dispatch(cfqq))
|
2009-10-07 18:02:57 +00:00
|
|
|
return true;
|
2007-02-14 18:59:49 +00:00
|
|
|
|
2016-01-12 15:24:19 +00:00
|
|
|
/*
|
|
|
|
* Treat ancestors of current cgroup the same way as current cgroup.
|
|
|
|
* For anybody else we disallow preemption to guarantee service
|
|
|
|
* fairness among cgroups.
|
|
|
|
*/
|
|
|
|
if (!cfqg_is_descendant(cfqq->cfqg, new_cfqq->cfqg))
|
2009-12-03 17:59:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (cfq_slice_used(cfqq))
|
|
|
|
return true;
|
|
|
|
|
2016-01-12 15:24:16 +00:00
|
|
|
/*
|
|
|
|
* Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice.
|
|
|
|
*/
|
|
|
|
if (cfq_class_rt(new_cfqq) && !cfq_class_rt(cfqq))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
WARN_ON_ONCE(cfqq->ioprio_class != new_cfqq->ioprio_class);
|
2009-12-03 17:59:50 +00:00
|
|
|
/* Allow preemption only if we are idling on sync-noidle tree */
|
2012-10-03 20:56:57 +00:00
|
|
|
if (cfqd->serving_wl_type == SYNC_NOIDLE_WORKLOAD &&
|
2009-12-03 17:59:50 +00:00
|
|
|
cfqq_type(new_cfqq) == SYNC_NOIDLE_WORKLOAD &&
|
|
|
|
RB_EMPTY_ROOT(&cfqq->sort_list))
|
|
|
|
return true;
|
|
|
|
|
2011-08-19 06:34:48 +00:00
|
|
|
/*
|
|
|
|
* So both queues are sync. Let the new request get disk time if
|
|
|
|
* it's a metadata request and the current queue is doing regular IO.
|
|
|
|
*/
|
2011-08-23 12:50:29 +00:00
|
|
|
if ((rq->cmd_flags & REQ_PRIO) && !cfqq->prio_pending)
|
2011-08-19 06:34:48 +00:00
|
|
|
return true;
|
|
|
|
|
2010-11-08 14:01:03 +00:00
|
|
|
/* An idle queue should not be idle now for some reason */
|
|
|
|
if (RB_EMPTY_ROOT(&cfqq->sort_list) && !cfq_should_idle(cfqd, cfqq))
|
|
|
|
return true;
|
|
|
|
|
2007-02-14 18:59:49 +00:00
|
|
|
if (!cfqd->active_cic || !cfq_cfqq_wait_request(cfqq))
|
2009-10-07 18:02:57 +00:00
|
|
|
return false;
|
2007-02-14 18:59:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if this request is as-good as one we would expect from the
|
|
|
|
* current cfqq, let it preempt
|
|
|
|
*/
|
2010-03-19 07:03:04 +00:00
|
|
|
if (cfq_rq_close(cfqd, cfqq, rq))
|
2009-10-07 18:02:57 +00:00
|
|
|
return true;
|
2007-02-14 18:59:49 +00:00
|
|
|
|
2009-10-07 18:02:57 +00:00
|
|
|
return false;
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cfqq preempts the active queue. if we allowed preempt with no slice left,
|
|
|
|
* let it have half of its nominal slice.
|
|
|
|
*/
|
|
|
|
static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
2012-01-19 08:20:09 +00:00
|
|
|
enum wl_type_t old_type = cfqq_type(cfqd->active_queue);
|
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "preempt");
|
2012-01-19 08:20:09 +00:00
|
|
|
cfq_slice_expired(cfqd, 1);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2011-01-14 07:41:02 +00:00
|
|
|
/*
|
|
|
|
* workload type is changed, don't save slice, otherwise preempt
|
|
|
|
* doesn't happen
|
|
|
|
*/
|
2012-01-19 08:20:09 +00:00
|
|
|
if (old_type != cfqq_type(cfqq))
|
2012-10-03 20:56:57 +00:00
|
|
|
cfqq->cfqg->saved_wl_slice = 0;
|
2011-01-14 07:41:02 +00:00
|
|
|
|
2006-07-19 18:29:12 +00:00
|
|
|
/*
|
|
|
|
* Put the new queue at the front of the of the current list,
|
|
|
|
* so we know that it will be selected next.
|
|
|
|
*/
|
|
|
|
BUG_ON(!cfq_cfqq_on_rr(cfqq));
|
2007-04-19 10:03:34 +00:00
|
|
|
|
|
|
|
cfq_service_tree_add(cfqd, cfqq, 1);
|
2011-03-22 20:26:49 +00:00
|
|
|
|
2011-03-23 07:25:44 +00:00
|
|
|
cfqq->slice_end = 0;
|
|
|
|
cfq_mark_cfqq_slice_new(cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-13 10:39:25 +00:00
|
|
|
* Called when a new fs request (rq) is added (to cfqq). Check if there's
|
2005-06-27 08:55:12 +00:00
|
|
|
* something we should do about it
|
|
|
|
*/
|
|
|
|
static void
|
2006-07-13 10:39:25 +00:00
|
|
|
cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
|
|
|
struct request *rq)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic = RQ_CIC(rq);
|
2006-06-01 08:09:56 +00:00
|
|
|
|
2008-08-26 13:52:36 +00:00
|
|
|
cfqd->rq_queued++;
|
2011-08-23 12:50:29 +00:00
|
|
|
if (rq->cmd_flags & REQ_PRIO)
|
|
|
|
cfqq->prio_pending++;
|
2006-07-22 23:42:19 +00:00
|
|
|
|
2011-07-12 12:24:35 +00:00
|
|
|
cfq_update_io_thinktime(cfqd, cfqq, cic);
|
2009-10-23 21:14:49 +00:00
|
|
|
cfq_update_io_seektime(cfqd, cfqq, rq);
|
2005-08-24 12:57:54 +00:00
|
|
|
cfq_update_idle_window(cfqd, cfqq, cic);
|
|
|
|
|
2009-10-23 21:14:49 +00:00
|
|
|
cfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
|
|
|
if (cfqq == cfqd->active_queue) {
|
|
|
|
/*
|
2009-04-07 09:38:31 +00:00
|
|
|
* Remember that we saw a request from this process, but
|
|
|
|
* don't start queuing just yet. Otherwise we risk seeing lots
|
|
|
|
* of tiny requests, because we disrupt the normal plugging
|
2009-04-14 12:18:16 +00:00
|
|
|
* and merging. If the request is already larger than a single
|
|
|
|
* page, let it rip immediately. For that case we assume that
|
2009-04-15 10:12:46 +00:00
|
|
|
* merging is already done. Ditto for a busy system that
|
|
|
|
* has other work pending, don't risk delaying until the
|
|
|
|
* idle timer unplug to continue working.
|
2005-06-27 08:55:12 +00:00
|
|
|
*/
|
2009-04-14 12:18:16 +00:00
|
|
|
if (cfq_cfqq_wait_request(cfqq)) {
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 12:29:47 +00:00
|
|
|
if (blk_rq_bytes(rq) > PAGE_SIZE ||
|
2009-04-15 10:12:46 +00:00
|
|
|
cfqd->busy_queues > 1) {
|
2010-04-09 04:15:35 +00:00
|
|
|
cfq_del_timer(cfqd, cfqq);
|
2009-12-10 08:38:39 +00:00
|
|
|
cfq_clear_cfqq_wait_request(cfqq);
|
2011-04-18 09:41:33 +00:00
|
|
|
__blk_run_queue(cfqd->queue);
|
2010-04-13 17:59:17 +00:00
|
|
|
} else {
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_idle_time(cfqq->cfqg);
|
2009-12-03 17:59:37 +00:00
|
|
|
cfq_mark_cfqq_must_dispatch(cfqq);
|
2010-04-13 17:59:17 +00:00
|
|
|
}
|
2009-04-14 12:18:16 +00:00
|
|
|
}
|
2006-07-13 10:39:25 +00:00
|
|
|
} else if (cfq_should_preempt(cfqd, cfqq, rq)) {
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* not the active queue - expire current slice if it is
|
|
|
|
* idle and has expired it's mean thinktime or this new queue
|
2009-01-30 11:46:41 +00:00
|
|
|
* has some old slice time left and is of higher priority or
|
|
|
|
* this new queue is RT and the current one is BE
|
2005-06-27 08:55:12 +00:00
|
|
|
*/
|
|
|
|
cfq_preempt_queue(cfqd, cfqq);
|
2011-04-18 09:41:33 +00:00
|
|
|
__blk_run_queue(cfqd->queue);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-24 07:28:11 +00:00
|
|
|
static void cfq_insert_request(struct request_queue *q, struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-10-20 14:42:29 +00:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "insert_request");
|
2012-03-19 22:10:57 +00:00
|
|
|
cfq_init_prio_data(cfqq, RQ_CIC(rq));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-08 14:55:34 +00:00
|
|
|
rq->fifo_time = ktime_get_ns() + cfqd->cfq_fifo_expire[rq_is_sync(rq)];
|
2005-06-27 08:55:12 +00:00
|
|
|
list_add_tail(&rq->queuelist, &cfqq->fifo);
|
2009-10-26 21:44:33 +00:00
|
|
|
cfq_add_rq_rb(rq);
|
2016-10-28 14:48:16 +00:00
|
|
|
cfqg_stats_update_io_add(RQ_CFQG(rq), cfqd->serving_group,
|
2012-04-01 21:38:44 +00:00
|
|
|
rq->cmd_flags);
|
2006-07-13 10:39:25 +00:00
|
|
|
cfq_rq_enqueued(cfqd, cfqq, rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-08-26 13:52:36 +00:00
|
|
|
/*
|
|
|
|
* Update hw_tag based on peak queue depth over 50 samples under
|
|
|
|
* sufficient load.
|
|
|
|
*/
|
|
|
|
static void cfq_update_hw_tag(struct cfq_data *cfqd)
|
|
|
|
{
|
2009-10-27 07:46:23 +00:00
|
|
|
struct cfq_queue *cfqq = cfqd->active_queue;
|
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
if (cfqd->rq_in_driver > cfqd->hw_tag_est_depth)
|
|
|
|
cfqd->hw_tag_est_depth = cfqd->rq_in_driver;
|
cfq-iosched: fix ncq detection code
CFQ's detection of queueing devices initially assumes a queuing device
and detects if the queue depth reaches a certain threshold.
However, it will reconsider this choice periodically.
Unfortunately, if device is considered not queuing, CFQ will force a
unit queue depth for some workloads, thus defeating the detection logic.
This leads to poor performance on queuing hardware,
since the idle window remains enabled.
Given this premise, switching to hw_tag = 0 after we have proved at
least once that the device is NCQ capable is not a good choice.
The new detection code starts in an indeterminate state, in which CFQ behaves
as if hw_tag = 1, and then, if for a long observation period we never saw
large depth, we switch to hw_tag = 0, otherwise we stick to hw_tag = 1,
without reconsidering it again.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-26 09:02:57 +00:00
|
|
|
|
|
|
|
if (cfqd->hw_tag == 1)
|
|
|
|
return;
|
2008-08-26 13:52:36 +00:00
|
|
|
|
|
|
|
if (cfqd->rq_queued <= CFQ_HW_QUEUE_MIN &&
|
2010-02-28 18:45:05 +00:00
|
|
|
cfqd->rq_in_driver <= CFQ_HW_QUEUE_MIN)
|
2008-08-26 13:52:36 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-27 07:46:23 +00:00
|
|
|
/*
|
|
|
|
* If active queue hasn't enough requests and can idle, cfq might not
|
|
|
|
* dispatch sufficient requests to hardware. Don't zero hw_tag in this
|
|
|
|
* case
|
|
|
|
*/
|
|
|
|
if (cfqq && cfq_cfqq_idle_window(cfqq) &&
|
|
|
|
cfqq->dispatched + cfqq->queued[0] + cfqq->queued[1] <
|
2010-02-28 18:45:05 +00:00
|
|
|
CFQ_HW_QUEUE_MIN && cfqd->rq_in_driver < CFQ_HW_QUEUE_MIN)
|
2009-10-27 07:46:23 +00:00
|
|
|
return;
|
|
|
|
|
2008-08-26 13:52:36 +00:00
|
|
|
if (cfqd->hw_tag_samples++ < 50)
|
|
|
|
return;
|
|
|
|
|
cfq-iosched: fix ncq detection code
CFQ's detection of queueing devices initially assumes a queuing device
and detects if the queue depth reaches a certain threshold.
However, it will reconsider this choice periodically.
Unfortunately, if device is considered not queuing, CFQ will force a
unit queue depth for some workloads, thus defeating the detection logic.
This leads to poor performance on queuing hardware,
since the idle window remains enabled.
Given this premise, switching to hw_tag = 0 after we have proved at
least once that the device is NCQ capable is not a good choice.
The new detection code starts in an indeterminate state, in which CFQ behaves
as if hw_tag = 1, and then, if for a long observation period we never saw
large depth, we switch to hw_tag = 0, otherwise we stick to hw_tag = 1,
without reconsidering it again.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-26 09:02:57 +00:00
|
|
|
if (cfqd->hw_tag_est_depth >= CFQ_HW_QUEUE_MIN)
|
2008-08-26 13:52:36 +00:00
|
|
|
cfqd->hw_tag = 1;
|
|
|
|
else
|
|
|
|
cfqd->hw_tag = 0;
|
|
|
|
}
|
|
|
|
|
2009-12-08 22:52:58 +00:00
|
|
|
static bool cfq_should_wait_busy(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic = cfqd->active_cic;
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2009-12-08 22:52:58 +00:00
|
|
|
|
2011-02-09 13:20:03 +00:00
|
|
|
/* If the queue already has requests, don't wait */
|
|
|
|
if (!RB_EMPTY_ROOT(&cfqq->sort_list))
|
|
|
|
return false;
|
|
|
|
|
2009-12-08 22:52:58 +00:00
|
|
|
/* If there are other queues in the group, don't wait */
|
|
|
|
if (cfqq->cfqg->nr_cfqq > 1)
|
|
|
|
return false;
|
|
|
|
|
2011-07-12 12:24:56 +00:00
|
|
|
/* the only queue in the group, but think time is big */
|
|
|
|
if (cfq_io_thinktime_big(cfqd, &cfqq->cfqg->ttime, true))
|
|
|
|
return false;
|
|
|
|
|
2009-12-08 22:52:58 +00:00
|
|
|
if (cfq_slice_used(cfqq))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* if slice left is less than think time, wait busy */
|
2011-07-12 12:24:35 +00:00
|
|
|
if (cic && sample_valid(cic->ttime.ttime_samples)
|
2016-06-08 14:55:34 +00:00
|
|
|
&& (cfqq->slice_end - now < cic->ttime.ttime_mean))
|
2009-12-08 22:52:58 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If think times is less than a jiffy than ttime_mean=0 and above
|
|
|
|
* will not be true. It might happen that slice has not expired yet
|
|
|
|
* but will expire soon (4-5 ns) during select_queue(). To cover the
|
|
|
|
* case where think time is less than a jiffy, mark the queue wait
|
|
|
|
* busy if only 1 jiffy is left in the slice.
|
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
if (cfqq->slice_end - now <= jiffies_to_nsecs(1))
|
2009-12-08 22:52:58 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-24 07:28:11 +00:00
|
|
|
static void cfq_completed_request(struct request_queue *q, struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-10-20 14:42:29 +00:00
|
|
|
struct cfq_data *cfqd = cfqq->cfqd;
|
2006-07-13 10:37:56 +00:00
|
|
|
const int sync = rq_is_sync(rq);
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 now = ktime_get_ns();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-11-01 13:40:09 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "complete rqnoidle %d", req_noidle(rq));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-08-26 13:52:36 +00:00
|
|
|
cfq_update_hw_tag(cfqd);
|
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
WARN_ON(!cfqd->rq_in_driver);
|
2007-04-25 10:44:27 +00:00
|
|
|
WARN_ON(!cfqq->dispatched);
|
2010-02-28 18:45:05 +00:00
|
|
|
cfqd->rq_in_driver--;
|
2007-04-25 10:44:27 +00:00
|
|
|
cfqq->dispatched--;
|
2010-08-23 10:24:26 +00:00
|
|
|
(RQ_CFQG(rq))->dispatched--;
|
2012-04-01 21:38:44 +00:00
|
|
|
cfqg_stats_update_completion(cfqq->cfqg, rq_start_time_ns(rq),
|
2016-10-28 14:48:16 +00:00
|
|
|
rq_io_start_time_ns(rq), rq->cmd_flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]--;
|
2007-04-23 06:33:33 +00:00
|
|
|
|
2009-10-03 13:21:27 +00:00
|
|
|
if (sync) {
|
2012-10-03 20:56:58 +00:00
|
|
|
struct cfq_rb_root *st;
|
2011-07-12 12:24:55 +00:00
|
|
|
|
2011-07-12 12:24:35 +00:00
|
|
|
RQ_CIC(rq)->ttime.last_end_request = now;
|
2011-07-12 12:24:55 +00:00
|
|
|
|
|
|
|
if (cfq_cfqq_on_rr(cfqq))
|
2012-10-03 20:56:58 +00:00
|
|
|
st = cfqq->service_tree;
|
2011-07-12 12:24:55 +00:00
|
|
|
else
|
2012-10-03 20:56:58 +00:00
|
|
|
st = st_for(cfqq->cfqg, cfqq_class(cfqq),
|
|
|
|
cfqq_type(cfqq));
|
|
|
|
|
|
|
|
st->ttime.last_end_request = now;
|
2016-06-28 07:04:01 +00:00
|
|
|
/*
|
|
|
|
* We have to do this check in jiffies since start_time is in
|
|
|
|
* jiffies and it is not trivial to convert to ns. If
|
|
|
|
* cfq_fifo_expire[1] ever comes close to 1 jiffie, this test
|
|
|
|
* will become problematic but so far we are fine (the default
|
|
|
|
* is 128 ms).
|
|
|
|
*/
|
|
|
|
if (!time_after(rq->start_time +
|
|
|
|
nsecs_to_jiffies(cfqd->cfq_fifo_expire[1]),
|
|
|
|
jiffies))
|
2009-12-06 10:48:52 +00:00
|
|
|
cfqd->last_delayed_sync = now;
|
2009-10-03 13:21:27 +00:00
|
|
|
}
|
2006-06-16 09:23:00 +00:00
|
|
|
|
2011-07-12 12:24:56 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
cfqq->cfqg->ttime.last_end_request = now;
|
|
|
|
#endif
|
|
|
|
|
2006-06-16 09:23:00 +00:00
|
|
|
/*
|
|
|
|
* If this is the active queue, check if it needs to be expired,
|
|
|
|
* or if we want to idle in case it has no pending requests.
|
|
|
|
*/
|
|
|
|
if (cfqd->active_queue == cfqq) {
|
2009-04-15 10:15:11 +00:00
|
|
|
const bool cfqq_empty = RB_EMPTY_ROOT(&cfqq->sort_list);
|
|
|
|
|
2007-01-19 00:51:58 +00:00
|
|
|
if (cfq_cfqq_slice_new(cfqq)) {
|
|
|
|
cfq_set_prio_slice(cfqd, cfqq);
|
|
|
|
cfq_clear_cfqq_slice_new(cfqq);
|
|
|
|
}
|
2009-12-03 17:59:53 +00:00
|
|
|
|
|
|
|
/*
|
2009-12-08 22:52:58 +00:00
|
|
|
* Should we wait for next request to come in before we expire
|
|
|
|
* the queue.
|
2009-12-03 17:59:53 +00:00
|
|
|
*/
|
2009-12-08 22:52:58 +00:00
|
|
|
if (cfq_should_wait_busy(cfqd, cfqq)) {
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 extend_sl = cfqd->cfq_slice_idle;
|
2010-08-23 10:24:26 +00:00
|
|
|
if (!cfqd->cfq_slice_idle)
|
|
|
|
extend_sl = cfqd->cfq_group_idle;
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqq->slice_end = now + extend_sl;
|
2009-12-03 17:59:53 +00:00
|
|
|
cfq_mark_cfqq_wait_busy(cfqq);
|
2010-03-25 14:45:03 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "will busy wait");
|
2009-12-03 17:59:53 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 10:15:11 +00:00
|
|
|
/*
|
2009-11-26 09:02:58 +00:00
|
|
|
* Idling is not enabled on:
|
|
|
|
* - expired queues
|
|
|
|
* - idle-priority queues
|
|
|
|
* - async queues
|
|
|
|
* - queues with still some requests queued
|
|
|
|
* - when there is a close cooperator
|
2009-04-15 10:15:11 +00:00
|
|
|
*/
|
2008-01-28 10:38:15 +00:00
|
|
|
if (cfq_slice_used(cfqq) || cfq_class_idle(cfqq))
|
2010-04-26 17:25:11 +00:00
|
|
|
cfq_slice_expired(cfqd, 1);
|
2009-11-26 09:02:58 +00:00
|
|
|
else if (sync && cfqq_empty &&
|
|
|
|
!cfq_close_cooperator(cfqd, cfqq)) {
|
2010-09-20 13:24:50 +00:00
|
|
|
cfq_arm_slice_timer(cfqd);
|
2009-11-26 09:02:58 +00:00
|
|
|
}
|
2006-06-16 09:23:00 +00:00
|
|
|
}
|
2007-04-25 10:44:27 +00:00
|
|
|
|
2010-02-28 18:45:05 +00:00
|
|
|
if (!cfqd->rq_in_driver)
|
2009-10-05 06:52:35 +00:00
|
|
|
cfq_schedule_dispatch(cfqd);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2016-10-28 14:48:16 +00:00
|
|
|
static void cfqq_boost_on_prio(struct cfq_queue *cfqq, unsigned int op)
|
2016-06-09 21:47:29 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If REQ_PRIO is set, boost class and prio level, if it's below
|
|
|
|
* BE/NORM. If prio is not set, restore the potentially boosted
|
|
|
|
* class/prio level.
|
|
|
|
*/
|
2016-10-28 14:48:16 +00:00
|
|
|
if (!(op & REQ_PRIO)) {
|
2016-06-09 21:47:29 +00:00
|
|
|
cfqq->ioprio_class = cfqq->org_ioprio_class;
|
|
|
|
cfqq->ioprio = cfqq->org_ioprio;
|
|
|
|
} else {
|
|
|
|
if (cfq_class_idle(cfqq))
|
|
|
|
cfqq->ioprio_class = IOPRIO_CLASS_BE;
|
|
|
|
if (cfqq->ioprio > IOPRIO_NORM)
|
|
|
|
cfqq->ioprio = IOPRIO_NORM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-22 14:48:31 +00:00
|
|
|
static inline int __cfq_may_queue(struct cfq_queue *cfqq)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2009-08-11 06:26:11 +00:00
|
|
|
if (cfq_cfqq_wait_request(cfqq) && !cfq_cfqq_must_alloc_slice(cfqq)) {
|
2005-06-27 08:56:24 +00:00
|
|
|
cfq_mark_cfqq_must_alloc_slice(cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
return ELV_MQUEUE_MUST;
|
2005-06-27 08:56:24 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
return ELV_MQUEUE_MAY;
|
|
|
|
}
|
|
|
|
|
2016-10-28 14:48:16 +00:00
|
|
|
static int cfq_may_queue(struct request_queue *q, unsigned int op)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
struct task_struct *tsk = current;
|
2011-12-13 23:33:41 +00:00
|
|
|
struct cfq_io_cq *cic;
|
2005-06-27 08:55:12 +00:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* don't force setup of a queue from here, as a call to may_queue
|
|
|
|
* does not necessarily imply that a request actually will be queued.
|
|
|
|
* so just lookup a possibly existing queue, or return 'may queue'
|
|
|
|
* if that fails
|
|
|
|
*/
|
2008-01-24 07:44:49 +00:00
|
|
|
cic = cfq_cic_lookup(cfqd, tsk->io_context);
|
2007-04-25 10:29:51 +00:00
|
|
|
if (!cic)
|
|
|
|
return ELV_MQUEUE_MAY;
|
|
|
|
|
2016-10-28 14:48:16 +00:00
|
|
|
cfqq = cic_to_cfqq(cic, op_is_sync(op));
|
2005-06-27 08:55:12 +00:00
|
|
|
if (cfqq) {
|
2012-03-19 22:10:57 +00:00
|
|
|
cfq_init_prio_data(cfqq, cic);
|
2016-10-28 14:48:16 +00:00
|
|
|
cfqq_boost_on_prio(cfqq, op);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2006-07-22 14:48:31 +00:00
|
|
|
return __cfq_may_queue(cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ELV_MQUEUE_MAY;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* queue lock held here
|
|
|
|
*/
|
2006-12-01 09:42:33 +00:00
|
|
|
static void cfq_put_request(struct request *rq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-07-13 10:39:25 +00:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-13 10:39:25 +00:00
|
|
|
if (cfqq) {
|
2005-06-27 08:55:12 +00:00
|
|
|
const int rw = rq_data_dir(rq);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
BUG_ON(!cfqq->allocated[rw]);
|
|
|
|
cfqq->allocated[rw]--;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-04-21 15:44:16 +00:00
|
|
|
/* Put down rq reference on cfqg */
|
2012-03-23 13:02:53 +00:00
|
|
|
cfqg_put(RQ_CFQG(rq));
|
2011-12-13 23:33:41 +00:00
|
|
|
rq->elv.priv[0] = NULL;
|
|
|
|
rq->elv.priv[1] = NULL;
|
2010-04-21 15:44:16 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-23 21:14:50 +00:00
|
|
|
static struct cfq_queue *
|
2011-12-13 23:33:41 +00:00
|
|
|
cfq_merge_cfqqs(struct cfq_data *cfqd, struct cfq_io_cq *cic,
|
2009-10-23 21:14:50 +00:00
|
|
|
struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
cfq_log_cfqq(cfqd, cfqq, "merging with queue %p", cfqq->new_cfqq);
|
|
|
|
cic_set_cfqq(cic, cfqq->new_cfqq, 1);
|
2009-10-23 21:14:51 +00:00
|
|
|
cfq_mark_cfqq_coop(cfqq->new_cfqq);
|
2009-10-23 21:14:50 +00:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
return cic_to_cfqq(cic, 1);
|
|
|
|
}
|
|
|
|
|
2009-10-23 21:14:52 +00:00
|
|
|
/*
|
|
|
|
* Returns NULL if a new cfqq should be allocated, or the old cfqq if this
|
|
|
|
* was the last process referring to said cfqq.
|
|
|
|
*/
|
|
|
|
static struct cfq_queue *
|
2011-12-13 23:33:41 +00:00
|
|
|
split_cfqq(struct cfq_io_cq *cic, struct cfq_queue *cfqq)
|
2009-10-23 21:14:52 +00:00
|
|
|
{
|
|
|
|
if (cfqq_process_refs(cfqq) == 1) {
|
|
|
|
cfqq->pid = current->pid;
|
|
|
|
cfq_clear_cfqq_coop(cfqq);
|
2010-02-05 12:11:45 +00:00
|
|
|
cfq_clear_cfqq_split_coop(cfqq);
|
2009-10-23 21:14:52 +00:00
|
|
|
return cfqq;
|
|
|
|
}
|
|
|
|
|
|
|
|
cic_set_cfqq(cic, NULL, 1);
|
2010-05-25 08:16:53 +00:00
|
|
|
|
|
|
|
cfq_put_cooperator(cfqq);
|
|
|
|
|
2009-10-23 21:14:52 +00:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2005-06-27 08:55:12 +00:00
|
|
|
* Allocate cfq data structures associated with this request.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2005-06-27 08:55:12 +00:00
|
|
|
static int
|
2012-03-05 21:15:27 +00:00
|
|
|
cfq_set_request(struct request_queue *q, struct request *rq, struct bio *bio,
|
|
|
|
gfp_t gfp_mask)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2011-12-13 23:33:42 +00:00
|
|
|
struct cfq_io_cq *cic = icq_to_cic(rq->elv.icq);
|
2005-04-16 22:20:36 +00:00
|
|
|
const int rw = rq_data_dir(rq);
|
2009-10-07 18:02:57 +00:00
|
|
|
const bool is_sync = rq_is_sync(rq);
|
2005-06-27 08:55:12 +00:00
|
|
|
struct cfq_queue *cfqq;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-12-13 23:33:38 +00:00
|
|
|
spin_lock_irq(q->queue_lock);
|
2011-12-13 23:33:42 +00:00
|
|
|
|
2012-03-19 22:10:58 +00:00
|
|
|
check_ioprio_changed(cic, bio);
|
|
|
|
check_blkcg_changed(cic, bio);
|
2009-10-23 21:14:52 +00:00
|
|
|
new_queue:
|
2007-04-25 10:29:51 +00:00
|
|
|
cfqq = cic_to_cfqq(cic, is_sync);
|
2009-07-09 20:13:16 +00:00
|
|
|
if (!cfqq || cfqq == &cfqd->oom_cfqq) {
|
2015-08-18 21:54:59 +00:00
|
|
|
if (cfqq)
|
|
|
|
cfq_put_queue(cfqq);
|
2015-08-18 21:55:02 +00:00
|
|
|
cfqq = cfq_get_queue(cfqd, is_sync, cic, bio);
|
2007-04-25 10:29:51 +00:00
|
|
|
cic_set_cfqq(cic, cfqq, is_sync);
|
2009-10-23 21:14:50 +00:00
|
|
|
} else {
|
2009-10-23 21:14:52 +00:00
|
|
|
/*
|
|
|
|
* If the queue was seeky for too long, break it apart.
|
|
|
|
*/
|
2010-02-05 12:11:45 +00:00
|
|
|
if (cfq_cfqq_coop(cfqq) && cfq_cfqq_split_coop(cfqq)) {
|
2009-10-23 21:14:52 +00:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "breaking apart cfqq");
|
|
|
|
cfqq = split_cfqq(cic, cfqq);
|
|
|
|
if (!cfqq)
|
|
|
|
goto new_queue;
|
|
|
|
}
|
|
|
|
|
2009-10-23 21:14:50 +00:00
|
|
|
/*
|
|
|
|
* Check to see if this queue is scheduled to merge with
|
|
|
|
* another, closely cooperating queue. The merging of
|
|
|
|
* queues happens here as it must be done in process context.
|
|
|
|
* The reference on new_cfqq was taken in merge_cfqqs.
|
|
|
|
*/
|
|
|
|
if (cfqq->new_cfqq)
|
|
|
|
cfqq = cfq_merge_cfqqs(cfqd, cic, cfqq);
|
2007-04-25 10:29:51 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
cfqq->allocated[rw]++;
|
|
|
|
|
2011-03-01 20:04:39 +00:00
|
|
|
cfqq->ref++;
|
2012-03-23 13:02:53 +00:00
|
|
|
cfqg_get(cfqq->cfqg);
|
2011-12-13 23:33:41 +00:00
|
|
|
rq->elv.priv[0] = cfqq;
|
2012-03-05 21:15:15 +00:00
|
|
|
rq->elv.priv[1] = cfqq->cfqg;
|
2011-12-13 23:33:38 +00:00
|
|
|
spin_unlock_irq(q->queue_lock);
|
2006-07-13 10:39:25 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-11-22 14:55:48 +00:00
|
|
|
static void cfq_kick_queue(struct work_struct *work)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2006-11-22 14:55:48 +00:00
|
|
|
struct cfq_data *cfqd =
|
2009-10-05 06:52:35 +00:00
|
|
|
container_of(work, struct cfq_data, unplug_work);
|
2007-07-24 07:28:11 +00:00
|
|
|
struct request_queue *q = cfqd->queue;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2009-04-15 10:11:10 +00:00
|
|
|
spin_lock_irq(q->queue_lock);
|
2011-04-18 09:41:33 +00:00
|
|
|
__blk_run_queue(cfqd->queue);
|
2009-04-15 10:11:10 +00:00
|
|
|
spin_unlock_irq(q->queue_lock);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timer running if the active_queue is currently idling inside its time slice
|
|
|
|
*/
|
2016-06-08 13:11:39 +00:00
|
|
|
static enum hrtimer_restart cfq_idle_slice_timer(struct hrtimer *timer)
|
2005-06-27 08:55:12 +00:00
|
|
|
{
|
2016-06-08 13:11:39 +00:00
|
|
|
struct cfq_data *cfqd = container_of(timer, struct cfq_data,
|
|
|
|
idle_slice_timer);
|
2005-06-27 08:55:12 +00:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
unsigned long flags;
|
2007-01-19 01:06:33 +00:00
|
|
|
int timed_out = 1;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2008-05-30 10:23:07 +00:00
|
|
|
cfq_log(cfqd, "idle timer fired");
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
spin_lock_irqsave(cfqd->queue->queue_lock, flags);
|
|
|
|
|
2008-01-31 12:08:54 +00:00
|
|
|
cfqq = cfqd->active_queue;
|
|
|
|
if (cfqq) {
|
2007-01-19 01:06:33 +00:00
|
|
|
timed_out = 0;
|
|
|
|
|
2009-04-07 09:38:31 +00:00
|
|
|
/*
|
|
|
|
* We saw a request before the queue expired, let it through
|
|
|
|
*/
|
|
|
|
if (cfq_cfqq_must_dispatch(cfqq))
|
|
|
|
goto out_kick;
|
|
|
|
|
2005-06-27 08:55:12 +00:00
|
|
|
/*
|
|
|
|
* expired
|
|
|
|
*/
|
2007-01-19 00:51:58 +00:00
|
|
|
if (cfq_slice_used(cfqq))
|
2005-06-27 08:55:12 +00:00
|
|
|
goto expire;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* only expire and reinvoke request handler, if there are
|
|
|
|
* other queues with pending requests
|
|
|
|
*/
|
2006-06-16 09:23:00 +00:00
|
|
|
if (!cfqd->busy_queues)
|
2005-06-27 08:55:12 +00:00
|
|
|
goto out_cont;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* not expired and it has a request pending, let it dispatch
|
|
|
|
*/
|
2009-04-07 06:56:14 +00:00
|
|
|
if (!RB_EMPTY_ROOT(&cfqq->sort_list))
|
2005-06-27 08:55:12 +00:00
|
|
|
goto out_kick;
|
2009-11-26 09:02:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue depth flag is reset only when the idle didn't succeed
|
|
|
|
*/
|
|
|
|
cfq_clear_cfqq_deep(cfqq);
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
expire:
|
2010-04-26 17:25:11 +00:00
|
|
|
cfq_slice_expired(cfqd, timed_out);
|
2005-06-27 08:55:12 +00:00
|
|
|
out_kick:
|
2009-10-05 06:52:35 +00:00
|
|
|
cfq_schedule_dispatch(cfqd);
|
2005-06-27 08:55:12 +00:00
|
|
|
out_cont:
|
|
|
|
spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
|
2016-06-08 13:11:39 +00:00
|
|
|
return HRTIMER_NORESTART;
|
2005-06-27 08:55:12 +00:00
|
|
|
}
|
|
|
|
|
2005-06-27 08:56:24 +00:00
|
|
|
static void cfq_shutdown_timer_wq(struct cfq_data *cfqd)
|
|
|
|
{
|
2016-06-08 13:11:39 +00:00
|
|
|
hrtimer_cancel(&cfqd->idle_slice_timer);
|
2009-10-05 06:52:35 +00:00
|
|
|
cancel_work_sync(&cfqd->unplug_work);
|
2005-06-27 08:56:24 +00:00
|
|
|
}
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2008-10-31 09:05:07 +00:00
|
|
|
static void cfq_exit_queue(struct elevator_queue *e)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-06-27 08:55:12 +00:00
|
|
|
struct cfq_data *cfqd = e->elevator_data;
|
2007-07-24 07:28:11 +00:00
|
|
|
struct request_queue *q = cfqd->queue;
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2005-06-27 08:56:24 +00:00
|
|
|
cfq_shutdown_timer_wq(cfqd);
|
2006-03-28 06:59:01 +00:00
|
|
|
|
2006-03-18 18:51:22 +00:00
|
|
|
spin_lock_irq(q->queue_lock);
|
2006-03-28 06:59:01 +00:00
|
|
|
|
2006-03-18 18:51:22 +00:00
|
|
|
if (cfqd->active_queue)
|
2010-04-26 17:25:11 +00:00
|
|
|
__cfq_slice_expired(cfqd, cfqd->active_queue, 0);
|
2006-03-28 06:59:01 +00:00
|
|
|
|
2012-03-05 21:15:19 +00:00
|
|
|
spin_unlock_irq(q->queue_lock);
|
|
|
|
|
2006-03-18 17:05:37 +00:00
|
|
|
cfq_shutdown_timer_wq(cfqd);
|
|
|
|
|
block: blkcg_policy_cfq shouldn't be used if !CONFIG_CFQ_GROUP_IOSCHED
cfq may be built w/ or w/o blkcg support depending on
CONFIG_CFQ_CGROUP_IOSCHED. If blkcg support is disabled, most of
related code is ifdef'd out but some part is left dangling -
blkcg_policy_cfq is left zero-filled and blkcg_policy_[un]register()
calls are made on it.
Feeding zero filled policy to blkcg_policy_register() is incorrect and
triggers the following WARN_ON() if CONFIG_BLK_CGROUP &&
!CONFIG_CFQ_GROUP_IOSCHED.
------------[ cut here ]------------
WARNING: at block/blk-cgroup.c:867
Modules linked in:
Modules linked in:
CPU: 3 Not tainted 3.4.0-09547-gfb21aff #1
Process swapper/0 (pid: 1, task: 000000003ff80000, ksp: 000000003ff7f8b8)
Krnl PSW : 0704100180000000 00000000003d76ca (blkcg_policy_register+0xca/0xe0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0 EA:3
Krnl GPRS: 0000000000000000 00000000014b85ec 00000000014b85b0 0000000000000000
000000000096fb60 0000000000000000 00000000009a8e78 0000000000000048
000000000099c070 0000000000b6f000 0000000000000000 000000000099c0b8
00000000014b85b0 0000000000667580 000000003ff7fd98 000000003ff7fd70
Krnl Code: 00000000003d76be: a7280001 lhi %r2,1
00000000003d76c2: a7f4ffdf brc 15,3d7680
#00000000003d76c6: a7f40001 brc 15,3d76c8
>00000000003d76ca: a7c8ffea lhi %r12,-22
00000000003d76ce: a7f4ffce brc 15,3d766a
00000000003d76d2: a7f40001 brc 15,3d76d4
00000000003d76d6: a7c80000 lhi %r12,0
00000000003d76da: a7f4ffc2 brc 15,3d765e
Call Trace:
([<0000000000b6f000>] initcall_debug+0x0/0x4)
[<0000000000989e8a>] cfq_init+0x62/0xd4
[<00000000001000ba>] do_one_initcall+0x3a/0x170
[<000000000096fb60>] kernel_init+0x214/0x2bc
[<0000000000623202>] kernel_thread_starter+0x6/0xc
[<00000000006231fc>] kernel_thread_starter+0x0/0xc
no locks held by swapper/0/1.
Last Breaking-Event-Address:
[<00000000003d76c6>] blkcg_policy_register+0xc6/0xe0
---[ end trace b8ef4903fcbf9dd3 ]---
This patch fixes the problem by ensuring all blkcg support code is
inside CONFIG_CFQ_GROUP_IOSCHED.
* blkcg_policy_cfq declaration and blkg_to_cfqg() definition are moved
inside the first CONFIG_CFQ_GROUP_IOSCHED block. __maybe_unused is
dropped from blkcg_policy_cfq decl.
* blkcg_deactivate_poilcy() invocation is moved inside ifdef. This
also makes the activation logic match cfq_init_queue().
* All blkcg_policy_[un]register() invocations are moved inside ifdef.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
LKML-Reference: <20120601112954.GC3535@osiris.boeblingen.de.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-06-04 08:02:29 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
blkcg_deactivate_policy(q, &blkcg_policy_cfq);
|
|
|
|
#else
|
2012-03-05 21:15:05 +00:00
|
|
|
kfree(cfqd->root_group);
|
2011-05-23 08:02:19 +00:00
|
|
|
#endif
|
2011-05-19 19:38:22 +00:00
|
|
|
kfree(cfqd);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-07-03 11:25:24 +00:00
|
|
|
static int cfq_init_queue(struct request_queue *q, struct elevator_type *e)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd;
|
2012-04-16 20:57:25 +00:00
|
|
|
struct blkcg_gq *blkg __maybe_unused;
|
2012-04-13 20:11:33 +00:00
|
|
|
int i, ret;
|
2013-07-03 11:25:24 +00:00
|
|
|
struct elevator_queue *eq;
|
|
|
|
|
|
|
|
eq = elevator_alloc(q, e);
|
|
|
|
if (!eq)
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-08-29 22:21:42 +00:00
|
|
|
cfqd = kzalloc_node(sizeof(*cfqd), GFP_KERNEL, q->node);
|
2013-07-03 11:25:24 +00:00
|
|
|
if (!cfqd) {
|
|
|
|
kobject_put(&eq->kobj);
|
2012-03-05 21:14:57 +00:00
|
|
|
return -ENOMEM;
|
2013-07-03 11:25:24 +00:00
|
|
|
}
|
|
|
|
eq->elevator_data = cfqd;
|
2010-05-20 19:21:41 +00:00
|
|
|
|
2012-03-05 21:15:05 +00:00
|
|
|
cfqd->queue = q;
|
2013-07-03 11:25:24 +00:00
|
|
|
spin_lock_irq(q->queue_lock);
|
|
|
|
q->elevator = eq;
|
|
|
|
spin_unlock_irq(q->queue_lock);
|
2012-03-05 21:15:05 +00:00
|
|
|
|
2009-12-03 17:59:41 +00:00
|
|
|
/* Init root service tree */
|
|
|
|
cfqd->grp_service_tree = CFQ_RB_ROOT;
|
|
|
|
|
2012-03-05 21:15:05 +00:00
|
|
|
/* Init root group and prefer root group over other groups by default */
|
2009-12-03 17:59:46 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 20:57:25 +00:00
|
|
|
ret = blkcg_activate_policy(q, &blkcg_policy_cfq);
|
2012-04-13 20:11:33 +00:00
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
2012-03-05 21:15:05 +00:00
|
|
|
|
2012-04-13 20:11:33 +00:00
|
|
|
cfqd->root_group = blkg_to_cfqg(q->root_blkg);
|
2012-03-05 21:15:05 +00:00
|
|
|
#else
|
2012-04-13 20:11:33 +00:00
|
|
|
ret = -ENOMEM;
|
2012-03-05 21:15:05 +00:00
|
|
|
cfqd->root_group = kzalloc_node(sizeof(*cfqd->root_group),
|
|
|
|
GFP_KERNEL, cfqd->queue->node);
|
2012-04-13 20:11:33 +00:00
|
|
|
if (!cfqd->root_group)
|
|
|
|
goto out_free;
|
2011-05-19 19:38:28 +00:00
|
|
|
|
2012-04-13 20:11:33 +00:00
|
|
|
cfq_init_cfqg_base(cfqd->root_group);
|
2015-08-18 21:55:35 +00:00
|
|
|
cfqd->root_group->weight = 2 * CFQ_WEIGHT_LEGACY_DFL;
|
|
|
|
cfqd->root_group->leaf_weight = 2 * CFQ_WEIGHT_LEGACY_DFL;
|
2015-08-18 21:55:36 +00:00
|
|
|
#endif
|
2011-05-19 19:38:28 +00:00
|
|
|
|
2009-04-23 10:13:27 +00:00
|
|
|
/*
|
|
|
|
* Not strictly needed (since RB_ROOT just clears the node and we
|
|
|
|
* zeroed cfqd on alloc), but better be safe in case someone decides
|
|
|
|
* to add magic to the rb code
|
|
|
|
*/
|
|
|
|
for (i = 0; i < CFQ_PRIO_LISTS; i++)
|
|
|
|
cfqd->prio_trees[i] = RB_ROOT;
|
|
|
|
|
2009-06-30 07:34:12 +00:00
|
|
|
/*
|
2015-08-18 21:55:04 +00:00
|
|
|
* Our fallback cfqq if cfq_get_queue() runs into OOM issues.
|
2009-06-30 07:34:12 +00:00
|
|
|
* Grab a permanent reference to it, so that the normal code flow
|
2012-03-05 21:15:05 +00:00
|
|
|
* will not attempt to free it. oom_cfqq is linked to root_group
|
|
|
|
* but shouldn't hold a reference as it'll never be unlinked. Lose
|
|
|
|
* the reference from linking right away.
|
2009-06-30 07:34:12 +00:00
|
|
|
*/
|
|
|
|
cfq_init_cfqq(cfqd, &cfqd->oom_cfqq, 1, 0);
|
2011-01-07 07:46:59 +00:00
|
|
|
cfqd->oom_cfqq.ref++;
|
2012-03-05 21:15:15 +00:00
|
|
|
|
|
|
|
spin_lock_irq(q->queue_lock);
|
2012-03-05 21:15:05 +00:00
|
|
|
cfq_link_cfqq_cfqg(&cfqd->oom_cfqq, cfqd->root_group);
|
2012-03-23 13:02:53 +00:00
|
|
|
cfqg_put(cfqd->root_group);
|
2012-03-05 21:15:15 +00:00
|
|
|
spin_unlock_irq(q->queue_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-08 13:11:39 +00:00
|
|
|
hrtimer_init(&cfqd->idle_slice_timer, CLOCK_MONOTONIC,
|
|
|
|
HRTIMER_MODE_REL);
|
2005-06-27 08:55:12 +00:00
|
|
|
cfqd->idle_slice_timer.function = cfq_idle_slice_timer;
|
|
|
|
|
2009-10-05 06:52:35 +00:00
|
|
|
INIT_WORK(&cfqd->unplug_work, cfq_kick_queue);
|
2005-06-27 08:55:12 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
cfqd->cfq_quantum = cfq_quantum;
|
2005-06-27 08:55:12 +00:00
|
|
|
cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0];
|
|
|
|
cfqd->cfq_fifo_expire[1] = cfq_fifo_expire[1];
|
2005-04-16 22:20:36 +00:00
|
|
|
cfqd->cfq_back_max = cfq_back_max;
|
|
|
|
cfqd->cfq_back_penalty = cfq_back_penalty;
|
2005-06-27 08:55:12 +00:00
|
|
|
cfqd->cfq_slice[0] = cfq_slice_async;
|
|
|
|
cfqd->cfq_slice[1] = cfq_slice_sync;
|
2012-04-01 21:33:39 +00:00
|
|
|
cfqd->cfq_target_latency = cfq_target_latency;
|
2005-06-27 08:55:12 +00:00
|
|
|
cfqd->cfq_slice_async_rq = cfq_slice_async_rq;
|
2015-06-10 14:01:20 +00:00
|
|
|
cfqd->cfq_slice_idle = cfq_slice_idle;
|
2010-08-23 10:24:26 +00:00
|
|
|
cfqd->cfq_group_idle = cfq_group_idle;
|
2009-10-03 17:42:18 +00:00
|
|
|
cfqd->cfq_latency = 1;
|
cfq-iosched: fix ncq detection code
CFQ's detection of queueing devices initially assumes a queuing device
and detects if the queue depth reaches a certain threshold.
However, it will reconsider this choice periodically.
Unfortunately, if device is considered not queuing, CFQ will force a
unit queue depth for some workloads, thus defeating the detection logic.
This leads to poor performance on queuing hardware,
since the idle window remains enabled.
Given this premise, switching to hw_tag = 0 after we have proved at
least once that the device is NCQ capable is not a good choice.
The new detection code starts in an indeterminate state, in which CFQ behaves
as if hw_tag = 1, and then, if for a long observation period we never saw
large depth, we switch to hw_tag = 0, otherwise we stick to hw_tag = 1,
without reconsidering it again.
Signed-off-by: Corrado Zoccolo <czoccolo@gmail.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-11-26 09:02:57 +00:00
|
|
|
cfqd->hw_tag = -1;
|
2009-12-09 19:56:04 +00:00
|
|
|
/*
|
|
|
|
* we optimistically start assuming sync ops weren't delayed in last
|
|
|
|
* second, in order to have larger depth for async operations.
|
|
|
|
*/
|
2016-06-08 14:55:34 +00:00
|
|
|
cfqd->last_delayed_sync = ktime_get_ns() - NSEC_PER_SEC;
|
2012-03-05 21:14:57 +00:00
|
|
|
return 0;
|
2012-04-13 20:11:33 +00:00
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree(cfqd);
|
2013-07-03 11:25:24 +00:00
|
|
|
kobject_put(&eq->kobj);
|
2012-04-13 20:11:33 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2015-06-10 14:01:20 +00:00
|
|
|
static void cfq_registered_queue(struct request_queue *q)
|
|
|
|
{
|
|
|
|
struct elevator_queue *e = q->elevator;
|
|
|
|
struct cfq_data *cfqd = e->elevator_data;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default to IOPS mode with no idling for SSDs
|
|
|
|
*/
|
|
|
|
if (blk_queue_nonrot(q))
|
|
|
|
cfqd->cfq_slice_idle = 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* sysfs parts below -->
|
|
|
|
*/
|
|
|
|
static ssize_t
|
|
|
|
cfq_var_show(unsigned int var, char *page)
|
|
|
|
{
|
2014-04-28 03:38:34 +00:00
|
|
|
return sprintf(page, "%u\n", var);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
cfq_var_store(unsigned int *var, const char *page, size_t count)
|
|
|
|
{
|
|
|
|
char *p = (char *) page;
|
|
|
|
|
|
|
|
*var = simple_strtoul(p, &p, 10);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SHOW_FUNCTION(__FUNC, __VAR, __CONV) \
|
2008-10-31 09:05:07 +00:00
|
|
|
static ssize_t __FUNC(struct elevator_queue *e, char *page) \
|
2005-04-16 22:20:36 +00:00
|
|
|
{ \
|
2006-03-18 23:35:43 +00:00
|
|
|
struct cfq_data *cfqd = e->elevator_data; \
|
2016-06-08 14:55:34 +00:00
|
|
|
u64 __data = __VAR; \
|
2005-04-16 22:20:36 +00:00
|
|
|
if (__CONV) \
|
2016-06-08 14:55:34 +00:00
|
|
|
__data = div_u64(__data, NSEC_PER_MSEC); \
|
2005-04-16 22:20:36 +00:00
|
|
|
return cfq_var_show(__data, (page)); \
|
|
|
|
}
|
|
|
|
SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0);
|
2005-06-27 08:55:12 +00:00
|
|
|
SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1);
|
|
|
|
SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1);
|
2006-03-19 03:27:18 +00:00
|
|
|
SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0);
|
|
|
|
SHOW_FUNCTION(cfq_back_seek_penalty_show, cfqd->cfq_back_penalty, 0);
|
2005-06-27 08:55:12 +00:00
|
|
|
SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
|
2010-08-23 10:24:26 +00:00
|
|
|
SHOW_FUNCTION(cfq_group_idle_show, cfqd->cfq_group_idle, 1);
|
2005-06-27 08:55:12 +00:00
|
|
|
SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
|
|
|
|
SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
|
|
|
|
SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0);
|
2009-10-03 17:42:18 +00:00
|
|
|
SHOW_FUNCTION(cfq_low_latency_show, cfqd->cfq_latency, 0);
|
2012-04-01 21:33:39 +00:00
|
|
|
SHOW_FUNCTION(cfq_target_latency_show, cfqd->cfq_target_latency, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
#undef SHOW_FUNCTION
|
|
|
|
|
2016-06-08 13:11:38 +00:00
|
|
|
#define USEC_SHOW_FUNCTION(__FUNC, __VAR) \
|
|
|
|
static ssize_t __FUNC(struct elevator_queue *e, char *page) \
|
|
|
|
{ \
|
|
|
|
struct cfq_data *cfqd = e->elevator_data; \
|
|
|
|
u64 __data = __VAR; \
|
|
|
|
__data = div_u64(__data, NSEC_PER_USEC); \
|
|
|
|
return cfq_var_show(__data, (page)); \
|
|
|
|
}
|
|
|
|
USEC_SHOW_FUNCTION(cfq_slice_idle_us_show, cfqd->cfq_slice_idle);
|
|
|
|
USEC_SHOW_FUNCTION(cfq_group_idle_us_show, cfqd->cfq_group_idle);
|
|
|
|
USEC_SHOW_FUNCTION(cfq_slice_sync_us_show, cfqd->cfq_slice[1]);
|
|
|
|
USEC_SHOW_FUNCTION(cfq_slice_async_us_show, cfqd->cfq_slice[0]);
|
|
|
|
USEC_SHOW_FUNCTION(cfq_target_latency_us_show, cfqd->cfq_target_latency);
|
|
|
|
#undef USEC_SHOW_FUNCTION
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \
|
2008-10-31 09:05:07 +00:00
|
|
|
static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count) \
|
2005-04-16 22:20:36 +00:00
|
|
|
{ \
|
2006-03-18 23:35:43 +00:00
|
|
|
struct cfq_data *cfqd = e->elevator_data; \
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int __data; \
|
|
|
|
int ret = cfq_var_store(&__data, (page), count); \
|
|
|
|
if (__data < (MIN)) \
|
|
|
|
__data = (MIN); \
|
|
|
|
else if (__data > (MAX)) \
|
|
|
|
__data = (MAX); \
|
|
|
|
if (__CONV) \
|
2016-06-08 14:55:34 +00:00
|
|
|
*(__PTR) = (u64)__data * NSEC_PER_MSEC; \
|
2005-04-16 22:20:36 +00:00
|
|
|
else \
|
|
|
|
*(__PTR) = __data; \
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0);
|
2008-01-31 12:08:54 +00:00
|
|
|
STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1,
|
|
|
|
UINT_MAX, 1);
|
|
|
|
STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1,
|
|
|
|
UINT_MAX, 1);
|
2006-03-19 03:27:18 +00:00
|
|
|
STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
|
2008-01-31 12:08:54 +00:00
|
|
|
STORE_FUNCTION(cfq_back_seek_penalty_store, &cfqd->cfq_back_penalty, 1,
|
|
|
|
UINT_MAX, 0);
|
2005-06-27 08:55:12 +00:00
|
|
|
STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
|
2010-08-23 10:24:26 +00:00
|
|
|
STORE_FUNCTION(cfq_group_idle_store, &cfqd->cfq_group_idle, 0, UINT_MAX, 1);
|
2005-06-27 08:55:12 +00:00
|
|
|
STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1);
|
|
|
|
STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
|
2008-01-31 12:08:54 +00:00
|
|
|
STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1,
|
|
|
|
UINT_MAX, 0);
|
2009-10-03 17:42:18 +00:00
|
|
|
STORE_FUNCTION(cfq_low_latency_store, &cfqd->cfq_latency, 0, 1, 0);
|
2012-04-01 21:33:39 +00:00
|
|
|
STORE_FUNCTION(cfq_target_latency_store, &cfqd->cfq_target_latency, 1, UINT_MAX, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
#undef STORE_FUNCTION
|
|
|
|
|
2016-06-08 13:11:38 +00:00
|
|
|
#define USEC_STORE_FUNCTION(__FUNC, __PTR, MIN, MAX) \
|
|
|
|
static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count) \
|
|
|
|
{ \
|
|
|
|
struct cfq_data *cfqd = e->elevator_data; \
|
|
|
|
unsigned int __data; \
|
|
|
|
int ret = cfq_var_store(&__data, (page), count); \
|
|
|
|
if (__data < (MIN)) \
|
|
|
|
__data = (MIN); \
|
|
|
|
else if (__data > (MAX)) \
|
|
|
|
__data = (MAX); \
|
|
|
|
*(__PTR) = (u64)__data * NSEC_PER_USEC; \
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
USEC_STORE_FUNCTION(cfq_slice_idle_us_store, &cfqd->cfq_slice_idle, 0, UINT_MAX);
|
|
|
|
USEC_STORE_FUNCTION(cfq_group_idle_us_store, &cfqd->cfq_group_idle, 0, UINT_MAX);
|
|
|
|
USEC_STORE_FUNCTION(cfq_slice_sync_us_store, &cfqd->cfq_slice[1], 1, UINT_MAX);
|
|
|
|
USEC_STORE_FUNCTION(cfq_slice_async_us_store, &cfqd->cfq_slice[0], 1, UINT_MAX);
|
|
|
|
USEC_STORE_FUNCTION(cfq_target_latency_us_store, &cfqd->cfq_target_latency, 1, UINT_MAX);
|
|
|
|
#undef USEC_STORE_FUNCTION
|
|
|
|
|
2006-03-19 03:27:18 +00:00
|
|
|
#define CFQ_ATTR(name) \
|
|
|
|
__ATTR(name, S_IRUGO|S_IWUSR, cfq_##name##_show, cfq_##name##_store)
|
|
|
|
|
|
|
|
static struct elv_fs_entry cfq_attrs[] = {
|
|
|
|
CFQ_ATTR(quantum),
|
|
|
|
CFQ_ATTR(fifo_expire_sync),
|
|
|
|
CFQ_ATTR(fifo_expire_async),
|
|
|
|
CFQ_ATTR(back_seek_max),
|
|
|
|
CFQ_ATTR(back_seek_penalty),
|
|
|
|
CFQ_ATTR(slice_sync),
|
2016-06-08 13:11:38 +00:00
|
|
|
CFQ_ATTR(slice_sync_us),
|
2006-03-19 03:27:18 +00:00
|
|
|
CFQ_ATTR(slice_async),
|
2016-06-08 13:11:38 +00:00
|
|
|
CFQ_ATTR(slice_async_us),
|
2006-03-19 03:27:18 +00:00
|
|
|
CFQ_ATTR(slice_async_rq),
|
|
|
|
CFQ_ATTR(slice_idle),
|
2016-06-08 13:11:38 +00:00
|
|
|
CFQ_ATTR(slice_idle_us),
|
2010-08-23 10:24:26 +00:00
|
|
|
CFQ_ATTR(group_idle),
|
2016-06-08 13:11:38 +00:00
|
|
|
CFQ_ATTR(group_idle_us),
|
2009-10-03 17:42:18 +00:00
|
|
|
CFQ_ATTR(low_latency),
|
2012-04-01 21:33:39 +00:00
|
|
|
CFQ_ATTR(target_latency),
|
2016-06-08 13:11:38 +00:00
|
|
|
CFQ_ATTR(target_latency_us),
|
2006-03-19 03:27:18 +00:00
|
|
|
__ATTR_NULL
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct elevator_type iosched_cfq = {
|
2016-12-10 22:13:59 +00:00
|
|
|
.ops.sq = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.elevator_merge_fn = cfq_merge,
|
|
|
|
.elevator_merged_fn = cfq_merged_request,
|
|
|
|
.elevator_merge_req_fn = cfq_merged_requests,
|
2016-07-07 18:48:22 +00:00
|
|
|
.elevator_allow_bio_merge_fn = cfq_allow_bio_merge,
|
|
|
|
.elevator_allow_rq_merge_fn = cfq_allow_rq_merge,
|
2010-04-09 04:14:23 +00:00
|
|
|
.elevator_bio_merged_fn = cfq_bio_merged,
|
2005-10-20 14:42:29 +00:00
|
|
|
.elevator_dispatch_fn = cfq_dispatch_requests,
|
2005-04-16 22:20:36 +00:00
|
|
|
.elevator_add_req_fn = cfq_insert_request,
|
2005-10-20 14:42:29 +00:00
|
|
|
.elevator_activate_req_fn = cfq_activate_request,
|
2005-04-16 22:20:36 +00:00
|
|
|
.elevator_deactivate_req_fn = cfq_deactivate_request,
|
|
|
|
.elevator_completed_req_fn = cfq_completed_request,
|
2006-07-13 10:33:14 +00:00
|
|
|
.elevator_former_req_fn = elv_rb_former_request,
|
|
|
|
.elevator_latter_req_fn = elv_rb_latter_request,
|
2011-12-13 23:33:42 +00:00
|
|
|
.elevator_init_icq_fn = cfq_init_icq,
|
2011-12-13 23:33:42 +00:00
|
|
|
.elevator_exit_icq_fn = cfq_exit_icq,
|
2005-04-16 22:20:36 +00:00
|
|
|
.elevator_set_req_fn = cfq_set_request,
|
|
|
|
.elevator_put_req_fn = cfq_put_request,
|
|
|
|
.elevator_may_queue_fn = cfq_may_queue,
|
|
|
|
.elevator_init_fn = cfq_init_queue,
|
|
|
|
.elevator_exit_fn = cfq_exit_queue,
|
2015-06-10 14:01:20 +00:00
|
|
|
.elevator_registered_fn = cfq_registered_queue,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
2011-12-13 23:33:42 +00:00
|
|
|
.icq_size = sizeof(struct cfq_io_cq),
|
|
|
|
.icq_align = __alignof__(struct cfq_io_cq),
|
2006-03-18 23:35:43 +00:00
|
|
|
.elevator_attrs = cfq_attrs,
|
2011-12-13 23:33:42 +00:00
|
|
|
.elevator_name = "cfq",
|
2005-04-16 22:20:36 +00:00
|
|
|
.elevator_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2009-12-04 15:36:42 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 20:57:25 +00:00
|
|
|
static struct blkcg_policy blkcg_policy_cfq = {
|
2015-08-18 21:55:34 +00:00
|
|
|
.dfl_cftypes = cfq_blkcg_files,
|
2015-08-18 21:55:30 +00:00
|
|
|
.legacy_cftypes = cfq_blkcg_legacy_files,
|
2012-04-16 20:57:27 +00:00
|
|
|
|
2015-08-18 21:55:16 +00:00
|
|
|
.cpd_alloc_fn = cfq_cpd_alloc,
|
block, cgroup: implement policy-specific per-blkcg data
The block IO (blkio) controller enables the block layer to provide service
guarantees in a hierarchical fashion. Specifically, service guarantees
are provided by registered request-accounting policies. As of now, a
proportional-share and a throttling policy are available. They are
implemented, respectively, by the CFQ I/O scheduler and the blk-throttle
subsystem. Unfortunately, as for adding new policies, the current
implementation of the block IO controller is only halfway ready to allow
new policies to be plugged in. This commit provides a solution to make
the block IO controller fully ready to handle new policies.
In what follows, we first describe briefly the current state, and then
list the changes made by this commit.
The throttling policy does not need any per-cgroup information to perform
its task. In contrast, the proportional share policy uses, for each cgroup,
both the weight assigned by the user to the cgroup, and a set of dynamically-
computed weights, one for each device.
The first, user-defined weight is stored in the blkcg data structure: the
block IO controller allocates a private blkcg data structure for each
cgroup in the blkio cgroups hierarchy (regardless of which policy is active).
In other words, the block IO controller internally mirrors the blkio cgroups
with private blkcg data structures.
On the other hand, for each cgroup and device, the corresponding dynamically-
computed weight is maintained in the following, different way. For each device,
the block IO controller keeps a private blkcg_gq structure for each cgroup in
blkio. In other words, block IO also keeps one private mirror copy of the blkio
cgroups hierarchy for each device, made of blkcg_gq structures.
Each blkcg_gq structure keeps per-policy information in a generic array of
dynamically-allocated 'dedicated' data structures, one for each registered
policy (so currently the array contains two elements). To be inserted into the
generic array, each dedicated data structure embeds a generic blkg_policy_data
structure. Consider now the array contained in the blkcg_gq structure
corresponding to a given pair of cgroup and device: one of the elements
of the array contains the dedicated data structure for the proportional-share
policy, and this dedicated data structure contains the dynamically-computed
weight for that pair of cgroup and device.
The generic strategy adopted for storing per-policy data in blkcg_gq structures
is already capable of handling new policies, whereas the one adopted with blkcg
structures is not, because per-policy data are hard-coded in the blkcg
structures themselves (currently only data related to the proportional-
share policy).
This commit addresses the above issues through the following changes:
. It generalizes blkcg structures so that per-policy data are stored in the same
way as in blkcg_gq structures.
Specifically, it lets also the blkcg structure store per-policy data in a
generic array of dynamically-allocated dedicated data structures. We will
refer to these data structures as blkcg dedicated data structures, to
distinguish them from the dedicated data structures inserted in the generic
arrays kept by blkcg_gq structures.
To allow blkcg dedicated data structures to be inserted in the generic array
inside a blkcg structure, this commit also introduces a new blkcg_policy_data
structure, which is the equivalent of blkg_policy_data for blkcg dedicated
data structures.
. It adds to the blkcg_policy structure, i.e., to the descriptor of a policy, a
cpd_size field and a cpd_init field, to be initialized by the policy with,
respectively, the size of the blkcg dedicated data structures, and the
address of a constructor function for blkcg dedicated data structures.
. It moves the CFQ-specific fields embedded in the blkcg data structure (i.e.,
the fields related to the proportional-share policy), into a new blkcg
dedicated data structure called cfq_group_data.
Signed-off-by: Paolo Valente <paolo.valente@unimore.it>
Signed-off-by: Arianna Avanzini <avanzini.arianna@gmail.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@fb.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
2015-06-05 21:38:42 +00:00
|
|
|
.cpd_init_fn = cfq_cpd_init,
|
2015-08-18 21:55:16 +00:00
|
|
|
.cpd_free_fn = cfq_cpd_free,
|
2015-08-18 21:55:36 +00:00
|
|
|
.cpd_bind_fn = cfq_cpd_bind,
|
2015-08-18 21:55:16 +00:00
|
|
|
|
2015-08-18 21:55:11 +00:00
|
|
|
.pd_alloc_fn = cfq_pd_alloc,
|
2012-04-16 20:57:27 +00:00
|
|
|
.pd_init_fn = cfq_pd_init,
|
2013-01-09 16:05:13 +00:00
|
|
|
.pd_offline_fn = cfq_pd_offline,
|
2015-08-18 21:55:11 +00:00
|
|
|
.pd_free_fn = cfq_pd_free,
|
2012-04-16 20:57:27 +00:00
|
|
|
.pd_reset_stats_fn = cfq_pd_reset_stats,
|
2009-12-04 15:36:42 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int __init cfq_init(void)
|
|
|
|
{
|
2011-12-13 23:33:42 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-08-23 10:24:26 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 20:57:25 +00:00
|
|
|
ret = blkcg_policy_register(&blkcg_policy_cfq);
|
2012-04-13 20:11:28 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
block: blkcg_policy_cfq shouldn't be used if !CONFIG_CFQ_GROUP_IOSCHED
cfq may be built w/ or w/o blkcg support depending on
CONFIG_CFQ_CGROUP_IOSCHED. If blkcg support is disabled, most of
related code is ifdef'd out but some part is left dangling -
blkcg_policy_cfq is left zero-filled and blkcg_policy_[un]register()
calls are made on it.
Feeding zero filled policy to blkcg_policy_register() is incorrect and
triggers the following WARN_ON() if CONFIG_BLK_CGROUP &&
!CONFIG_CFQ_GROUP_IOSCHED.
------------[ cut here ]------------
WARNING: at block/blk-cgroup.c:867
Modules linked in:
Modules linked in:
CPU: 3 Not tainted 3.4.0-09547-gfb21aff #1
Process swapper/0 (pid: 1, task: 000000003ff80000, ksp: 000000003ff7f8b8)
Krnl PSW : 0704100180000000 00000000003d76ca (blkcg_policy_register+0xca/0xe0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0 EA:3
Krnl GPRS: 0000000000000000 00000000014b85ec 00000000014b85b0 0000000000000000
000000000096fb60 0000000000000000 00000000009a8e78 0000000000000048
000000000099c070 0000000000b6f000 0000000000000000 000000000099c0b8
00000000014b85b0 0000000000667580 000000003ff7fd98 000000003ff7fd70
Krnl Code: 00000000003d76be: a7280001 lhi %r2,1
00000000003d76c2: a7f4ffdf brc 15,3d7680
#00000000003d76c6: a7f40001 brc 15,3d76c8
>00000000003d76ca: a7c8ffea lhi %r12,-22
00000000003d76ce: a7f4ffce brc 15,3d766a
00000000003d76d2: a7f40001 brc 15,3d76d4
00000000003d76d6: a7c80000 lhi %r12,0
00000000003d76da: a7f4ffc2 brc 15,3d765e
Call Trace:
([<0000000000b6f000>] initcall_debug+0x0/0x4)
[<0000000000989e8a>] cfq_init+0x62/0xd4
[<00000000001000ba>] do_one_initcall+0x3a/0x170
[<000000000096fb60>] kernel_init+0x214/0x2bc
[<0000000000623202>] kernel_thread_starter+0x6/0xc
[<00000000006231fc>] kernel_thread_starter+0x0/0xc
no locks held by swapper/0/1.
Last Breaking-Event-Address:
[<00000000003d76c6>] blkcg_policy_register+0xc6/0xe0
---[ end trace b8ef4903fcbf9dd3 ]---
This patch fixes the problem by ensuring all blkcg support code is
inside CONFIG_CFQ_GROUP_IOSCHED.
* blkcg_policy_cfq declaration and blkg_to_cfqg() definition are moved
inside the first CONFIG_CFQ_GROUP_IOSCHED block. __maybe_unused is
dropped from blkcg_policy_cfq decl.
* blkcg_deactivate_poilcy() invocation is moved inside ifdef. This
also makes the activation logic match cfq_init_queue().
* All blkcg_policy_[un]register() invocations are moved inside ifdef.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
LKML-Reference: <20120601112954.GC3535@osiris.boeblingen.de.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-06-04 08:02:29 +00:00
|
|
|
#else
|
|
|
|
cfq_group_idle = 0;
|
|
|
|
#endif
|
2012-04-13 20:11:28 +00:00
|
|
|
|
2012-06-04 08:01:38 +00:00
|
|
|
ret = -ENOMEM;
|
2011-12-13 23:33:42 +00:00
|
|
|
cfq_pool = KMEM_CACHE(cfq_queue, 0);
|
|
|
|
if (!cfq_pool)
|
2012-04-13 20:11:28 +00:00
|
|
|
goto err_pol_unreg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-12-13 23:33:42 +00:00
|
|
|
ret = elv_register(&iosched_cfq);
|
2012-04-13 20:11:28 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_free_pool;
|
2011-12-13 23:33:42 +00:00
|
|
|
|
2007-12-12 17:51:56 +00:00
|
|
|
return 0;
|
2012-04-13 20:11:28 +00:00
|
|
|
|
|
|
|
err_free_pool:
|
|
|
|
kmem_cache_destroy(cfq_pool);
|
|
|
|
err_pol_unreg:
|
block: blkcg_policy_cfq shouldn't be used if !CONFIG_CFQ_GROUP_IOSCHED
cfq may be built w/ or w/o blkcg support depending on
CONFIG_CFQ_CGROUP_IOSCHED. If blkcg support is disabled, most of
related code is ifdef'd out but some part is left dangling -
blkcg_policy_cfq is left zero-filled and blkcg_policy_[un]register()
calls are made on it.
Feeding zero filled policy to blkcg_policy_register() is incorrect and
triggers the following WARN_ON() if CONFIG_BLK_CGROUP &&
!CONFIG_CFQ_GROUP_IOSCHED.
------------[ cut here ]------------
WARNING: at block/blk-cgroup.c:867
Modules linked in:
Modules linked in:
CPU: 3 Not tainted 3.4.0-09547-gfb21aff #1
Process swapper/0 (pid: 1, task: 000000003ff80000, ksp: 000000003ff7f8b8)
Krnl PSW : 0704100180000000 00000000003d76ca (blkcg_policy_register+0xca/0xe0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0 EA:3
Krnl GPRS: 0000000000000000 00000000014b85ec 00000000014b85b0 0000000000000000
000000000096fb60 0000000000000000 00000000009a8e78 0000000000000048
000000000099c070 0000000000b6f000 0000000000000000 000000000099c0b8
00000000014b85b0 0000000000667580 000000003ff7fd98 000000003ff7fd70
Krnl Code: 00000000003d76be: a7280001 lhi %r2,1
00000000003d76c2: a7f4ffdf brc 15,3d7680
#00000000003d76c6: a7f40001 brc 15,3d76c8
>00000000003d76ca: a7c8ffea lhi %r12,-22
00000000003d76ce: a7f4ffce brc 15,3d766a
00000000003d76d2: a7f40001 brc 15,3d76d4
00000000003d76d6: a7c80000 lhi %r12,0
00000000003d76da: a7f4ffc2 brc 15,3d765e
Call Trace:
([<0000000000b6f000>] initcall_debug+0x0/0x4)
[<0000000000989e8a>] cfq_init+0x62/0xd4
[<00000000001000ba>] do_one_initcall+0x3a/0x170
[<000000000096fb60>] kernel_init+0x214/0x2bc
[<0000000000623202>] kernel_thread_starter+0x6/0xc
[<00000000006231fc>] kernel_thread_starter+0x0/0xc
no locks held by swapper/0/1.
Last Breaking-Event-Address:
[<00000000003d76c6>] blkcg_policy_register+0xc6/0xe0
---[ end trace b8ef4903fcbf9dd3 ]---
This patch fixes the problem by ensuring all blkcg support code is
inside CONFIG_CFQ_GROUP_IOSCHED.
* blkcg_policy_cfq declaration and blkg_to_cfqg() definition are moved
inside the first CONFIG_CFQ_GROUP_IOSCHED block. __maybe_unused is
dropped from blkcg_policy_cfq decl.
* blkcg_deactivate_poilcy() invocation is moved inside ifdef. This
also makes the activation logic match cfq_init_queue().
* All blkcg_policy_[un]register() invocations are moved inside ifdef.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
LKML-Reference: <20120601112954.GC3535@osiris.boeblingen.de.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-06-04 08:02:29 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 20:57:25 +00:00
|
|
|
blkcg_policy_unregister(&blkcg_policy_cfq);
|
block: blkcg_policy_cfq shouldn't be used if !CONFIG_CFQ_GROUP_IOSCHED
cfq may be built w/ or w/o blkcg support depending on
CONFIG_CFQ_CGROUP_IOSCHED. If blkcg support is disabled, most of
related code is ifdef'd out but some part is left dangling -
blkcg_policy_cfq is left zero-filled and blkcg_policy_[un]register()
calls are made on it.
Feeding zero filled policy to blkcg_policy_register() is incorrect and
triggers the following WARN_ON() if CONFIG_BLK_CGROUP &&
!CONFIG_CFQ_GROUP_IOSCHED.
------------[ cut here ]------------
WARNING: at block/blk-cgroup.c:867
Modules linked in:
Modules linked in:
CPU: 3 Not tainted 3.4.0-09547-gfb21aff #1
Process swapper/0 (pid: 1, task: 000000003ff80000, ksp: 000000003ff7f8b8)
Krnl PSW : 0704100180000000 00000000003d76ca (blkcg_policy_register+0xca/0xe0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0 EA:3
Krnl GPRS: 0000000000000000 00000000014b85ec 00000000014b85b0 0000000000000000
000000000096fb60 0000000000000000 00000000009a8e78 0000000000000048
000000000099c070 0000000000b6f000 0000000000000000 000000000099c0b8
00000000014b85b0 0000000000667580 000000003ff7fd98 000000003ff7fd70
Krnl Code: 00000000003d76be: a7280001 lhi %r2,1
00000000003d76c2: a7f4ffdf brc 15,3d7680
#00000000003d76c6: a7f40001 brc 15,3d76c8
>00000000003d76ca: a7c8ffea lhi %r12,-22
00000000003d76ce: a7f4ffce brc 15,3d766a
00000000003d76d2: a7f40001 brc 15,3d76d4
00000000003d76d6: a7c80000 lhi %r12,0
00000000003d76da: a7f4ffc2 brc 15,3d765e
Call Trace:
([<0000000000b6f000>] initcall_debug+0x0/0x4)
[<0000000000989e8a>] cfq_init+0x62/0xd4
[<00000000001000ba>] do_one_initcall+0x3a/0x170
[<000000000096fb60>] kernel_init+0x214/0x2bc
[<0000000000623202>] kernel_thread_starter+0x6/0xc
[<00000000006231fc>] kernel_thread_starter+0x0/0xc
no locks held by swapper/0/1.
Last Breaking-Event-Address:
[<00000000003d76c6>] blkcg_policy_register+0xc6/0xe0
---[ end trace b8ef4903fcbf9dd3 ]---
This patch fixes the problem by ensuring all blkcg support code is
inside CONFIG_CFQ_GROUP_IOSCHED.
* blkcg_policy_cfq declaration and blkg_to_cfqg() definition are moved
inside the first CONFIG_CFQ_GROUP_IOSCHED block. __maybe_unused is
dropped from blkcg_policy_cfq decl.
* blkcg_deactivate_poilcy() invocation is moved inside ifdef. This
also makes the activation logic match cfq_init_queue().
* All blkcg_policy_[un]register() invocations are moved inside ifdef.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
LKML-Reference: <20120601112954.GC3535@osiris.boeblingen.de.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-06-04 08:02:29 +00:00
|
|
|
#endif
|
2012-04-13 20:11:28 +00:00
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cfq_exit(void)
|
|
|
|
{
|
block: blkcg_policy_cfq shouldn't be used if !CONFIG_CFQ_GROUP_IOSCHED
cfq may be built w/ or w/o blkcg support depending on
CONFIG_CFQ_CGROUP_IOSCHED. If blkcg support is disabled, most of
related code is ifdef'd out but some part is left dangling -
blkcg_policy_cfq is left zero-filled and blkcg_policy_[un]register()
calls are made on it.
Feeding zero filled policy to blkcg_policy_register() is incorrect and
triggers the following WARN_ON() if CONFIG_BLK_CGROUP &&
!CONFIG_CFQ_GROUP_IOSCHED.
------------[ cut here ]------------
WARNING: at block/blk-cgroup.c:867
Modules linked in:
Modules linked in:
CPU: 3 Not tainted 3.4.0-09547-gfb21aff #1
Process swapper/0 (pid: 1, task: 000000003ff80000, ksp: 000000003ff7f8b8)
Krnl PSW : 0704100180000000 00000000003d76ca (blkcg_policy_register+0xca/0xe0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0 EA:3
Krnl GPRS: 0000000000000000 00000000014b85ec 00000000014b85b0 0000000000000000
000000000096fb60 0000000000000000 00000000009a8e78 0000000000000048
000000000099c070 0000000000b6f000 0000000000000000 000000000099c0b8
00000000014b85b0 0000000000667580 000000003ff7fd98 000000003ff7fd70
Krnl Code: 00000000003d76be: a7280001 lhi %r2,1
00000000003d76c2: a7f4ffdf brc 15,3d7680
#00000000003d76c6: a7f40001 brc 15,3d76c8
>00000000003d76ca: a7c8ffea lhi %r12,-22
00000000003d76ce: a7f4ffce brc 15,3d766a
00000000003d76d2: a7f40001 brc 15,3d76d4
00000000003d76d6: a7c80000 lhi %r12,0
00000000003d76da: a7f4ffc2 brc 15,3d765e
Call Trace:
([<0000000000b6f000>] initcall_debug+0x0/0x4)
[<0000000000989e8a>] cfq_init+0x62/0xd4
[<00000000001000ba>] do_one_initcall+0x3a/0x170
[<000000000096fb60>] kernel_init+0x214/0x2bc
[<0000000000623202>] kernel_thread_starter+0x6/0xc
[<00000000006231fc>] kernel_thread_starter+0x0/0xc
no locks held by swapper/0/1.
Last Breaking-Event-Address:
[<00000000003d76c6>] blkcg_policy_register+0xc6/0xe0
---[ end trace b8ef4903fcbf9dd3 ]---
This patch fixes the problem by ensuring all blkcg support code is
inside CONFIG_CFQ_GROUP_IOSCHED.
* blkcg_policy_cfq declaration and blkg_to_cfqg() definition are moved
inside the first CONFIG_CFQ_GROUP_IOSCHED block. __maybe_unused is
dropped from blkcg_policy_cfq decl.
* blkcg_deactivate_poilcy() invocation is moved inside ifdef. This
also makes the activation logic match cfq_init_queue().
* All blkcg_policy_[un]register() invocations are moved inside ifdef.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
LKML-Reference: <20120601112954.GC3535@osiris.boeblingen.de.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-06-04 08:02:29 +00:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 20:57:25 +00:00
|
|
|
blkcg_policy_unregister(&blkcg_policy_cfq);
|
block: blkcg_policy_cfq shouldn't be used if !CONFIG_CFQ_GROUP_IOSCHED
cfq may be built w/ or w/o blkcg support depending on
CONFIG_CFQ_CGROUP_IOSCHED. If blkcg support is disabled, most of
related code is ifdef'd out but some part is left dangling -
blkcg_policy_cfq is left zero-filled and blkcg_policy_[un]register()
calls are made on it.
Feeding zero filled policy to blkcg_policy_register() is incorrect and
triggers the following WARN_ON() if CONFIG_BLK_CGROUP &&
!CONFIG_CFQ_GROUP_IOSCHED.
------------[ cut here ]------------
WARNING: at block/blk-cgroup.c:867
Modules linked in:
Modules linked in:
CPU: 3 Not tainted 3.4.0-09547-gfb21aff #1
Process swapper/0 (pid: 1, task: 000000003ff80000, ksp: 000000003ff7f8b8)
Krnl PSW : 0704100180000000 00000000003d76ca (blkcg_policy_register+0xca/0xe0)
R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0 EA:3
Krnl GPRS: 0000000000000000 00000000014b85ec 00000000014b85b0 0000000000000000
000000000096fb60 0000000000000000 00000000009a8e78 0000000000000048
000000000099c070 0000000000b6f000 0000000000000000 000000000099c0b8
00000000014b85b0 0000000000667580 000000003ff7fd98 000000003ff7fd70
Krnl Code: 00000000003d76be: a7280001 lhi %r2,1
00000000003d76c2: a7f4ffdf brc 15,3d7680
#00000000003d76c6: a7f40001 brc 15,3d76c8
>00000000003d76ca: a7c8ffea lhi %r12,-22
00000000003d76ce: a7f4ffce brc 15,3d766a
00000000003d76d2: a7f40001 brc 15,3d76d4
00000000003d76d6: a7c80000 lhi %r12,0
00000000003d76da: a7f4ffc2 brc 15,3d765e
Call Trace:
([<0000000000b6f000>] initcall_debug+0x0/0x4)
[<0000000000989e8a>] cfq_init+0x62/0xd4
[<00000000001000ba>] do_one_initcall+0x3a/0x170
[<000000000096fb60>] kernel_init+0x214/0x2bc
[<0000000000623202>] kernel_thread_starter+0x6/0xc
[<00000000006231fc>] kernel_thread_starter+0x0/0xc
no locks held by swapper/0/1.
Last Breaking-Event-Address:
[<00000000003d76c6>] blkcg_policy_register+0xc6/0xe0
---[ end trace b8ef4903fcbf9dd3 ]---
This patch fixes the problem by ensuring all blkcg support code is
inside CONFIG_CFQ_GROUP_IOSCHED.
* blkcg_policy_cfq declaration and blkg_to_cfqg() definition are moved
inside the first CONFIG_CFQ_GROUP_IOSCHED block. __maybe_unused is
dropped from blkcg_policy_cfq decl.
* blkcg_deactivate_poilcy() invocation is moved inside ifdef. This
also makes the activation logic match cfq_init_queue().
* All blkcg_policy_[un]register() invocations are moved inside ifdef.
Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Heiko Carstens <heiko.carstens@de.ibm.com>
LKML-Reference: <20120601112954.GC3535@osiris.boeblingen.de.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-06-04 08:02:29 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
elv_unregister(&iosched_cfq);
|
2011-12-13 23:33:42 +00:00
|
|
|
kmem_cache_destroy(cfq_pool);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(cfq_init);
|
|
|
|
module_exit(cfq_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Jens Axboe");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Completely Fair Queueing IO scheduler");
|