2005-04-16 16:20:36 -06: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 07:41:16 -06:00
|
|
|
* Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
|
2005-04-16 16:20:36 -06: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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2006-03-18 10:29:52 -07:00
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/elevator.h>
|
2009-11-11 05:47:45 -07:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/rbtree.h>
|
2005-06-27 02:55:12 -06:00
|
|
|
#include <linux/ioprio.h>
|
2008-05-30 04:23:07 -06:00
|
|
|
#include <linux/blktrace_api.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 16:33:38 -07:00
|
|
|
#include "blk.h"
|
2012-04-01 15:38:44 -06:00
|
|
|
#include "blk-cgroup.h"
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* tunables
|
|
|
|
*/
|
2008-01-31 05:08:54 -07:00
|
|
|
/* max queue in one round of service */
|
2010-03-01 01:20:54 -07:00
|
|
|
static const int cfq_quantum = 8;
|
2006-01-06 01:46:02 -07:00
|
|
|
static const int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 };
|
2008-01-31 05:08:54 -07: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;
|
2006-01-06 01:46:02 -07:00
|
|
|
static const int cfq_slice_sync = HZ / 10;
|
2005-06-27 02:56:24 -06:00
|
|
|
static int cfq_slice_async = HZ / 25;
|
2006-01-06 01:46:02 -07:00
|
|
|
static const int cfq_slice_async_rq = 2;
|
2006-06-16 03:23:00 -06:00
|
|
|
static int cfq_slice_idle = HZ / 125;
|
2010-08-23 04:24:26 -06:00
|
|
|
static int cfq_group_idle = HZ / 125;
|
2009-10-26 15:44:04 -06:00
|
|
|
static const int cfq_target_latency = HZ * 3/10; /* 300 ms */
|
|
|
|
static const int cfq_hist_divisor = 4;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2007-04-20 06:27:50 -06:00
|
|
|
/*
|
2008-01-28 03:38:15 -07:00
|
|
|
* offset from end of service tree
|
2007-04-20 06:27:50 -06:00
|
|
|
*/
|
2008-01-28 03:38:15 -07:00
|
|
|
#define CFQ_IDLE_DELAY (HZ / 5)
|
2007-04-20 06:27:50 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* below this threshold, we consider thinktime immediate
|
|
|
|
*/
|
|
|
|
#define CFQ_MIN_TT (2)
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
#define CFQ_SLICE_SCALE (5)
|
2008-08-26 07:52:36 -06:00
|
|
|
#define CFQ_HW_QUEUE_MIN (5)
|
2009-12-03 10:59:43 -07:00
|
|
|
#define CFQ_SERVICE_SHIFT 12
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2010-02-27 11:45:39 -07:00
|
|
|
#define CFQQ_SEEK_THR (sector_t)(8 * 100)
|
2010-03-19 01:03:04 -06:00
|
|
|
#define CFQQ_CLOSE_THR (sector_t)(8 * 1024)
|
2010-02-27 11:45:40 -07:00
|
|
|
#define CFQQ_SECT_THR_NONROT (sector_t)(2 * 32)
|
2010-02-27 11:45:39 -07:00
|
|
|
#define CFQQ_SEEKY(cfqq) (hweight32(cfqq->seek_history) > 32/8)
|
2010-02-05 05:11:45 -07:00
|
|
|
|
2011-12-13 16:33:41 -07: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 16:20:36 -06:00
|
|
|
|
2006-12-06 21:33:20 -07:00
|
|
|
static struct kmem_cache *cfq_pool;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06: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 04:03:44 -07:00
|
|
|
#define sample_valid(samples) ((samples) > 80)
|
2009-12-03 10:59:41 -07:00
|
|
|
#define rb_entry_cfqg(node) rb_entry((node), struct cfq_group, rb_node)
|
2006-03-28 04:03:44 -07:00
|
|
|
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_ttime {
|
|
|
|
unsigned long last_end_request;
|
|
|
|
|
|
|
|
unsigned long ttime_total;
|
|
|
|
unsigned long ttime_samples;
|
|
|
|
unsigned long ttime_mean;
|
|
|
|
};
|
|
|
|
|
2007-04-26 04:53:50 -06: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 15:44:33 -06:00
|
|
|
unsigned count;
|
2009-12-03 10:59:41 -07:00
|
|
|
u64 min_vdisktime;
|
2011-07-12 06:24:55 -06:00
|
|
|
struct cfq_ttime ttime;
|
2007-04-26 04:53:50 -06:00
|
|
|
};
|
2011-07-12 06:24:55 -06:00
|
|
|
#define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT, \
|
|
|
|
.ttime = {.last_end_request = jiffies,},}
|
2007-04-26 04:53:50 -06:00
|
|
|
|
2009-06-30 01:34:12 -06:00
|
|
|
/*
|
|
|
|
* Per process-grouping structure
|
|
|
|
*/
|
|
|
|
struct cfq_queue {
|
|
|
|
/* reference count */
|
2011-01-07 00:46:59 -07:00
|
|
|
int ref;
|
2009-06-30 01:34:12 -06: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 */
|
|
|
|
unsigned long rb_key;
|
|
|
|
/* 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 10:59:45 -07:00
|
|
|
/* time when queue got scheduled in to dispatch first request. */
|
|
|
|
unsigned long dispatch_start;
|
2009-12-03 10:59:53 -07:00
|
|
|
unsigned int allocated_slice;
|
2010-02-22 05:49:24 -07:00
|
|
|
unsigned int slice_dispatch;
|
2009-12-03 10:59:45 -07:00
|
|
|
/* time when first request from queue completed and slice started. */
|
|
|
|
unsigned long slice_start;
|
2009-06-30 01:34:12 -06:00
|
|
|
unsigned long slice_end;
|
|
|
|
long slice_resid;
|
|
|
|
|
2011-08-23 06:50:29 -06:00
|
|
|
/* pending priority requests */
|
|
|
|
int prio_pending;
|
2009-06-30 01:34:12 -06: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;
|
2011-07-12 00:31:45 -06:00
|
|
|
unsigned short ioprio_class;
|
2009-06-30 01:34:12 -06:00
|
|
|
|
2010-02-22 05:49:24 -07:00
|
|
|
pid_t pid;
|
|
|
|
|
2010-02-27 11:45:39 -07:00
|
|
|
u32 seek_history;
|
2009-10-23 15:14:49 -06:00
|
|
|
sector_t last_request_pos;
|
|
|
|
|
2009-10-26 15:44:33 -06:00
|
|
|
struct cfq_rb_root *service_tree;
|
2009-10-23 15:14:50 -06:00
|
|
|
struct cfq_queue *new_cfqq;
|
2009-12-03 10:59:38 -07:00
|
|
|
struct cfq_group *cfqg;
|
2010-08-23 04:25:03 -06:00
|
|
|
/* Number of sectors dispatched from queue in single dispatch round */
|
|
|
|
unsigned long nr_sectors;
|
2009-06-30 01:34:12 -06:00
|
|
|
};
|
|
|
|
|
2009-10-27 12:16:03 -06: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 15:45:29 -06:00
|
|
|
* First index in the service_trees.
|
2009-10-27 12:16:03 -06:00
|
|
|
* IDLE is handled separately, so it has negative index
|
|
|
|
*/
|
2012-10-03 14:56:56 -06:00
|
|
|
enum wl_class_t {
|
2009-10-27 12:16:03 -06:00
|
|
|
BE_WORKLOAD = 0,
|
2009-12-03 10:59:39 -07:00
|
|
|
RT_WORKLOAD = 1,
|
|
|
|
IDLE_WORKLOAD = 2,
|
2010-10-22 01:48:43 -06:00
|
|
|
CFQ_PRIO_NR,
|
2009-10-27 12:16:03 -06: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 15:45:29 -06:00
|
|
|
/*
|
|
|
|
* Second index in the service_trees.
|
|
|
|
*/
|
|
|
|
enum wl_type_t {
|
|
|
|
ASYNC_WORKLOAD = 0,
|
|
|
|
SYNC_NOIDLE_WORKLOAD = 1,
|
|
|
|
SYNC_WORKLOAD = 2
|
|
|
|
};
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfqg_stats {
|
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
/* total bytes transferred */
|
|
|
|
struct blkg_rwstat service_bytes;
|
|
|
|
/* total IOs serviced, post merge */
|
|
|
|
struct blkg_rwstat serviced;
|
|
|
|
/* 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 sectors transferred */
|
|
|
|
struct blkg_stat sectors;
|
|
|
|
/* 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 14:57:25 -06:00
|
|
|
/* time spent idling for this blkcg_gq */
|
2012-04-01 15:38:44 -06: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 */
|
|
|
|
};
|
|
|
|
|
2009-12-03 10:59:38 -07:00
|
|
|
/* This is per cgroup per device grouping structure */
|
|
|
|
struct cfq_group {
|
2012-04-16 14:57:26 -06:00
|
|
|
/* must be the first member */
|
|
|
|
struct blkg_policy_data pd;
|
|
|
|
|
2009-12-03 10:59:41 -07:00
|
|
|
/* group service_tree member */
|
|
|
|
struct rb_node rb_node;
|
|
|
|
|
|
|
|
/* group service_tree key */
|
|
|
|
u64 vdisktime;
|
2013-01-09 09:05:10 -07:00
|
|
|
|
2013-01-09 09:05:11 -07: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 09:05:11 -07: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 09:05:10 -07: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 10:59:43 -07:00
|
|
|
unsigned int weight;
|
2011-03-17 09:12:36 -06:00
|
|
|
unsigned int new_weight;
|
2012-04-01 15:38:44 -06:00
|
|
|
unsigned int dev_weight;
|
2009-12-03 10:59:41 -07:00
|
|
|
|
2013-01-09 09:05:10 -07:00
|
|
|
unsigned int leaf_weight;
|
|
|
|
unsigned int new_leaf_weight;
|
|
|
|
unsigned int dev_leaf_weight;
|
|
|
|
|
2009-12-03 10:59:41 -07:00
|
|
|
/* number of cfqq currently on this group */
|
|
|
|
int nr_cfqq;
|
|
|
|
|
2009-12-03 10:59:38 -07:00
|
|
|
/*
|
2011-05-31 02:04:09 -06:00
|
|
|
* Per group busy queues average. Useful for workload slice calc. We
|
2010-10-22 01:48:43 -06: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 10:59:38 -07: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 10:59:45 -07:00
|
|
|
|
2012-10-03 14:56:57 -06:00
|
|
|
unsigned long saved_wl_slice;
|
|
|
|
enum wl_type_t saved_wl_type;
|
|
|
|
enum wl_class_t saved_wl_class;
|
2012-03-05 14:15:18 -07:00
|
|
|
|
2010-08-23 04:24:26 -06:00
|
|
|
/* number of requests that are on the dispatch list or inside driver */
|
|
|
|
int dispatched;
|
2011-07-12 06:24:56 -06:00
|
|
|
struct cfq_ttime ttime;
|
2013-01-09 09:05:13 -07:00
|
|
|
struct cfqg_stats stats; /* stats for this cfqg */
|
|
|
|
struct cfqg_stats dead_stats; /* stats pushed from dead children */
|
2009-12-03 10:59:38 -07: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 15:45:29 -06:00
|
|
|
|
2011-12-13 16:33:41 -07: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 16:10:58 -06:00
|
|
|
int ioprio; /* the current ioprio */
|
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
uint64_t blkcg_id; /* the current blkcg ID */
|
|
|
|
#endif
|
2011-12-13 16:33:41 -07:00
|
|
|
};
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
|
|
|
* Per block device queue structure
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
struct cfq_data {
|
2007-07-24 01:28:11 -06:00
|
|
|
struct request_queue *queue;
|
2009-12-03 10:59:41 -07:00
|
|
|
/* Root service tree for cfq_groups */
|
|
|
|
struct cfq_rb_root grp_service_tree;
|
2012-03-05 14:15:05 -07:00
|
|
|
struct cfq_group *root_group;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2009-10-27 12:16:03 -06:00
|
|
|
/*
|
|
|
|
* The priority currently being served
|
2005-06-27 02:55:12 -06:00
|
|
|
*/
|
2012-10-03 14:56:57 -06:00
|
|
|
enum wl_class_t serving_wl_class;
|
|
|
|
enum wl_type_t serving_wl_type;
|
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 15:45:29 -06:00
|
|
|
unsigned long workload_expires;
|
2009-12-03 10:59:38 -07:00
|
|
|
struct cfq_group *serving_group;
|
2009-04-15 04:15:11 -06: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 02:55:12 -06:00
|
|
|
unsigned int busy_queues;
|
2011-03-07 01:26:29 -07:00
|
|
|
unsigned int busy_sync_queues;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2010-02-28 11:45:05 -07:00
|
|
|
int rq_in_driver;
|
|
|
|
int rq_in_flight[2];
|
2008-08-26 07:52:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* queue-depth detection
|
|
|
|
*/
|
|
|
|
int rq_queued;
|
2006-06-01 02:12:26 -06: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 02:02:57 -07: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 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
|
|
|
* idle window management
|
|
|
|
*/
|
|
|
|
struct timer_list idle_slice_timer;
|
2009-10-05 00:52:35 -06:00
|
|
|
struct work_struct unplug_work;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
struct cfq_queue *active_queue;
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *active_cic;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2007-07-20 02:06:38 -06:00
|
|
|
/*
|
|
|
|
* async queue for each priority case
|
|
|
|
*/
|
|
|
|
struct cfq_queue *async_cfqq[2][IOPRIO_BE_NR];
|
|
|
|
struct cfq_queue *async_idle_cfqq;
|
2007-07-10 05:43:25 -06:00
|
|
|
|
2007-04-25 04:44:27 -06:00
|
|
|
sector_t last_position;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* tunables, see top of file
|
|
|
|
*/
|
|
|
|
unsigned int cfq_quantum;
|
2005-06-27 02:55:12 -06:00
|
|
|
unsigned int cfq_fifo_expire[2];
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned int cfq_back_penalty;
|
|
|
|
unsigned int cfq_back_max;
|
2005-06-27 02:55:12 -06:00
|
|
|
unsigned int cfq_slice[2];
|
|
|
|
unsigned int cfq_slice_async_rq;
|
|
|
|
unsigned int cfq_slice_idle;
|
2010-08-23 04:24:26 -06:00
|
|
|
unsigned int cfq_group_idle;
|
2009-10-03 11:42:18 -06:00
|
|
|
unsigned int cfq_latency;
|
2012-04-01 15:33:39 -06:00
|
|
|
unsigned int cfq_target_latency;
|
2006-03-18 11:51:22 -07:00
|
|
|
|
2009-06-30 01:34:12 -06:00
|
|
|
/*
|
|
|
|
* Fallback dummy cfqq for extreme OOM conditions
|
|
|
|
*/
|
|
|
|
struct cfq_queue oom_cfqq;
|
2009-10-03 07:21:27 -06:00
|
|
|
|
2009-12-06 03:48:52 -07:00
|
|
|
unsigned long last_delayed_sync;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2009-12-03 10:59:46 -07:00
|
|
|
static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd);
|
|
|
|
|
2012-10-03 14:56:58 -06:00
|
|
|
static struct cfq_rb_root *st_for(struct cfq_group *cfqg,
|
2012-10-03 14:56:56 -06:00
|
|
|
enum wl_class_t class,
|
2009-12-16 15:52:59 -07:00
|
|
|
enum wl_type_t type)
|
2009-10-27 12:16:03 -06:00
|
|
|
{
|
2009-12-03 10:59:41 -07:00
|
|
|
if (!cfqg)
|
|
|
|
return NULL;
|
|
|
|
|
2012-10-03 14:56:56 -06:00
|
|
|
if (class == IDLE_WORKLOAD)
|
2009-12-03 10:59:38 -07:00
|
|
|
return &cfqg->service_tree_idle;
|
2009-10-27 12:16:03 -06:00
|
|
|
|
2012-10-03 14:56:56 -06:00
|
|
|
return &cfqg->service_trees[class][type];
|
2009-10-27 12:16:03 -06:00
|
|
|
}
|
|
|
|
|
2005-06-27 02:56:24 -06:00
|
|
|
enum cfqq_state_flags {
|
2007-01-18 17:35:30 -07:00
|
|
|
CFQ_CFQQ_FLAG_on_rr = 0, /* on round-robin busy list */
|
|
|
|
CFQ_CFQQ_FLAG_wait_request, /* waiting for a request */
|
2009-04-07 03:38:31 -06:00
|
|
|
CFQ_CFQQ_FLAG_must_dispatch, /* must be allowed a dispatch */
|
2007-01-18 17:35:30 -07: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-18 17:51:58 -07:00
|
|
|
CFQ_CFQQ_FLAG_slice_new, /* no requests dispatched in slice */
|
2007-04-25 04:29:51 -06:00
|
|
|
CFQ_CFQQ_FLAG_sync, /* synchronous queue */
|
2009-10-23 15:14:51 -06:00
|
|
|
CFQ_CFQQ_FLAG_coop, /* cfqq is shared */
|
2010-02-05 05:11:45 -07:00
|
|
|
CFQ_CFQQ_FLAG_split_coop, /* shared cfqq will be splitted */
|
2009-11-26 02:02:58 -07:00
|
|
|
CFQ_CFQQ_FLAG_deep, /* sync cfqq experienced large depth */
|
2009-12-03 10:59:53 -07:00
|
|
|
CFQ_CFQQ_FLAG_wait_busy, /* Waiting for next request */
|
2005-06-27 02:56:24 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CFQ_CFQQ_FNS(name) \
|
|
|
|
static inline void cfq_mark_cfqq_##name(struct cfq_queue *cfqq) \
|
|
|
|
{ \
|
2008-01-31 05:08:54 -07:00
|
|
|
(cfqq)->flags |= (1 << CFQ_CFQQ_FLAG_##name); \
|
2005-06-27 02:56:24 -06:00
|
|
|
} \
|
|
|
|
static inline void cfq_clear_cfqq_##name(struct cfq_queue *cfqq) \
|
|
|
|
{ \
|
2008-01-31 05:08:54 -07:00
|
|
|
(cfqq)->flags &= ~(1 << CFQ_CFQQ_FLAG_##name); \
|
2005-06-27 02:56:24 -06:00
|
|
|
} \
|
|
|
|
static inline int cfq_cfqq_##name(const struct cfq_queue *cfqq) \
|
|
|
|
{ \
|
2008-01-31 05:08:54 -07:00
|
|
|
return ((cfqq)->flags & (1 << CFQ_CFQQ_FLAG_##name)) != 0; \
|
2005-06-27 02:56:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
CFQ_CFQQ_FNS(on_rr);
|
|
|
|
CFQ_CFQQ_FNS(wait_request);
|
2009-04-07 03:38:31 -06:00
|
|
|
CFQ_CFQQ_FNS(must_dispatch);
|
2005-06-27 02:56:24 -06:00
|
|
|
CFQ_CFQQ_FNS(must_alloc_slice);
|
|
|
|
CFQ_CFQQ_FNS(fifo_expire);
|
|
|
|
CFQ_CFQQ_FNS(idle_window);
|
|
|
|
CFQ_CFQQ_FNS(prio_changed);
|
2007-01-18 17:51:58 -07:00
|
|
|
CFQ_CFQQ_FNS(slice_new);
|
2007-04-25 04:29:51 -06:00
|
|
|
CFQ_CFQQ_FNS(sync);
|
2009-04-15 04:15:11 -06:00
|
|
|
CFQ_CFQQ_FNS(coop);
|
2010-02-05 05:11:45 -07:00
|
|
|
CFQ_CFQQ_FNS(split_coop);
|
2009-11-26 02:02:58 -07:00
|
|
|
CFQ_CFQQ_FNS(deep);
|
2009-12-03 10:59:53 -07:00
|
|
|
CFQ_CFQQ_FNS(wait_busy);
|
2005-06-27 02:56:24 -06:00
|
|
|
#undef CFQ_CFQQ_FNS
|
|
|
|
|
2012-04-16 14:57:26 -06: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 inline struct blkcg_gq *cfqg_to_blkg(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
return pd_to_blkg(&cfqg->pd);
|
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
#if defined(CONFIG_CFQ_GROUP_IOSCHED) && defined(CONFIG_DEBUG_BLK_CGROUP)
|
2012-04-01 15:38:43 -06:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
/* cfqg stats flags */
|
|
|
|
enum cfqg_stats_flags {
|
|
|
|
CFQG_stats_waiting = 0,
|
|
|
|
CFQG_stats_idling,
|
|
|
|
CFQG_stats_empty,
|
2012-04-01 15:38:44 -06:00
|
|
|
};
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
#define CFQG_FLAG_FNS(name) \
|
|
|
|
static inline void cfqg_stats_mark_##name(struct cfqg_stats *stats) \
|
2012-04-01 15:38:44 -06:00
|
|
|
{ \
|
2012-04-01 15:38:44 -06:00
|
|
|
stats->flags |= (1 << CFQG_stats_##name); \
|
2012-04-01 15:38:44 -06:00
|
|
|
} \
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_clear_##name(struct cfqg_stats *stats) \
|
2012-04-01 15:38:44 -06:00
|
|
|
{ \
|
2012-04-01 15:38:44 -06:00
|
|
|
stats->flags &= ~(1 << CFQG_stats_##name); \
|
2012-04-01 15:38:44 -06:00
|
|
|
} \
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline int cfqg_stats_##name(struct cfqg_stats *stats) \
|
2012-04-01 15:38:44 -06:00
|
|
|
{ \
|
2012-04-01 15:38:44 -06:00
|
|
|
return (stats->flags & (1 << CFQG_stats_##name)) != 0; \
|
2012-04-01 15:38:44 -06:00
|
|
|
} \
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
CFQG_FLAG_FNS(waiting)
|
|
|
|
CFQG_FLAG_FNS(idling)
|
|
|
|
CFQG_FLAG_FNS(empty)
|
|
|
|
#undef CFQG_FLAG_FNS
|
2012-04-01 15:38:44 -06:00
|
|
|
|
|
|
|
/* This should be called with the queue_lock held. */
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_update_group_wait_time(struct cfqg_stats *stats)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
|
|
|
unsigned long long now;
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
if (!cfqg_stats_waiting(stats))
|
2012-04-01 15:38:44 -06: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 15:38:44 -06:00
|
|
|
cfqg_stats_clear_waiting(stats);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be called with the queue_lock held. */
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_set_start_group_wait_time(struct cfq_group *cfqg,
|
|
|
|
struct cfq_group *curr_cfqg)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 15:38:44 -06:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
if (cfqg_stats_waiting(stats))
|
2012-04-01 15:38:44 -06:00
|
|
|
return;
|
2012-04-01 15:38:44 -06:00
|
|
|
if (cfqg == curr_cfqg)
|
2012-04-01 15:38:44 -06:00
|
|
|
return;
|
2012-04-01 15:38:44 -06:00
|
|
|
stats->start_group_wait_time = sched_clock();
|
|
|
|
cfqg_stats_mark_waiting(stats);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be called with the queue_lock held. */
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_end_empty_time(struct cfqg_stats *stats)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
|
|
|
unsigned long long now;
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
if (!cfqg_stats_empty(stats))
|
2012-04-01 15:38:44 -06: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 15:38:44 -06:00
|
|
|
cfqg_stats_clear_empty(stats);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_update_dequeue(struct cfq_group *cfqg)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_stat_add(&cfqg->stats.dequeue, 1);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_set_start_empty_time(struct cfq_group *cfqg)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 15:38:44 -06:00
|
|
|
|
2013-01-09 09:05:12 -07:00
|
|
|
if (blkg_rwstat_total(&stats->queued))
|
2012-04-01 15:38:44 -06: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 15:38:44 -06:00
|
|
|
if (cfqg_stats_empty(stats))
|
2012-04-01 15:38:44 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
stats->start_empty_time = sched_clock();
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_mark_empty(stats);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_update_idle_time(struct cfq_group *cfqg)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 15:38:44 -06:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
if (cfqg_stats_idling(stats)) {
|
2012-04-01 15:38:44 -06: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 15:38:44 -06:00
|
|
|
cfqg_stats_clear_idling(stats);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_set_start_idle_time(struct cfq_group *cfqg)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 15:38:44 -06:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
BUG_ON(cfqg_stats_idling(stats));
|
2012-04-01 15:38:44 -06:00
|
|
|
|
|
|
|
stats->start_idle_time = sched_clock();
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_mark_idling(stats);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static void cfqg_stats_update_avg_queue_size(struct cfq_group *cfqg)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 15:38:44 -06:00
|
|
|
|
|
|
|
blkg_stat_add(&stats->avg_queue_size_sum,
|
2013-01-09 09:05:12 -07:00
|
|
|
blkg_rwstat_total(&stats->queued));
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_stat_add(&stats->avg_queue_size_samples, 1);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_group_wait_time(stats);
|
2012-04-01 15:38:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* CONFIG_CFQ_GROUP_IOSCHED && CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
|
2012-04-13 14:11:25 -06: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 15:38:44 -06:00
|
|
|
|
|
|
|
#endif /* CONFIG_CFQ_GROUP_IOSCHED && CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-01 15:38:43 -06:00
|
|
|
|
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 02:02:29 -06: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));
|
|
|
|
}
|
|
|
|
|
2013-01-09 09:05:11 -07:00
|
|
|
static inline struct cfq_group *cfqg_parent(struct cfq_group *cfqg)
|
2013-01-09 09:05:11 -07:00
|
|
|
{
|
2013-01-09 09:05:11 -07:00
|
|
|
struct blkcg_gq *pblkg = cfqg_to_blkg(cfqg)->parent;
|
2013-01-09 09:05:11 -07:00
|
|
|
|
2013-01-09 09:05:11 -07:00
|
|
|
return pblkg ? blkg_to_cfqg(pblkg) : NULL;
|
2013-01-09 09:05:11 -07:00
|
|
|
}
|
|
|
|
|
2012-03-23 07:02:53 -06: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 14:57:23 -06: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 14:57:01 -06: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 14:57:23 -06: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 10:59:48 -07:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg,
|
|
|
|
struct cfq_group *curr_cfqg, int rw)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_rwstat_add(&cfqg->stats.queued, rw, 1);
|
|
|
|
cfqg_stats_end_empty_time(&cfqg->stats);
|
|
|
|
cfqg_stats_set_start_group_wait_time(cfqg, curr_cfqg);
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg,
|
|
|
|
unsigned long time, unsigned long unaccounted_time)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_stat_add(&cfqg->stats.time, time);
|
2012-04-01 15:38:44 -06:00
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_stat_add(&cfqg->stats.unaccounted_time, unaccounted_time);
|
2012-04-01 15:38:44 -06:00
|
|
|
#endif
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg, int rw)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_rwstat_add(&cfqg->stats.queued, rw, -1);
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg, int rw)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_rwstat_add(&cfqg->stats.merged, rw, 1);
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_update_dispatch(struct cfq_group *cfqg,
|
|
|
|
uint64_t bytes, int rw)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
blkg_stat_add(&cfqg->stats.sectors, bytes >> 9);
|
|
|
|
blkg_rwstat_add(&cfqg->stats.serviced, rw, 1);
|
|
|
|
blkg_rwstat_add(&cfqg->stats.service_bytes, rw, bytes);
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
|
|
|
|
uint64_t start_time, uint64_t io_start_time, int rw)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfqg_stats *stats = &cfqg->stats;
|
2012-04-01 15:38:44 -06:00
|
|
|
unsigned long long now = sched_clock();
|
|
|
|
|
|
|
|
if (time_after64(now, io_start_time))
|
|
|
|
blkg_rwstat_add(&stats->service_time, rw, now - io_start_time);
|
|
|
|
if (time_after64(io_start_time, start_time))
|
|
|
|
blkg_rwstat_add(&stats->wait_time, rw,
|
|
|
|
io_start_time - start_time);
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
2013-01-09 09:05:13 -07:00
|
|
|
/* @stats = 0 */
|
|
|
|
static void cfqg_stats_reset(struct cfqg_stats *stats)
|
2012-04-01 15:38:44 -06:00
|
|
|
{
|
|
|
|
/* queued stats shouldn't be cleared */
|
|
|
|
blkg_rwstat_reset(&stats->service_bytes);
|
|
|
|
blkg_rwstat_reset(&stats->serviced);
|
|
|
|
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 09:05:13 -07:00
|
|
|
/* @to += @from */
|
|
|
|
static void cfqg_stats_merge(struct cfqg_stats *to, struct cfqg_stats *from)
|
|
|
|
{
|
|
|
|
/* queued stats shouldn't be cleared */
|
|
|
|
blkg_rwstat_merge(&to->service_bytes, &from->service_bytes);
|
|
|
|
blkg_rwstat_merge(&to->serviced, &from->serviced);
|
|
|
|
blkg_rwstat_merge(&to->merged, &from->merged);
|
|
|
|
blkg_rwstat_merge(&to->service_time, &from->service_time);
|
|
|
|
blkg_rwstat_merge(&to->wait_time, &from->wait_time);
|
|
|
|
blkg_stat_merge(&from->time, &from->time);
|
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
|
|
|
blkg_stat_merge(&to->unaccounted_time, &from->unaccounted_time);
|
|
|
|
blkg_stat_merge(&to->avg_queue_size_sum, &from->avg_queue_size_sum);
|
|
|
|
blkg_stat_merge(&to->avg_queue_size_samples, &from->avg_queue_size_samples);
|
|
|
|
blkg_stat_merge(&to->dequeue, &from->dequeue);
|
|
|
|
blkg_stat_merge(&to->group_wait_time, &from->group_wait_time);
|
|
|
|
blkg_stat_merge(&to->idle_time, &from->idle_time);
|
|
|
|
blkg_stat_merge(&to->empty_time, &from->empty_time);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer @cfqg's stats to its parent's dead_stats so that the ancestors'
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
cfqg_stats_merge(&parent->dead_stats, &cfqg->stats);
|
|
|
|
cfqg_stats_merge(&parent->dead_stats, &cfqg->dead_stats);
|
|
|
|
cfqg_stats_reset(&cfqg->stats);
|
|
|
|
cfqg_stats_reset(&cfqg->dead_stats);
|
|
|
|
}
|
|
|
|
|
2012-03-23 07:02:53 -06:00
|
|
|
#else /* CONFIG_CFQ_GROUP_IOSCHED */
|
|
|
|
|
2013-01-09 09:05:11 -07:00
|
|
|
static inline struct cfq_group *cfqg_parent(struct cfq_group *cfqg) { return NULL; }
|
2012-03-23 07:02:53 -06:00
|
|
|
static inline void cfqg_get(struct cfq_group *cfqg) { }
|
|
|
|
static inline void cfqg_put(struct cfq_group *cfqg) { }
|
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
#define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \
|
2012-10-03 14:57:01 -06: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 02:04:09 -06:00
|
|
|
#define cfq_log_cfqg(cfqd, cfqg, fmt, args...) do {} while (0)
|
2012-03-23 07:02:53 -06:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg,
|
|
|
|
struct cfq_group *curr_cfqg, int rw) { }
|
|
|
|
static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg,
|
|
|
|
unsigned long time, unsigned long unaccounted_time) { }
|
|
|
|
static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg, int rw) { }
|
|
|
|
static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg, int rw) { }
|
|
|
|
static inline void cfqg_stats_update_dispatch(struct cfq_group *cfqg,
|
|
|
|
uint64_t bytes, int rw) { }
|
|
|
|
static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
|
|
|
|
uint64_t start_time, uint64_t io_start_time, int rw) { }
|
2012-04-01 15:38:43 -06:00
|
|
|
|
2012-03-23 07:02:53 -06:00
|
|
|
#endif /* CONFIG_CFQ_GROUP_IOSCHED */
|
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
#define cfq_log(cfqd, fmt, args...) \
|
|
|
|
blk_add_trace_msg((cfqd)->queue, "cfq " fmt, ##args)
|
|
|
|
|
2009-12-03 10:59:39 -07: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 06:24:55 -06:00
|
|
|
static inline bool cfq_io_thinktime_big(struct cfq_data *cfqd,
|
|
|
|
struct cfq_ttime *ttime, bool group_idle)
|
|
|
|
{
|
|
|
|
unsigned long slice;
|
|
|
|
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 10:59:39 -07:00
|
|
|
|
2010-08-23 04:23:53 -06: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 14:56:56 -06:00
|
|
|
static inline enum wl_class_t cfqq_class(struct cfq_queue *cfqq)
|
2009-10-27 12:16:03 -06: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 15:45:29 -06: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 14:56:56 -06:00
|
|
|
static inline int cfq_group_busy_queues_wl(enum wl_class_t wl_class,
|
2009-12-03 10:59:44 -07:00
|
|
|
struct cfq_data *cfqd,
|
|
|
|
struct cfq_group *cfqg)
|
2009-10-27 12:16:03 -06:00
|
|
|
{
|
2012-10-03 14:56:56 -06:00
|
|
|
if (wl_class == IDLE_WORKLOAD)
|
2009-12-03 10:59:38 -07:00
|
|
|
return cfqg->service_tree_idle.count;
|
2009-10-27 12:16:03 -06:00
|
|
|
|
2012-10-03 14:56:58 -06: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 12:16:03 -06:00
|
|
|
}
|
|
|
|
|
2009-12-03 10:59:54 -07:00
|
|
|
static inline int cfqg_busy_async_queues(struct cfq_data *cfqd,
|
|
|
|
struct cfq_group *cfqg)
|
|
|
|
{
|
2012-10-03 14:56:58 -06:00
|
|
|
return cfqg->service_trees[RT_WORKLOAD][ASYNC_WORKLOAD].count +
|
|
|
|
cfqg->service_trees[BE_WORKLOAD][ASYNC_WORKLOAD].count;
|
2009-12-03 10:59:54 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static void cfq_dispatch_insert(struct request_queue *, struct request *);
|
2012-03-05 14:15:28 -07:00
|
|
|
static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, bool is_sync,
|
2012-03-19 16:10:57 -06:00
|
|
|
struct cfq_io_cq *cic, struct bio *bio,
|
2012-03-05 14:15:28 -07:00
|
|
|
gfp_t gfp_mask);
|
2007-04-25 04:29:51 -06:00
|
|
|
|
2011-12-13 16:33:41 -07: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 16:33:42 -07: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 16:33:41 -07:00
|
|
|
static inline struct cfq_queue *cic_to_cfqq(struct cfq_io_cq *cic, bool is_sync)
|
2007-04-25 04:29:51 -06:00
|
|
|
{
|
2009-10-07 12:02:57 -06:00
|
|
|
return cic->cfqq[is_sync];
|
2007-04-25 04:29:51 -06:00
|
|
|
}
|
|
|
|
|
2011-12-13 16:33:41 -07:00
|
|
|
static inline void cic_set_cfqq(struct cfq_io_cq *cic, struct cfq_queue *cfqq,
|
|
|
|
bool is_sync)
|
2007-04-25 04:29:51 -06:00
|
|
|
{
|
2009-10-07 12:02:57 -06:00
|
|
|
cic->cfqq[is_sync] = cfqq;
|
2007-04-25 04:29:51 -06:00
|
|
|
}
|
|
|
|
|
2011-12-13 16:33:41 -07:00
|
|
|
static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic)
|
2010-05-20 13:21:34 -06:00
|
|
|
{
|
2011-12-13 16:33:41 -07:00
|
|
|
return cic->icq.q->elevator->elevator_data;
|
2010-05-20 13:21:34 -06:00
|
|
|
}
|
|
|
|
|
2007-04-25 04:29:51 -06:00
|
|
|
/*
|
|
|
|
* We regard a request as SYNC, if it's either a read or has the SYNC bit
|
|
|
|
* set (in which case it could also be direct WRITE).
|
|
|
|
*/
|
2009-10-07 12:02:57 -06:00
|
|
|
static inline bool cfq_bio_sync(struct bio *bio)
|
2007-04-25 04:29:51 -06:00
|
|
|
{
|
2010-08-07 10:20:39 -06:00
|
|
|
return bio_data_dir(bio) == READ || (bio->bi_rw & REQ_SYNC);
|
2007-04-25 04:29:51 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 21:14:05 -06:00
|
|
|
/*
|
|
|
|
* scheduler run of queue, if there are requests pending and no one in the
|
|
|
|
* driver that will restart queueing
|
|
|
|
*/
|
2009-10-05 00:52:35 -06:00
|
|
|
static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
|
2005-06-27 21:14:05 -06:00
|
|
|
{
|
2008-05-30 04:23:07 -06:00
|
|
|
if (cfqd->busy_queues) {
|
|
|
|
cfq_log(cfqd, "schedule dispatch");
|
2009-10-05 00:52:35 -06:00
|
|
|
kblockd_schedule_work(cfqd->queue, &cfqd->unplug_work);
|
2008-05-30 04:23:07 -06:00
|
|
|
}
|
2005-06-27 21:14:05 -06:00
|
|
|
}
|
|
|
|
|
2007-01-18 17:51:58 -07: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.
|
|
|
|
*/
|
2009-10-07 12:02:57 -06:00
|
|
|
static inline int cfq_prio_slice(struct cfq_data *cfqd, bool sync,
|
2007-04-20 06:27:50 -06:00
|
|
|
unsigned short prio)
|
2007-01-18 17:51:58 -07:00
|
|
|
{
|
2007-04-20 06:27:50 -06:00
|
|
|
const int base_slice = cfqd->cfq_slice[sync];
|
2007-01-18 17:51:58 -07:00
|
|
|
|
2007-04-20 06:27:50 -06:00
|
|
|
WARN_ON(prio >= IOPRIO_BE_NR);
|
|
|
|
|
|
|
|
return base_slice + (base_slice/CFQ_SLICE_SCALE * (4 - prio));
|
|
|
|
}
|
2007-01-18 17:51:58 -07:00
|
|
|
|
2007-04-20 06:27:50 -06:00
|
|
|
static inline int
|
|
|
|
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-18 17:51:58 -07: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 09:05:11 -07: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.
|
|
|
|
*/
|
|
|
|
static inline u64 cfqg_scale_charge(unsigned long charge,
|
|
|
|
unsigned int vfraction)
|
2009-12-03 10:59:43 -07: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 09:05:11 -07:00
|
|
|
u64 c = charge << CFQ_SERVICE_SHIFT; /* make it fixed point */
|
2009-12-03 10:59:43 -07: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 09:05:11 -07:00
|
|
|
/* charge / vfraction */
|
|
|
|
c <<= CFQ_SERVICE_SHIFT;
|
|
|
|
do_div(c, vfraction);
|
|
|
|
return c;
|
2009-12-03 10:59:43 -07: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 01:28:09 -07:00
|
|
|
st->min_vdisktime = max_vdisktime(st->min_vdisktime,
|
|
|
|
cfqg->vdisktime);
|
2009-12-03 10:59:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-26 15:44:04 -06: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 10:59:44 -07:00
|
|
|
static inline unsigned cfq_group_get_avg_queues(struct cfq_data *cfqd,
|
|
|
|
struct cfq_group *cfqg, bool rt)
|
2009-10-28 02:27:07 -06:00
|
|
|
{
|
2009-10-26 15:44:04 -06:00
|
|
|
unsigned min_q, max_q;
|
|
|
|
unsigned mult = cfq_hist_divisor - 1;
|
|
|
|
unsigned round = cfq_hist_divisor / 2;
|
2009-12-03 10:59:44 -07:00
|
|
|
unsigned busy = cfq_group_busy_queues_wl(rt, cfqd, cfqg);
|
2009-10-26 15:44:04 -06:00
|
|
|
|
2009-12-03 10:59:44 -07: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 15:44:04 -06:00
|
|
|
cfq_hist_divisor;
|
2009-12-03 10:59:44 -07:00
|
|
|
return cfqg->busy_queues_avg[rt];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned
|
|
|
|
cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg)
|
|
|
|
{
|
2013-01-09 09:05:11 -07:00
|
|
|
return cfqd->cfq_target_latency * cfqg->vfraction >> CFQ_SERVICE_SHIFT;
|
2009-10-26 15:44:04 -06:00
|
|
|
}
|
|
|
|
|
2011-01-14 00:41:03 -07:00
|
|
|
static inline unsigned
|
2011-01-19 08:25:02 -07:00
|
|
|
cfq_scaled_cfqq_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2007-01-18 17:51:58 -07:00
|
|
|
{
|
2009-10-26 15:44:04 -06:00
|
|
|
unsigned slice = cfq_prio_to_slice(cfqd, cfqq);
|
|
|
|
if (cfqd->cfq_latency) {
|
2009-12-03 10:59:44 -07: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));
|
2009-10-26 15:44:04 -06:00
|
|
|
unsigned sync_slice = cfqd->cfq_slice[1];
|
|
|
|
unsigned expect_latency = sync_slice * iq;
|
2009-12-03 10:59:44 -07:00
|
|
|
unsigned group_slice = cfq_group_slice(cfqd, cfqq->cfqg);
|
|
|
|
|
|
|
|
if (expect_latency > group_slice) {
|
2009-10-26 15:44:04 -06:00
|
|
|
unsigned base_low_slice = 2 * cfqd->cfq_slice_idle;
|
|
|
|
/* scale low_slice according to IO priority
|
|
|
|
* and sync vs async */
|
|
|
|
unsigned low_slice =
|
|
|
|
min(slice, base_low_slice * slice / sync_slice);
|
|
|
|
/* the adapted slice value is scaled to fit all iqs
|
|
|
|
* into the target latency */
|
2009-12-03 10:59:44 -07:00
|
|
|
slice = max(slice * group_slice / expect_latency,
|
2009-10-26 15:44:04 -06:00
|
|
|
low_slice);
|
|
|
|
}
|
|
|
|
}
|
2011-01-14 00:41:03 -07:00
|
|
|
return slice;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
2011-01-19 08:25:02 -07:00
|
|
|
unsigned slice = cfq_scaled_cfqq_slice(cfqd, cfqq);
|
2011-01-14 00:41:03 -07:00
|
|
|
|
2009-12-03 10:59:45 -07:00
|
|
|
cfqq->slice_start = jiffies;
|
2009-10-26 15:44:04 -06:00
|
|
|
cfqq->slice_end = jiffies + slice;
|
2009-12-03 10:59:53 -07:00
|
|
|
cfqq->allocated_slice = slice;
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "set_slice=%lu", cfqq->slice_end - jiffies);
|
2007-01-18 17:51:58 -07: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 12:02:57 -06:00
|
|
|
static inline bool cfq_slice_used(struct cfq_queue *cfqq)
|
2007-01-18 17:51:58 -07:00
|
|
|
{
|
|
|
|
if (cfq_cfqq_slice_new(cfqq))
|
2010-11-08 07:01:02 -07:00
|
|
|
return false;
|
2007-01-18 17:51:58 -07:00
|
|
|
if (time_before(jiffies, cfqq->slice_end))
|
2010-11-08 07:01:02 -07:00
|
|
|
return false;
|
2007-01-18 17:51:58 -07:00
|
|
|
|
2010-11-08 07:01:02 -07:00
|
|
|
return true;
|
2007-01-18 17:51:58 -07:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2006-07-13 04:39:25 -06:00
|
|
|
* Lifted from AS - choose which of rq1 and rq2 that is best served now.
|
2005-04-16 16:20:36 -06:00
|
|
|
* We choose the request that is closest to the head right now. Distance
|
2006-03-27 23:59:49 -07:00
|
|
|
* behind the head is penalized and only allowed to a certain extent.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2006-07-13 04:39:25 -06: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 09:16:46 -07:00
|
|
|
cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2, sector_t last)
|
2005-04-16 16:20:36 -06: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 09:16:46 -07:00
|
|
|
sector_t s1, s2, d1 = 0, d2 = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long back_max;
|
2006-03-27 23:59:49 -07: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 16:20:36 -06:00
|
|
|
|
2006-07-13 04:39:25 -06:00
|
|
|
if (rq1 == NULL || rq1 == rq2)
|
|
|
|
return rq2;
|
|
|
|
if (rq2 == NULL)
|
|
|
|
return rq1;
|
2005-08-24 06:57:54 -06:00
|
|
|
|
2011-05-24 02:23:21 -06:00
|
|
|
if (rq_is_sync(rq1) != rq_is_sync(rq2))
|
|
|
|
return rq_is_sync(rq1) ? rq1 : rq2;
|
|
|
|
|
2011-08-23 06:50:29 -06:00
|
|
|
if ((rq1->cmd_flags ^ rq2->cmd_flags) & REQ_PRIO)
|
|
|
|
return rq1->cmd_flags & REQ_PRIO ? rq1 : rq2;
|
2011-08-19 00:34:48 -06:00
|
|
|
|
2009-05-07 07:24:39 -06:00
|
|
|
s1 = blk_rq_pos(rq1);
|
|
|
|
s2 = blk_rq_pos(rq2);
|
2005-04-16 16:20:36 -06: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-27 23:59:49 -07:00
|
|
|
wrap |= CFQ_RQ1_WRAP;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (s2 >= last)
|
|
|
|
d2 = s2 - last;
|
|
|
|
else if (s2 + back_max >= last)
|
|
|
|
d2 = (last - s2) * cfqd->cfq_back_penalty;
|
|
|
|
else
|
2006-03-27 23:59:49 -07:00
|
|
|
wrap |= CFQ_RQ2_WRAP;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Found required data */
|
2006-03-27 23:59:49 -07: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 04:39:25 -06:00
|
|
|
case 0: /* common case for CFQ: rq1 and rq2 not wrapped */
|
2006-03-27 23:59:49 -07:00
|
|
|
if (d1 < d2)
|
2006-07-13 04:39:25 -06:00
|
|
|
return rq1;
|
2006-03-27 23:59:49 -07:00
|
|
|
else if (d2 < d1)
|
2006-07-13 04:39:25 -06:00
|
|
|
return rq2;
|
2006-03-27 23:59:49 -07:00
|
|
|
else {
|
|
|
|
if (s1 >= s2)
|
2006-07-13 04:39:25 -06:00
|
|
|
return rq1;
|
2006-03-27 23:59:49 -07:00
|
|
|
else
|
2006-07-13 04:39:25 -06:00
|
|
|
return rq2;
|
2006-03-27 23:59:49 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-03-27 23:59:49 -07:00
|
|
|
case CFQ_RQ2_WRAP:
|
2006-07-13 04:39:25 -06:00
|
|
|
return rq1;
|
2006-03-27 23:59:49 -07:00
|
|
|
case CFQ_RQ1_WRAP:
|
2006-07-13 04:39:25 -06:00
|
|
|
return rq2;
|
|
|
|
case (CFQ_RQ1_WRAP|CFQ_RQ2_WRAP): /* both rqs wrapped */
|
2006-03-27 23:59:49 -07: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 04:39:25 -06:00
|
|
|
return rq1;
|
2005-04-16 16:20:36 -06:00
|
|
|
else
|
2006-07-13 04:39:25 -06:00
|
|
|
return rq2;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-26 04:54:48 -06:00
|
|
|
/*
|
|
|
|
* The below is leftmost cache rbtree addon
|
|
|
|
*/
|
2008-01-28 03:38:15 -07:00
|
|
|
static struct cfq_queue *cfq_rb_first(struct cfq_rb_root *root)
|
2007-04-26 04:53:50 -06:00
|
|
|
{
|
2009-12-03 10:59:39 -07:00
|
|
|
/* Service tree is empty */
|
|
|
|
if (!root->count)
|
|
|
|
return NULL;
|
|
|
|
|
2007-04-26 04:53:50 -06:00
|
|
|
if (!root->left)
|
|
|
|
root->left = rb_first(&root->rb);
|
|
|
|
|
2008-01-28 03:38:15 -07:00
|
|
|
if (root->left)
|
|
|
|
return rb_entry(root->left, struct cfq_queue, rb_node);
|
|
|
|
|
|
|
|
return NULL;
|
2007-04-26 04:53:50 -06:00
|
|
|
}
|
|
|
|
|
2009-12-03 10:59:41 -07: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 04:15:11 -06: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 04:53:50 -06: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 04:15:11 -06:00
|
|
|
rb_erase_init(n, &root->rb);
|
2009-10-26 15:44:33 -06:00
|
|
|
--root->count;
|
2007-04-26 04:53:50 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* would be nice to take fifo expire time into account as well
|
|
|
|
*/
|
2006-07-13 04:39:25 -06:00
|
|
|
static struct request *
|
|
|
|
cfq_find_next_rq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
|
|
|
struct request *last)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:33:14 -06:00
|
|
|
struct rb_node *rbnext = rb_next(&last->rb_node);
|
|
|
|
struct rb_node *rbprev = rb_prev(&last->rb_node);
|
2006-07-13 04:39:25 -06:00
|
|
|
struct request *next = NULL, *prev = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-07-13 04:33:14 -06:00
|
|
|
BUG_ON(RB_EMPTY_NODE(&last->rb_node));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (rbprev)
|
2006-07-13 04:39:25 -06:00
|
|
|
prev = rb_entry_rq(rbprev);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-07-13 04:33:14 -06:00
|
|
|
if (rbnext)
|
2006-07-13 04:39:25 -06:00
|
|
|
next = rb_entry_rq(rbnext);
|
2006-07-13 04:33:14 -06:00
|
|
|
else {
|
|
|
|
rbnext = rb_first(&cfqq->sort_list);
|
|
|
|
if (rbnext && rbnext != &last->rb_node)
|
2006-07-13 04:39:25 -06:00
|
|
|
next = rb_entry_rq(rbnext);
|
2006-07-13 04:33:14 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06: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 09:16:46 -07:00
|
|
|
return cfq_choose_req(cfqd, next, prev, blk_rq_pos(last));
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-04-20 06:27:50 -06:00
|
|
|
static unsigned long cfq_slice_offset(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-04-20 06:27:50 -06:00
|
|
|
/*
|
|
|
|
* just an approximation, should be ok.
|
|
|
|
*/
|
2009-12-03 10:59:38 -07:00
|
|
|
return (cfqq->cfqg->nr_cfqq - 1) * (cfq_prio_slice(cfqd, 1, 0) -
|
2009-11-30 01:38:13 -07:00
|
|
|
cfq_prio_slice(cfqd, cfq_cfqq_sync(cfqq), cfqq->ioprio));
|
2007-04-20 06:27:50 -06:00
|
|
|
}
|
|
|
|
|
2009-12-03 10:59:41 -07: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-17 09:12:36 -06:00
|
|
|
cfq_update_group_weight(struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node));
|
2013-01-09 09:05:10 -07:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
if (cfqg->new_weight) {
|
2011-03-17 09:12:36 -06:00
|
|
|
cfqg->weight = cfqg->new_weight;
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg->new_weight = 0;
|
2011-03-17 09:12:36 -06:00
|
|
|
}
|
2013-01-09 09:05:10 -07:00
|
|
|
|
|
|
|
if (cfqg->new_leaf_weight) {
|
|
|
|
cfqg->leaf_weight = cfqg->new_leaf_weight;
|
|
|
|
cfqg->new_leaf_weight = 0;
|
|
|
|
}
|
2011-03-17 09:12:36 -06: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 09:05:11 -07:00
|
|
|
unsigned int vfr = 1 << CFQ_SERVICE_SHIFT; /* start with 1 */
|
2013-01-09 09:05:11 -07: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 09:05:11 -07:00
|
|
|
struct cfq_group *parent;
|
2013-01-09 09:05:11 -07:00
|
|
|
bool propagate;
|
|
|
|
|
|
|
|
/* add to the service tree */
|
2011-03-17 09:12:36 -06:00
|
|
|
BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node));
|
|
|
|
|
|
|
|
cfq_update_group_weight(cfqg);
|
|
|
|
__cfq_group_service_tree_add(st, cfqg);
|
2013-01-09 09:05:11 -07: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 09:05:11 -07: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 09:05:11 -07: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 09:05:11 -07:00
|
|
|
vfr = vfr * pos->leaf_weight / pos->children_weight;
|
2013-01-09 09:05:11 -07: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 09:05:11 -07: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 09:05:11 -07: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 09:05:11 -07:00
|
|
|
if (propagate) {
|
|
|
|
propagate = !parent->nr_active++;
|
|
|
|
parent->children_weight += pos->weight;
|
|
|
|
}
|
|
|
|
vfr = vfr * pos->weight / parent->children_weight;
|
2013-01-09 09:05:11 -07: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 09:05:11 -07:00
|
|
|
|
|
|
|
cfqg->vfraction = max_t(unsigned, vfr, 1);
|
2011-03-17 09:12:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg)
|
2009-12-03 10:59:41 -07:00
|
|
|
{
|
|
|
|
struct cfq_rb_root *st = &cfqd->grp_service_tree;
|
|
|
|
struct cfq_group *__cfqg;
|
|
|
|
struct rb_node *n;
|
|
|
|
|
|
|
|
cfqg->nr_cfqq++;
|
2010-11-30 12:52:47 -07:00
|
|
|
if (!RB_EMPTY_NODE(&cfqg->rb_node))
|
2009-12-03 10:59:41 -07: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-30 19:57:33 -06:00
|
|
|
* if group does not loose all if it was not continuously backlogged.
|
2009-12-03 10:59:41 -07: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 09:12:36 -06:00
|
|
|
cfq_group_service_tree_add(st, cfqg);
|
|
|
|
}
|
2009-12-03 10:59:41 -07:00
|
|
|
|
2011-03-17 09:12:36 -06:00
|
|
|
static void
|
|
|
|
cfq_group_service_tree_del(struct cfq_rb_root *st, struct cfq_group *cfqg)
|
|
|
|
{
|
2013-01-09 09:05:11 -07: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 09:05:11 -07:00
|
|
|
struct cfq_group *parent = cfqg_parent(pos);
|
2013-01-09 09:05:11 -07: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 09:05:11 -07:00
|
|
|
pos->vfraction = 0;
|
2013-01-09 09:05:11 -07:00
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
propagate = !--parent->nr_active;
|
|
|
|
parent->children_weight -= pos->weight;
|
|
|
|
pos = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove from the service tree */
|
2011-03-17 09:12:36 -06:00
|
|
|
if (!RB_EMPTY_NODE(&cfqg->rb_node))
|
|
|
|
cfq_rb_erase(&cfqg->rb_node, st);
|
2009-12-03 10:59:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-03-17 09:12:36 -06:00
|
|
|
cfq_group_notify_queue_del(struct cfq_data *cfqd, struct cfq_group *cfqg)
|
2009-12-03 10:59:41 -07:00
|
|
|
{
|
|
|
|
struct cfq_rb_root *st = &cfqd->grp_service_tree;
|
|
|
|
|
|
|
|
BUG_ON(cfqg->nr_cfqq < 1);
|
|
|
|
cfqg->nr_cfqq--;
|
2009-12-03 10:59:43 -07:00
|
|
|
|
2009-12-03 10:59:41 -07:00
|
|
|
/* If there are other cfq queues under this group, don't delete it */
|
|
|
|
if (cfqg->nr_cfqq)
|
|
|
|
return;
|
|
|
|
|
2009-12-03 10:59:48 -07:00
|
|
|
cfq_log_cfqg(cfqd, cfqg, "del_from_rr group");
|
2011-03-17 09:12:36 -06:00
|
|
|
cfq_group_service_tree_del(st, cfqg);
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqg->saved_wl_slice = 0;
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_dequeue(cfqg);
|
2009-12-03 10:59:45 -07:00
|
|
|
}
|
|
|
|
|
2011-03-12 08:54:00 -07:00
|
|
|
static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq,
|
|
|
|
unsigned int *unaccounted_time)
|
2009-12-03 10:59:45 -07:00
|
|
|
{
|
2009-12-03 10:59:53 -07:00
|
|
|
unsigned int slice_used;
|
2009-12-03 10:59:45 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue got expired before even a single request completed or
|
|
|
|
* got expired immediately after first request completion.
|
|
|
|
*/
|
|
|
|
if (!cfqq->slice_start || cfqq->slice_start == jiffies) {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
slice_used = max_t(unsigned, (jiffies - cfqq->dispatch_start),
|
|
|
|
1);
|
|
|
|
} else {
|
|
|
|
slice_used = jiffies - cfqq->slice_start;
|
2011-03-12 08:54:00 -07:00
|
|
|
if (slice_used > cfqq->allocated_slice) {
|
|
|
|
*unaccounted_time = slice_used - cfqq->allocated_slice;
|
2009-12-03 10:59:53 -07:00
|
|
|
slice_used = cfqq->allocated_slice;
|
2011-03-12 08:54:00 -07:00
|
|
|
}
|
|
|
|
if (time_after(cfqq->slice_start, cfqq->dispatch_start))
|
|
|
|
*unaccounted_time += cfqq->slice_start -
|
|
|
|
cfqq->dispatch_start;
|
2009-12-03 10:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return slice_used;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,
|
2010-04-26 11:25:11 -06:00
|
|
|
struct cfq_queue *cfqq)
|
2009-12-03 10:59:45 -07:00
|
|
|
{
|
|
|
|
struct cfq_rb_root *st = &cfqd->grp_service_tree;
|
2011-03-12 08:54:00 -07:00
|
|
|
unsigned int used_sl, charge, unaccounted_sl = 0;
|
2009-12-03 10:59:54 -07: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 09:05:11 -07:00
|
|
|
unsigned int vfr;
|
2009-12-03 10:59:54 -07:00
|
|
|
|
|
|
|
BUG_ON(nr_sync < 0);
|
2011-03-12 08:54:00 -07:00
|
|
|
used_sl = charge = cfq_cfqq_slice_usage(cfqq, &unaccounted_sl);
|
2009-12-03 10:59:45 -07:00
|
|
|
|
2010-08-23 04:23:53 -06:00
|
|
|
if (iops_mode(cfqd))
|
|
|
|
charge = cfqq->slice_dispatch;
|
|
|
|
else if (!cfq_cfqq_sync(cfqq) && !nr_sync)
|
|
|
|
charge = cfqq->allocated_slice;
|
2009-12-03 10:59:45 -07: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 09:05:11 -07: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 09:12:36 -06: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 09:05:11 -07:00
|
|
|
cfqg->vdisktime += cfqg_scale_charge(charge, vfr);
|
2011-03-17 09:12:36 -06:00
|
|
|
cfq_group_service_tree_add(st, cfqg);
|
2009-12-03 10:59:45 -07:00
|
|
|
|
|
|
|
/* This group is being expired. Save the context */
|
|
|
|
if (time_after(cfqd->workload_expires, jiffies)) {
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqg->saved_wl_slice = cfqd->workload_expires
|
2009-12-03 10:59:45 -07:00
|
|
|
- jiffies;
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqg->saved_wl_type = cfqd->serving_wl_type;
|
|
|
|
cfqg->saved_wl_class = cfqd->serving_wl_class;
|
2009-12-03 10:59:45 -07:00
|
|
|
} else
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqg->saved_wl_slice = 0;
|
2009-12-03 10:59:48 -07:00
|
|
|
|
|
|
|
cfq_log_cfqg(cfqd, cfqg, "served: vt=%llu min_vt=%llu", cfqg->vdisktime,
|
|
|
|
st->min_vdisktime);
|
2011-06-13 02:42:49 -06:00
|
|
|
cfq_log_cfqq(cfqq->cfqd, cfqq,
|
|
|
|
"sl_used=%u disp=%u charge=%u iops=%u sect=%lu",
|
|
|
|
used_sl, cfqq->slice_dispatch, charge,
|
|
|
|
iops_mode(cfqd), cfqq->nr_sectors);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_timeslice_used(cfqg, used_sl, unaccounted_sl);
|
|
|
|
cfqg_stats_set_start_empty_time(cfqg);
|
2009-12-03 10:59:41 -07:00
|
|
|
}
|
|
|
|
|
2012-03-05 14:15:05 -07: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);
|
|
|
|
|
|
|
|
cfqg->ttime.last_end_request = jiffies;
|
|
|
|
}
|
|
|
|
|
2009-12-03 10:59:46 -07:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2013-11-12 20:42:14 -07:00
|
|
|
static void cfqg_stats_init(struct cfqg_stats *stats)
|
|
|
|
{
|
|
|
|
blkg_rwstat_init(&stats->service_bytes);
|
|
|
|
blkg_rwstat_init(&stats->serviced);
|
|
|
|
blkg_rwstat_init(&stats->merged);
|
|
|
|
blkg_rwstat_init(&stats->service_time);
|
|
|
|
blkg_rwstat_init(&stats->wait_time);
|
|
|
|
blkg_rwstat_init(&stats->queued);
|
|
|
|
|
|
|
|
blkg_stat_init(&stats->sectors);
|
|
|
|
blkg_stat_init(&stats->time);
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
|
|
|
blkg_stat_init(&stats->unaccounted_time);
|
|
|
|
blkg_stat_init(&stats->avg_queue_size_sum);
|
|
|
|
blkg_stat_init(&stats->avg_queue_size_samples);
|
|
|
|
blkg_stat_init(&stats->dequeue);
|
|
|
|
blkg_stat_init(&stats->group_wait_time);
|
|
|
|
blkg_stat_init(&stats->idle_time);
|
|
|
|
blkg_stat_init(&stats->empty_time);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-04-16 14:57:25 -06:00
|
|
|
static void cfq_pd_init(struct blkcg_gq *blkg)
|
2011-05-19 13:38:23 -06:00
|
|
|
{
|
2012-03-05 14:15:14 -07:00
|
|
|
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
|
2009-12-03 10:59:46 -07:00
|
|
|
|
2012-03-05 14:15:05 -07:00
|
|
|
cfq_init_cfqg_base(cfqg);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg->weight = blkg->blkcg->cfq_weight;
|
2013-01-09 09:05:10 -07:00
|
|
|
cfqg->leaf_weight = blkg->blkcg->cfq_leaf_weight;
|
2013-11-12 20:42:14 -07:00
|
|
|
cfqg_stats_init(&cfqg->stats);
|
|
|
|
cfqg_stats_init(&cfqg->dead_stats);
|
2009-12-03 10:59:46 -07:00
|
|
|
}
|
|
|
|
|
2013-01-09 09:05:13 -07:00
|
|
|
static void cfq_pd_offline(struct blkcg_gq *blkg)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* @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...
|
|
|
|
*/
|
|
|
|
cfqg_stats_xfer_dead(blkg_to_cfqg(blkg));
|
|
|
|
}
|
|
|
|
|
2013-01-09 09:05:13 -07:00
|
|
|
/* offset delta from cfqg->stats to cfqg->dead_stats */
|
|
|
|
static const int dead_stats_off_delta = offsetof(struct cfq_group, dead_stats) -
|
|
|
|
offsetof(struct cfq_group, stats);
|
|
|
|
|
|
|
|
/* to be used by recursive prfill, sums live and dead stats recursively */
|
|
|
|
static u64 cfqg_stat_pd_recursive_sum(struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
|
|
|
u64 sum = 0;
|
|
|
|
|
|
|
|
sum += blkg_stat_recursive_sum(pd, off);
|
|
|
|
sum += blkg_stat_recursive_sum(pd, off + dead_stats_off_delta);
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* to be used by recursive prfill, sums live and dead rwstats recursively */
|
|
|
|
static struct blkg_rwstat cfqg_rwstat_pd_recursive_sum(struct blkg_policy_data *pd,
|
|
|
|
int off)
|
|
|
|
{
|
|
|
|
struct blkg_rwstat a, b;
|
|
|
|
|
|
|
|
a = blkg_rwstat_recursive_sum(pd, off);
|
|
|
|
b = blkg_rwstat_recursive_sum(pd, off + dead_stats_off_delta);
|
|
|
|
blkg_rwstat_merge(&a, &b);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-01-09 09:05:13 -07:00
|
|
|
static void cfq_pd_reset_stats(struct blkcg_gq *blkg)
|
|
|
|
{
|
|
|
|
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
|
|
|
|
|
|
|
|
cfqg_stats_reset(&cfqg->stats);
|
2013-01-09 09:05:13 -07:00
|
|
|
cfqg_stats_reset(&cfqg->dead_stats);
|
2009-12-03 10:59:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-05-19 13:38:21 -06:00
|
|
|
* Search for the cfq group current task belongs to. request_queue lock must
|
|
|
|
* be held.
|
2009-12-03 10:59:46 -07:00
|
|
|
*/
|
2012-03-05 14:15:06 -07:00
|
|
|
static struct cfq_group *cfq_lookup_create_cfqg(struct cfq_data *cfqd,
|
2012-04-16 14:57:25 -06:00
|
|
|
struct blkcg *blkcg)
|
2009-12-03 10:59:46 -07:00
|
|
|
{
|
2011-05-19 13:38:23 -06:00
|
|
|
struct request_queue *q = cfqd->queue;
|
2012-03-05 14:15:06 -07:00
|
|
|
struct cfq_group *cfqg = NULL;
|
2009-12-03 10:59:46 -07:00
|
|
|
|
2012-04-16 14:57:25 -06:00
|
|
|
/* avoid lookup for the common case where there's no blkcg */
|
|
|
|
if (blkcg == &blkcg_root) {
|
2012-03-05 14:15:06 -07:00
|
|
|
cfqg = cfqd->root_group;
|
|
|
|
} else {
|
2012-04-16 14:57:25 -06:00
|
|
|
struct blkcg_gq *blkg;
|
2011-05-19 13:38:23 -06:00
|
|
|
|
2012-04-13 14:11:34 -06:00
|
|
|
blkg = blkg_lookup_create(blkcg, q);
|
2012-03-05 14:15:06 -07:00
|
|
|
if (!IS_ERR(blkg))
|
2012-03-05 14:15:14 -07:00
|
|
|
cfqg = blkg_to_cfqg(blkg);
|
2012-03-05 14:15:06 -07:00
|
|
|
}
|
2011-05-19 13:38:23 -06:00
|
|
|
|
2009-12-03 10:59:46 -07:00
|
|
|
return cfqg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg)
|
|
|
|
{
|
|
|
|
/* Currently, all async queues are mapped to root group */
|
|
|
|
if (!cfq_cfqq_sync(cfqq))
|
2012-03-05 14:15:05 -07:00
|
|
|
cfqg = cfqq->cfqd->root_group;
|
2009-12-03 10:59:46 -07:00
|
|
|
|
|
|
|
cfqq->cfqg = cfqg;
|
2009-12-03 10:59:47 -07:00
|
|
|
/* cfqq reference on cfqg */
|
2012-03-23 07:02:53 -06:00
|
|
|
cfqg_get(cfqg);
|
2009-12-03 10:59:47 -07:00
|
|
|
}
|
|
|
|
|
2012-04-16 14:57:26 -06:00
|
|
|
static u64 cfqg_prfill_weight_device(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-16 14:57:26 -06:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
2012-04-01 15:38:44 -06:00
|
|
|
|
|
|
|
if (!cfqg->dev_weight)
|
2012-04-01 15:38:43 -06:00
|
|
|
return 0;
|
2012-04-16 14:57:26 -06:00
|
|
|
return __blkg_prfill_u64(sf, pd, cfqg->dev_weight);
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfqg_print_weight_device(struct seq_file *sf, void *v)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2013-12-05 10:28:04 -07:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_weight_device, &blkcg_policy_cfq,
|
|
|
|
0, false);
|
2012-04-01 15:38:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-09 09:05:10 -07: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 10:28:04 -07:00
|
|
|
static int cfqg_print_leaf_weight_device(struct seq_file *sf, void *v)
|
2013-01-09 09:05:10 -07:00
|
|
|
{
|
2013-12-05 10:28:04 -07:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_leaf_weight_device, &blkcg_policy_cfq,
|
|
|
|
0, false);
|
2013-01-09 09:05:10 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfq_print_weight(struct seq_file *sf, void *v)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2013-12-05 10:28:04 -07:00
|
|
|
seq_printf(sf, "%u\n", css_to_blkcg(seq_css(sf))->cfq_weight);
|
2012-04-01 15:38:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfq_print_leaf_weight(struct seq_file *sf, void *v)
|
2013-01-09 09:05:10 -07:00
|
|
|
{
|
2013-12-05 10:28:04 -07:00
|
|
|
seq_printf(sf, "%u\n", css_to_blkcg(seq_css(sf))->cfq_leaf_weight);
|
2013-01-09 09:05:10 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-08 18:11:24 -06:00
|
|
|
static int __cfqg_set_weight_device(struct cgroup_subsys_state *css,
|
|
|
|
struct cftype *cft, const char *buf,
|
|
|
|
bool is_leaf_weight)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2013-08-08 18:11:24 -06:00
|
|
|
struct blkcg *blkcg = css_to_blkcg(css);
|
2012-04-01 15:38:43 -06:00
|
|
|
struct blkg_conf_ctx ctx;
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfq_group *cfqg;
|
2012-04-01 15:38:43 -06:00
|
|
|
int ret;
|
|
|
|
|
2012-04-16 14:57:25 -06:00
|
|
|
ret = blkg_conf_prep(blkcg, &blkcg_policy_cfq, buf, &ctx);
|
2012-04-01 15:38:43 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg = blkg_to_cfqg(ctx.blkg);
|
2012-04-13 14:11:33 -06:00
|
|
|
if (!ctx.v || (ctx.v >= CFQ_WEIGHT_MIN && ctx.v <= CFQ_WEIGHT_MAX)) {
|
2013-01-09 09:05:10 -07:00
|
|
|
if (!is_leaf_weight) {
|
|
|
|
cfqg->dev_weight = ctx.v;
|
|
|
|
cfqg->new_weight = ctx.v ?: blkcg->cfq_weight;
|
|
|
|
} else {
|
|
|
|
cfqg->dev_leaf_weight = ctx.v;
|
|
|
|
cfqg->new_leaf_weight = ctx.v ?: blkcg->cfq_leaf_weight;
|
|
|
|
}
|
2012-04-01 15:38:43 -06:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
blkg_conf_finish(&ctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-08 18:11:24 -06:00
|
|
|
static int cfqg_set_weight_device(struct cgroup_subsys_state *css,
|
|
|
|
struct cftype *cft, const char *buf)
|
2013-01-09 09:05:10 -07:00
|
|
|
{
|
2013-08-08 18:11:24 -06:00
|
|
|
return __cfqg_set_weight_device(css, cft, buf, false);
|
2013-01-09 09:05:10 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:11:24 -06:00
|
|
|
static int cfqg_set_leaf_weight_device(struct cgroup_subsys_state *css,
|
|
|
|
struct cftype *cft, const char *buf)
|
2013-01-09 09:05:10 -07:00
|
|
|
{
|
2013-08-08 18:11:24 -06:00
|
|
|
return __cfqg_set_weight_device(css, cft, buf, true);
|
2013-01-09 09:05:10 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:11:24 -06:00
|
|
|
static int __cfq_set_weight(struct cgroup_subsys_state *css, struct cftype *cft,
|
|
|
|
u64 val, bool is_leaf_weight)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2013-08-08 18:11:24 -06:00
|
|
|
struct blkcg *blkcg = css_to_blkcg(css);
|
2012-04-16 14:57:25 -06:00
|
|
|
struct blkcg_gq *blkg;
|
2012-04-01 15:38:43 -06:00
|
|
|
|
2012-04-01 15:38:44 -06:00
|
|
|
if (val < CFQ_WEIGHT_MIN || val > CFQ_WEIGHT_MAX)
|
2012-04-01 15:38:43 -06:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irq(&blkcg->lock);
|
2013-01-09 09:05:10 -07:00
|
|
|
|
|
|
|
if (!is_leaf_weight)
|
|
|
|
blkcg->cfq_weight = val;
|
|
|
|
else
|
|
|
|
blkcg->cfq_leaf_weight = val;
|
2012-04-01 15:38:43 -06: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-27 18:06:00 -07:00
|
|
|
hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node) {
|
2012-04-01 15:38:44 -06:00
|
|
|
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
|
2012-04-01 15:38:43 -06:00
|
|
|
|
2013-01-09 09:05:10 -07:00
|
|
|
if (!cfqg)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!is_leaf_weight) {
|
|
|
|
if (!cfqg->dev_weight)
|
|
|
|
cfqg->new_weight = blkcg->cfq_weight;
|
|
|
|
} else {
|
|
|
|
if (!cfqg->dev_leaf_weight)
|
|
|
|
cfqg->new_leaf_weight = blkcg->cfq_leaf_weight;
|
|
|
|
}
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irq(&blkcg->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-08 18:11:24 -06:00
|
|
|
static int cfq_set_weight(struct cgroup_subsys_state *css, struct cftype *cft,
|
|
|
|
u64 val)
|
2013-01-09 09:05:10 -07:00
|
|
|
{
|
2013-08-08 18:11:24 -06:00
|
|
|
return __cfq_set_weight(css, cft, val, false);
|
2013-01-09 09:05:10 -07:00
|
|
|
}
|
|
|
|
|
2013-08-08 18:11:24 -06:00
|
|
|
static int cfq_set_leaf_weight(struct cgroup_subsys_state *css,
|
|
|
|
struct cftype *cft, u64 val)
|
2013-01-09 09:05:10 -07:00
|
|
|
{
|
2013-08-08 18:11:24 -06:00
|
|
|
return __cfq_set_weight(css, cft, val, true);
|
2013-01-09 09:05:10 -07:00
|
|
|
}
|
|
|
|
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfqg_print_stat(struct seq_file *sf, void *v)
|
2012-04-01 15:38:45 -06:00
|
|
|
{
|
2013-12-05 10:28:04 -07: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 15:38:45 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfqg_print_rwstat(struct seq_file *sf, void *v)
|
2012-04-01 15:38:45 -06:00
|
|
|
{
|
2013-12-05 10:28:04 -07: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 15:38:45 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-09 09:05:13 -07:00
|
|
|
static u64 cfqg_prfill_stat_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
|
|
|
u64 sum = cfqg_stat_pd_recursive_sum(pd, off);
|
|
|
|
|
|
|
|
return __blkg_prfill_u64(sf, pd, sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 cfqg_prfill_rwstat_recursive(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
|
|
|
{
|
|
|
|
struct blkg_rwstat sum = cfqg_rwstat_pd_recursive_sum(pd, off);
|
|
|
|
|
|
|
|
return __blkg_prfill_rwstat(sf, pd, &sum);
|
|
|
|
}
|
|
|
|
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfqg_print_stat_recursive(struct seq_file *sf, void *v)
|
2013-01-09 09:05:13 -07:00
|
|
|
{
|
2013-12-05 10:28:04 -07: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 09:05:13 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfqg_print_rwstat_recursive(struct seq_file *sf, void *v)
|
2013-01-09 09:05:13 -07:00
|
|
|
{
|
2013-12-05 10:28:04 -07: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 09:05:13 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-01 15:38:43 -06:00
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
2012-04-16 14:57:26 -06:00
|
|
|
static u64 cfqg_prfill_avg_queue_size(struct seq_file *sf,
|
|
|
|
struct blkg_policy_data *pd, int off)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2012-04-16 14:57:26 -06:00
|
|
|
struct cfq_group *cfqg = pd_to_cfqg(pd);
|
2012-04-01 15:38:44 -06:00
|
|
|
u64 samples = blkg_stat_read(&cfqg->stats.avg_queue_size_samples);
|
2012-04-01 15:38:43 -06:00
|
|
|
u64 v = 0;
|
|
|
|
|
|
|
|
if (samples) {
|
2012-04-01 15:38:44 -06:00
|
|
|
v = blkg_stat_read(&cfqg->stats.avg_queue_size_sum);
|
2013-09-22 12:43:47 -06:00
|
|
|
v = div64_u64(v, samples);
|
2012-04-01 15:38:43 -06:00
|
|
|
}
|
2012-04-16 14:57:26 -06:00
|
|
|
__blkg_prfill_u64(sf, pd, v);
|
2012-04-01 15:38:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print avg_queue_size */
|
2013-12-05 10:28:04 -07:00
|
|
|
static int cfqg_print_avg_queue_size(struct seq_file *sf, void *v)
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
2013-12-05 10:28:04 -07:00
|
|
|
blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
|
|
|
|
cfqg_prfill_avg_queue_size, &blkcg_policy_cfq,
|
|
|
|
0, false);
|
2012-04-01 15:38:43 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
|
|
|
|
static struct cftype cfq_blkcg_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 09:05:11 -07:00
|
|
|
/* on root, weight is mapped to leaf_weight */
|
2012-04-01 15:38:43 -06: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 09:05:11 -07:00
|
|
|
.flags = CFTYPE_ONLY_ON_ROOT,
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_leaf_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 09:05:11 -07:00
|
|
|
.write_string = cfqg_set_leaf_weight_device,
|
2012-04-01 15:38:43 -06:00
|
|
|
.max_write_len = 256,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.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 09:05:11 -07:00
|
|
|
.flags = CFTYPE_ONLY_ON_ROOT,
|
2013-12-05 10:28:04 -07: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 09:05:11 -07:00
|
|
|
.write_u64 = cfq_set_leaf_weight,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
2013-01-09 09:05:10 -07: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 09:05:11 -07:00
|
|
|
/* no such mapping necessary for !roots */
|
2012-04-01 15:38:43 -06: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 09:05:11 -07:00
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_weight_device,
|
2012-04-01 15:38:44 -06:00
|
|
|
.write_string = cfqg_set_weight_device,
|
2012-04-01 15:38:43 -06:00
|
|
|
.max_write_len = 256,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.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 09:05:11 -07:00
|
|
|
.flags = CFTYPE_NOT_ON_ROOT,
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfq_print_weight,
|
2012-04-01 15:38:44 -06:00
|
|
|
.write_u64 = cfq_set_weight,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
2013-01-09 09:05:10 -07:00
|
|
|
|
|
|
|
{
|
|
|
|
.name = "leaf_weight_device",
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_leaf_weight_device,
|
2013-01-09 09:05:10 -07:00
|
|
|
.write_string = cfqg_set_leaf_weight_device,
|
|
|
|
.max_write_len = 256,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "leaf_weight",
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfq_print_leaf_weight,
|
2013-01-09 09:05:10 -07:00
|
|
|
.write_u64 = cfq_set_leaf_weight,
|
|
|
|
},
|
|
|
|
|
2013-01-09 09:05:13 -07:00
|
|
|
/* statistics, covers only the tasks in the cfqg */
|
2012-04-01 15:38:43 -06:00
|
|
|
{
|
|
|
|
.name = "time",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "sectors",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.sectors),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_bytes",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.service_bytes),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_serviced",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.serviced),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_time",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.service_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_wait_time",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.wait_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_merged",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.merged),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_queued",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.queued),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
2013-01-09 09:05:13 -07:00
|
|
|
|
|
|
|
/* the same statictics which cover the cfqg and its descendants */
|
|
|
|
{
|
|
|
|
.name = "time_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "sectors_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.sectors),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_bytes_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.service_bytes),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_serviced_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.serviced),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_service_time_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.service_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_wait_time_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.wait_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_merged_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.merged),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "io_queued_recursive",
|
|
|
|
.private = offsetof(struct cfq_group, stats.queued),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_rwstat_recursive,
|
2013-01-09 09:05:13 -07:00
|
|
|
},
|
2012-04-01 15:38:43 -06:00
|
|
|
#ifdef CONFIG_DEBUG_BLK_CGROUP
|
|
|
|
{
|
|
|
|
.name = "avg_queue_size",
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_avg_queue_size,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "group_wait_time",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.group_wait_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "idle_time",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.idle_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "empty_time",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.empty_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "dequeue",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.dequeue),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "unaccounted_time",
|
2012-04-01 15:38:45 -06:00
|
|
|
.private = offsetof(struct cfq_group, stats.unaccounted_time),
|
2013-12-05 10:28:04 -07:00
|
|
|
.seq_show = cfqg_print_stat,
|
2012-04-01 15:38:43 -06:00
|
|
|
},
|
|
|
|
#endif /* CONFIG_DEBUG_BLK_CGROUP */
|
|
|
|
{ } /* terminate */
|
|
|
|
};
|
2009-12-03 10:59:46 -07:00
|
|
|
#else /* GROUP_IOSCHED */
|
2012-03-05 14:15:06 -07:00
|
|
|
static struct cfq_group *cfq_lookup_create_cfqg(struct cfq_data *cfqd,
|
2012-04-16 14:57:25 -06:00
|
|
|
struct blkcg *blkcg)
|
2009-12-03 10:59:46 -07:00
|
|
|
{
|
2012-03-05 14:15:05 -07:00
|
|
|
return cfqd->root_group;
|
2009-12-03 10:59:46 -07:00
|
|
|
}
|
2010-04-21 09:44:16 -06:00
|
|
|
|
2009-12-03 10:59:46 -07: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 04:54:48 -06:00
|
|
|
/*
|
2009-10-27 12:16:03 -06:00
|
|
|
* The cfqd->service_trees holds all pending cfq_queue's that have
|
2007-04-26 04:54:48 -06:00
|
|
|
* requests waiting to be processed. It is sorted in the order that
|
|
|
|
* we will service the queues.
|
|
|
|
*/
|
2009-04-15 04:15:11 -06:00
|
|
|
static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2009-10-07 12:02:57 -06:00
|
|
|
bool add_front)
|
2007-04-20 06:27:50 -06:00
|
|
|
{
|
2008-01-28 03:38:15 -07:00
|
|
|
struct rb_node **p, *parent;
|
|
|
|
struct cfq_queue *__cfqq;
|
2007-04-20 06:27:50 -06:00
|
|
|
unsigned long rb_key;
|
2012-10-03 14:56:58 -06:00
|
|
|
struct cfq_rb_root *st;
|
2007-04-26 04:54:48 -06:00
|
|
|
int left;
|
2009-12-03 10:59:45 -07:00
|
|
|
int new_cfqq = 1;
|
2009-12-03 10:59:55 -07:00
|
|
|
|
2012-10-03 14:56:58 -06:00
|
|
|
st = st_for(cfqq->cfqg, cfqq_class(cfqq), cfqq_type(cfqq));
|
2008-01-28 03:38:15 -07:00
|
|
|
if (cfq_class_idle(cfqq)) {
|
|
|
|
rb_key = CFQ_IDLE_DELAY;
|
2012-10-03 14:56:58 -06:00
|
|
|
parent = rb_last(&st->rb);
|
2008-01-28 03:38:15 -07:00
|
|
|
if (parent && parent != &cfqq->rb_node) {
|
|
|
|
__cfqq = rb_entry(parent, struct cfq_queue, rb_node);
|
|
|
|
rb_key += __cfqq->rb_key;
|
|
|
|
} else
|
|
|
|
rb_key += jiffies;
|
|
|
|
} else if (!add_front) {
|
2009-10-06 12:53:44 -06: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.
|
|
|
|
*/
|
2007-04-19 04:03:34 -06:00
|
|
|
rb_key = cfq_slice_offset(cfqd, cfqq) + jiffies;
|
2009-10-06 12:53:44 -06:00
|
|
|
rb_key -= cfqq->slice_resid;
|
2007-04-19 04:03:34 -06:00
|
|
|
cfqq->slice_resid = 0;
|
2009-10-05 00:49:23 -06:00
|
|
|
} else {
|
|
|
|
rb_key = -HZ;
|
2012-10-03 14:56:58 -06:00
|
|
|
__cfqq = cfq_rb_first(st);
|
2009-10-05 00:49:23 -06:00
|
|
|
rb_key += __cfqq ? __cfqq->rb_key : jiffies;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-04-20 06:27:50 -06:00
|
|
|
if (!RB_EMPTY_NODE(&cfqq->rb_node)) {
|
2009-12-03 10:59:45 -07:00
|
|
|
new_cfqq = 0;
|
2007-02-05 03:56:25 -07:00
|
|
|
/*
|
2007-04-20 06:27:50 -06:00
|
|
|
* same position, nothing more to do
|
2007-02-05 03:56:25 -07:00
|
|
|
*/
|
2012-10-03 14:56:58 -06:00
|
|
|
if (rb_key == cfqq->rb_key && cfqq->service_tree == st)
|
2007-04-20 06:27:50 -06:00
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-10-26 15:44:33 -06:00
|
|
|
cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree);
|
|
|
|
cfqq->service_tree = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2007-04-20 06:27:50 -06:00
|
|
|
|
2007-04-26 04:54:48 -06:00
|
|
|
left = 1;
|
2008-01-28 03:38:15 -07:00
|
|
|
parent = NULL;
|
2012-10-03 14:56:58 -06:00
|
|
|
cfqq->service_tree = st;
|
|
|
|
p = &st->rb.rb_node;
|
2007-04-20 06:27:50 -06:00
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
__cfqq = rb_entry(parent, struct cfq_queue, rb_node);
|
|
|
|
|
2007-04-18 12:01:57 -06:00
|
|
|
/*
|
2009-10-27 12:16:03 -06:00
|
|
|
* sort by key, that represents service time.
|
2007-04-18 12:01:57 -06:00
|
|
|
*/
|
2009-10-27 12:16:03 -06:00
|
|
|
if (time_before(rb_key, __cfqq->rb_key))
|
2012-10-03 14:57:00 -06:00
|
|
|
p = &parent->rb_left;
|
2009-10-27 12:16:03 -06:00
|
|
|
else {
|
2012-10-03 14:57:00 -06:00
|
|
|
p = &parent->rb_right;
|
2007-04-26 04:53:50 -06:00
|
|
|
left = 0;
|
2009-10-27 12:16:03 -06:00
|
|
|
}
|
2007-04-20 06:27:50 -06:00
|
|
|
}
|
|
|
|
|
2007-04-26 04:53:50 -06:00
|
|
|
if (left)
|
2012-10-03 14:56:58 -06:00
|
|
|
st->left = &cfqq->rb_node;
|
2007-04-26 04:53:50 -06:00
|
|
|
|
2007-04-20 06:27:50 -06:00
|
|
|
cfqq->rb_key = rb_key;
|
|
|
|
rb_link_node(&cfqq->rb_node, parent, p);
|
2012-10-03 14:56:58 -06:00
|
|
|
rb_insert_color(&cfqq->rb_node, &st->rb);
|
|
|
|
st->count++;
|
2011-05-24 02:23:22 -06:00
|
|
|
if (add_front || !new_cfqq)
|
2009-12-03 10:59:45 -07:00
|
|
|
return;
|
2011-03-17 09:12:36 -06:00
|
|
|
cfq_group_notify_queue_add(cfqd, cfqq->cfqg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-04-15 04:15:11 -06:00
|
|
|
static struct cfq_queue *
|
2009-04-23 04:19:38 -06: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 04:15:11 -06: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 07:24:41 -06:00
|
|
|
if (sector > blk_rq_pos(cfqq->next_rq))
|
2009-04-15 04:15:11 -06:00
|
|
|
n = &(*p)->rb_right;
|
2009-05-07 07:24:41 -06:00
|
|
|
else if (sector < blk_rq_pos(cfqq->next_rq))
|
2009-04-15 04:15:11 -06:00
|
|
|
n = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
p = n;
|
2009-04-23 04:14:56 -06:00
|
|
|
cfqq = NULL;
|
2009-04-15 04:15:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
*ret_parent = parent;
|
|
|
|
if (rb_link)
|
|
|
|
*rb_link = p;
|
2009-04-23 04:14:56 -06:00
|
|
|
return cfqq;
|
2009-04-15 04:15:11 -06: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 04:19:38 -06:00
|
|
|
if (cfqq->p_root) {
|
|
|
|
rb_erase(&cfqq->p_node, cfqq->p_root);
|
|
|
|
cfqq->p_root = NULL;
|
|
|
|
}
|
2009-04-15 04:15:11 -06:00
|
|
|
|
|
|
|
if (cfq_class_idle(cfqq))
|
|
|
|
return;
|
|
|
|
if (!cfqq->next_rq)
|
|
|
|
return;
|
|
|
|
|
2009-04-23 04:19:38 -06:00
|
|
|
cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio];
|
2009-05-07 07:24:41 -06:00
|
|
|
__cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root,
|
|
|
|
blk_rq_pos(cfqq->next_rq), &parent, &p);
|
2009-04-23 04:14:56 -06:00
|
|
|
if (!__cfqq) {
|
|
|
|
rb_link_node(&cfqq->p_node, parent, p);
|
2009-04-23 04:19:38 -06:00
|
|
|
rb_insert_color(&cfqq->p_node, cfqq->p_root);
|
|
|
|
} else
|
|
|
|
cfqq->p_root = NULL;
|
2009-04-15 04:15:11 -06:00
|
|
|
}
|
|
|
|
|
2007-04-26 04:54:48 -06:00
|
|
|
/*
|
|
|
|
* Update cfqq's position in the service tree.
|
|
|
|
*/
|
2007-04-19 04:03:34 -06:00
|
|
|
static void cfq_resort_rr_list(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2007-04-25 04:44:27 -06:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Resorting requires the cfqq to be on the RR list already.
|
|
|
|
*/
|
2009-04-15 04:15:11 -06:00
|
|
|
if (cfq_cfqq_on_rr(cfqq)) {
|
2007-04-19 04:03:34 -06:00
|
|
|
cfq_service_tree_add(cfqd, cfqq, 0);
|
2009-04-15 04:15:11 -06:00
|
|
|
cfq_prio_tree_add(cfqd, cfqq);
|
|
|
|
}
|
2007-04-25 04:44:27 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* add to busy list of queues for service, trying to be fair in ordering
|
2005-06-27 02:55:12 -06:00
|
|
|
* the pending list according to last request service
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2008-01-28 05:19:43 -07:00
|
|
|
static void cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "add_to_rr");
|
2005-06-27 02:56:24 -06:00
|
|
|
BUG_ON(cfq_cfqq_on_rr(cfqq));
|
|
|
|
cfq_mark_cfqq_on_rr(cfqq);
|
2005-04-16 16:20:36 -06:00
|
|
|
cfqd->busy_queues++;
|
2011-03-07 01:26:29 -07:00
|
|
|
if (cfq_cfqq_sync(cfqq))
|
|
|
|
cfqd->busy_sync_queues++;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-04-19 04:03:34 -06:00
|
|
|
cfq_resort_rr_list(cfqd, cfqq);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-04-26 04:54:48 -06:00
|
|
|
/*
|
|
|
|
* Called when the cfqq no longer has requests pending, remove it from
|
|
|
|
* the service tree.
|
|
|
|
*/
|
2008-01-28 05:19:43 -07:00
|
|
|
static void cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "del_from_rr");
|
2005-06-27 02:56:24 -06:00
|
|
|
BUG_ON(!cfq_cfqq_on_rr(cfqq));
|
|
|
|
cfq_clear_cfqq_on_rr(cfqq);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-10-26 15:44:33 -06:00
|
|
|
if (!RB_EMPTY_NODE(&cfqq->rb_node)) {
|
|
|
|
cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree);
|
|
|
|
cfqq->service_tree = NULL;
|
|
|
|
}
|
2009-04-23 04:19:38 -06:00
|
|
|
if (cfqq->p_root) {
|
|
|
|
rb_erase(&cfqq->p_node, cfqq->p_root);
|
|
|
|
cfqq->p_root = NULL;
|
|
|
|
}
|
2007-04-20 06:27:50 -06:00
|
|
|
|
2011-03-17 09:12:36 -06:00
|
|
|
cfq_group_notify_queue_del(cfqd, cfqq->cfqg);
|
2005-04-16 16:20:36 -06:00
|
|
|
BUG_ON(!cfqd->busy_queues);
|
|
|
|
cfqd->busy_queues--;
|
2011-03-07 01:26:29 -07:00
|
|
|
if (cfq_cfqq_sync(cfqq))
|
|
|
|
cfqd->busy_sync_queues--;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rb tree support functions
|
|
|
|
*/
|
2008-01-28 05:19:43 -07:00
|
|
|
static void cfq_del_rq_rb(struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
|
|
|
const int sync = rq_is_sync(rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-10-20 08:42:29 -06:00
|
|
|
BUG_ON(!cfqq->queued[sync]);
|
|
|
|
cfqq->queued[sync]--;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-07-13 04:39:25 -06:00
|
|
|
elv_rb_del(&cfqq->sort_list, rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-12-03 10:59:40 -07: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 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-07-13 04:39:25 -06:00
|
|
|
static void cfq_add_rq_rb(struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-04-16 16:20:36 -06: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 13:19:05 -06:00
|
|
|
struct request *prev;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-07-13 04:37:56 -06:00
|
|
|
cfqq->queued[rq_is_sync(rq)]++;
|
2005-04-16 16:20:36 -06: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 13:19:05 -06:00
|
|
|
elv_rb_add(&cfqq->sort_list, rq);
|
2006-10-31 06:21:55 -07:00
|
|
|
|
|
|
|
if (!cfq_cfqq_on_rr(cfqq))
|
|
|
|
cfq_add_cfqq_rr(cfqd, cfqq);
|
2007-04-25 03:53:48 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check if this request is a better next-serve candidate
|
|
|
|
*/
|
2009-04-15 04:15:11 -06: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 09:16:46 -07:00
|
|
|
cfqq->next_rq = cfq_choose_req(cfqd, cfqq->next_rq, rq, cfqd->last_position);
|
2009-04-15 04:15:11 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* adjust priority tree position, if ->next_rq changes
|
|
|
|
*/
|
|
|
|
if (prev != cfqq->next_rq)
|
|
|
|
cfq_prio_tree_add(cfqd, cfqq);
|
|
|
|
|
2007-04-25 03:53:48 -06:00
|
|
|
BUG_ON(!cfqq->next_rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-01-28 05:19:43 -07:00
|
|
|
static void cfq_reposition_rq_rb(struct cfq_queue *cfqq, struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:37:56 -06:00
|
|
|
elv_rb_del(&cfqq->sort_list, rq);
|
|
|
|
cfqq->queued[rq_is_sync(rq)]--;
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_io_remove(RQ_CFQG(rq), rq->cmd_flags);
|
2006-07-13 04:39:25 -06:00
|
|
|
cfq_add_rq_rb(rq);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_io_add(RQ_CFQG(rq), cfqq->cfqd->serving_group,
|
|
|
|
rq->cmd_flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-28 04:03:44 -07:00
|
|
|
static struct request *
|
|
|
|
cfq_find_rq_fmerge(struct cfq_data *cfqd, struct bio *bio)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-03-28 04:03:44 -07:00
|
|
|
struct task_struct *tsk = current;
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic;
|
2006-03-28 04:03:44 -07:00
|
|
|
struct cfq_queue *cfqq;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-01-24 00:44:49 -07:00
|
|
|
cic = cfq_cic_lookup(cfqd, tsk->io_context);
|
2007-04-25 04:29:51 -06:00
|
|
|
if (!cic)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio));
|
2012-09-25 16:05:12 -06:00
|
|
|
if (cfqq)
|
|
|
|
return elv_rb_find(&cfqq->sort_list, bio_end_sector(bio));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static void cfq_activate_request(struct request_queue *q, struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-06-27 02:55:12 -06:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2005-06-27 02:56:24 -06:00
|
|
|
|
2010-02-28 11:45:05 -07:00
|
|
|
cfqd->rq_in_driver++;
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d",
|
2010-02-28 11:45:05 -07:00
|
|
|
cfqd->rq_in_driver);
|
2006-06-01 02:12:26 -06:00
|
|
|
|
2009-05-07 07:24:38 -06:00
|
|
|
cfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static void cfq_deactivate_request(struct request_queue *q, struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-10-20 08:42:29 -06:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
|
2010-02-28 11:45:05 -07:00
|
|
|
WARN_ON(!cfqd->rq_in_driver);
|
|
|
|
cfqd->rq_in_driver--;
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "deactivate rq, drv=%d",
|
2010-02-28 11:45:05 -07:00
|
|
|
cfqd->rq_in_driver);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2005-10-20 08:42:29 -06:00
|
|
|
static void cfq_remove_request(struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2006-07-13 04:33:14 -06:00
|
|
|
|
2006-07-13 04:39:25 -06:00
|
|
|
if (cfqq->next_rq == rq)
|
|
|
|
cfqq->next_rq = cfq_find_next_rq(cfqq->cfqd, cfqq, rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-10-20 08:42:29 -06:00
|
|
|
list_del_init(&rq->queuelist);
|
2006-07-13 04:39:25 -06:00
|
|
|
cfq_del_rq_rb(rq);
|
2006-07-22 17:42:19 -06:00
|
|
|
|
2008-08-26 07:52:36 -06:00
|
|
|
cfqq->cfqd->rq_queued--;
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_io_remove(RQ_CFQG(rq), rq->cmd_flags);
|
2011-08-23 06:50:29 -06:00
|
|
|
if (rq->cmd_flags & REQ_PRIO) {
|
|
|
|
WARN_ON(!cfqq->prio_pending);
|
|
|
|
cfqq->prio_pending--;
|
2011-08-19 00:34:48 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static int cfq_merge(struct request_queue *q, struct request **req,
|
|
|
|
struct bio *bio)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
struct request *__rq;
|
|
|
|
|
2006-03-28 04:03:44 -07:00
|
|
|
__rq = cfq_find_rq_fmerge(cfqd, bio);
|
2005-06-27 02:55:12 -06:00
|
|
|
if (__rq && elv_rq_merge_ok(__rq, bio)) {
|
2006-07-28 01:23:08 -06:00
|
|
|
*req = __rq;
|
|
|
|
return ELEVATOR_FRONT_MERGE;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return ELEVATOR_NO_MERGE;
|
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static void cfq_merged_request(struct request_queue *q, struct request *req,
|
2006-07-13 04:33:14 -06:00
|
|
|
int type)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:33:14 -06:00
|
|
|
if (type == ELEVATOR_FRONT_MERGE) {
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(req);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-07-13 04:39:25 -06:00
|
|
|
cfq_reposition_rq_rb(cfqq, req);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-08 22:14:23 -06:00
|
|
|
static void cfq_bio_merged(struct request_queue *q, struct request *req,
|
|
|
|
struct bio *bio)
|
|
|
|
{
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_io_merged(RQ_CFQG(req), bio->bi_rw);
|
2010-04-08 22:14:23 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static void
|
2007-07-24 01:28:11 -06:00
|
|
|
cfq_merged_requests(struct request_queue *q, struct request *rq,
|
2005-04-16 16:20:36 -06: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 09:16:46 -07:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2011-12-16 06:00:22 -07:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
|
|
|
* reposition in fifo if next is older than rq
|
|
|
|
*/
|
|
|
|
if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist) &&
|
2012-11-06 04:39:51 -07:00
|
|
|
time_before(rq_fifo_time(next), rq_fifo_time(rq)) &&
|
|
|
|
cfqq == RQ_CFQQ(next)) {
|
2005-06-27 02:55:12 -06:00
|
|
|
list_move(&rq->queuelist, &next->queuelist);
|
2009-10-05 03:03:39 -06:00
|
|
|
rq_set_fifo_time(rq, rq_fifo_time(next));
|
|
|
|
}
|
2005-06-27 02:55:12 -06: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 09:16:46 -07:00
|
|
|
if (cfqq->next_rq == next)
|
|
|
|
cfqq->next_rq = rq;
|
2005-10-20 08:42:29 -06:00
|
|
|
cfq_remove_request(next);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_io_merged(RQ_CFQG(rq), next->cmd_flags);
|
2011-12-16 06:00:22 -07: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 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static int cfq_allow_merge(struct request_queue *q, struct request *rq,
|
2006-12-20 03:04:12 -07:00
|
|
|
struct bio *bio)
|
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic;
|
2006-12-20 03:04:12 -07:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
|
|
|
|
/*
|
2007-01-02 10:32:11 -07:00
|
|
|
* Disallow merge of a sync bio into an async request.
|
2006-12-20 03:04:12 -07:00
|
|
|
*/
|
2007-04-25 04:29:51 -06:00
|
|
|
if (cfq_bio_sync(bio) && !rq_is_sync(rq))
|
2009-10-07 12:02:57 -06:00
|
|
|
return false;
|
2006-12-20 03:04:12 -07:00
|
|
|
|
|
|
|
/*
|
2011-12-13 16:33:39 -07: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 01:19:42 -07:00
|
|
|
* merge only if rq is queued there.
|
2011-12-13 16:33:39 -07: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 01:19:42 -07:00
|
|
|
cic = cfq_cic_lookup(cfqd, current->io_context);
|
|
|
|
if (!cic)
|
|
|
|
return false;
|
2006-12-22 01:38:53 -07:00
|
|
|
|
2007-04-25 04:29:51 -06:00
|
|
|
cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio));
|
2009-10-07 12:02:57 -06:00
|
|
|
return cfqq == RQ_CFQQ(rq);
|
2006-12-20 03:04:12 -07:00
|
|
|
}
|
|
|
|
|
2010-04-08 22:15:35 -06:00
|
|
|
static inline void cfq_del_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
del_timer(&cfqd->idle_slice_timer);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_idle_time(cfqq->cfqg);
|
2010-04-08 22:15:35 -06:00
|
|
|
}
|
|
|
|
|
2008-01-28 05:19:43 -07:00
|
|
|
static void __cfq_set_active_queue(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
|
|
|
if (cfqq) {
|
2012-10-03 14:56:56 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "set_active wl_class:%d wl_type:%d",
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_avg_queue_size(cfqq->cfqg);
|
2011-03-23 01:25:44 -06:00
|
|
|
cfqq->slice_start = 0;
|
|
|
|
cfqq->dispatch_start = jiffies;
|
|
|
|
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 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
cfqd->active_queue = cfqq;
|
|
|
|
}
|
|
|
|
|
2006-02-28 01:35:11 -07: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 11:25:11 -06:00
|
|
|
bool timed_out)
|
2006-02-28 01:35:11 -07:00
|
|
|
{
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "slice expired t=%d", timed_out);
|
|
|
|
|
2006-02-28 01:35:11 -07:00
|
|
|
if (cfq_cfqq_wait_request(cfqq))
|
2010-04-08 22:15:35 -06:00
|
|
|
cfq_del_timer(cfqd, cfqq);
|
2006-02-28 01:35:11 -07:00
|
|
|
|
|
|
|
cfq_clear_cfqq_wait_request(cfqq);
|
2009-12-03 10:59:53 -07:00
|
|
|
cfq_clear_cfqq_wait_busy(cfqq);
|
2006-02-28 01:35:11 -07:00
|
|
|
|
2010-02-05 05:11:45 -07: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 01:35:11 -07:00
|
|
|
/*
|
2007-04-23 00:25:00 -06:00
|
|
|
* store what was left of this slice, if the queue idled/timed out
|
2006-02-28 01:35:11 -07:00
|
|
|
*/
|
2011-01-14 00:41:03 -07:00
|
|
|
if (timed_out) {
|
|
|
|
if (cfq_cfqq_slice_new(cfqq))
|
2011-01-19 08:25:02 -07:00
|
|
|
cfqq->slice_resid = cfq_scaled_cfqq_slice(cfqd, cfqq);
|
2011-01-14 00:41:03 -07:00
|
|
|
else
|
|
|
|
cfqq->slice_resid = cfqq->slice_end - jiffies;
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "resid=%ld", cfqq->slice_resid);
|
|
|
|
}
|
2006-02-28 01:35:11 -07:00
|
|
|
|
2010-04-26 11:25:11 -06:00
|
|
|
cfq_group_served(cfqd, cfqq->cfqg, cfqq);
|
2009-12-03 10:59:45 -07:00
|
|
|
|
2009-12-03 10:59:40 -07:00
|
|
|
if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list))
|
|
|
|
cfq_del_cfqq_rr(cfqd, cfqq);
|
|
|
|
|
2007-04-19 04:03:34 -06:00
|
|
|
cfq_resort_rr_list(cfqd, cfqq);
|
2006-02-28 01:35:11 -07:00
|
|
|
|
|
|
|
if (cfqq == cfqd->active_queue)
|
|
|
|
cfqd->active_queue = NULL;
|
|
|
|
|
|
|
|
if (cfqd->active_cic) {
|
2012-02-06 23:51:30 -07:00
|
|
|
put_io_context(cfqd->active_cic->icq.ioc);
|
2006-02-28 01:35:11 -07:00
|
|
|
cfqd->active_cic = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-26 11:25:11 -06:00
|
|
|
static inline void cfq_slice_expired(struct cfq_data *cfqd, bool timed_out)
|
2006-02-28 01:35:11 -07:00
|
|
|
{
|
|
|
|
struct cfq_queue *cfqq = cfqd->active_queue;
|
|
|
|
|
|
|
|
if (cfqq)
|
2010-04-26 11:25:11 -06:00
|
|
|
__cfq_slice_expired(cfqd, cfqq, timed_out);
|
2006-02-28 01:35:11 -07:00
|
|
|
}
|
|
|
|
|
2007-04-26 04:54:48 -06: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 04:44:27 -06:00
|
|
|
static struct cfq_queue *cfq_get_next_queue(struct cfq_data *cfqd)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2012-10-03 14:56:58 -06:00
|
|
|
struct cfq_rb_root *st = st_for(cfqd->serving_group,
|
|
|
|
cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2007-04-20 06:27:50 -06:00
|
|
|
|
2009-12-03 10:59:40 -07:00
|
|
|
if (!cfqd->rq_queued)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 10:59:41 -07:00
|
|
|
/* There is nothing to dispatch */
|
2012-10-03 14:56:58 -06:00
|
|
|
if (!st)
|
2009-12-03 10:59:41 -07:00
|
|
|
return NULL;
|
2012-10-03 14:56:58 -06:00
|
|
|
if (RB_EMPTY_ROOT(&st->rb))
|
2009-10-27 12:16:03 -06:00
|
|
|
return NULL;
|
2012-10-03 14:56:58 -06:00
|
|
|
return cfq_rb_first(st);
|
2007-04-25 04:44:27 -06:00
|
|
|
}
|
|
|
|
|
2009-12-03 10:59:40 -07:00
|
|
|
static struct cfq_queue *cfq_get_next_queue_forced(struct cfq_data *cfqd)
|
|
|
|
{
|
2009-12-03 10:59:46 -07:00
|
|
|
struct cfq_group *cfqg;
|
2009-12-03 10:59:40 -07:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
int i, j;
|
|
|
|
struct cfq_rb_root *st;
|
|
|
|
|
|
|
|
if (!cfqd->rq_queued)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 10:59:46 -07:00
|
|
|
cfqg = cfq_get_next_cfqg(cfqd);
|
|
|
|
if (!cfqg)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 10:59:40 -07:00
|
|
|
for_each_cfqg_st(cfqg, i, j, st)
|
|
|
|
if ((cfqq = cfq_rb_first(st)) != NULL)
|
|
|
|
return cfqq;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-04-26 04:54:48 -06:00
|
|
|
/*
|
|
|
|
* Get and set a new active queue for service.
|
|
|
|
*/
|
2009-04-15 04:15:11 -06:00
|
|
|
static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
2007-04-25 04:44:27 -06:00
|
|
|
{
|
2009-11-04 00:54:55 -07:00
|
|
|
if (!cfqq)
|
2009-04-15 04:15:11 -06:00
|
|
|
cfqq = cfq_get_next_queue(cfqd);
|
2007-04-25 04:44:27 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
__cfq_set_active_queue(cfqd, cfqq);
|
2005-06-27 02:56:24 -06:00
|
|
|
return cfqq;
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
2007-04-20 06:27:50 -06:00
|
|
|
static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd,
|
|
|
|
struct request *rq)
|
|
|
|
{
|
2009-05-07 07:24:39 -06:00
|
|
|
if (blk_rq_pos(rq) >= cfqd->last_position)
|
|
|
|
return blk_rq_pos(rq) - cfqd->last_position;
|
2007-04-20 06:27:50 -06:00
|
|
|
else
|
2009-05-07 07:24:39 -06:00
|
|
|
return cfqd->last_position - blk_rq_pos(rq);
|
2007-04-20 06:27:50 -06:00
|
|
|
}
|
|
|
|
|
2009-10-23 15:14:49 -06:00
|
|
|
static inline int cfq_rq_close(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2010-03-19 01:03:04 -06:00
|
|
|
struct request *rq)
|
2007-04-25 04:44:27 -06:00
|
|
|
{
|
2010-03-19 01:03:04 -06:00
|
|
|
return cfq_dist_from_last(cfqd, rq) <= CFQQ_CLOSE_THR;
|
2007-04-25 04:44:27 -06:00
|
|
|
}
|
|
|
|
|
2009-04-15 04:15:11 -06:00
|
|
|
static struct cfq_queue *cfqq_close(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cur_cfqq)
|
|
|
|
{
|
2009-04-23 04:19:38 -06:00
|
|
|
struct rb_root *root = &cfqd->prio_trees[cur_cfqq->org_ioprio];
|
2009-04-15 04:15:11 -06: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 04:19:38 -06:00
|
|
|
__cfqq = cfq_prio_tree_lookup(cfqd, root, sector, &parent, NULL);
|
2009-04-15 04:15:11 -06: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 01:03:04 -06:00
|
|
|
if (cfq_rq_close(cfqd, cur_cfqq, __cfqq->next_rq))
|
2009-04-15 04:15:11 -06:00
|
|
|
return __cfqq;
|
|
|
|
|
2009-05-07 07:24:41 -06:00
|
|
|
if (blk_rq_pos(__cfqq->next_rq) < sector)
|
2009-04-15 04:15:11 -06: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 01:03:04 -06:00
|
|
|
if (cfq_rq_close(cfqd, cur_cfqq, __cfqq->next_rq))
|
2009-04-15 04:15:11 -06: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 15:14:51 -06:00
|
|
|
struct cfq_queue *cur_cfqq)
|
2007-04-25 04:44:27 -06:00
|
|
|
{
|
2009-04-15 04:15:11 -06:00
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
|
2010-03-25 08:45:57 -06:00
|
|
|
if (cfq_class_idle(cur_cfqq))
|
|
|
|
return NULL;
|
2009-10-23 15:14:52 -06:00
|
|
|
if (!cfq_cfqq_sync(cur_cfqq))
|
|
|
|
return NULL;
|
|
|
|
if (CFQQ_SEEKY(cur_cfqq))
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-08 00:54:17 -07: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 04:44:27 -06:00
|
|
|
/*
|
2007-04-20 06:27:50 -06: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 04:44:27 -06:00
|
|
|
*/
|
2009-04-15 04:15:11 -06:00
|
|
|
cfqq = cfqq_close(cfqd, cur_cfqq);
|
|
|
|
if (!cfqq)
|
|
|
|
return NULL;
|
|
|
|
|
2009-12-03 10:59:50 -07:00
|
|
|
/* If new queue belongs to different cfq_group, don't choose it */
|
|
|
|
if (cur_cfqq->cfqg != cfqq->cfqg)
|
|
|
|
return NULL;
|
|
|
|
|
2009-10-23 15:14:50 -06:00
|
|
|
/*
|
|
|
|
* It only makes sense to merge sync queues.
|
|
|
|
*/
|
|
|
|
if (!cfq_cfqq_sync(cfqq))
|
|
|
|
return NULL;
|
2009-10-23 15:14:52 -06:00
|
|
|
if (CFQQ_SEEKY(cfqq))
|
|
|
|
return NULL;
|
2009-10-23 15:14:50 -06:00
|
|
|
|
2009-10-27 12:16:03 -06:00
|
|
|
/*
|
|
|
|
* Do not merge queues of different priority classes
|
|
|
|
*/
|
|
|
|
if (cfq_class_rt(cfqq) != cfq_class_rt(cur_cfqq))
|
|
|
|
return NULL;
|
|
|
|
|
2009-04-15 04:15:11 -06:00
|
|
|
return cfqq;
|
2007-04-25 04:44:27 -06: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 15:45:11 -06: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 14:56:56 -06:00
|
|
|
enum wl_class_t wl_class = cfqq_class(cfqq);
|
2012-10-03 14:56:58 -06: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 15:45:11 -06:00
|
|
|
|
2012-10-03 14:56:58 -06:00
|
|
|
BUG_ON(!st);
|
|
|
|
BUG_ON(!st->count);
|
2009-12-03 10:59:40 -07:00
|
|
|
|
2010-08-23 04:23:33 -06: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 15:45:11 -06:00
|
|
|
/* We never do for idle class queues. */
|
2012-10-03 14:56:56 -06: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 15:45:11 -06:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* We do for queues that were marked with idle window flag. */
|
2009-12-04 05:12:06 -07: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 15:45:11 -06:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise, we do only if they are the last ones
|
|
|
|
* in their service tree.
|
|
|
|
*/
|
2012-10-03 14:56:58 -06:00
|
|
|
if (st->count == 1 && cfq_cfqq_sync(cfqq) &&
|
|
|
|
!cfq_io_thinktime_big(cfqd, &st->ttime, false))
|
2010-11-08 07:01:02 -07:00
|
|
|
return true;
|
2012-10-03 14:56:58 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "Not idling. st->count:%d", st->count);
|
2010-11-08 07:01:02 -07: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 15:45:11 -06:00
|
|
|
}
|
|
|
|
|
2007-04-25 04:44:27 -06:00
|
|
|
static void cfq_arm_slice_timer(struct cfq_data *cfqd)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2007-01-18 17:59:30 -07:00
|
|
|
struct cfq_queue *cfqq = cfqd->active_queue;
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic;
|
2010-08-23 04:24:26 -06:00
|
|
|
unsigned long sl, group_idle = 0;
|
2006-02-28 01:35:11 -07:00
|
|
|
|
2008-09-24 05:03:33 -06:00
|
|
|
/*
|
2008-09-25 03:37:50 -06: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 05:03:33 -06:00
|
|
|
*/
|
2008-09-25 03:37:50 -06:00
|
|
|
if (blk_queue_nonrot(cfqd->queue) && cfqd->hw_tag)
|
2008-09-24 05:03:33 -06:00
|
|
|
return;
|
|
|
|
|
2006-06-21 01:36:18 -06:00
|
|
|
WARN_ON(!RB_EMPTY_ROOT(&cfqq->sort_list));
|
2007-04-25 04:44:27 -06:00
|
|
|
WARN_ON(cfq_cfqq_slice_new(cfqq));
|
2005-06-27 02:55:12 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* idle is disabled, either manually or by past process history
|
|
|
|
*/
|
2010-08-23 04:24:26 -06: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 04:44:27 -06:00
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
/*
|
2009-11-26 02:02:58 -07:00
|
|
|
* still active requests from this queue, don't idle
|
2008-05-30 04:23:07 -06:00
|
|
|
*/
|
2009-11-26 02:02:58 -07:00
|
|
|
if (cfqq->dispatched)
|
2008-05-30 04:23:07 -06:00
|
|
|
return;
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
|
|
|
* task has exited, don't wait
|
|
|
|
*/
|
2006-03-28 04:03:44 -07:00
|
|
|
cic = cfqd->active_cic;
|
2012-03-05 14:15:26 -07:00
|
|
|
if (!cic || !atomic_read(&cic->icq.ioc->active_ref))
|
2007-04-25 04:44:27 -06:00
|
|
|
return;
|
|
|
|
|
2009-10-08 00:43:32 -06: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 06:24:35 -06:00
|
|
|
if (sample_valid(cic->ttime.ttime_samples) &&
|
|
|
|
(cfqq->slice_end - jiffies < cic->ttime.ttime_mean)) {
|
2011-06-13 02:42:49 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "Not idling. think_time:%lu",
|
2011-07-12 06:24:35 -06:00
|
|
|
cic->ttime.ttime_mean);
|
2009-10-08 00:43:32 -06:00
|
|
|
return;
|
2010-03-25 08:45:03 -06:00
|
|
|
}
|
2009-10-08 00:43:32 -06:00
|
|
|
|
2010-08-23 04:24:26 -06:00
|
|
|
/* There are other queues in the group, don't do group idle */
|
|
|
|
if (group_idle && cfqq->cfqg->nr_cfqq > 1)
|
|
|
|
return;
|
|
|
|
|
2005-06-27 02:56:24 -06:00
|
|
|
cfq_mark_cfqq_wait_request(cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2010-08-23 04:24:26 -06:00
|
|
|
if (group_idle)
|
|
|
|
sl = cfqd->cfq_group_idle;
|
|
|
|
else
|
|
|
|
sl = cfqd->cfq_slice_idle;
|
2006-03-28 04:03:44 -07:00
|
|
|
|
2006-02-28 01:35:11 -07:00
|
|
|
mod_timer(&cfqd->idle_slice_timer, jiffies + sl);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_set_start_idle_time(cfqq->cfqg);
|
2010-08-23 04:24:26 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "arm_idle: %lu group_idle: %d", sl,
|
|
|
|
group_idle ? 1 : 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-04-26 04:54:48 -06:00
|
|
|
/*
|
|
|
|
* Move request from internal lists to the request queue dispatch list.
|
|
|
|
*/
|
2007-07-24 01:28:11 -06:00
|
|
|
static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-04-23 00:33:33 -06:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "dispatch_insert");
|
|
|
|
|
2009-09-11 09:08:59 -06:00
|
|
|
cfqq->next_rq = cfq_find_next_rq(cfqd, cfqq, rq);
|
2006-07-13 04:37:56 -06:00
|
|
|
cfq_remove_request(rq);
|
2007-04-25 04:44:27 -06:00
|
|
|
cfqq->dispatched++;
|
2010-08-23 04:24:26 -06:00
|
|
|
(RQ_CFQG(rq))->dispatched++;
|
2006-07-13 04:37:56 -06:00
|
|
|
elv_dispatch_sort(q, rq);
|
2007-04-23 00:33:33 -06:00
|
|
|
|
2010-02-28 11:45:05 -07:00
|
|
|
cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]++;
|
2010-08-23 04:25:03 -06:00
|
|
|
cfqq->nr_sectors += blk_rq_sectors(rq);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_dispatch(cfqq->cfqg, blk_rq_bytes(rq), rq->cmd_flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return expired entry, or NULL to just start from scratch in rbtree
|
|
|
|
*/
|
2008-01-28 05:19:43 -07:00
|
|
|
static struct request *cfq_check_fifo(struct cfq_queue *cfqq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-10-05 03:03:39 -06:00
|
|
|
struct request *rq = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:56:24 -06:00
|
|
|
if (cfq_cfqq_fifo_expire(cfqq))
|
2005-04-16 16:20:36 -06:00
|
|
|
return NULL;
|
2007-01-18 18:01:16 -07:00
|
|
|
|
|
|
|
cfq_mark_cfqq_fifo_expire(cfqq);
|
|
|
|
|
2006-07-22 08:48:31 -06:00
|
|
|
if (list_empty(&cfqq->fifo))
|
|
|
|
return NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-07-22 08:48:31 -06:00
|
|
|
rq = rq_entry_fifo(cfqq->fifo.next);
|
2009-10-05 03:03:39 -06:00
|
|
|
if (time_before(jiffies, rq_fifo_time(rq)))
|
2008-05-30 04:23:07 -06:00
|
|
|
rq = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-10-05 03:03:39 -06:00
|
|
|
cfq_log_cfqq(cfqq->cfqd, cfqq, "fifo=%p", rq);
|
2007-04-25 04:44:27 -06:00
|
|
|
return rq;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2005-06-27 02:55:12 -06: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 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-05-24 02:23:21 -06:00
|
|
|
return 2 * base_rq * (IOPRIO_BE_NR - cfqq->ioprio);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-10-23 15:14:50 -06: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 00:46:59 -07:00
|
|
|
process_refs = cfqq->ref - io_refs;
|
2009-10-23 15:14:50 -06: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 15:14:52 -06:00
|
|
|
int process_refs, new_process_refs;
|
2009-10-23 15:14:50 -06: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 08:19:11 -06: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 15:14:50 -06: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 08:19:11 -06:00
|
|
|
new_process_refs = cfqq_process_refs(new_cfqq);
|
2009-10-23 15:14:50 -06: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 08:19:11 -06:00
|
|
|
if (process_refs == 0 || new_process_refs == 0)
|
2009-10-23 15:14:50 -06:00
|
|
|
return;
|
|
|
|
|
2009-10-23 15:14:52 -06: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 00:46:59 -07:00
|
|
|
new_cfqq->ref += process_refs;
|
2009-10-23 15:14:52 -06:00
|
|
|
} else {
|
|
|
|
new_cfqq->new_cfqq = cfqq;
|
2011-01-07 00:46:59 -07:00
|
|
|
cfqq->ref += new_process_refs;
|
2009-10-23 15:14:52 -06:00
|
|
|
}
|
2009-10-23 15:14:50 -06:00
|
|
|
}
|
|
|
|
|
2012-10-03 14:56:59 -06:00
|
|
|
static enum wl_type_t cfq_choose_wl_type(struct cfq_data *cfqd,
|
2012-10-03 14:56:56 -06: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 15:45:29 -06:00
|
|
|
{
|
|
|
|
struct cfq_queue *queue;
|
|
|
|
int i;
|
|
|
|
bool key_valid = false;
|
|
|
|
unsigned long lowest_key = 0;
|
|
|
|
enum wl_type_t cur_best = SYNC_NOIDLE_WORKLOAD;
|
|
|
|
|
2009-12-16 15:52:59 -07:00
|
|
|
for (i = 0; i <= SYNC_WORKLOAD; ++i) {
|
|
|
|
/* select the one with lowest rb_key */
|
2012-10-03 14:56:58 -06: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 15:45:29 -06:00
|
|
|
if (queue &&
|
|
|
|
(!key_valid || time_before(queue->rb_key, lowest_key))) {
|
|
|
|
lowest_key = queue->rb_key;
|
|
|
|
cur_best = i;
|
|
|
|
key_valid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cur_best;
|
|
|
|
}
|
|
|
|
|
2012-10-03 14:56:59 -06: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 15:45:29 -06:00
|
|
|
{
|
|
|
|
unsigned slice;
|
|
|
|
unsigned count;
|
2009-12-03 10:59:38 -07:00
|
|
|
struct cfq_rb_root *st;
|
2009-12-03 10:59:44 -07:00
|
|
|
unsigned group_slice;
|
2012-10-03 14:56:57 -06:00
|
|
|
enum wl_class_t original_class = cfqd->serving_wl_class;
|
2009-12-03 10:59:41 -07: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 15:45:29 -06:00
|
|
|
/* Choose next priority. RT > BE > IDLE */
|
2009-12-03 10:59:44 -07:00
|
|
|
if (cfq_group_busy_queues_wl(RT_WORKLOAD, cfqd, cfqg))
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqd->serving_wl_class = RT_WORKLOAD;
|
2009-12-03 10:59:44 -07:00
|
|
|
else if (cfq_group_busy_queues_wl(BE_WORKLOAD, cfqd, cfqg))
|
2012-10-03 14:56:57 -06: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 15:45:29 -06:00
|
|
|
else {
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqd->serving_wl_class = IDLE_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 15:45:29 -06:00
|
|
|
cfqd->workload_expires = jiffies + 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-03 14:56:57 -06:00
|
|
|
if (original_class != cfqd->serving_wl_class)
|
2010-12-13 06:32:22 -07: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 15:45:29 -06: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 14:56:58 -06:00
|
|
|
st = st_for(cfqg, cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2009-12-03 10:59:38 -07: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 15:45:29 -06:00
|
|
|
|
|
|
|
/*
|
2009-12-16 15:52:59 -07: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 15:45:29 -06:00
|
|
|
*/
|
2009-12-16 15:52:59 -07:00
|
|
|
if (count && !time_after(jiffies, 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 15:45:29 -06:00
|
|
|
return;
|
|
|
|
|
2010-12-13 06:32:22 -07: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 15:45:29 -06:00
|
|
|
/* otherwise select new workload type */
|
2012-10-03 14:56:59 -06:00
|
|
|
cfqd->serving_wl_type = cfq_choose_wl_type(cfqd, cfqg,
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqd->serving_wl_class);
|
2012-10-03 14:56:58 -06:00
|
|
|
st = st_for(cfqg, cfqd->serving_wl_class, cfqd->serving_wl_type);
|
2009-12-03 10:59:38 -07: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 15:45:29 -06: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 10:59:44 -07:00
|
|
|
group_slice = cfq_group_slice(cfqd, cfqg);
|
|
|
|
|
|
|
|
slice = group_slice * count /
|
2012-10-03 14:56:57 -06:00
|
|
|
max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_wl_class],
|
|
|
|
cfq_group_busy_queues_wl(cfqd->serving_wl_class, cfqd,
|
2012-10-03 14:56:56 -06: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 15:45:29 -06:00
|
|
|
|
2012-10-03 14:56:57 -06:00
|
|
|
if (cfqd->serving_wl_type == ASYNC_WORKLOAD) {
|
2009-12-03 10:59:54 -07:00
|
|
|
unsigned int tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 15:33:39 -06:00
|
|
|
tmp = cfqd->cfq_target_latency *
|
|
|
|
cfqg_busy_async_queues(cfqd, cfqg);
|
2009-12-03 10:59:54 -07:00
|
|
|
tmp = tmp/cfqd->busy_queues;
|
|
|
|
slice = min_t(unsigned, slice, tmp);
|
|
|
|
|
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 15:45:29 -06:00
|
|
|
/* async workload slice is scaled down according to
|
|
|
|
* the sync/async slice ratio. */
|
|
|
|
slice = slice * cfqd->cfq_slice[0] / cfqd->cfq_slice[1];
|
2009-12-03 10:59:54 -07: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 15:45:29 -06:00
|
|
|
/* sync workload slice is at least 2 * cfq_slice_idle */
|
|
|
|
slice = max(slice, 2 * cfqd->cfq_slice_idle);
|
|
|
|
|
|
|
|
slice = max_t(unsigned, slice, CFQ_MIN_TT);
|
2010-03-25 08:45:03 -06:00
|
|
|
cfq_log(cfqd, "workload slice:%d", 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 15:45:29 -06:00
|
|
|
cfqd->workload_expires = jiffies + slice;
|
|
|
|
}
|
|
|
|
|
2009-12-03 10:59:41 -07: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 10:59:43 -07:00
|
|
|
struct cfq_group *cfqg;
|
2009-12-03 10:59:41 -07:00
|
|
|
|
|
|
|
if (RB_EMPTY_ROOT(&st->rb))
|
|
|
|
return NULL;
|
2009-12-03 10:59:43 -07:00
|
|
|
cfqg = cfq_rb_first_group(st);
|
|
|
|
update_min_vdisktime(st);
|
|
|
|
return cfqg;
|
2009-12-03 10:59:41 -07:00
|
|
|
}
|
|
|
|
|
2009-12-03 10:59:38 -07:00
|
|
|
static void cfq_choose_cfqg(struct cfq_data *cfqd)
|
|
|
|
{
|
2009-12-03 10:59:41 -07:00
|
|
|
struct cfq_group *cfqg = cfq_get_next_cfqg(cfqd);
|
|
|
|
|
|
|
|
cfqd->serving_group = cfqg;
|
2009-12-03 10:59:45 -07:00
|
|
|
|
|
|
|
/* Restore the workload type data */
|
2012-10-03 14:56:57 -06:00
|
|
|
if (cfqg->saved_wl_slice) {
|
|
|
|
cfqd->workload_expires = jiffies + cfqg->saved_wl_slice;
|
|
|
|
cfqd->serving_wl_type = cfqg->saved_wl_type;
|
|
|
|
cfqd->serving_wl_class = cfqg->saved_wl_class;
|
2009-12-15 02:08:45 -07:00
|
|
|
} else
|
|
|
|
cfqd->workload_expires = jiffies - 1;
|
|
|
|
|
2012-10-03 14:56:59 -06:00
|
|
|
choose_wl_class_and_type(cfqd, cfqg);
|
2009-12-03 10:59:38 -07:00
|
|
|
}
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
2007-04-26 04:54:48 -06: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 02:55:12 -06:00
|
|
|
*/
|
2005-11-10 00:49:19 -07:00
|
|
|
static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-04-15 04:15:11 -06:00
|
|
|
struct cfq_queue *cfqq, *new_cfqq = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
cfqq = cfqd->active_queue;
|
|
|
|
if (!cfqq)
|
|
|
|
goto new_queue;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-12-03 10:59:40 -07:00
|
|
|
if (!cfqd->rq_queued)
|
|
|
|
return NULL;
|
2009-12-08 15:52:57 -07: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 02:55:12 -06:00
|
|
|
/*
|
2007-04-25 04:44:27 -06:00
|
|
|
* The active queue has run out of time, expire it and select new.
|
2005-06-27 02:55:12 -06:00
|
|
|
*/
|
2009-12-08 15:52:58 -07: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 11:25:41 -07: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 15:52:58 -07:00
|
|
|
goto keep_queue;
|
2009-12-10 11:25:41 -07:00
|
|
|
} else
|
2010-08-23 04:24:26 -06:00
|
|
|
goto check_group_idle;
|
2009-12-08 15:52:58 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
2007-04-25 04:44:27 -06:00
|
|
|
* The active queue has requests and isn't expired, allow it to
|
|
|
|
* dispatch.
|
2005-06-27 02:55:12 -06:00
|
|
|
*/
|
2006-06-21 01:36:18 -06:00
|
|
|
if (!RB_EMPTY_ROOT(&cfqq->sort_list))
|
2005-06-27 02:55:12 -06:00
|
|
|
goto keep_queue;
|
2007-04-25 04:44:27 -06:00
|
|
|
|
2009-04-15 04:15:11 -06: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 15:14:50 -06:00
|
|
|
* tree. If possible, merge the expiring queue with the new cfqq.
|
2009-04-15 04:15:11 -06:00
|
|
|
*/
|
2009-10-23 15:14:51 -06:00
|
|
|
new_cfqq = cfq_close_cooperator(cfqd, cfqq);
|
2009-10-23 15:14:50 -06:00
|
|
|
if (new_cfqq) {
|
|
|
|
if (!cfqq->new_cfqq)
|
|
|
|
cfq_setup_merge(cfqq, new_cfqq);
|
2009-04-15 04:15:11 -06:00
|
|
|
goto expire;
|
2009-10-23 15:14:50 -06:00
|
|
|
}
|
2009-04-15 04:15:11 -06:00
|
|
|
|
2007-04-25 04:44:27 -06: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.
|
|
|
|
*/
|
2010-08-23 04:24:26 -06:00
|
|
|
if (timer_pending(&cfqd->idle_slice_timer)) {
|
|
|
|
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 07:01:04 -07: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) ||
|
|
|
|
(cfqq->slice_end - jiffies > jiffies - cfqq->slice_start))) {
|
|
|
|
cfq_clear_cfqq_deep(cfqq);
|
|
|
|
cfq_clear_cfqq_idle_window(cfqq);
|
|
|
|
}
|
|
|
|
|
2010-08-23 04:24:26 -06: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 06:24:56 -06: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 03:23:00 -06:00
|
|
|
cfqq = NULL;
|
|
|
|
goto keep_queue;
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
2005-06-27 02:56:24 -06:00
|
|
|
expire:
|
2010-04-26 11:25:11 -06:00
|
|
|
cfq_slice_expired(cfqd, 0);
|
2005-06-27 02:56:24 -06: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 15:45:29 -06:00
|
|
|
/*
|
|
|
|
* Current queue expired. Check if we have to switch to a new
|
|
|
|
* service tree
|
|
|
|
*/
|
|
|
|
if (!new_cfqq)
|
2009-12-03 10:59:38 -07: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 15:45:29 -06:00
|
|
|
|
2009-04-15 04:15:11 -06:00
|
|
|
cfqq = cfq_set_active_queue(cfqd, new_cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
keep_queue:
|
2005-06-27 02:56:24 -06:00
|
|
|
return cfqq;
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
2008-01-28 05:19:43 -07:00
|
|
|
static int __cfq_forced_dispatch_cfqq(struct cfq_queue *cfqq)
|
2007-04-20 06:27:50 -06: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 10:59:40 -07:00
|
|
|
|
|
|
|
/* By default cfqq is not expired if it is empty. Do it explicitly */
|
2010-04-26 11:25:11 -06:00
|
|
|
__cfq_slice_expired(cfqq->cfqd, cfqq, 0);
|
2007-04-20 06:27:50 -06:00
|
|
|
return dispatched;
|
|
|
|
}
|
|
|
|
|
2007-04-26 04:54:48 -06:00
|
|
|
/*
|
|
|
|
* Drain our current requests. Used for barriers and when switching
|
|
|
|
* io schedulers on-the-fly.
|
|
|
|
*/
|
2007-04-20 06:27:50 -06:00
|
|
|
static int cfq_forced_dispatch(struct cfq_data *cfqd)
|
2005-11-10 00:49:19 -07:00
|
|
|
{
|
2008-01-28 03:38:15 -07:00
|
|
|
struct cfq_queue *cfqq;
|
2007-04-20 06:27:50 -06:00
|
|
|
int dispatched = 0;
|
2009-12-03 10:59:38 -07:00
|
|
|
|
2010-04-09 01:29:57 -06:00
|
|
|
/* Expire the timeslice of the current active queue first */
|
2010-04-26 11:25:11 -06:00
|
|
|
cfq_slice_expired(cfqd, 0);
|
2010-04-09 01:29:57 -06:00
|
|
|
while ((cfqq = cfq_get_next_queue_forced(cfqd)) != NULL) {
|
|
|
|
__cfq_set_active_queue(cfqd, cfqq);
|
2009-12-03 10:59:40 -07:00
|
|
|
dispatched += __cfq_forced_dispatch_cfqq(cfqq);
|
2010-04-09 01:29:57 -06:00
|
|
|
}
|
2005-11-10 00:49:19 -07:00
|
|
|
|
|
|
|
BUG_ON(cfqd->busy_queues);
|
|
|
|
|
2009-06-12 07:29:30 -06:00
|
|
|
cfq_log(cfqd, "forced_dispatch=%d", dispatched);
|
2005-11-10 00:49:19 -07:00
|
|
|
return dispatched;
|
|
|
|
}
|
|
|
|
|
2010-03-01 01:20:54 -07:00
|
|
|
static inline bool cfq_slice_used_soon(struct cfq_data *cfqd,
|
|
|
|
struct cfq_queue *cfqq)
|
|
|
|
{
|
|
|
|
/* the queue hasn't finished any request, can't estimate */
|
|
|
|
if (cfq_cfqq_slice_new(cfqq))
|
2010-11-08 07:01:02 -07:00
|
|
|
return true;
|
2010-03-01 01:20:54 -07:00
|
|
|
if (time_after(jiffies + cfqd->cfq_slice_idle * cfqq->dispatched,
|
|
|
|
cfqq->slice_end))
|
2010-11-08 07:01:02 -07:00
|
|
|
return true;
|
2010-03-01 01:20:54 -07:00
|
|
|
|
2010-11-08 07:01:02 -07:00
|
|
|
return false;
|
2010-03-01 01:20:54 -07:00
|
|
|
}
|
|
|
|
|
2009-10-06 12:49:37 -06:00
|
|
|
static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
2009-04-07 00:51:19 -06:00
|
|
|
{
|
|
|
|
unsigned int max_dispatch;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2009-07-03 04:57:48 -06:00
|
|
|
/*
|
|
|
|
* Drain async requests before we start sync IO
|
|
|
|
*/
|
2010-02-28 11:45:05 -07:00
|
|
|
if (cfq_should_idle(cfqd, cfqq) && cfqd->rq_in_flight[BLK_RW_ASYNC])
|
2009-10-06 12:49:37 -06:00
|
|
|
return false;
|
2009-07-03 04:57:48 -06:00
|
|
|
|
2009-04-07 00:51:19 -06:00
|
|
|
/*
|
|
|
|
* If this is an async queue and we have sync IO in flight, let it wait
|
|
|
|
*/
|
2010-02-28 11:45:05 -07:00
|
|
|
if (cfqd->rq_in_flight[BLK_RW_SYNC] && !cfq_cfqq_sync(cfqq))
|
2009-10-06 12:49:37 -06:00
|
|
|
return false;
|
2009-04-07 00:51:19 -06:00
|
|
|
|
2010-03-01 01:20:54 -07:00
|
|
|
max_dispatch = max_t(unsigned int, cfqd->cfq_quantum / 2, 1);
|
2009-04-07 00:51:19 -06:00
|
|
|
if (cfq_class_idle(cfqq))
|
|
|
|
max_dispatch = 1;
|
2005-10-20 08:42:29 -06:00
|
|
|
|
2009-04-07 00:51:19 -06:00
|
|
|
/*
|
|
|
|
* Does this cfqq already have too much IO in flight?
|
|
|
|
*/
|
|
|
|
if (cfqq->dispatched >= max_dispatch) {
|
2011-03-07 01:26:29 -07:00
|
|
|
bool promote_sync = false;
|
2009-04-07 00:51:19 -06:00
|
|
|
/*
|
|
|
|
* idle queue must always only have a single IO in flight
|
|
|
|
*/
|
2007-04-23 00:33:33 -06:00
|
|
|
if (cfq_class_idle(cfqq))
|
2009-10-06 12:49:37 -06:00
|
|
|
return false;
|
2007-04-23 00:33:33 -06:00
|
|
|
|
2011-03-07 01:26:29 -07:00
|
|
|
/*
|
2011-03-23 01:30:34 -06:00
|
|
|
* If there is only one sync queue
|
|
|
|
* we can ignore async queue here and give the sync
|
2011-03-07 01:26:29 -07: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 01:30:34 -06:00
|
|
|
if (cfq_cfqq_sync(cfqq) && cfqd->busy_sync_queues == 1)
|
|
|
|
promote_sync = true;
|
2011-03-07 01:26:29 -07:00
|
|
|
|
2009-04-07 00:51:19 -06:00
|
|
|
/*
|
|
|
|
* We have other queues, don't allow more IO from this one
|
|
|
|
*/
|
2011-03-07 01:26:29 -07:00
|
|
|
if (cfqd->busy_queues > 1 && cfq_slice_used_soon(cfqd, cfqq) &&
|
|
|
|
!promote_sync)
|
2009-10-06 12:49:37 -06:00
|
|
|
return false;
|
2007-01-18 18:11:44 -07:00
|
|
|
|
2009-10-03 07:21:27 -06:00
|
|
|
/*
|
2009-12-03 04:58:05 -07:00
|
|
|
* Sole queue user, no limit
|
2009-10-03 07:21:27 -06:00
|
|
|
*/
|
2011-03-07 01:26:29 -07:00
|
|
|
if (cfqd->busy_queues == 1 || promote_sync)
|
2010-03-01 01:20:54 -07: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 08:26:03 -06: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 11:42:18 -06:00
|
|
|
if (!cfq_cfqq_sync(cfqq) && cfqd->cfq_latency) {
|
2009-12-06 03:48:52 -07:00
|
|
|
unsigned long last_sync = jiffies - cfqd->last_delayed_sync;
|
2009-10-03 08:26:03 -06:00
|
|
|
unsigned int depth;
|
2009-10-03 07:21:27 -06:00
|
|
|
|
2009-10-03 11:46:03 -06:00
|
|
|
depth = last_sync / cfqd->cfq_slice[1];
|
2009-10-04 12:36:19 -06:00
|
|
|
if (!depth && !cfqq->dispatched)
|
|
|
|
depth = 1;
|
2009-10-03 08:26:03 -06:00
|
|
|
if (depth < max_dispatch)
|
|
|
|
max_dispatch = depth;
|
2009-04-07 00:51:19 -06:00
|
|
|
}
|
2007-04-23 00:33:33 -06:00
|
|
|
|
2009-10-06 12:49:37 -06: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));
|
|
|
|
|
|
|
|
if (!cfq_may_dispatch(cfqd, cfqq))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* follow expired path, else get first next available
|
|
|
|
*/
|
|
|
|
rq = cfq_check_fifo(cfqq);
|
|
|
|
if (!rq)
|
|
|
|
rq = cfqq->next_rq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* insert request into driver dispatch list
|
|
|
|
*/
|
|
|
|
cfq_dispatch_insert(cfqd->queue, rq);
|
|
|
|
|
|
|
|
if (!cfqd->active_cic) {
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic = RQ_CIC(rq);
|
2009-10-06 12:49:37 -06:00
|
|
|
|
2011-12-13 16:33:41 -07:00
|
|
|
atomic_long_inc(&cic->icq.ioc->refcount);
|
2009-10-06 12:49:37 -06: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 08:26:03 -06:00
|
|
|
return 0;
|
|
|
|
|
2009-04-07 00:51:19 -06:00
|
|
|
/*
|
2009-10-06 12:49:37 -06:00
|
|
|
* Dispatch a request from this cfqq, if it is allowed
|
2009-04-07 00:51:19 -06:00
|
|
|
*/
|
2009-10-06 12:49:37 -06:00
|
|
|
if (!cfq_dispatch_request(cfqd, cfqq))
|
|
|
|
return 0;
|
|
|
|
|
2009-04-07 00:51:19 -06:00
|
|
|
cfqq->slice_dispatch++;
|
2009-04-07 03:38:31 -06:00
|
|
|
cfq_clear_cfqq_must_dispatch(cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2009-04-07 00:51:19 -06: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))) {
|
|
|
|
cfqq->slice_end = jiffies + 1;
|
2010-04-26 11:25:11 -06:00
|
|
|
cfq_slice_expired(cfqd, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2009-09-01 02:06:42 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "dispatched a request");
|
2009-04-07 00:51:19 -06:00
|
|
|
return 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-13 04:39:25 -06: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 16:20:36 -06:00
|
|
|
*
|
2009-12-03 10:59:47 -07:00
|
|
|
* Each cfq queue took a reference on the parent group. Drop it now.
|
2005-04-16 16:20:36 -06:00
|
|
|
* queue lock must be held here.
|
|
|
|
*/
|
|
|
|
static void cfq_put_queue(struct cfq_queue *cfqq)
|
|
|
|
{
|
2005-06-27 02:55:12 -06:00
|
|
|
struct cfq_data *cfqd = cfqq->cfqd;
|
2011-03-01 13:05:08 -07:00
|
|
|
struct cfq_group *cfqg;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2011-01-07 00:46:59 -07:00
|
|
|
BUG_ON(cfqq->ref <= 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-01-07 00:46:59 -07:00
|
|
|
cfqq->ref--;
|
|
|
|
if (cfqq->ref)
|
2005-04-16 16:20:36 -06:00
|
|
|
return;
|
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "put_queue");
|
2005-04-16 16:20:36 -06:00
|
|
|
BUG_ON(rb_first(&cfqq->sort_list));
|
2005-06-27 02:55:12 -06:00
|
|
|
BUG_ON(cfqq->allocated[READ] + cfqq->allocated[WRITE]);
|
2009-12-03 10:59:47 -07:00
|
|
|
cfqg = cfqq->cfqg;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-01-18 18:09:53 -07:00
|
|
|
if (unlikely(cfqd->active_queue == cfqq)) {
|
2010-04-26 11:25:11 -06:00
|
|
|
__cfq_slice_expired(cfqd, cfqq, 0);
|
2009-10-05 00:52:35 -06:00
|
|
|
cfq_schedule_dispatch(cfqd);
|
2007-01-18 18:09:53 -07:00
|
|
|
}
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2009-12-03 10:59:40 -07:00
|
|
|
BUG_ON(cfq_cfqq_on_rr(cfqq));
|
2005-04-16 16:20:36 -06:00
|
|
|
kmem_cache_free(cfq_pool, cfqq);
|
2012-03-23 07:02:53 -06:00
|
|
|
cfqg_put(cfqg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-05-25 02:16:53 -06:00
|
|
|
static void cfq_put_cooperator(struct cfq_queue *cfqq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2009-10-23 15:14:50 -06: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 02:16:53 -06: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 15:14:50 -06:00
|
|
|
|
2006-07-22 08:48:31 -06:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
}
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2011-12-13 16:33:42 -07:00
|
|
|
static void cfq_init_icq(struct io_cq *icq)
|
|
|
|
{
|
|
|
|
struct cfq_io_cq *cic = icq_to_cic(icq);
|
|
|
|
|
|
|
|
cic->ttime.last_end_request = jiffies;
|
|
|
|
}
|
|
|
|
|
2011-12-13 16:33:41 -07:00
|
|
|
static void cfq_exit_icq(struct io_cq *icq)
|
2006-07-22 08:48:31 -06:00
|
|
|
{
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic = icq_to_cic(icq);
|
2011-12-13 16:33:38 -07:00
|
|
|
struct cfq_data *cfqd = cic_to_cfqd(cic);
|
2008-04-10 00:28:01 -06:00
|
|
|
|
2009-04-08 02:58:57 -06:00
|
|
|
if (cic->cfqq[BLK_RW_ASYNC]) {
|
|
|
|
cfq_exit_cfqq(cfqd, cic->cfqq[BLK_RW_ASYNC]);
|
|
|
|
cic->cfqq[BLK_RW_ASYNC] = NULL;
|
2006-03-18 11:38:01 -07:00
|
|
|
}
|
|
|
|
|
2009-04-08 02:58:57 -06:00
|
|
|
if (cic->cfqq[BLK_RW_SYNC]) {
|
|
|
|
cfq_exit_cfqq(cfqd, cic->cfqq[BLK_RW_SYNC]);
|
|
|
|
cic->cfqq[BLK_RW_SYNC] = NULL;
|
2006-03-18 11:38:01 -07:00
|
|
|
}
|
2006-07-22 08:48:31 -06:00
|
|
|
}
|
|
|
|
|
2012-03-19 16:10:57 -06:00
|
|
|
static void cfq_init_prio_data(struct cfq_queue *cfqq, struct cfq_io_cq *cic)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
|
|
|
struct task_struct *tsk = current;
|
|
|
|
int ioprio_class;
|
|
|
|
|
2005-06-27 02:56:24 -06:00
|
|
|
if (!cfq_cfqq_prio_changed(cfqq))
|
2005-06-27 02:55:12 -06:00
|
|
|
return;
|
|
|
|
|
2012-03-19 16:10:58 -06:00
|
|
|
ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
|
2005-06-27 02:55:12 -06:00
|
|
|
switch (ioprio_class) {
|
2008-01-31 05:08:54 -07:00
|
|
|
default:
|
|
|
|
printk(KERN_ERR "cfq: bad prio %x\n", ioprio_class);
|
|
|
|
case IOPRIO_CLASS_NONE:
|
|
|
|
/*
|
2008-05-07 01:51:23 -06:00
|
|
|
* no prio set, inherit CPU scheduling settings
|
2008-01-31 05:08:54 -07:00
|
|
|
*/
|
|
|
|
cfqq->ioprio = task_nice_ioprio(tsk);
|
2008-05-07 01:51:23 -06:00
|
|
|
cfqq->ioprio_class = task_nice_ioclass(tsk);
|
2008-01-31 05:08:54 -07:00
|
|
|
break;
|
|
|
|
case IOPRIO_CLASS_RT:
|
2012-03-19 16:10:58 -06:00
|
|
|
cfqq->ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
|
2008-01-31 05:08:54 -07:00
|
|
|
cfqq->ioprio_class = IOPRIO_CLASS_RT;
|
|
|
|
break;
|
|
|
|
case IOPRIO_CLASS_BE:
|
2012-03-19 16:10:58 -06:00
|
|
|
cfqq->ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
|
2008-01-31 05:08:54 -07: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 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* keep track of original prio settings in case we have to temporarily
|
|
|
|
* elevate the priority of this queue
|
|
|
|
*/
|
|
|
|
cfqq->org_ioprio = cfqq->ioprio;
|
2005-06-27 02:56:24 -06:00
|
|
|
cfq_clear_cfqq_prio_changed(cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
2012-03-19 16:10:58 -06:00
|
|
|
static void check_ioprio_changed(struct cfq_io_cq *cic, struct bio *bio)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2012-03-19 16:10:58 -06:00
|
|
|
int ioprio = cic->icq.ioc->ioprio;
|
2010-05-20 13:21:34 -06:00
|
|
|
struct cfq_data *cfqd = cic_to_cfqd(cic);
|
2006-03-18 11:25:24 -07:00
|
|
|
struct cfq_queue *cfqq;
|
2006-06-14 01:10:45 -06:00
|
|
|
|
2012-03-19 16:10:58 -06: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 03:23:00 -06:00
|
|
|
return;
|
|
|
|
|
2009-04-08 02:58:57 -06:00
|
|
|
cfqq = cic->cfqq[BLK_RW_ASYNC];
|
2006-06-16 03:23:00 -06:00
|
|
|
if (cfqq) {
|
|
|
|
struct cfq_queue *new_cfqq;
|
2012-03-19 16:10:57 -06:00
|
|
|
new_cfqq = cfq_get_queue(cfqd, BLK_RW_ASYNC, cic, bio,
|
|
|
|
GFP_ATOMIC);
|
2006-06-16 03:23:00 -06:00
|
|
|
if (new_cfqq) {
|
2009-04-08 02:58:57 -06:00
|
|
|
cic->cfqq[BLK_RW_ASYNC] = new_cfqq;
|
2006-06-16 03:23:00 -06:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
}
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
2006-06-16 03:23:00 -06:00
|
|
|
|
2009-04-08 02:58:57 -06:00
|
|
|
cfqq = cic->cfqq[BLK_RW_SYNC];
|
2006-06-16 03:23:00 -06:00
|
|
|
if (cfqq)
|
|
|
|
cfq_mark_cfqq_prio_changed(cfqq);
|
2012-03-19 16:10:58 -06:00
|
|
|
|
|
|
|
cic->ioprio = ioprio;
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
2009-06-26 02:44:34 -06:00
|
|
|
static void cfq_init_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2009-10-07 12:02:57 -06:00
|
|
|
pid_t pid, bool is_sync)
|
2009-06-26 02:44:34 -06:00
|
|
|
{
|
|
|
|
RB_CLEAR_NODE(&cfqq->rb_node);
|
|
|
|
RB_CLEAR_NODE(&cfqq->p_node);
|
|
|
|
INIT_LIST_HEAD(&cfqq->fifo);
|
|
|
|
|
2011-01-07 00:46:59 -07:00
|
|
|
cfqq->ref = 0;
|
2009-06-26 02:44:34 -06: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 10:59:51 -07:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-03-19 16:10:58 -06:00
|
|
|
static void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio)
|
2009-12-03 10:59:51 -07:00
|
|
|
{
|
2010-05-20 13:21:34 -06:00
|
|
|
struct cfq_data *cfqd = cic_to_cfqd(cic);
|
2012-03-19 16:10:58 -06:00
|
|
|
struct cfq_queue *sync_cfqq;
|
|
|
|
uint64_t id;
|
2009-12-03 10:59:51 -07:00
|
|
|
|
2012-03-19 16:10:58 -06:00
|
|
|
rcu_read_lock();
|
2012-04-16 14:57:25 -06:00
|
|
|
id = bio_blkcg(bio)->id;
|
2012-03-19 16:10:58 -06:00
|
|
|
rcu_read_unlock();
|
2009-12-03 10:59:51 -07:00
|
|
|
|
2012-03-19 16:10:58 -06:00
|
|
|
/*
|
|
|
|
* Check whether blkcg has changed. The condition may trigger
|
|
|
|
* spuriously on a newly created cic but there's no harm.
|
|
|
|
*/
|
|
|
|
if (unlikely(!cfqd) || likely(cic->blkcg_id == id))
|
|
|
|
return;
|
2009-12-03 10:59:51 -07:00
|
|
|
|
2012-03-19 16:10:58 -06:00
|
|
|
sync_cfqq = cic_to_cfqq(cic, 1);
|
2009-12-03 10:59:51 -07:00
|
|
|
if (sync_cfqq) {
|
|
|
|
/*
|
|
|
|
* Drop reference to sync queue. A new sync queue will be
|
|
|
|
* assigned in new group upon arrival of a fresh request.
|
|
|
|
*/
|
|
|
|
cfq_log_cfqq(cfqd, sync_cfqq, "changed cgroup");
|
|
|
|
cic_set_cfqq(cic, NULL, 1);
|
|
|
|
cfq_put_queue(sync_cfqq);
|
|
|
|
}
|
2012-03-19 16:10:58 -06:00
|
|
|
|
|
|
|
cic->blkcg_id = id;
|
2009-12-03 10:59:51 -07:00
|
|
|
}
|
2012-03-19 16:10:58 -06:00
|
|
|
#else
|
|
|
|
static inline void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio) { }
|
2009-12-03 10:59:51 -07:00
|
|
|
#endif /* CONFIG_CFQ_GROUP_IOSCHED */
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
static struct cfq_queue *
|
2012-03-19 16:10:57 -06:00
|
|
|
cfq_find_alloc_queue(struct cfq_data *cfqd, bool is_sync, struct cfq_io_cq *cic,
|
|
|
|
struct bio *bio, gfp_t gfp_mask)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2012-04-16 14:57:25 -06:00
|
|
|
struct blkcg *blkcg;
|
2005-06-27 02:55:12 -06:00
|
|
|
struct cfq_queue *cfqq, *new_cfqq = NULL;
|
2009-12-03 10:59:38 -07:00
|
|
|
struct cfq_group *cfqg;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
|
|
|
retry:
|
2012-03-05 14:15:01 -07:00
|
|
|
rcu_read_lock();
|
|
|
|
|
2012-04-16 14:57:25 -06:00
|
|
|
blkcg = bio_blkcg(bio);
|
2012-03-05 14:15:06 -07:00
|
|
|
cfqg = cfq_lookup_create_cfqg(cfqd, blkcg);
|
2007-04-25 04:29:51 -06:00
|
|
|
cfqq = cic_to_cfqq(cic, is_sync);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2009-06-30 01:34:12 -06:00
|
|
|
/*
|
|
|
|
* Always try a new alloc if we fell back to the OOM cfqq
|
|
|
|
* originally, since it should just be a temporary situation.
|
|
|
|
*/
|
|
|
|
if (!cfqq || cfqq == &cfqd->oom_cfqq) {
|
|
|
|
cfqq = NULL;
|
2005-06-27 02:55:12 -06:00
|
|
|
if (new_cfqq) {
|
|
|
|
cfqq = new_cfqq;
|
|
|
|
new_cfqq = NULL;
|
|
|
|
} else if (gfp_mask & __GFP_WAIT) {
|
2012-03-05 14:15:01 -07:00
|
|
|
rcu_read_unlock();
|
2005-06-27 02:55:12 -06:00
|
|
|
spin_unlock_irq(cfqd->queue->queue_lock);
|
2007-07-17 05:03:29 -06:00
|
|
|
new_cfqq = kmem_cache_alloc_node(cfq_pool,
|
2009-06-30 01:34:12 -06:00
|
|
|
gfp_mask | __GFP_ZERO,
|
2007-07-17 05:03:29 -06:00
|
|
|
cfqd->queue->node);
|
2005-06-27 02:55:12 -06:00
|
|
|
spin_lock_irq(cfqd->queue->queue_lock);
|
2009-06-30 01:34:12 -06:00
|
|
|
if (new_cfqq)
|
|
|
|
goto retry;
|
cfq: fix lock imbalance with failed allocations
While stress-running very-small container scenarios with the Kernel Memory
Controller, I've run into a lockdep-detected lock imbalance in
cfq-iosched.c.
I'll apologize beforehand for not posting a backlog: I didn't anticipate
it would be so hard to reproduce, so I didn't save my serial output and
went directly on debugging. Turns out that it did not happen again in
more than 20 runs, making it a quite rare pattern.
But here is my analysis:
When we are in very low-memory situations, we will arrive at
cfq_find_alloc_queue and may not find a queue, having to resort to the oom
queue, in an rcu-locked condition:
if (!cfqq || cfqq == &cfqd->oom_cfqq)
[ ... ]
Next, we will release the rcu lock, and try to allocate a queue, retrying
if we succeed:
rcu_read_unlock();
spin_unlock_irq(cfqd->queue->queue_lock);
new_cfqq = kmem_cache_alloc_node(cfq_pool,
gfp_mask | __GFP_ZERO,
cfqd->queue->node);
spin_lock_irq(cfqd->queue->queue_lock);
if (new_cfqq)
goto retry;
We are unlocked at this point, but it should be fine, since we will
reacquire the rcu_read_lock when we retry.
Except of course, that we may not retry: the allocation may very well fail
and we'll keep on going through the flow:
The next branch is:
if (cfqq) {
[ ... ]
} else
cfqq = &cfqd->oom_cfqq;
And right before exiting, we'll issue rcu_read_unlock().
Being already unlocked, this is the likely source of our imbalance. Since
cfqq is either already NULL or made NULL in the first statement of the
outter branch, the only viable alternative here seems to be to return the
oom queue right away in case of allocation failure.
Please review the following patch and apply if you agree with my analysis.
Signed-off-by: Glauber Costa <glommer@parallels.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2013-02-21 16:16:41 -07:00
|
|
|
else
|
|
|
|
return &cfqd->oom_cfqq;
|
2005-06-27 02:55:12 -06:00
|
|
|
} else {
|
2007-07-17 05:03:29 -06:00
|
|
|
cfqq = kmem_cache_alloc_node(cfq_pool,
|
|
|
|
gfp_mask | __GFP_ZERO,
|
|
|
|
cfqd->queue->node);
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
2009-06-30 01:34:12 -06:00
|
|
|
if (cfqq) {
|
|
|
|
cfq_init_cfqq(cfqd, cfqq, current->pid, is_sync);
|
2012-03-19 16:10:57 -06:00
|
|
|
cfq_init_prio_data(cfqq, cic);
|
2009-12-03 10:59:38 -07:00
|
|
|
cfq_link_cfqq_cfqg(cfqq, cfqg);
|
2009-06-30 01:34:12 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "alloced");
|
|
|
|
} else
|
|
|
|
cfqq = &cfqd->oom_cfqq;
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (new_cfqq)
|
|
|
|
kmem_cache_free(cfq_pool, new_cfqq);
|
|
|
|
|
2012-03-05 14:15:01 -07:00
|
|
|
rcu_read_unlock();
|
2005-06-27 02:55:12 -06:00
|
|
|
return cfqq;
|
|
|
|
}
|
|
|
|
|
2007-07-20 02:06:38 -06:00
|
|
|
static struct cfq_queue **
|
|
|
|
cfq_async_queue_prio(struct cfq_data *cfqd, int ioprio_class, int ioprio)
|
|
|
|
{
|
2008-01-31 05:08:54 -07:00
|
|
|
switch (ioprio_class) {
|
2007-07-20 02:06:38 -06:00
|
|
|
case IOPRIO_CLASS_RT:
|
|
|
|
return &cfqd->async_cfqq[0][ioprio];
|
2012-03-19 16:10:58 -06:00
|
|
|
case IOPRIO_CLASS_NONE:
|
|
|
|
ioprio = IOPRIO_NORM;
|
|
|
|
/* fall through */
|
2007-07-20 02:06:38 -06:00
|
|
|
case IOPRIO_CLASS_BE:
|
|
|
|
return &cfqd->async_cfqq[1][ioprio];
|
|
|
|
case IOPRIO_CLASS_IDLE:
|
|
|
|
return &cfqd->async_idle_cfqq;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 05:43:25 -06:00
|
|
|
static struct cfq_queue *
|
2012-03-19 16:10:57 -06:00
|
|
|
cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct cfq_io_cq *cic,
|
2012-03-05 14:15:28 -07:00
|
|
|
struct bio *bio, gfp_t gfp_mask)
|
2007-07-10 05:43:25 -06:00
|
|
|
{
|
2012-03-19 16:10:58 -06:00
|
|
|
const int ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio);
|
|
|
|
const int ioprio = IOPRIO_PRIO_DATA(cic->ioprio);
|
2007-07-20 02:06:38 -06:00
|
|
|
struct cfq_queue **async_cfqq = NULL;
|
2007-07-10 05:43:25 -06:00
|
|
|
struct cfq_queue *cfqq = NULL;
|
|
|
|
|
2007-07-20 02:06:38 -06:00
|
|
|
if (!is_sync) {
|
|
|
|
async_cfqq = cfq_async_queue_prio(cfqd, ioprio_class, ioprio);
|
|
|
|
cfqq = *async_cfqq;
|
|
|
|
}
|
|
|
|
|
2009-06-30 01:34:12 -06:00
|
|
|
if (!cfqq)
|
2012-03-19 16:10:57 -06:00
|
|
|
cfqq = cfq_find_alloc_queue(cfqd, is_sync, cic, bio, gfp_mask);
|
2007-07-10 05:43:25 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* pin the queue now that it's allocated, scheduler exit will prune it
|
|
|
|
*/
|
2007-07-20 02:06:38 -06:00
|
|
|
if (!is_sync && !(*async_cfqq)) {
|
2011-01-07 00:46:59 -07:00
|
|
|
cfqq->ref++;
|
2007-07-20 02:06:38 -06:00
|
|
|
*async_cfqq = cfqq;
|
2007-07-10 05:43:25 -06:00
|
|
|
}
|
|
|
|
|
2011-01-07 00:46:59 -07:00
|
|
|
cfqq->ref++;
|
2007-07-10 05:43:25 -06:00
|
|
|
return cfqq;
|
|
|
|
}
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
static void
|
2011-07-12 06:24:35 -06:00
|
|
|
__cfq_update_io_thinktime(struct cfq_ttime *ttime, unsigned long slice_idle)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2011-07-12 06:24:35 -06:00
|
|
|
unsigned long elapsed = jiffies - ttime->last_end_request;
|
|
|
|
elapsed = min(elapsed, 2UL * slice_idle);
|
2005-06-17 08:15:10 -06:00
|
|
|
|
2011-07-12 06:24:35 -06:00
|
|
|
ttime->ttime_samples = (7*ttime->ttime_samples + 256) / 8;
|
|
|
|
ttime->ttime_total = (7*ttime->ttime_total + 256*elapsed) / 8;
|
|
|
|
ttime->ttime_mean = (ttime->ttime_total + 128) / ttime->ttime_samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cfq_update_io_thinktime(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic)
|
2011-07-12 06:24:35 -06:00
|
|
|
{
|
2011-07-12 06:24:55 -06:00
|
|
|
if (cfq_cfqq_sync(cfqq)) {
|
2011-07-12 06:24:35 -06:00
|
|
|
__cfq_update_io_thinktime(&cic->ttime, cfqd->cfq_slice_idle);
|
2011-07-12 06:24:55 -06:00
|
|
|
__cfq_update_io_thinktime(&cfqq->service_tree->ttime,
|
|
|
|
cfqd->cfq_slice_idle);
|
|
|
|
}
|
2011-07-12 06:24:56 -06:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
__cfq_update_io_thinktime(&cfqq->cfqg->ttime, cfqd->cfq_group_idle);
|
|
|
|
#endif
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-03-28 04:03:44 -07:00
|
|
|
static void
|
2009-10-23 15:14:49 -06:00
|
|
|
cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
2007-04-25 04:44:27 -06:00
|
|
|
struct request *rq)
|
2006-03-28 04:03:44 -07:00
|
|
|
{
|
2010-02-27 11:45:39 -07:00
|
|
|
sector_t sdist = 0;
|
2010-02-27 11:45:40 -07:00
|
|
|
sector_t n_sec = blk_rq_sectors(rq);
|
2010-02-27 11:45:39 -07: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 04:03:44 -07:00
|
|
|
|
2010-02-27 11:45:39 -07:00
|
|
|
cfqq->seek_history <<= 1;
|
2010-02-27 11:45:40 -07: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 04:03:44 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06: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 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2008-05-30 04:23:07 -06:00
|
|
|
int old_idle, enable_idle;
|
2007-04-19 06:32:26 -06:00
|
|
|
|
2008-01-28 03:38:15 -07:00
|
|
|
/*
|
|
|
|
* Don't idle for async or idle io prio class
|
|
|
|
*/
|
|
|
|
if (!cfq_cfqq_sync(cfqq) || cfq_class_idle(cfqq))
|
2007-04-19 06:32:26 -06:00
|
|
|
return;
|
|
|
|
|
2008-06-26 05:49:33 -06:00
|
|
|
enable_idle = old_idle = cfq_cfqq_idle_window(cfqq);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-11-26 02:02:58 -07:00
|
|
|
if (cfqq->queued[0] + cfqq->queued[1] >= 4)
|
|
|
|
cfq_mark_cfqq_deep(cfqq);
|
|
|
|
|
2010-09-20 07:24:50 -06:00
|
|
|
if (cfqq->next_rq && (cfqq->next_rq->cmd_flags & REQ_NOIDLE))
|
|
|
|
enable_idle = 0;
|
2012-03-05 14:15:26 -07:00
|
|
|
else if (!atomic_read(&cic->icq.ioc->active_ref) ||
|
2011-12-13 16:33:41 -07:00
|
|
|
!cfqd->cfq_slice_idle ||
|
|
|
|
(!cfq_cfqq_deep(cfqq) && CFQQ_SEEKY(cfqq)))
|
2005-06-27 02:55:12 -06:00
|
|
|
enable_idle = 0;
|
2011-07-12 06:24:35 -06:00
|
|
|
else if (sample_valid(cic->ttime.ttime_samples)) {
|
|
|
|
if (cic->ttime.ttime_mean > cfqd->cfq_slice_idle)
|
2005-06-27 02:55:12 -06:00
|
|
|
enable_idle = 0;
|
|
|
|
else
|
|
|
|
enable_idle = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-05-30 04:23:07 -06: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 02:55:12 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06: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 12:02:57 -06:00
|
|
|
static bool
|
2005-06-27 02:55:12 -06:00
|
|
|
cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
|
2006-07-13 04:39:25 -06:00
|
|
|
struct request *rq)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2007-04-25 04:44:27 -06:00
|
|
|
struct cfq_queue *cfqq;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2007-04-25 04:44:27 -06:00
|
|
|
cfqq = cfqd->active_queue;
|
|
|
|
if (!cfqq)
|
2009-10-07 12:02:57 -06:00
|
|
|
return false;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2007-04-25 04:44:27 -06:00
|
|
|
if (cfq_class_idle(new_cfqq))
|
2009-10-07 12:02:57 -06:00
|
|
|
return false;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
|
|
|
if (cfq_class_idle(cfqq))
|
2009-10-07 12:02:57 -06:00
|
|
|
return true;
|
2007-02-14 11:59:49 -07:00
|
|
|
|
2010-01-06 19:58:20 -07: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 17:42:19 -06:00
|
|
|
/*
|
|
|
|
* if the new request is sync, but the currently running queue is
|
|
|
|
* not, let the sync request have priority.
|
|
|
|
*/
|
2006-07-13 04:39:25 -06:00
|
|
|
if (rq_is_sync(rq) && !cfq_cfqq_sync(cfqq))
|
2009-10-07 12:02:57 -06:00
|
|
|
return true;
|
2007-02-14 11:59:49 -07:00
|
|
|
|
2009-12-03 10:59:50 -07:00
|
|
|
if (new_cfqq->cfqg != cfqq->cfqg)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (cfq_slice_used(cfqq))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Allow preemption only if we are idling on sync-noidle tree */
|
2012-10-03 14:56:57 -06:00
|
|
|
if (cfqd->serving_wl_type == SYNC_NOIDLE_WORKLOAD &&
|
2009-12-03 10:59:50 -07:00
|
|
|
cfqq_type(new_cfqq) == SYNC_NOIDLE_WORKLOAD &&
|
|
|
|
new_cfqq->service_tree->count == 2 &&
|
|
|
|
RB_EMPTY_ROOT(&cfqq->sort_list))
|
|
|
|
return true;
|
|
|
|
|
2011-08-19 00:34:48 -06: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 06:50:29 -06:00
|
|
|
if ((rq->cmd_flags & REQ_PRIO) && !cfqq->prio_pending)
|
2011-08-19 00:34:48 -06:00
|
|
|
return true;
|
|
|
|
|
2009-01-30 04:46:41 -07:00
|
|
|
/*
|
|
|
|
* Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice.
|
|
|
|
*/
|
|
|
|
if (cfq_class_rt(new_cfqq) && !cfq_class_rt(cfqq))
|
2009-10-07 12:02:57 -06:00
|
|
|
return true;
|
2009-01-30 04:46:41 -07:00
|
|
|
|
2010-11-08 07:01:03 -07: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 11:59:49 -07:00
|
|
|
if (!cfqd->active_cic || !cfq_cfqq_wait_request(cfqq))
|
2009-10-07 12:02:57 -06:00
|
|
|
return false;
|
2007-02-14 11:59:49 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if this request is as-good as one we would expect from the
|
|
|
|
* current cfqq, let it preempt
|
|
|
|
*/
|
2010-03-19 01:03:04 -06:00
|
|
|
if (cfq_rq_close(cfqd, cfqq, rq))
|
2009-10-07 12:02:57 -06:00
|
|
|
return true;
|
2007-02-14 11:59:49 -07:00
|
|
|
|
2009-10-07 12:02:57 -06:00
|
|
|
return false;
|
2005-06-27 02:55:12 -06: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 01:20:09 -07:00
|
|
|
enum wl_type_t old_type = cfqq_type(cfqd->active_queue);
|
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "preempt");
|
2012-01-19 01:20:09 -07:00
|
|
|
cfq_slice_expired(cfqd, 1);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2011-01-14 00:41:02 -07:00
|
|
|
/*
|
|
|
|
* workload type is changed, don't save slice, otherwise preempt
|
|
|
|
* doesn't happen
|
|
|
|
*/
|
2012-01-19 01:20:09 -07:00
|
|
|
if (old_type != cfqq_type(cfqq))
|
2012-10-03 14:56:57 -06:00
|
|
|
cfqq->cfqg->saved_wl_slice = 0;
|
2011-01-14 00:41:02 -07:00
|
|
|
|
2006-07-19 12:29:12 -06: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 04:03:34 -06:00
|
|
|
|
|
|
|
cfq_service_tree_add(cfqd, cfqq, 1);
|
2011-03-22 14:26:49 -06:00
|
|
|
|
2011-03-23 01:25:44 -06:00
|
|
|
cfqq->slice_end = 0;
|
|
|
|
cfq_mark_cfqq_slice_new(cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-07-13 04:39:25 -06:00
|
|
|
* Called when a new fs request (rq) is added (to cfqq). Check if there's
|
2005-06-27 02:55:12 -06:00
|
|
|
* something we should do about it
|
|
|
|
*/
|
|
|
|
static void
|
2006-07-13 04:39:25 -06:00
|
|
|
cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
|
|
|
|
struct request *rq)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic = RQ_CIC(rq);
|
2006-06-01 02:09:56 -06:00
|
|
|
|
2008-08-26 07:52:36 -06:00
|
|
|
cfqd->rq_queued++;
|
2011-08-23 06:50:29 -06:00
|
|
|
if (rq->cmd_flags & REQ_PRIO)
|
|
|
|
cfqq->prio_pending++;
|
2006-07-22 17:42:19 -06:00
|
|
|
|
2011-07-12 06:24:35 -06:00
|
|
|
cfq_update_io_thinktime(cfqd, cfqq, cic);
|
2009-10-23 15:14:49 -06:00
|
|
|
cfq_update_io_seektime(cfqd, cfqq, rq);
|
2005-08-24 06:57:54 -06:00
|
|
|
cfq_update_idle_window(cfqd, cfqq, cic);
|
|
|
|
|
2009-10-23 15:14:49 -06:00
|
|
|
cfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
|
|
|
if (cfqq == cfqd->active_queue) {
|
|
|
|
/*
|
2009-04-07 03:38:31 -06: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 06:18:16 -06: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 04:12:46 -06: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 02:55:12 -06:00
|
|
|
*/
|
2009-04-14 06:18:16 -06:00
|
|
|
if (cfq_cfqq_wait_request(cfqq)) {
|
2009-04-15 04:12:46 -06:00
|
|
|
if (blk_rq_bytes(rq) > PAGE_CACHE_SIZE ||
|
|
|
|
cfqd->busy_queues > 1) {
|
2010-04-08 22:15:35 -06:00
|
|
|
cfq_del_timer(cfqd, cfqq);
|
2009-12-10 01:38:39 -07:00
|
|
|
cfq_clear_cfqq_wait_request(cfqq);
|
2011-04-18 03:41:33 -06:00
|
|
|
__blk_run_queue(cfqd->queue);
|
2010-04-13 11:59:17 -06:00
|
|
|
} else {
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_idle_time(cfqq->cfqg);
|
2009-12-03 10:59:37 -07:00
|
|
|
cfq_mark_cfqq_must_dispatch(cfqq);
|
2010-04-13 11:59:17 -06:00
|
|
|
}
|
2009-04-14 06:18:16 -06:00
|
|
|
}
|
2006-07-13 04:39:25 -06:00
|
|
|
} else if (cfq_should_preempt(cfqd, cfqq, rq)) {
|
2005-06-27 02:55:12 -06: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 04:46:41 -07: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 02:55:12 -06:00
|
|
|
*/
|
|
|
|
cfq_preempt_queue(cfqd, cfqq);
|
2011-04-18 03:41:33 -06:00
|
|
|
__blk_run_queue(cfqd->queue);
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static void cfq_insert_request(struct request_queue *q, struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-10-20 08:42:29 -06:00
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "insert_request");
|
2012-03-19 16:10:57 -06:00
|
|
|
cfq_init_prio_data(cfqq, RQ_CIC(rq));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2009-10-05 03:03:39 -06:00
|
|
|
rq_set_fifo_time(rq, jiffies + cfqd->cfq_fifo_expire[rq_is_sync(rq)]);
|
2005-06-27 02:55:12 -06:00
|
|
|
list_add_tail(&rq->queuelist, &cfqq->fifo);
|
2009-10-26 15:44:33 -06:00
|
|
|
cfq_add_rq_rb(rq);
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_io_add(RQ_CFQG(rq), cfqd->serving_group,
|
|
|
|
rq->cmd_flags);
|
2006-07-13 04:39:25 -06:00
|
|
|
cfq_rq_enqueued(cfqd, cfqq, rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-08-26 07:52:36 -06: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 01:46:23 -06:00
|
|
|
struct cfq_queue *cfqq = cfqd->active_queue;
|
|
|
|
|
2010-02-28 11:45:05 -07: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 02:02:57 -07:00
|
|
|
|
|
|
|
if (cfqd->hw_tag == 1)
|
|
|
|
return;
|
2008-08-26 07:52:36 -06:00
|
|
|
|
|
|
|
if (cfqd->rq_queued <= CFQ_HW_QUEUE_MIN &&
|
2010-02-28 11:45:05 -07:00
|
|
|
cfqd->rq_in_driver <= CFQ_HW_QUEUE_MIN)
|
2008-08-26 07:52:36 -06:00
|
|
|
return;
|
|
|
|
|
2009-10-27 01:46:23 -06: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 11:45:05 -07:00
|
|
|
CFQ_HW_QUEUE_MIN && cfqd->rq_in_driver < CFQ_HW_QUEUE_MIN)
|
2009-10-27 01:46:23 -06:00
|
|
|
return;
|
|
|
|
|
2008-08-26 07:52:36 -06: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 02:02:57 -07:00
|
|
|
if (cfqd->hw_tag_est_depth >= CFQ_HW_QUEUE_MIN)
|
2008-08-26 07:52:36 -06:00
|
|
|
cfqd->hw_tag = 1;
|
|
|
|
else
|
|
|
|
cfqd->hw_tag = 0;
|
|
|
|
}
|
|
|
|
|
2009-12-08 15:52:58 -07:00
|
|
|
static bool cfq_should_wait_busy(struct cfq_data *cfqd, struct cfq_queue *cfqq)
|
|
|
|
{
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic = cfqd->active_cic;
|
2009-12-08 15:52:58 -07:00
|
|
|
|
2011-02-09 06:20:03 -07:00
|
|
|
/* If the queue already has requests, don't wait */
|
|
|
|
if (!RB_EMPTY_ROOT(&cfqq->sort_list))
|
|
|
|
return false;
|
|
|
|
|
2009-12-08 15:52:58 -07:00
|
|
|
/* If there are other queues in the group, don't wait */
|
|
|
|
if (cfqq->cfqg->nr_cfqq > 1)
|
|
|
|
return false;
|
|
|
|
|
2011-07-12 06:24:56 -06: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 15:52:58 -07:00
|
|
|
if (cfq_slice_used(cfqq))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* if slice left is less than think time, wait busy */
|
2011-07-12 06:24:35 -06:00
|
|
|
if (cic && sample_valid(cic->ttime.ttime_samples)
|
|
|
|
&& (cfqq->slice_end - jiffies < cic->ttime.ttime_mean))
|
2009-12-08 15:52:58 -07: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.
|
|
|
|
*/
|
|
|
|
if (cfqq->slice_end - jiffies == 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static void cfq_completed_request(struct request_queue *q, struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-10-20 08:42:29 -06:00
|
|
|
struct cfq_data *cfqd = cfqq->cfqd;
|
2006-07-13 04:37:56 -06:00
|
|
|
const int sync = rq_is_sync(rq);
|
2005-10-20 08:42:29 -06:00
|
|
|
unsigned long now;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-10-20 08:42:29 -06:00
|
|
|
now = jiffies;
|
2010-08-07 10:17:56 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "complete rqnoidle %d",
|
|
|
|
!!(rq->cmd_flags & REQ_NOIDLE));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-08-26 07:52:36 -06:00
|
|
|
cfq_update_hw_tag(cfqd);
|
|
|
|
|
2010-02-28 11:45:05 -07:00
|
|
|
WARN_ON(!cfqd->rq_in_driver);
|
2007-04-25 04:44:27 -06:00
|
|
|
WARN_ON(!cfqq->dispatched);
|
2010-02-28 11:45:05 -07:00
|
|
|
cfqd->rq_in_driver--;
|
2007-04-25 04:44:27 -06:00
|
|
|
cfqq->dispatched--;
|
2010-08-23 04:24:26 -06:00
|
|
|
(RQ_CFQG(rq))->dispatched--;
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqg_stats_update_completion(cfqq->cfqg, rq_start_time_ns(rq),
|
|
|
|
rq_io_start_time_ns(rq), rq->cmd_flags);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-28 11:45:05 -07:00
|
|
|
cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]--;
|
2007-04-23 00:33:33 -06:00
|
|
|
|
2009-10-03 07:21:27 -06:00
|
|
|
if (sync) {
|
2012-10-03 14:56:58 -06:00
|
|
|
struct cfq_rb_root *st;
|
2011-07-12 06:24:55 -06:00
|
|
|
|
2011-07-12 06:24:35 -06:00
|
|
|
RQ_CIC(rq)->ttime.last_end_request = now;
|
2011-07-12 06:24:55 -06:00
|
|
|
|
|
|
|
if (cfq_cfqq_on_rr(cfqq))
|
2012-10-03 14:56:58 -06:00
|
|
|
st = cfqq->service_tree;
|
2011-07-12 06:24:55 -06:00
|
|
|
else
|
2012-10-03 14:56:58 -06:00
|
|
|
st = st_for(cfqq->cfqg, cfqq_class(cfqq),
|
|
|
|
cfqq_type(cfqq));
|
|
|
|
|
|
|
|
st->ttime.last_end_request = now;
|
2009-12-06 03:48:52 -07:00
|
|
|
if (!time_after(rq->start_time + cfqd->cfq_fifo_expire[1], now))
|
|
|
|
cfqd->last_delayed_sync = now;
|
2009-10-03 07:21:27 -06:00
|
|
|
}
|
2006-06-16 03:23:00 -06:00
|
|
|
|
2011-07-12 06:24:56 -06:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
cfqq->cfqg->ttime.last_end_request = now;
|
|
|
|
#endif
|
|
|
|
|
2006-06-16 03:23:00 -06: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 04:15:11 -06:00
|
|
|
const bool cfqq_empty = RB_EMPTY_ROOT(&cfqq->sort_list);
|
|
|
|
|
2007-01-18 17:51:58 -07:00
|
|
|
if (cfq_cfqq_slice_new(cfqq)) {
|
|
|
|
cfq_set_prio_slice(cfqd, cfqq);
|
|
|
|
cfq_clear_cfqq_slice_new(cfqq);
|
|
|
|
}
|
2009-12-03 10:59:53 -07:00
|
|
|
|
|
|
|
/*
|
2009-12-08 15:52:58 -07:00
|
|
|
* Should we wait for next request to come in before we expire
|
|
|
|
* the queue.
|
2009-12-03 10:59:53 -07:00
|
|
|
*/
|
2009-12-08 15:52:58 -07:00
|
|
|
if (cfq_should_wait_busy(cfqd, cfqq)) {
|
2010-08-23 04:24:26 -06:00
|
|
|
unsigned long extend_sl = cfqd->cfq_slice_idle;
|
|
|
|
if (!cfqd->cfq_slice_idle)
|
|
|
|
extend_sl = cfqd->cfq_group_idle;
|
|
|
|
cfqq->slice_end = jiffies + extend_sl;
|
2009-12-03 10:59:53 -07:00
|
|
|
cfq_mark_cfqq_wait_busy(cfqq);
|
2010-03-25 08:45:03 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "will busy wait");
|
2009-12-03 10:59:53 -07:00
|
|
|
}
|
|
|
|
|
2009-04-15 04:15:11 -06:00
|
|
|
/*
|
2009-11-26 02:02:58 -07: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 04:15:11 -06:00
|
|
|
*/
|
2008-01-28 03:38:15 -07:00
|
|
|
if (cfq_slice_used(cfqq) || cfq_class_idle(cfqq))
|
2010-04-26 11:25:11 -06:00
|
|
|
cfq_slice_expired(cfqd, 1);
|
2009-11-26 02:02:58 -07:00
|
|
|
else if (sync && cfqq_empty &&
|
|
|
|
!cfq_close_cooperator(cfqd, cfqq)) {
|
2010-09-20 07:24:50 -06:00
|
|
|
cfq_arm_slice_timer(cfqd);
|
2009-11-26 02:02:58 -07:00
|
|
|
}
|
2006-06-16 03:23:00 -06:00
|
|
|
}
|
2007-04-25 04:44:27 -06:00
|
|
|
|
2010-02-28 11:45:05 -07:00
|
|
|
if (!cfqd->rq_in_driver)
|
2009-10-05 00:52:35 -06:00
|
|
|
cfq_schedule_dispatch(cfqd);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-07-22 08:48:31 -06:00
|
|
|
static inline int __cfq_may_queue(struct cfq_queue *cfqq)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2009-08-11 00:26:11 -06:00
|
|
|
if (cfq_cfqq_wait_request(cfqq) && !cfq_cfqq_must_alloc_slice(cfqq)) {
|
2005-06-27 02:56:24 -06:00
|
|
|
cfq_mark_cfqq_must_alloc_slice(cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
return ELV_MQUEUE_MUST;
|
2005-06-27 02:56:24 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
return ELV_MQUEUE_MAY;
|
|
|
|
}
|
|
|
|
|
2007-07-24 01:28:11 -06:00
|
|
|
static int cfq_may_queue(struct request_queue *q, int rw)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
|
|
|
struct task_struct *tsk = current;
|
2011-12-13 16:33:41 -07:00
|
|
|
struct cfq_io_cq *cic;
|
2005-06-27 02:55:12 -06: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 00:44:49 -07:00
|
|
|
cic = cfq_cic_lookup(cfqd, tsk->io_context);
|
2007-04-25 04:29:51 -06:00
|
|
|
if (!cic)
|
|
|
|
return ELV_MQUEUE_MAY;
|
|
|
|
|
2009-04-08 02:56:08 -06:00
|
|
|
cfqq = cic_to_cfqq(cic, rw_is_sync(rw));
|
2005-06-27 02:55:12 -06:00
|
|
|
if (cfqq) {
|
2012-03-19 16:10:57 -06:00
|
|
|
cfq_init_prio_data(cfqq, cic);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2006-07-22 08:48:31 -06:00
|
|
|
return __cfq_may_queue(cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return ELV_MQUEUE_MAY;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* queue lock held here
|
|
|
|
*/
|
2006-12-01 02:42:33 -07:00
|
|
|
static void cfq_put_request(struct request *rq)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-07-13 04:39:25 -06:00
|
|
|
struct cfq_queue *cfqq = RQ_CFQQ(rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-07-13 04:39:25 -06:00
|
|
|
if (cfqq) {
|
2005-06-27 02:55:12 -06:00
|
|
|
const int rw = rq_data_dir(rq);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
BUG_ON(!cfqq->allocated[rw]);
|
|
|
|
cfqq->allocated[rw]--;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-04-21 09:44:16 -06:00
|
|
|
/* Put down rq reference on cfqg */
|
2012-03-23 07:02:53 -06:00
|
|
|
cfqg_put(RQ_CFQG(rq));
|
2011-12-13 16:33:41 -07:00
|
|
|
rq->elv.priv[0] = NULL;
|
|
|
|
rq->elv.priv[1] = NULL;
|
2010-04-21 09:44:16 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-23 15:14:50 -06:00
|
|
|
static struct cfq_queue *
|
2011-12-13 16:33:41 -07:00
|
|
|
cfq_merge_cfqqs(struct cfq_data *cfqd, struct cfq_io_cq *cic,
|
2009-10-23 15:14:50 -06: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 15:14:51 -06:00
|
|
|
cfq_mark_cfqq_coop(cfqq->new_cfqq);
|
2009-10-23 15:14:50 -06:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
return cic_to_cfqq(cic, 1);
|
|
|
|
}
|
|
|
|
|
2009-10-23 15:14:52 -06: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 16:33:41 -07:00
|
|
|
split_cfqq(struct cfq_io_cq *cic, struct cfq_queue *cfqq)
|
2009-10-23 15:14:52 -06:00
|
|
|
{
|
|
|
|
if (cfqq_process_refs(cfqq) == 1) {
|
|
|
|
cfqq->pid = current->pid;
|
|
|
|
cfq_clear_cfqq_coop(cfqq);
|
2010-02-05 05:11:45 -07:00
|
|
|
cfq_clear_cfqq_split_coop(cfqq);
|
2009-10-23 15:14:52 -06:00
|
|
|
return cfqq;
|
|
|
|
}
|
|
|
|
|
|
|
|
cic_set_cfqq(cic, NULL, 1);
|
2010-05-25 02:16:53 -06:00
|
|
|
|
|
|
|
cfq_put_cooperator(cfqq);
|
|
|
|
|
2009-10-23 15:14:52 -06:00
|
|
|
cfq_put_queue(cfqq);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2005-06-27 02:55:12 -06:00
|
|
|
* Allocate cfq data structures associated with this request.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
2005-06-27 02:55:12 -06:00
|
|
|
static int
|
2012-03-05 14:15:27 -07:00
|
|
|
cfq_set_request(struct request_queue *q, struct request *rq, struct bio *bio,
|
|
|
|
gfp_t gfp_mask)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = q->elevator->elevator_data;
|
2011-12-13 16:33:42 -07:00
|
|
|
struct cfq_io_cq *cic = icq_to_cic(rq->elv.icq);
|
2005-04-16 16:20:36 -06:00
|
|
|
const int rw = rq_data_dir(rq);
|
2009-10-07 12:02:57 -06:00
|
|
|
const bool is_sync = rq_is_sync(rq);
|
2005-06-27 02:55:12 -06:00
|
|
|
struct cfq_queue *cfqq;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
might_sleep_if(gfp_mask & __GFP_WAIT);
|
|
|
|
|
2011-12-13 16:33:38 -07:00
|
|
|
spin_lock_irq(q->queue_lock);
|
2011-12-13 16:33:42 -07:00
|
|
|
|
2012-03-19 16:10:58 -06:00
|
|
|
check_ioprio_changed(cic, bio);
|
|
|
|
check_blkcg_changed(cic, bio);
|
2009-10-23 15:14:52 -06:00
|
|
|
new_queue:
|
2007-04-25 04:29:51 -06:00
|
|
|
cfqq = cic_to_cfqq(cic, is_sync);
|
2009-07-09 14:13:16 -06:00
|
|
|
if (!cfqq || cfqq == &cfqd->oom_cfqq) {
|
2012-03-19 16:10:57 -06:00
|
|
|
cfqq = cfq_get_queue(cfqd, is_sync, cic, bio, gfp_mask);
|
2007-04-25 04:29:51 -06:00
|
|
|
cic_set_cfqq(cic, cfqq, is_sync);
|
2009-10-23 15:14:50 -06:00
|
|
|
} else {
|
2009-10-23 15:14:52 -06:00
|
|
|
/*
|
|
|
|
* If the queue was seeky for too long, break it apart.
|
|
|
|
*/
|
2010-02-05 05:11:45 -07:00
|
|
|
if (cfq_cfqq_coop(cfqq) && cfq_cfqq_split_coop(cfqq)) {
|
2009-10-23 15:14:52 -06:00
|
|
|
cfq_log_cfqq(cfqd, cfqq, "breaking apart cfqq");
|
|
|
|
cfqq = split_cfqq(cic, cfqq);
|
|
|
|
if (!cfqq)
|
|
|
|
goto new_queue;
|
|
|
|
}
|
|
|
|
|
2009-10-23 15:14:50 -06: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 04:29:51 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
cfqq->allocated[rw]++;
|
|
|
|
|
2011-03-01 13:04:39 -07:00
|
|
|
cfqq->ref++;
|
2012-03-23 07:02:53 -06:00
|
|
|
cfqg_get(cfqq->cfqg);
|
2011-12-13 16:33:41 -07:00
|
|
|
rq->elv.priv[0] = cfqq;
|
2012-03-05 14:15:15 -07:00
|
|
|
rq->elv.priv[1] = cfqq->cfqg;
|
2011-12-13 16:33:38 -07:00
|
|
|
spin_unlock_irq(q->queue_lock);
|
2006-07-13 04:39:25 -06:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-11-22 07:55:48 -07:00
|
|
|
static void cfq_kick_queue(struct work_struct *work)
|
2005-06-27 02:55:12 -06:00
|
|
|
{
|
2006-11-22 07:55:48 -07:00
|
|
|
struct cfq_data *cfqd =
|
2009-10-05 00:52:35 -06:00
|
|
|
container_of(work, struct cfq_data, unplug_work);
|
2007-07-24 01:28:11 -06:00
|
|
|
struct request_queue *q = cfqd->queue;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2009-04-15 04:11:10 -06:00
|
|
|
spin_lock_irq(q->queue_lock);
|
2011-04-18 03:41:33 -06:00
|
|
|
__blk_run_queue(cfqd->queue);
|
2009-04-15 04:11:10 -06:00
|
|
|
spin_unlock_irq(q->queue_lock);
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timer running if the active_queue is currently idling inside its time slice
|
|
|
|
*/
|
|
|
|
static void cfq_idle_slice_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct cfq_data *cfqd = (struct cfq_data *) data;
|
|
|
|
struct cfq_queue *cfqq;
|
|
|
|
unsigned long flags;
|
2007-01-18 18:06:33 -07:00
|
|
|
int timed_out = 1;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2008-05-30 04:23:07 -06:00
|
|
|
cfq_log(cfqd, "idle timer fired");
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
spin_lock_irqsave(cfqd->queue->queue_lock, flags);
|
|
|
|
|
2008-01-31 05:08:54 -07:00
|
|
|
cfqq = cfqd->active_queue;
|
|
|
|
if (cfqq) {
|
2007-01-18 18:06:33 -07:00
|
|
|
timed_out = 0;
|
|
|
|
|
2009-04-07 03:38:31 -06:00
|
|
|
/*
|
|
|
|
* We saw a request before the queue expired, let it through
|
|
|
|
*/
|
|
|
|
if (cfq_cfqq_must_dispatch(cfqq))
|
|
|
|
goto out_kick;
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
|
|
|
* expired
|
|
|
|
*/
|
2007-01-18 17:51:58 -07:00
|
|
|
if (cfq_slice_used(cfqq))
|
2005-06-27 02:55:12 -06:00
|
|
|
goto expire;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* only expire and reinvoke request handler, if there are
|
|
|
|
* other queues with pending requests
|
|
|
|
*/
|
2006-06-16 03:23:00 -06:00
|
|
|
if (!cfqd->busy_queues)
|
2005-06-27 02:55:12 -06:00
|
|
|
goto out_cont;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* not expired and it has a request pending, let it dispatch
|
|
|
|
*/
|
2009-04-07 00:56:14 -06:00
|
|
|
if (!RB_EMPTY_ROOT(&cfqq->sort_list))
|
2005-06-27 02:55:12 -06:00
|
|
|
goto out_kick;
|
2009-11-26 02:02:58 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue depth flag is reset only when the idle didn't succeed
|
|
|
|
*/
|
|
|
|
cfq_clear_cfqq_deep(cfqq);
|
2005-06-27 02:55:12 -06:00
|
|
|
}
|
|
|
|
expire:
|
2010-04-26 11:25:11 -06:00
|
|
|
cfq_slice_expired(cfqd, timed_out);
|
2005-06-27 02:55:12 -06:00
|
|
|
out_kick:
|
2009-10-05 00:52:35 -06:00
|
|
|
cfq_schedule_dispatch(cfqd);
|
2005-06-27 02:55:12 -06:00
|
|
|
out_cont:
|
|
|
|
spin_unlock_irqrestore(cfqd->queue->queue_lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-06-27 02:56:24 -06:00
|
|
|
static void cfq_shutdown_timer_wq(struct cfq_data *cfqd)
|
|
|
|
{
|
|
|
|
del_timer_sync(&cfqd->idle_slice_timer);
|
2009-10-05 00:52:35 -06:00
|
|
|
cancel_work_sync(&cfqd->unplug_work);
|
2005-06-27 02:56:24 -06:00
|
|
|
}
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2007-07-20 02:06:38 -06:00
|
|
|
static void cfq_put_async_queues(struct cfq_data *cfqd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < IOPRIO_BE_NR; i++) {
|
|
|
|
if (cfqd->async_cfqq[0][i])
|
|
|
|
cfq_put_queue(cfqd->async_cfqq[0][i]);
|
|
|
|
if (cfqd->async_cfqq[1][i])
|
|
|
|
cfq_put_queue(cfqd->async_cfqq[1][i]);
|
|
|
|
}
|
2007-11-05 00:58:05 -07:00
|
|
|
|
|
|
|
if (cfqd->async_idle_cfqq)
|
|
|
|
cfq_put_queue(cfqd->async_idle_cfqq);
|
2007-07-20 02:06:38 -06:00
|
|
|
}
|
|
|
|
|
2008-10-31 03:05:07 -06:00
|
|
|
static void cfq_exit_queue(struct elevator_queue *e)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-06-27 02:55:12 -06:00
|
|
|
struct cfq_data *cfqd = e->elevator_data;
|
2007-07-24 01:28:11 -06:00
|
|
|
struct request_queue *q = cfqd->queue;
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2005-06-27 02:56:24 -06:00
|
|
|
cfq_shutdown_timer_wq(cfqd);
|
2006-03-27 23:59:01 -07:00
|
|
|
|
2006-03-18 11:51:22 -07:00
|
|
|
spin_lock_irq(q->queue_lock);
|
2006-03-27 23:59:01 -07:00
|
|
|
|
2006-03-18 11:51:22 -07:00
|
|
|
if (cfqd->active_queue)
|
2010-04-26 11:25:11 -06:00
|
|
|
__cfq_slice_expired(cfqd, cfqd->active_queue, 0);
|
2006-03-27 23:59:01 -07:00
|
|
|
|
2007-07-20 02:06:38 -06:00
|
|
|
cfq_put_async_queues(cfqd);
|
2012-03-05 14:15:19 -07:00
|
|
|
|
|
|
|
spin_unlock_irq(q->queue_lock);
|
|
|
|
|
2006-03-18 10:05:37 -07: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 02:02:29 -06:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
blkcg_deactivate_policy(q, &blkcg_policy_cfq);
|
|
|
|
#else
|
2012-03-05 14:15:05 -07:00
|
|
|
kfree(cfqd->root_group);
|
2011-05-23 02:02:19 -06:00
|
|
|
#endif
|
2011-05-19 13:38:22 -06:00
|
|
|
kfree(cfqd);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2013-07-03 05:25:24 -06:00
|
|
|
static int cfq_init_queue(struct request_queue *q, struct elevator_type *e)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct cfq_data *cfqd;
|
2012-04-16 14:57:25 -06:00
|
|
|
struct blkcg_gq *blkg __maybe_unused;
|
2012-04-13 14:11:33 -06:00
|
|
|
int i, ret;
|
2013-07-03 05:25:24 -06:00
|
|
|
struct elevator_queue *eq;
|
|
|
|
|
|
|
|
eq = elevator_alloc(q, e);
|
|
|
|
if (!eq)
|
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-08-29 16:21:42 -06:00
|
|
|
cfqd = kzalloc_node(sizeof(*cfqd), GFP_KERNEL, q->node);
|
2013-07-03 05:25:24 -06:00
|
|
|
if (!cfqd) {
|
|
|
|
kobject_put(&eq->kobj);
|
2012-03-05 14:14:57 -07:00
|
|
|
return -ENOMEM;
|
2013-07-03 05:25:24 -06:00
|
|
|
}
|
|
|
|
eq->elevator_data = cfqd;
|
2010-05-20 13:21:41 -06:00
|
|
|
|
2012-03-05 14:15:05 -07:00
|
|
|
cfqd->queue = q;
|
2013-07-03 05:25:24 -06:00
|
|
|
spin_lock_irq(q->queue_lock);
|
|
|
|
q->elevator = eq;
|
|
|
|
spin_unlock_irq(q->queue_lock);
|
2012-03-05 14:15:05 -07:00
|
|
|
|
2009-12-03 10:59:41 -07:00
|
|
|
/* Init root service tree */
|
|
|
|
cfqd->grp_service_tree = CFQ_RB_ROOT;
|
|
|
|
|
2012-03-05 14:15:05 -07:00
|
|
|
/* Init root group and prefer root group over other groups by default */
|
2009-12-03 10:59:46 -07:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 14:57:25 -06:00
|
|
|
ret = blkcg_activate_policy(q, &blkcg_policy_cfq);
|
2012-04-13 14:11:33 -06:00
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
2012-03-05 14:15:05 -07:00
|
|
|
|
2012-04-13 14:11:33 -06:00
|
|
|
cfqd->root_group = blkg_to_cfqg(q->root_blkg);
|
2012-03-05 14:15:05 -07:00
|
|
|
#else
|
2012-04-13 14:11:33 -06:00
|
|
|
ret = -ENOMEM;
|
2012-03-05 14:15:05 -07:00
|
|
|
cfqd->root_group = kzalloc_node(sizeof(*cfqd->root_group),
|
|
|
|
GFP_KERNEL, cfqd->queue->node);
|
2012-04-13 14:11:33 -06:00
|
|
|
if (!cfqd->root_group)
|
|
|
|
goto out_free;
|
2011-05-19 13:38:28 -06:00
|
|
|
|
2012-04-13 14:11:33 -06:00
|
|
|
cfq_init_cfqg_base(cfqd->root_group);
|
|
|
|
#endif
|
2012-04-01 15:38:44 -06:00
|
|
|
cfqd->root_group->weight = 2 * CFQ_WEIGHT_DEFAULT;
|
2013-01-09 09:05:10 -07:00
|
|
|
cfqd->root_group->leaf_weight = 2 * CFQ_WEIGHT_DEFAULT;
|
2011-05-19 13:38:28 -06:00
|
|
|
|
2009-04-23 04:13:27 -06: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 01:34:12 -06:00
|
|
|
/*
|
|
|
|
* Our fallback cfqq if cfq_find_alloc_queue() runs into OOM issues.
|
|
|
|
* Grab a permanent reference to it, so that the normal code flow
|
2012-03-05 14:15:05 -07: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 01:34:12 -06:00
|
|
|
*/
|
|
|
|
cfq_init_cfqq(cfqd, &cfqd->oom_cfqq, 1, 0);
|
2011-01-07 00:46:59 -07:00
|
|
|
cfqd->oom_cfqq.ref++;
|
2012-03-05 14:15:15 -07:00
|
|
|
|
|
|
|
spin_lock_irq(q->queue_lock);
|
2012-03-05 14:15:05 -07:00
|
|
|
cfq_link_cfqq_cfqg(&cfqd->oom_cfqq, cfqd->root_group);
|
2012-03-23 07:02:53 -06:00
|
|
|
cfqg_put(cfqd->root_group);
|
2012-03-05 14:15:15 -07:00
|
|
|
spin_unlock_irq(q->queue_lock);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
init_timer(&cfqd->idle_slice_timer);
|
|
|
|
cfqd->idle_slice_timer.function = cfq_idle_slice_timer;
|
|
|
|
cfqd->idle_slice_timer.data = (unsigned long) cfqd;
|
|
|
|
|
2009-10-05 00:52:35 -06:00
|
|
|
INIT_WORK(&cfqd->unplug_work, cfq_kick_queue);
|
2005-06-27 02:55:12 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
cfqd->cfq_quantum = cfq_quantum;
|
2005-06-27 02:55:12 -06:00
|
|
|
cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0];
|
|
|
|
cfqd->cfq_fifo_expire[1] = cfq_fifo_expire[1];
|
2005-04-16 16:20:36 -06:00
|
|
|
cfqd->cfq_back_max = cfq_back_max;
|
|
|
|
cfqd->cfq_back_penalty = cfq_back_penalty;
|
2005-06-27 02:55:12 -06:00
|
|
|
cfqd->cfq_slice[0] = cfq_slice_async;
|
|
|
|
cfqd->cfq_slice[1] = cfq_slice_sync;
|
2012-04-01 15:33:39 -06:00
|
|
|
cfqd->cfq_target_latency = cfq_target_latency;
|
2005-06-27 02:55:12 -06:00
|
|
|
cfqd->cfq_slice_async_rq = cfq_slice_async_rq;
|
|
|
|
cfqd->cfq_slice_idle = cfq_slice_idle;
|
2010-08-23 04:24:26 -06:00
|
|
|
cfqd->cfq_group_idle = cfq_group_idle;
|
2009-10-03 11:42:18 -06: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 02:02:57 -07:00
|
|
|
cfqd->hw_tag = -1;
|
2009-12-09 12:56:04 -07:00
|
|
|
/*
|
|
|
|
* we optimistically start assuming sync ops weren't delayed in last
|
|
|
|
* second, in order to have larger depth for async operations.
|
|
|
|
*/
|
2009-12-06 03:48:52 -07:00
|
|
|
cfqd->last_delayed_sync = jiffies - HZ;
|
2012-03-05 14:14:57 -07:00
|
|
|
return 0;
|
2012-04-13 14:11:33 -06:00
|
|
|
|
|
|
|
out_free:
|
|
|
|
kfree(cfqd);
|
2013-07-03 05:25:24 -06:00
|
|
|
kobject_put(&eq->kobj);
|
2012-04-13 14:11:33 -06:00
|
|
|
return ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sysfs parts below -->
|
|
|
|
*/
|
|
|
|
static ssize_t
|
|
|
|
cfq_var_show(unsigned int var, char *page)
|
|
|
|
{
|
|
|
|
return sprintf(page, "%d\n", var);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 03:05:07 -06:00
|
|
|
static ssize_t __FUNC(struct elevator_queue *e, char *page) \
|
2005-04-16 16:20:36 -06:00
|
|
|
{ \
|
2006-03-18 16:35:43 -07:00
|
|
|
struct cfq_data *cfqd = e->elevator_data; \
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned int __data = __VAR; \
|
|
|
|
if (__CONV) \
|
|
|
|
__data = jiffies_to_msecs(__data); \
|
|
|
|
return cfq_var_show(__data, (page)); \
|
|
|
|
}
|
|
|
|
SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0);
|
2005-06-27 02:55:12 -06: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-18 20:27:18 -07: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 02:55:12 -06:00
|
|
|
SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
|
2010-08-23 04:24:26 -06:00
|
|
|
SHOW_FUNCTION(cfq_group_idle_show, cfqd->cfq_group_idle, 1);
|
2005-06-27 02:55:12 -06: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 11:42:18 -06:00
|
|
|
SHOW_FUNCTION(cfq_low_latency_show, cfqd->cfq_latency, 0);
|
2012-04-01 15:33:39 -06:00
|
|
|
SHOW_FUNCTION(cfq_target_latency_show, cfqd->cfq_target_latency, 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
#undef SHOW_FUNCTION
|
|
|
|
|
|
|
|
#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \
|
2008-10-31 03:05:07 -06:00
|
|
|
static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count) \
|
2005-04-16 16:20:36 -06:00
|
|
|
{ \
|
2006-03-18 16:35:43 -07:00
|
|
|
struct cfq_data *cfqd = e->elevator_data; \
|
2005-04-16 16:20:36 -06: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) \
|
|
|
|
*(__PTR) = msecs_to_jiffies(__data); \
|
|
|
|
else \
|
|
|
|
*(__PTR) = __data; \
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0);
|
2008-01-31 05:08:54 -07: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-18 20:27:18 -07:00
|
|
|
STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
|
2008-01-31 05:08:54 -07:00
|
|
|
STORE_FUNCTION(cfq_back_seek_penalty_store, &cfqd->cfq_back_penalty, 1,
|
|
|
|
UINT_MAX, 0);
|
2005-06-27 02:55:12 -06:00
|
|
|
STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
|
2010-08-23 04:24:26 -06:00
|
|
|
STORE_FUNCTION(cfq_group_idle_store, &cfqd->cfq_group_idle, 0, UINT_MAX, 1);
|
2005-06-27 02:55:12 -06: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 05:08:54 -07:00
|
|
|
STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1,
|
|
|
|
UINT_MAX, 0);
|
2009-10-03 11:42:18 -06:00
|
|
|
STORE_FUNCTION(cfq_low_latency_store, &cfqd->cfq_latency, 0, 1, 0);
|
2012-04-01 15:33:39 -06:00
|
|
|
STORE_FUNCTION(cfq_target_latency_store, &cfqd->cfq_target_latency, 1, UINT_MAX, 1);
|
2005-04-16 16:20:36 -06:00
|
|
|
#undef STORE_FUNCTION
|
|
|
|
|
2006-03-18 20:27:18 -07: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),
|
|
|
|
CFQ_ATTR(slice_async),
|
|
|
|
CFQ_ATTR(slice_async_rq),
|
|
|
|
CFQ_ATTR(slice_idle),
|
2010-08-23 04:24:26 -06:00
|
|
|
CFQ_ATTR(group_idle),
|
2009-10-03 11:42:18 -06:00
|
|
|
CFQ_ATTR(low_latency),
|
2012-04-01 15:33:39 -06:00
|
|
|
CFQ_ATTR(target_latency),
|
2006-03-18 20:27:18 -07:00
|
|
|
__ATTR_NULL
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct elevator_type iosched_cfq = {
|
|
|
|
.ops = {
|
|
|
|
.elevator_merge_fn = cfq_merge,
|
|
|
|
.elevator_merged_fn = cfq_merged_request,
|
|
|
|
.elevator_merge_req_fn = cfq_merged_requests,
|
2006-12-20 03:04:12 -07:00
|
|
|
.elevator_allow_merge_fn = cfq_allow_merge,
|
2010-04-08 22:14:23 -06:00
|
|
|
.elevator_bio_merged_fn = cfq_bio_merged,
|
2005-10-20 08:42:29 -06:00
|
|
|
.elevator_dispatch_fn = cfq_dispatch_requests,
|
2005-04-16 16:20:36 -06:00
|
|
|
.elevator_add_req_fn = cfq_insert_request,
|
2005-10-20 08:42:29 -06:00
|
|
|
.elevator_activate_req_fn = cfq_activate_request,
|
2005-04-16 16:20:36 -06:00
|
|
|
.elevator_deactivate_req_fn = cfq_deactivate_request,
|
|
|
|
.elevator_completed_req_fn = cfq_completed_request,
|
2006-07-13 04:33:14 -06:00
|
|
|
.elevator_former_req_fn = elv_rb_former_request,
|
|
|
|
.elevator_latter_req_fn = elv_rb_latter_request,
|
2011-12-13 16:33:42 -07:00
|
|
|
.elevator_init_icq_fn = cfq_init_icq,
|
2011-12-13 16:33:42 -07:00
|
|
|
.elevator_exit_icq_fn = cfq_exit_icq,
|
2005-04-16 16:20:36 -06: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,
|
|
|
|
},
|
2011-12-13 16:33:42 -07:00
|
|
|
.icq_size = sizeof(struct cfq_io_cq),
|
|
|
|
.icq_align = __alignof__(struct cfq_io_cq),
|
2006-03-18 16:35:43 -07:00
|
|
|
.elevator_attrs = cfq_attrs,
|
2011-12-13 16:33:42 -07:00
|
|
|
.elevator_name = "cfq",
|
2005-04-16 16:20:36 -06:00
|
|
|
.elevator_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2009-12-04 08:36:42 -07:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 14:57:25 -06:00
|
|
|
static struct blkcg_policy blkcg_policy_cfq = {
|
2012-04-16 14:57:27 -06:00
|
|
|
.pd_size = sizeof(struct cfq_group),
|
|
|
|
.cftypes = cfq_blkcg_files,
|
|
|
|
|
|
|
|
.pd_init_fn = cfq_pd_init,
|
2013-01-09 09:05:13 -07:00
|
|
|
.pd_offline_fn = cfq_pd_offline,
|
2012-04-16 14:57:27 -06:00
|
|
|
.pd_reset_stats_fn = cfq_pd_reset_stats,
|
2009-12-04 08:36:42 -07:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static int __init cfq_init(void)
|
|
|
|
{
|
2011-12-13 16:33:42 -07:00
|
|
|
int ret;
|
|
|
|
|
2005-06-27 02:55:12 -06:00
|
|
|
/*
|
|
|
|
* could be 0 on HZ < 1000 setups
|
|
|
|
*/
|
|
|
|
if (!cfq_slice_async)
|
|
|
|
cfq_slice_async = 1;
|
|
|
|
if (!cfq_slice_idle)
|
|
|
|
cfq_slice_idle = 1;
|
|
|
|
|
2010-08-23 04:24:26 -06:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
|
|
|
if (!cfq_group_idle)
|
|
|
|
cfq_group_idle = 1;
|
2012-04-13 14:11:28 -06:00
|
|
|
|
2012-04-16 14:57:25 -06:00
|
|
|
ret = blkcg_policy_register(&blkcg_policy_cfq);
|
2012-04-13 14:11:28 -06: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 02:02:29 -06:00
|
|
|
#else
|
|
|
|
cfq_group_idle = 0;
|
|
|
|
#endif
|
2012-04-13 14:11:28 -06:00
|
|
|
|
2012-06-04 02:01:38 -06:00
|
|
|
ret = -ENOMEM;
|
2011-12-13 16:33:42 -07:00
|
|
|
cfq_pool = KMEM_CACHE(cfq_queue, 0);
|
|
|
|
if (!cfq_pool)
|
2012-04-13 14:11:28 -06:00
|
|
|
goto err_pol_unreg;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2011-12-13 16:33:42 -07:00
|
|
|
ret = elv_register(&iosched_cfq);
|
2012-04-13 14:11:28 -06:00
|
|
|
if (ret)
|
|
|
|
goto err_free_pool;
|
2011-12-13 16:33:42 -07:00
|
|
|
|
2007-12-12 10:51:56 -07:00
|
|
|
return 0;
|
2012-04-13 14:11:28 -06: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 02:02:29 -06:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 14:57:25 -06: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 02:02:29 -06:00
|
|
|
#endif
|
2012-04-13 14:11:28 -06:00
|
|
|
return ret;
|
2005-04-16 16:20:36 -06: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 02:02:29 -06:00
|
|
|
#ifdef CONFIG_CFQ_GROUP_IOSCHED
|
2012-04-16 14:57:25 -06: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 02:02:29 -06:00
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
elv_unregister(&iosched_cfq);
|
2011-12-13 16:33:42 -07:00
|
|
|
kmem_cache_destroy(cfq_pool);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(cfq_init);
|
|
|
|
module_exit(cfq_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Jens Axboe");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Completely Fair Queueing IO scheduler");
|