IO scheduler based IO controller V7
Subsystems (19)
Hi All,
Here is the V7 of the IO controller patches generated on top of 2.6.31-rc4.
For ease of patching, a consolidated patch is available here.
http://people.redhat.com/~vgoyal/io-controller/io-scheduler-based-io-controller-v7.patch
Previous versions of the patches was posted here.
(V1) http://lkml.org/lkml/2009/3/11/486
(V2) http://lkml.org/lkml/2009/5/5/275
(V3) http://lkml.org/lkml/2009/5/26/472
(V4) http://lkml.org/lkml/2009/6/8/580
(V5) http://lkml.org/lkml/2009/6/19/279
(V6) http://lkml.org/lkml/2009/7/2/369
Changes from V6
===============
- Introduced the notion of group_idling where we idle for next request to come from the same group before we expire it. It is along the lines of cfq's slice_idle thing to provide fairness. Switching to group idling now helps in the sense that we don't have to rely whether queue idling was turned on or not by CFQ. It becomes too much of debugging pain with different work loads and different kind of storage media. Introduction of group_idle should help.
- Moved some of the code like dynamic queue idling update, arming queue idling timer, keeping track of average think time etc back to CFQ. With group idling we don't need it now. Reduce the amount of change.
- Enabled cfq's close cooperator functionality in groups. So far this worked only in root group. Now it should work in non-root groups also.
- Got rid of the patch where we calculated disk time based on average disk rate in some circumstances. It was giving bad numbers in early queue deletion cases. Also did not think that it was helping a lot. Remvoed it for the time being.
- Added an experimental patch to map sync requests using bio tracking info and not task context. This is only for noop, deadline and AS.
- Got rid of experimental patch of idling for async queues. Don't think it was helping.
- Got rid of wait_busy and wait_busy_done logic from queue. Instead implemented it for groups.
- Introduced oom_ioq to accomodate oom_cfqq change recently.
- Broke-up elv_init_ioq() fn into smaller functions. It had 7 arguments and looked complicated.
- Fixed a bug in blk_queue_io_group_congested(). Thanks to Munehiro Ikeda.
- Merged gui's patch to fix the cgroup file format issue.
- Merged gui's patch to update per group congestion limit when q->nr_group_requests is updated.
- Fixed a bug where close cooperation will not work if we wait for all the requests to finish from previous queue.
- Fixed group deletion accouting where deletion from idle tree were also appearing in the log.
- Got rid of busy_rt_queues infrastructure.
- Got rid of elv_ioq_request_dispatched(). An helper function just to increment a variable.
Limitations
===========
- This IO controller provides the bandwidth control at the IO scheduler level (leaf node in stacked hiearchy of logical devices). So there can be cases (depending on configuration) where application does not see proportional BW division at higher logical level device.
LWN has written an article about the issue here.
http://lwn.net/Articles/332839/
How to solve the issue of fairness at higher level logical devices
==================================================================
(Do we really need it? That's not where the contention for resources is.)
Couple of suggestions have come forward.
- Implement IO control at IO scheduler layer and then with the help of some daemon, adjust the weight on underlying devices dynamiclly, depending on what kind of BW gurantees are to be achieved at higher level logical block devices.
- Also implement a higher level IO controller along with IO scheduler based controller and let user choose one depending on his needs.
A higher level controller does not know about the assumptions/policies of unerldying IO scheduler, hence it has the potential to break down the IO scheduler's policy with-in cgroup. A lower level controller can work with IO scheduler much more closely and efficiently.
Other active IO controller developments
=======================================
IO throttling
-------------
This is a max bandwidth controller and not the proportional one. Secondly it is a second level controller which can break the IO scheduler's policy/assumtions with-in cgroup.
dm-ioband
---------
This is a proportional bandwidth controller implemented as device mapper driver. It is also a second level controller which can break the IO scheduler's policy/assumptions with-in cgroup.
TODO
====
- code cleanups, testing, bug fixing, optimizations, benchmarking etc...
Testing
=======
I have been able to do some testing as follows. All my testing is with ext3 file system with a SATA drive which supports queue depth of 31.
Test1 (Isolation between two KVM virtual machines)
==================================================
Created two KVM virtual machines. Partitioned a disk on host in two partitions and gave one partition to each virtual machine. Put both the virtual machines in two different cgroup of weight 1000 and 500 each. Virtual machines created ext3 file system on the partitions exported from host and did buffered writes. Host seems writes as synchronous and virtual machine with higher weight gets double the disk time of virtual machine of lower weight. Used deadline scheduler in this test case.
Some more details about configuration are in documentation patch.
Test2 (Fairness for synchronous reads)
======================================
- Two dd in two cgroups with cgrop weights 1000 and 500. Ran two "dd" in those cgroups (With CFQ scheduler and /sys/block/<device>/queue/fairness = 1)
Higher weight dd finishes first and at that point of time my script takes care of reading cgroup files io.disk_time and io.disk_sectors for both the groups and display the results.
dd if=/mnt/$BLOCKDEV/zerofile1 of=/dev/null &
dd if=/mnt/$BLOCKDEV/zerofile2 of=/dev/null &
234179072 bytes (234 MB) copied, 3.9065 s, 59.9 MB/s 234179072 bytes (234 MB) copied, 5.19232 s, 45.1 MB/s
group1 time=8 16 2471 group1 sectors=8 16 457840 group2 time=8 16 1220 group2 sectors=8 16 225736
First two fields in time and sectors statistics represent major and minor number of the device. Third field represents disk time in milliseconds and number of sectors transferred respectively.
This patchset tries to provide fairness in terms of disk time received. group1 got almost double of group2 disk time (At the time of first dd finish). These time and sectors statistics can be read using io.disk_time and io.disk_sector files in cgroup. More about it in documentation file.
Test3 (Reader Vs Buffered Writes)
================================
Buffered writes can be problematic and can overwhelm readers, especially with noop and deadline. IO controller can provide isolation between readers and buffered (async) writers.
First I ran the test without io controller to see the severity of the issue. Ran a hostile writer and then after 10 seconds started a reader and then monitored the completion time of reader. Reader reads a 256 MB file. Tested this with noop scheduler.
sample script
------------
sync
echo 3 > /proc/sys/vm/drop_caches
time dd if=/dev/zero of=/mnt/sdb/reader-writer-zerofile bs=4K count=2097152 conv=fdatasync &
sleep 10
time dd if=/mnt/sdb/256M-file of=/dev/null &
Results
-------
8589934592 bytes (8.6 GB) copied, 106.045 s, 81.0 MB/s (Writer) 268435456 bytes (268 MB) copied, 96.5237 s, 2.8 MB/s (Reader)
Now it was time to test io controller whether it can provide isolation between readers and writers with noop. I created two cgroups of weight 1000 each and put reader in group1 and writer in group 2 and ran the test again. Upon comletion of reader, my scripts read io.dis_time and io.disk_group cgroup files to get an estimate how much disk time each group got and how many sectors each group did IO for.
For more accurate accounting of disk time for buffered writes with queuing hardware I had to set /sys/block/<disk>/queue/iosched/fairness to "1".
sample script
-------------
echo $$ > /cgroup/bfqio/test2/tasks
dd if=/dev/zero of=/mnt/$BLOCKDEV/testzerofile bs=4K count=2097152 & sleep 10
echo noop > /sys/block/$BLOCKDEV/queue/scheduler
echo 1 > /sys/block/$BLOCKDEV/queue/iosched/fairness echo $$ > /cgroup/bfqio/test1/tasks
dd if=/mnt/$BLOCKDEV/256M-file of=/dev/null &
wait $!
# Some code for reading cgroup files upon completion of reader.
-------------------------
Results
=======
268435456 bytes (268 MB) copied, 6.65819 s, 40.3 MB/s (Reader)
group1 time=8 16 3063 group1 sectors=8 16 524808
group2 time=8 16 3071 group2 sectors=8 16 441752
Note, reader finishes now much lesser time and both group1 and group2 got almost 3 seconds of disk time. Hence io-controller provides isolation from buffered writes.
Test4 (AIO)
===========
AIO reads
-----------
Set up two fio, AIO read jobs in two cgroup with weight 1000 and 500 respectively. I am using cfq scheduler. Following are some lines from my test script.
---------------------------------------------------------------
echo 1000 > /cgroup/bfqio/test1/io.weight
echo 500 > /cgroup/bfqio/test2/io.weight
fio_args="--ioengine=libaio --rw=read --size=512M --direct=1" echo 1 > /sys/block/$BLOCKDEV/queue/iosched/fairness
echo $$ > /cgroup/bfqio/test1/tasks
fio $fio_args --name=test1 --directory=/mnt/$BLOCKDEV/fio1/ --output=/mnt/$BLOCKDEV/fio1/test1.log --exec_postrun="../read-and-display-group-stats.sh $maj_dev $minor_dev" &
echo $$ > /cgroup/bfqio/test2/tasks
fio $fio_args --name=test2 --directory=/mnt/$BLOCKDEV/fio2/ --output=/mnt/$BLOCKDEV/fio2/test2.log &
----------------------------------------------------------------
test1 and test2 are two groups with weight 1000 and 500 respectively. "read-and-display-group-stats.sh" is one small script which reads the test1 and test2 cgroup files to determine how much disk time each group got till first fio job finished.
Results
------
test1 statistics: time=8 16 22403 sectors=8 16 1049640
test2 statistics: time=8 16 11400 sectors=8 16 552864
Above shows that by the time first fio (higher weight), finished, group test1 got 22403 ms of disk time and group test2 got 11400 ms of disk time. similarly the statistics for number of sectors transferred are also shown.
Note that disk time given to group test1 is almost double of group2 disk time.
AIO writes
----------
Set up two fio, AIO direct write jobs in two cgroup with weight 1000 and 500 respectively. I am using cfq scheduler. Following are some lines from my test script.
------------------------------------------------
echo 1000 > /cgroup/bfqio/test1/io.weight
echo 500 > /cgroup/bfqio/test2/io.weight fio_args="--ioengine=libaio --rw=write --size=512M --direct=1"
echo 1 > /sys/block/$BLOCKDEV/queue/iosched/fairness
echo $$ > /cgroup/bfqio/test1/tasks
fio $fio_args --name=test1 --directory=/mnt/$BLOCKDEV/fio1/ --output=/mnt/$BLOCKDEV/fio1/test1.log --exec_postrun="../read-and-display-group-stats.sh $maj_dev $minor_dev" &
echo $$ > /cgroup/bfqio/test2/tasks
fio $fio_args --name=test2 --directory=/mnt/$BLOCKDEV/fio2/ --output=/mnt/$BLOCKDEV/fio2/test2.log &
-------------------------------------------------
test1 and test2 are two groups with weight 1000 and 500 respectively. "read-and-display-group-stats.sh" is one small script which reads the test1 and test2 cgroup files to determine how much disk time each group got till first fio job finished.
Following are the results.
test1 statistics: time=8 16 29085 sectors=8 16 1049656
test2 statistics: time=8 16 14652 sectors=8 16 516728
Above shows that by the time first fio (higher weight), finished, group test1 got 28085 ms of disk time and group test2 got 14652 ms of disk time. similarly the statistics for number of sectors transferred are also shown.
Note that disk time given to group test1 is almost double of group2 disk time.
Test5 (Fairness for async writes, Buffered Write Vs Buffered Write)
===================================================================
Fairness for async writes is tricky and biggest reason is that async writes are cached in higher layers (page cahe) as well as possibly in file system layer also (btrfs, xfs etc), and are dispatched to lower layers not necessarily in proportional manner.
For example, consider two dd threads reading /dev/zero as input file and doing writes of huge files. Very soon we will cross vm_dirty_ratio and dd thread will be forced to write out some pages to disk before more pages can be dirtied. But not necessarily dirty pages of same thread are picked. It can very well pick the inode of lesser priority dd thread and do some writeout. So effectively higher weight dd is doing writeouts of lower weight dd pages and we don't see service differentation.
IOW, the core problem with async write fairness is that higher weight thread does not throw enought IO traffic at IO controller to keep the queue continuously backlogged. In my testing, there are many .2 to .8 second intervals where higher weight queue is empty and in that duration lower weight queue get lots of job done giving the impression that there was no service differentiation.
In summary, from IO controller point of view async writes support is there. Because page cache has not been designed in such a manner that higher prio/weight writer can do more write out as compared to lower prio/weight writer, gettting service differentiation is hard and it is visible in some cases and not visible in some cases.
Do we really care that much for fairness among two writer cgroups? One can choose to do direct writes or sync writes if fairness for writes really matters for him.
Following is the only case where it is hard to ensure fairness between cgroups.
- Buffered writes Vs Buffered Writes.
So to test async writes I created two partitions on a disk and created ext3 file systems on both the partitions. Also created two cgroups and generated lots of write traffic in two cgroups (50 fio threads) and watched the disk time statistics in respective cgroups at the interval of 2 seconds. Thanks to ryo tsuruta for the test case.
*****************************************************************
sync
echo 3 > /proc/sys/vm/drop_caches
fio_args="--size=64m --rw=write --numjobs=50 --group_reporting"
echo $$ > /cgroup/bfqio/test1/tasks
fio $fio_args --name=test1 --directory=/mnt/sdd1/fio/ --output=/mnt/sdd1/fio/test1.log &
echo $$ > /cgroup/bfqio/test2/tasks
fio $fio_args --name=test2 --directory=/mnt/sdd2/fio/ --output=/mnt/sdd2/fio/test2.log &
***********************************************************************
And watched the disk time and sector statistics for the both the cgroups every 2 seconds using a script. How is snippet from output.
test1 statistics: time=8 48 1315 sectors=8 48 55776 dq=8 48 1
test2 statistics: time=8 48 633 sectors=8 48 14720 dq=8 48 2
test1 statistics: time=8 48 5586 sectors=8 48 339064 dq=8 48 2
test2 statistics: time=8 48 2985 sectors=8 48 146656 dq=8 48 3
test1 statistics: time=8 48 9935 sectors=8 48 628728 dq=8 48 3
test2 statistics: time=8 48 5265 sectors=8 48 278688 dq=8 48 4
test1 statistics: time=8 48 14156 sectors=8 48 932488 dq=8 48 6
test2 statistics: time=8 48 7646 sectors=8 48 412704 dq=8 48 7
test1 statistics: time=8 48 18141 sectors=8 48 1231488 dq=8 48 10
test2 statistics: time=8 48 9820 sectors=8 48 548400 dq=8 48 8
test1 statistics: time=8 48 21953 sectors=8 48 1485632 dq=8 48 13
test2 statistics: time=8 48 12394 sectors=8 48 698288 dq=8 48 10
test1 statistics: time=8 48 25167 sectors=8 48 1705264 dq=8 48 13
test2 statistics: time=8 48 14042 sectors=8 48 817808 dq=8 48 10
First two fields in time and sectors statistics represent major and minor number of the device. Third field represents disk time in milliseconds and number of sectors transferred respectively.
So disk time consumed by group1 is almost double of group2 in this case.
Your feedback is welcome.
Thanks
Vivek
PATCH 1/24 io-controller: Documentation
o Documentation for io-controller.
--- Documentation/block/00-INDEX | 2 + Documentation/block/io-controller.txt | 452 +++++++++++++++++++++++++++++++++ 2 files changed, 454 insertions(+), 0 deletions(-) create mode 100644 Documentation/block/io-controller.txt
Documentation/block/00-INDEX +2 -0
@@ -10,6 +10,8 @@ capability.txt - Generic Block Device Capability (/sys/block/<disk>/capability) deadline-iosched.txt - Deadline IO scheduler tunables +io-controller.txt + - IO controller for provding hierarchical IO scheduling ioprio.txt - Block io priorities (in CFQ scheduler) request.txt
Documentation/block/io-controller.txt new file +452 -0
452 lines not on this page · raw message
Signature · 1 line
1.6.0.6
A message that is not in the archive (sent off-list or not yet received): 1248467274-32073-1-git-send-email-vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
PATCH 1/24 io-controller: Documentation
o Documentation for io-controller.
--- Documentation/block/00-INDEX | 2 + Documentation/block/io-controller.txt | 452 +++++++++++++++++++++++++++++++++ 2 files changed, 454 insertions(+), 0 deletions(-) create mode 100644 Documentation/block/io-controller.txt
Documentation/block/00-INDEX +2 -0
@@ -10,6 +10,8 @@ capability.txt - Generic Block Device Capability (/sys/block/<disk>/capability) deadline-iosched.txt - Deadline IO scheduler tunables +io-controller.txt + - IO controller for provding hierarchical IO scheduling ioprio.txt - Block io priorities (in CFQ scheduler) request.txt
Documentation/block/io-controller.txt new file +452 -0
452 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 2/24 io-controller: Core of the B-WF2Q+ scheduler
In reply to a message not in the archiveThis is core of the BFQ(B-WF2Q+) scheduler originally implemented by Paolo and Fabio in BFQ patches. Since then I have taken relevant pieces from BFQ and continued the work on IO controller. It is not the full patch. Just pulled out the some bits to show how core scheduler looks like and it becomes easier to review.
Originally BFQ code was hierarchical. This patch only shows non-hierarchical bits. Hierarhical code comes in later patches.
This code is the building base of introducing fair queuing logic in common elevator layer so that it can be used by all the four IO schedulers. In later patches, CFQ's weighted round robin scheduler will be replaced with B-WF2Q+ scheduler.
Also note that BFQ originally provided fairness in-terms of number of sectors of IO done by the queue. It has been modified to provide fairness in terms of disk time (like CFQ allocate disk time slices proportionate to prio/weight).
B-WF2Q+ is based on WF2Q+, that is described in [2], together with H-WF2Q+, while the augmented tree used to implement B-WF2Q+ with O(log N) complexity derives from the one introduced with EEVDF in [3].
[1] P. Valente and F. Checconi, ``High Throughput Disk Scheduling with Deterministic Guarantees on Bandwidth Distribution,'' to be published.
http://algo.ing.unimo.it/people/paolo/disk_sched/bfq.pdf
[2] Jon C.R. Bennett and H. Zhang, ``Hierarchical Packet Fair Queueing
Algorithms,'' IEEE/ACM Transactions on Networking, 5(5):675-689,
Oct 1997.
http://www.cs.cmu.edu/~hzhang/papers/TON-97-Oct.ps.gz[3] I. Stoica and H. Abdel-Wahab, ``Earliest Eligible Virtual Deadline
First: A Flexible and Accurate Mechanism for Proportional Share Resource Allocation,'' technical report.
http://www.cs.berkeley.edu/~istoica/papers/eevdf-tr-95.pdf
--- block/elevator-fq.c | 715 +++++++++++++++++++++++++++++++++++++++++++++++++++ block/elevator-fq.h | 172 ++++++++++++ 2 files changed, 887 insertions(+), 0 deletions(-) create mode 100644 block/elevator-fq.c create mode 100644 block/elevator-fq.h
block/elevator-fq.c new file +715 -0
@@ -0,0 +1,715 @@ +/* +* elevator fair queuing Layer. Uses B-WF2Q+ hierarchical scheduler for +* fair queuing. +* +* Based on ideas and code from CFQ: +* Copyright (C) 2003 Jens Axboe <axboe-tSWWG44O7X1aa/[email protected]> +* +* Copyright (C) 2008 Fabio Checconi <[email protected]> +* Paolo Valente <[email protected]> +* +* Copyright (C) 2009 Vivek Goyal <[email protected]> +* Nauman Rafique <[email protected]> +*/ + +#include <linux/blkdev.h> +#include "elevator-fq.h" + +#define IO_SERVICE_TREE_INIT ((struct io_service_tree) \ + { RB_ROOT, RB_ROOT, NULL, NULL, 0, 0 }) + +/* Mainly the BFQ scheduling code Follows */ + +/* +* Shift for timestamp calculations. This actually limits the maximum +* service allowed in one timestamp delta (small shift values increase it), +* the maximum total weight that can be used for the queues in the system +* (big shift values increase it), and the period of virtual time wraparounds. +*/ +#define WFQ_SERVICE_SHIFT 22 + +/** +* bfq_gt - compare two timestamps. +* @a: first ts. +* @b: second ts. +* +* Return @a > @b, dealing with wrapping correctly. +*/ +static inline int bfq_gt (u64 a,u64 b) +{ +return (s64)(a - b) >0 ; +} + +/** +* bfq_delta - map service into the virtual time domain. +* @service: amount of service. +* @weight: scale factor. +*/ +static inline u64 bfq_delta (unsigned long service,unsigned int weight) +{ +u64 d = (u64 )service <<WFQ_SERVICE_SHIFT ; + +do_div (d, weight); +return d; +} + +/** +* bfq_calc_finish - assign the finish time to an entity. +* @entity: the entity to act upon. +* @service: the service to be charged to the entity. +*/ +static inline void bfq_calc_finish (struct io_entity *entity, +unsigned long service) +{ +BUG_ON (entity->weight ==0 ); + + entity->finish = entity->start +bfq_delta (service, entity->weight); +} + +static inline struct io_queue *io_entity_to_ioq (struct io_entity *entity) +{ +struct io_queue *ioq =NULL ; + +BUG_ON (entity ==NULL ); +if (entity->my_sched_data ==NULL ) + ioq = container_of(entity, struct io_queue, entity); +return ioq; +} + +/** +* io_entity_of - get an entity from a node. +* @node: the node field of the entity. +* +* Convert a node pointer to the relative entity. This is used only +* to simplify the logic of some functions and not as the generic +* conversion mechanism because, e.g., in the tree walking functions, +* the check for a %NULL value would be redundant. +*/ +static inline struct io_entity *io_entity_of (struct rb_node *node) +{ +struct io_entity *entity =NULL ; + +if (node !=NULL ) + entity = rb_entry(node, struct io_entity, rb_node); + +return entity; +} + +/** +* bfq_remove - remove an entity from a tree. +* @root: the tree root. +* @entity: the entity to remove. +*/ +static inline void bfq_remove (struct rb_root *root,struct io_entity *entity) +{ +BUG_ON (entity->tree != root); + + entity->tree =NULL ; +rb_erase (&entity->rb_node, root); +} + +/** +* bfq_idle_remove - remove an entity from the idle tree. +* @st: the service tree of the owning @entity. +* @entity: the entity being removed. +*/ +static void bfq_idle_remove (struct io_service_tree *st, +struct io_entity *entity) +{ +struct rb_node *next; + +BUG_ON (entity->tree != &st->idle); + +if (entity == st->first_idle) { + next =rb_next (&entity->rb_node); + st->first_idle =io_entity_of (next); + } + +if (entity == st->last_idle) { + next =rb_prev (&entity->rb_node); + st->last_idle =io_entity_of (next); + } + +bfq_remove (&st->idle, entity); +} + +/** +* bfq_insert - generic tree insertion. +* @root: tree root. +* @entity: entity to insert. +* +* This is used for the idle and the active tree, since they are both +* ordered by finish time. +*/ +static void bfq_insert (struct rb_root *root,struct io_entity *entity) +{ +struct io_entity *entry; +struct rb_node **node = &root->rb_node; +struct rb_node *parent =NULL ; + +BUG_ON (entity->tree !=NULL ); + +while (*node !=NULL ) { + parent = *node; + entry = rb_entry(parent, struct io_entity, rb_node); + +if (bfq_gt (entry->finish, entity->finish)) + node = &parent->rb_left; +else + node = &parent->rb_right; + } + +rb_link_node (&entity->rb_node, parent, node); +rb_insert_color (&entity->rb_node, root); + + entity->tree = root; +} + +/** +* bfq_update_min - update the min_start field of a entity. +* @entity: the entity to update. +* @node: one of its children. +* +* This function is called when @entity may store an invalid value for +* min_start due to updates to the active tree. The function assumes +* that the subtree rooted at @node (which may be its left or its right +* child) has a valid min_start value. +*/ +static inline void bfq_update_min (struct io_entity *entity, +struct rb_node *node) +{ +struct io_entity *child; + +if (node !=NULL ) { + child = rb_entry(node, struct io_entity, rb_node); +if (bfq_gt (entity->min_start, child->min_start)) + entity->min_start = child->min_start; + } +} + +/** +* bfq_update_active_node - recalculate min_start. +* @node: the node to update. +* +* @node may have changed position or one of its children may have moved, +* this function updates its min_start value. The left and right subtrees +* are assumed to hold a correct min_start value. +*/ +static inline void bfq_update_active_node (struct rb_node *node) +{ + struct io_entity *entity = rb_entry(node, struct io_entity, rb_node); + + entity->min_start = entity->start; +bfq_update_min (entity, node->rb_right); +bfq_update_min (entity, node->rb_left); +} + +/** +* bfq_update_active_tree - update min_start for the whole active tree. +* @node: the starting node. +* +* @node must be the deepest modified node after an update. This function +* updates its min_start using the values held by its children, assuming +* that they did not change, and then updates all the nodes that may have +* changed in the path to the root. The only nodes that may have changed +* are the ones in the path or their siblings. +*/ +static void bfq_update_active_tree (struct rb_node *node) +{ +struct rb_node *parent; + +up: +bfq_update_active_node (node); + + parent =rb_parent (node); +if (parent ==NULL ) +return ; + +if (node == parent->rb_left && parent->rb_right !=NULL ) +bfq_update_active_node (parent->rb_right); +else if (parent->rb_left !=NULL ) +bfq_update_active_node (parent->rb_left); + + node = parent; + goto up; +} + +/** +* bfq_active_insert - insert an entity in the active tree of its group/device. +* @st: the service tree of the entity. +* @entity: the entity being inserted. +* +* The active tree is ordered by finish time, but an extra key is kept +* per each node, containing the minimum value for the start times of +* its children (and the node itself), so it's possible to search for +* the eligible node with the lowest finish time in logarithmic time. +*/ +static void bfq_active_insert (struct io_service_tree *st, +struct io_entity *entity) +{ +struct rb_node *node = &entity->rb_node; + +bfq_insert (&st->active, entity); + +if (node->rb_left !=NULL ) + node = node->rb_left; +else if (node->rb_right !=NULL ) + node = node->rb_right; + +bfq_update_active_tree (node); +} + +static void bfq_get_entity (struct io_entity *entity) +{ +struct io_queue *ioq =io_entity_to_ioq (entity); + +if (ioq) +elv_get_ioq (ioq); +} + +static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +{ + entity->sched_data = &iog->sched_data; +} + +/** +* bfq_find_deepest - find the deepest node that an extraction can modify. +* @node: the node being removed. +* +* Do the first step of an extraction in an rb tree, looking for the +* node that will replace @node, and returning the deepest node that +* the following modifications to the tree can touch. If @node is the +* last node in the tree return %NULL. +*/ +static struct rb_node *bfq_find_deepest (struct rb_node *node) +{ +struct rb_node *deepest; + +if (node->rb_right ==NULL && node->rb_left ==NULL ) + deepest =rb_parent (node); +else if (node->rb_right ==NULL ) + deepest = node->rb_left; +else if (node->rb_left ==NULL ) + deepest = node->rb_right; +else { + deepest =rb_next (node); +if (deepest->rb_right !=NULL ) + deepest = deepest->rb_right; +else if (rb_parent (deepest) != node) + deepest =rb_parent (deepest); + } + +return deepest; +} + +/** +* bfq_active_remove - remove an entity from the active tree. +* @st: the service_tree containing the tree. +* @entity: the entity being removed. +*/ +static void bfq_active_remove (struct io_service_tree *st, +struct io_entity *entity) +{ +struct rb_node *node; + + node =bfq_find_deepest (&entity->rb_node); +bfq_remove (&st->active, entity); + +if (node !=NULL ) +bfq_update_active_tree (node); +} + +/** +* bfq_idle_insert - insert an entity into the idle tree. +* @st: the service tree containing the tree. +* @entity: the entity to insert. +*/ +static void bfq_idle_insert (struct io_service_tree *st, +struct io_entity *entity) +{ +struct io_entity *first_idle = st->first_idle; +struct io_entity *last_idle = st->last_idle; + +if (first_idle ==NULL ||bfq_gt (first_idle->finish, entity->finish)) + st->first_idle = entity; +if (last_idle ==NULL ||bfq_gt (entity->finish, last_idle->finish)) + st->last_idle = entity; + +bfq_insert (&st->idle, entity); +} + +/** +* bfq_forget_entity - remove an entity from the wfq trees. +* @st: the service tree. +* @entity: the entity being removed. +* +* Update the device status and forget everything about @entity, putting +* the device reference to it, if it is a queue. Entities belonging to +* groups are not refcounted. +*/ +static void bfq_forget_entity (struct io_service_tree *st, +struct io_entity *entity) +{ +struct io_queue *ioq =NULL ; + +BUG_ON (!entity->on_st); + entity->on_st =0 ; + st->wsum -= entity->weight; + ioq =io_entity_to_ioq (entity); +if (!ioq) +return ; +elv_put_ioq (ioq); +} + +/** +* bfq_put_idle_entity - release the idle tree ref of an entity. +* @st: service tree for the entity. +* @entity: the entity being released. +*/ +static void bfq_put_idle_entity (struct io_service_tree *st, +struct io_entity *entity) +{ +bfq_idle_remove (st, entity); +bfq_forget_entity (st, entity); +} + +/** +* bfq_forget_idle - update the idle tree if necessary. +* @st: the service tree to act upon. +* +* To preserve the global O(log N) complexity we only remove one entry here; +* as the idle tree will not grow indefinitely this can be done safely. +*/ +static void bfq_forget_idle (struct io_service_tree *st) +{ +struct io_entity *first_idle = st->first_idle; +struct io_entity *last_idle = st->last_idle; + +if (RB_EMPTY_ROOT (&st->active) && last_idle !=NULL && + !bfq_gt (last_idle->finish, st->vtime)) { +/* +* Active tree is empty. Pull back vtime to finish time of +* last idle entity on idle tree. +* Rational seems to be that it reduces the possibility of +* vtime wraparound (bfq_gt(V-F) < 0). +*/ + st->vtime = last_idle->finish; + } + +if (first_idle !=NULL && !bfq_gt (first_idle->finish, st->vtime)) +bfq_put_idle_entity (st, first_idle); +} + + +static struct io_service_tree * +__bfq_entity_update_prio (struct io_service_tree *old_st, +struct io_entity *entity) +{ +struct io_service_tree *new_st = old_st; +struct io_queue *ioq =io_entity_to_ioq (entity); + +if (entity->ioprio_changed) { + old_st->wsum -= entity->weight; + entity->ioprio = entity->new_ioprio; + entity->ioprio_class = entity->new_ioprio_class; + entity->weight = entity->new_weight; + entity->ioprio_changed =0 ; + +/* +* Also update the scaled budget for ioq. Group will get the +* updated budget once ioq is selected to run next. +*/ +if (ioq) { +struct elv_fq_data *efqd = ioq->efqd; +/* +* elv_prio_to_slice() is defined in later patches +* where a slice length is calculated from the +* ioprio of the queue. +*/ + entity->budget =elv_prio_to_slice (efqd, ioq); + } + +/* +* NOTE: here we may be changing the weight too early, +* this will cause unfairness. The correct approach +* would have required additional complexity to defer +* weight changes to the proper time instants (i.e., +* when entity->finish <= old_st->vtime). +*/ + new_st =io_entity_service_tree (entity); + new_st->wsum += entity->weight; + +if (new_st != old_st) + entity->start = new_st->vtime; + } + +return new_st; +} + +/** +* bfq_update_vtime - update vtime if necessary. +* @st: the service tree to act upon. +* +* If necessary update the service tree vtime to have at least one +* eligible entity, skipping to its start time. Assumes that the +* active tree of the device is not empty. +* +* NOTE: this hierarchical implementation updates vtimes quite often, +* we may end up with reactivated tasks getting timestamps after a +* vtime skip done because we needed a ->first_active entity on some +* intermediate node. +*/ +static void bfq_update_vtime (struct io_service_tree *st) +{ +struct io_entity *entry; +struct rb_node *node = st->active.rb_node; + + entry = rb_entry(node, struct io_entity, rb_node); +if (bfq_gt (entry->min_start, st->vtime)) { + st->vtime = entry->min_start; +bfq_forget_idle (st); + } +} + +/** +* bfq_first_active - find the eligible entity with the smallest finish time +* @st: the service tree to select from. +* +* This function searches the first schedulable entity, starting from the +* root of the tree and going on the left every time on this side there is +* a subtree with at least one eligible (start <= vtime) entity. The path +* on the right is followed only if a) the left subtree contains no eligible +* entities and b) no eligible entity has been found yet. +*/ +static struct io_entity *bfq_first_active_entity (struct io_service_tree *st) +{ +struct io_entity *entry, *first =NULL ; +struct rb_node *node = st->active.rb_node; + +while (node !=NULL ) { + entry = rb_entry(node, struct io_entity, rb_node); +left: +if (!bfq_gt (entry->start, st->vtime)) + first = entry; + +BUG_ON (bfq_gt (entry->min_start, st->vtime)); + +if (node->rb_left !=NULL ) { + entry =rb_entry (node->rb_left, + struct io_entity, rb_node); +if (!bfq_gt (entry->min_start, st->vtime)) { + node = node->rb_left; + goto left; + } + } +if (first !=NULL ) +break ; + node = node->rb_right; + } + +BUG_ON (first ==NULL && !RB_EMPTY_ROOT (&st->active)); +return first; +} + +/** +* __bfq_lookup_next_entity - return the first eligible entity in @st. +* @st: the service tree. +* +* Update the virtual time in @st and return the first eligible entity +* it contains. +*/ +static struct io_entity *__bfq_lookup_next_entity (struct io_service_tree *st) +{ +struct io_entity *entity; + +if (RB_EMPTY_ROOT (&st->active)) +return NULL ; + +bfq_update_vtime (st); + entity =bfq_first_active_entity (st); +BUG_ON (bfq_gt (entity->start, st->vtime)); + +return entity; +} + +/** +* bfq_lookup_next_entity - return the first eligible entity in @sd. +* @sd: the sched_data. +* @extract: if true the returned entity will be also extracted from @sd. +* +* NOTE: since we cache the next_active entity at each level of the +* hierarchy, the complexity of the lookup can be decreased with +* absolutely no effort just returning the cached next_active value; +* we prefer to do full lookups to test the consistency of * the data +* structures. +*/ +static struct io_entity *bfq_lookup_next_entity (struct io_sched_data *sd, +int extract) +{ +struct io_service_tree *st = sd->service_tree; +struct io_entity *entity; +int i; + +/* +* We should not call lookup when an entity is active, as doing lookup +* can result in an erroneous vtime jump. +*/ +BUG_ON (sd->active_entity !=NULL ); + +for (i =0 ; i <IO_IOPRIO_CLASSES ; i++, st++) { + entity =__bfq_lookup_next_entity (st); +if (entity !=NULL ) { +if (extract) { +bfq_active_remove (st, entity); + sd->active_entity = entity; + } +break ; + } + } + +return entity; +} + +/** +* __bfq_activate_entity - activate an entity. +* @entity: the entity being activated. +* +* Called whenever an entity is activated, i.e., it is not active and one +* of its children receives a new request, or has to be reactivated due to +* budget exhaustion. It uses the current budget of the entity (and the +* service received if @entity is active) of the queue to calculate its +* timestamps. +*/ +static void __bfq_activate_entity (struct io_entity *entity) +{ +struct io_sched_data *sd = entity->sched_data; +struct io_service_tree *st =io_entity_service_tree (entity); + +if (entity == sd->active_entity) { +BUG_ON (entity->tree !=NULL ); +/* +* If we are requeueing the current entity we have +* to take care of not charging to it service it has +* not received. +*/ +bfq_calc_finish (entity, entity->service); + entity->start = entity->finish; + sd->active_entity =NULL ; + }else if (entity->tree == &st->active) { +/* +* Requeueing an entity due to a change of some +* next_active entity below it. We reuse the old +* start time. +*/ +bfq_active_remove (st, entity); + }else if (entity->tree == &st->idle) { +/* +* Must be on the idle tree, bfq_idle_remove() will +* check for that. +*/ +bfq_idle_remove (st, entity); + entity->start =bfq_gt (st->vtime, entity->finish) ? + st->vtime : entity->finish; + }else { +/* +* The finish time of the entity may be invalid, and +* it is in the past for sure, otherwise the queue +* would have been on the idle tree. +*/ + entity->start = st->vtime; + st->wsum += entity->weight; +bfq_get_entity (entity); + +BUG_ON (entity->on_st); + entity->on_st =1 ; + } + + st =__bfq_entity_update_prio (st, entity); +bfq_calc_finish (entity, entity->budget); +bfq_active_insert (st, entity); +} + +/** +* bfq_activate_entity - activate an entity. +* @entity: the entity to activate. +*/ +static void bfq_activate_entity (struct io_entity *entity) +{ +__bfq_activate_entity (entity); +} + +/** +* __bfq_deactivate_entity - deactivate an entity from its service tree. +* @entity: the entity to deactivate. +* @requeue: if false, the entity will not be put into the idle tree. +* +* Deactivate an entity, independently from its previous state. If the +* entity was not on a service tree just return, otherwise if it is on +* any scheduler tree, extract it from that tree, and if necessary +* and if the caller did not specify @requeue, put it on the idle tree. +* +*/ +static int __bfq_deactivate_entity (struct io_entity *entity,int requeue) +{ +struct io_sched_data *sd = entity->sched_data; +struct io_service_tree *st =io_entity_service_tree (entity); +int was_active = entity == sd->active_entity; +int ret =0 ; + +if (!entity->on_st) +return 0 ; + +BUG_ON (was_active && entity->tree !=NULL ); + +if (was_active) { +bfq_calc_finish (entity, entity->service); + sd->active_entity =NULL ; + }else if (entity->tree == &st->active) +bfq_active_remove (st, entity); +else if (entity->tree == &st->idle) +bfq_idle_remove (st, entity); +else if (entity->tree !=NULL ) +BUG (); + +if (!requeue || !bfq_gt (entity->finish, st->vtime)) +bfq_forget_entity (st, entity); +else +bfq_idle_insert (st, entity); + +BUG_ON (sd->active_entity == entity); + +return ret; +} + +/** +* bfq_deactivate_entity - deactivate an entity. +* @entity: the entity to deactivate. +* @requeue: true if the entity can be put on the idle tree +*/ +static void bfq_deactivate_entity (struct io_entity *entity,int requeue) +{ +__bfq_deactivate_entity (entity, requeue); +} + +static void entity_served (struct io_entity *entity,unsigned long served) +{ +struct io_service_tree *st; + + st =io_entity_service_tree (entity); + entity->service += served; +BUG_ON (st->wsum ==0 ); + st->vtime +=bfq_delta (served, st->wsum); +bfq_forget_idle (st); +} + +/** +* io_flush_idle_tree - deactivate any entity on the idle tree of @st. +* @st: the service tree being flushed. +*/ +static void io_flush_idle_tree (struct io_service_tree *st) +{ +struct io_entity *entity = st->first_idle; + +for (; entity !=NULL ; entity = st->first_idle) +__bfq_deactivate_entity (entity,0 ); +}
block/elevator-fq.h new file +172 -0
172 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 3/24 io-controller: bfq support of in-class preemption
In reply to a message not in the archiveo Generally preemption is associated with cross class where if an request from RT class is pending it will preempt the ongoing BE or IDLE class request.
o CFQ also does in-class preemtions like a sync request queue preempting the async request queue. In that case it looks like preempting queue gains share and it is not fair.
o Implement the similar functionality in bfq so that we can retain the existing CFQ behavior.
o This patch creates a bypass path so that a queue can be put at the front of the service tree (add_front, similar to CFQ), so that it will be selected next to run. That's a different thing that in the process this queue gains share.
--- block/elevator-fq.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 5 deletions(-)
block/elevator-fq.c +41 -5
@@ -267,7 +267,8 @@ static void bfq_get_entity(struct io_entity *entity)elv_get_ioq (ioq); } -static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +static inline void +bfq_init_entity (struct io_entity *entity,struct io_group *iog) { entity->sched_data = &iog->sched_data; }
@@ -580,7 +581,7 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd,* service received if @entity is active) of the queue to calculate its * timestamps. */ -static void __bfq_activate_entity (struct io_entity *entity) +static void __bfq_activate_entity (struct io_entity *entity,int add_front) {struct io_sched_data *sd = entity->sched_data;struct io_service_tree *st =io_entity_service_tree (entity);
@@ -625,7 +626,42 @@ static void __bfq_activate_entity(struct io_entity *entity) } st =__bfq_entity_update_prio (st, entity); -bfq_calc_finish (entity, entity->budget); +/* +* This is to emulate cfq like functionality where preemption can +* happen with-in same class, like sync queue preempting async queue +* May be this is not a very good idea from fairness point of view +* as preempting queue gains share. Keeping it for now. +*/ +if (add_front) { +struct io_entity *next_entity; + +/* +* Determine the entity which will be dispatched next +* Use sd->next_active once hierarchical patch is applied +*/ + next_entity =bfq_lookup_next_entity (sd,0 ); + +if (next_entity && next_entity != entity) { +struct io_service_tree *new_st; +u64 delta; + + new_st =io_entity_service_tree (next_entity); + +/* +* At this point, both entities should belong to +* same service tree as cross service tree preemption +* is automatically taken care by algorithm +*/ +BUG_ON (new_st != st); + entity->finish = next_entity->finish -1 ; + delta =bfq_delta (entity->budget, entity->weight); + entity->start = entity->finish - delta; +if (bfq_gt (entity->start, st->vtime)) + entity->start = st->vtime; + } + }else { +bfq_calc_finish (entity, entity->budget); + }bfq_active_insert (st, entity); }
@@ -633,9 +669,9 @@ static void __bfq_activate_entity(struct io_entity *entity)* bfq_activate_entity - activate an entity. * @entity: the entity to activate. */ -static void bfq_activate_entity (struct io_entity *entity) +static void bfq_activate_entity (struct io_entity *entity,int add_front) { -__bfq_activate_entity (entity); +__bfq_activate_entity (entity, add_front); }/**
Signature · 1 line
1.6.0.6
PATCH 4/24 io-controller: Common flat fair queuing code in elevaotor layer
In reply to a message not in the archiveThis is common fair queuing code in elevator layer. This is controlled by config option CONFIG_ELV_FAIR_QUEUING. This patch initially only introduces flat fair queuing support where there is only one group, "root group" and all the tasks belong to root group.
This elevator layer changes are backward compatible. That means any ioscheduler using old interfaces will continue to work.
This code is essentially the CFQ code for fair queuing. The primary difference is that flat rounding robin algorithm of CFQ has been replaced with BFQ (WF2Q+).
--- block/Kconfig.iosched | 13 + block/Makefile | 1 + block/as-iosched.c | 2 +- block/blk.h | 4 + block/cfq-iosched.c | 2 +- block/deadline-iosched.c | 3 +- block/elevator-fq.c | 1112 +++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 281 ++++++++++++ block/elevator.c | 44 ++- block/noop-iosched.c | 2 +- include/linux/blkdev.h | 14 + include/linux/elevator.h | 51 ++- 12 files changed, 1507 insertions(+), 22 deletions(-)
block/Kconfig.iosched +13 -0
@@ -2,6 +2,19 @@ if BLOCK menu "IO Schedulers" +config ELV_FAIR_QUEUING + bool "Elevator Fair Queuing Support" + default n + ---help--- + Traditionally only cfq had notion of multiple queues and it did + fair queuing at its own. With the cgroups and need of controlling + IO, now even the simple io schedulers like noop, deadline, as will + have one queue per cgroup and will need hierarchical fair queuing. + Instead of every io scheduler implementing its own fair queuing + logic, this option enables fair queuing in elevator layer so that + other ioschedulers can make use of it. + If unsure, say N. + config IOSCHED_NOOP bool default y
block/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o obj-$(CONFIG_BLK_DEV_INTEGRITY) += blk-integrity.o +obj-$(CONFIG_ELV_FAIR_QUEUING) += elevator-fq.o
block/as-iosched.c +1 -1
@@ -1351,7 +1351,7 @@ static void as_exit_queue(struct elevator_queue *e)/* * initialize elevator private data (as_data). */ -static void *as_init_queue (struct request_queue *q) +static void *as_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct as_data *ad;
block/blk.h +4 -0
@@ -71,6 +71,8 @@ static inline void elv_activate_rq(struct request_queue *q, struct request *rq) {struct elevator_queue *e = q->elevator; +elv_fq_activate_rq (q, rq); +if (e->ops->elevator_activate_req_fn) e->ops->elevator_activate_req_fn (q, rq); }
@@ -79,6 +81,8 @@ static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq {struct elevator_queue *e = q->elevator; +elv_fq_deactivate_rq (q, rq); +if (e->ops->elevator_deactivate_req_fn) e->ops->elevator_deactivate_req_fn (q, rq); }
block/cfq-iosched.c +1 -1
@@ -2448,7 +2448,7 @@ static void cfq_exit_queue(struct elevator_queue *e)kfree (cfqd); } -static void *cfq_init_queue (struct request_queue *q) +static void *cfq_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct cfq_data *cfqd;int i;
block/deadline-iosched.c +2 -1
@@ -347,7 +347,8 @@ static void deadline_exit_queue(struct elevator_queue *e)/* * initialize elevator private data (deadline_data). */ -static void *deadline_init_queue (struct request_queue *q) +static void * +deadline_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct deadline_data *dd;
block/elevator-fq.c +1107 -5
1,139 lines not on this page · raw message
block/elevator-fq.h +281 -0
306 lines not on this page · raw message
block/elevator.c +32 -12
108 lines not on this page · raw message
block/noop-iosched.c +1 -1
@@ -65,7 +65,7 @@ noop_latter_request(struct request_queue *q, struct request *rq) return list_entry(rq->queuelist.next, struct request, queuelist); } -static void *noop_init_queue (struct request_queue *q) +static void *noop_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct noop_data *nd;
include/linux/blkdev.h +14 -0
@@ -229,6 +229,11 @@ struct request {/* for bidi */ struct request *next_rq; + +#ifdef CONFIG_ELV_FAIR_QUEUING +/* io queue request belongs to */ +struct io_queue *ioq; +#endif };static inline unsigned short req_get_ioprio (struct request *req)
@@ -236,6 +241,15 @@ static inline unsigned short req_get_ioprio(struct request *req)return req->ioprio; } +static inline struct io_queue *req_ioq (struct request *req) +{ +#ifdef CONFIG_ELV_FAIR_QUEUING +return req->ioq; +#else +return NULL ; +#endif +} +/* * State information carried for REQ_TYPE_PM_SUSPEND and REQ_TYPE_PM_RESUME * requests. Some step values could eventually be made generic.
include/linux/elevator.h +50 -1
87 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 5/24 io-controller: Modify cfq to make use of flat elevator fair queuing
In reply to a message not in the archiveThis patch changes cfq to use fair queuing code from elevator layer.
--- block/Kconfig.iosched | 3 +- block/cfq-iosched.c | 1007 +++++++++++-------------------------------------- 2 files changed, 231 insertions(+), 779 deletions(-)
block/Kconfig.iosched +2 -1
@@ -3,7 +3,7 @@ if BLOCK menu "IO Schedulers" config ELV_FAIR_QUEUING - bool "Elevator Fair Queuing Support" + bool default n ---help--- Traditionally only cfq had notion of multiple queues and it did
@@ -46,6 +46,7 @@ config IOSCHED_DEADLINE config IOSCHED_CFQ tristate "CFQ I/O scheduler" + select ELV_FAIR_QUEUING default y ---help--- The CFQ I/O scheduler tries to distribute bandwidth equally
block/cfq-iosched.c +229 -778
1,659 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 6/24 io-controller: core bfq scheduler changes for hierarchical setup
In reply to a message not in the archiveo Some of the core bfq scheduler changes for hiearchical groups.
--- block/elevator-fq.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++----- block/elevator-fq.h | 4 + init/Kconfig | 8 +++ 3 files changed, 165 insertions(+), 16 deletions(-)
block/elevator-fq.c +153 -16
@@ -38,6 +38,69 @@ static struct kmem_cache *elv_ioq_pool;*/ #define WFQ_SERVICE_SHIFT 22 +#ifdef CONFIG_GROUP_IOSCHED +#define for_each_entity (entity) \ + for (; entity != NULL; entity = entity->parent) + +#define for_each_entity_safe (entity, parent) \ + for (; entity && ({ parent = entity->parent; 1; }); entity = parent) + + +static struct io_entity *bfq_lookup_next_entity (struct io_sched_data *sd, +int extract); + +static int bfq_update_next_active (struct io_sched_data *sd) +{ +struct io_group *iog; +struct io_entity *entity, *next_active; + +if (sd->active_entity !=NULL ) +/* will update/requeue at the end of service */ +return 0 ; + +/* +* NOTE: this can be improved in may ways, such as returning +* 1 (and thus propagating upwards the update) only when the +* budget changes, or caching the bfqq that will be scheduled +* next from this subtree. By now we worry more about +* correctness than about performance... +*/ + next_active =bfq_lookup_next_entity (sd,0 ); + sd->next_active = next_active; + +if (next_active !=NULL ) { + iog = container_of(sd, struct io_group, sched_data); + entity = iog->my_entity; +if (entity !=NULL ) + entity->budget = next_active->budget; + } + +return 1 ; +} + +static inline void bfq_check_next_active (struct io_sched_data *sd, +struct io_entity *entity) +{ +BUG_ON (sd->next_active != entity); +} +#else /* GROUP_IOSCHED */ +#define for_each_entity (entity) \ + for (; entity != NULL; entity = NULL) + +#define for_each_entity_safe (entity, parent) \ + for (parent = NULL; entity != NULL; entity = parent) + +static inline int bfq_update_next_active (struct io_sched_data *sd) +{ +return 0 ; +} + +static inline void bfq_check_next_active (struct io_sched_data *sd, +struct io_entity *entity) +{ +} +#endif /* GROUP_IOSCHED */ +static inline int elv_prio_slice (struct elv_fq_data *efqd,int sync,unsigned short prio) {
@@ -582,8 +645,10 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd, entity =__bfq_lookup_next_entity (st);if (entity !=NULL ) {if (extract) { +bfq_check_next_active (sd, entity);bfq_active_remove (st, entity); sd->active_entity = entity; + sd->next_active =NULL ; }break ; }
@@ -660,11 +725,8 @@ static void __bfq_activate_entity(struct io_entity *entity, int add_front)if (add_front) {struct io_entity *next_entity; -/* -* Determine the entity which will be dispatched next -* Use sd->next_active once hierarchical patch is applied -*/ - next_entity =bfq_lookup_next_entity (sd,0 ); +/* Determine the entity which will be dispatched next */ + next_entity = sd->next_active;if (next_entity && next_entity != entity) {struct io_service_tree *new_st;
@@ -696,7 +758,21 @@ static void __bfq_activate_entity(struct io_entity *entity, int add_front)*/ static void bfq_activate_entity (struct io_entity *entity,int add_front) { -__bfq_activate_entity (entity, add_front); +struct io_sched_data *sd; + +for_each_entity (entity) { +__bfq_activate_entity (entity, add_front); + + add_front =0 ; + sd = entity->sched_data; +if (!bfq_update_next_active (sd)) +/* +* No need to propagate the activation to the +* upper entities, as they will be updated when +* the active entity is rescheduled. +*/ +break ; + } }/**
@@ -731,6 +807,8 @@ static int __bfq_deactivate_entity(struct io_entity *entity, int requeue)bfq_idle_remove (st, entity); else if (entity->tree != NULL) BUG(); +if (was_active || sd->next_active == entity) + ret =bfq_update_next_active (sd);if (!requeue || !bfq_gt (entity->finish, st->vtime))bfq_forget_entity (st, entity);
@@ -738,6 +816,7 @@ static int __bfq_deactivate_entity(struct io_entity *entity, int requeue)bfq_idle_insert (st, entity);BUG_ON (sd->active_entity == entity); +BUG_ON (sd->next_active == entity);return ret; }
@@ -749,18 +828,62 @@ static int __bfq_deactivate_entity(struct io_entity *entity, int requeue)*/ static void bfq_deactivate_entity (struct io_entity *entity,int requeue) { -__bfq_deactivate_entity (entity, requeue); +struct io_sched_data *sd; +struct io_entity *parent; + +for_each_entity_safe (entity, parent) { + sd = entity->sched_data; + +if (!__bfq_deactivate_entity (entity, requeue)) +/* +* The parent entity is still backlogged, and +* we don't need to update it as it is still +* under service. +*/ +break ; + +if (sd->next_active !=NULL ) { +/* +* The parent entity is still backlogged and +* the budgets on the path towards the root +* need to be updated. +*/ + goto update; + } + +/* +* If we reach there the parent is no more backlogged and +* we want to propagate the dequeue upwards. +* +*/ + + requeue =1 ; + } + +return ; + +update: + entity = parent; +for_each_entity (entity) { +__bfq_activate_entity (entity,0 ); + + sd = entity->sched_data; +if (!bfq_update_next_active (sd)) +break ; + } }static void entity_served (struct io_entity *entity,unsigned long served) {struct io_service_tree *st; - st =io_entity_service_tree (entity); - entity->service += served; -BUG_ON (st->wsum ==0 ); - st->vtime +=bfq_delta (served, st->wsum); -bfq_forget_idle (st); +for_each_entity (entity) { + st =io_entity_service_tree (entity); + entity->service += served; +BUG_ON (st->wsum ==0 ); + st->vtime +=bfq_delta (served, st->wsum); +bfq_forget_idle (st); + } }/**
@@ -1068,11 +1191,25 @@ static struct io_queue *elv_get_next_ioq(struct request_queue *q, int extract)return NULL ; sd = &efqd->root_group->sched_data; - entity =bfq_lookup_next_entity (sd,1 ); -BUG_ON (!entity); -if (extract) - entity->service =0 ; +for (; sd !=NULL ; sd = entity->my_sched_data) { + entity =bfq_lookup_next_entity (sd,1 ); +/* +* entity can be null despite the fact that there are busy +* queues. if all the busy queues are under a group which is +* currently under service. +* So if we are just looking for next ioq while something is +* being served, null entity is not an error. +*/ +BUG_ON (!entity && extract); + +if (extract) + entity->service =0 ; + +if (!entity) +return NULL ; + } + ioq =io_entity_to_ioq (entity);return ioq;
block/elevator-fq.h +4 -0
@@ -72,6 +72,7 @@ struct io_service_tree {*/ struct io_sched_data {struct io_entity *active_entity; +struct io_entity *next_active;struct io_service_tree service_tree[IO_IOPRIO_CLASSES ]; };
@@ -178,7 +179,10 @@ struct io_queue { };struct io_group { +struct io_entity entity;struct io_sched_data sched_data; +struct io_entity *my_entity; +/* * async queue for each priority case for RT and BE class. * Used only for cfq.
init/Kconfig +8 -0
@@ -612,6 +612,14 @@ config CGROUP_MEM_RES_CTLR_SWAP Now, memory usage of swap_cgroup is 2 bytes per entry. If swap page size is 4096bytes, 512k per 1Gbytes of swap. +config GROUP_IOSCHED + bool "Group IO Scheduler" + depends on CGROUPS && ELV_FAIR_QUEUING + default n + ---help--- + This feature lets IO scheduler recognize task groups and control + disk bandwidth allocation to such task groups. + endif # CGROUPS config MM_OWNER
Signature · 1 line
1.6.0.6
PATCH 7/24 io-controller: cgroup related changes for hierarchical group support
In reply to a message not in the archiveo This patch introduces some of the cgroup related code for io controller.
--- block/blk-ioc.c | 3 + block/elevator-fq.c | 174 +++++++++++++++++++++++++++++++++++++++++ block/elevator-fq.h | 38 +++++++++- include/linux/cgroup_subsys.h | 6 ++ include/linux/iocontext.h | 5 + 5 files changed, 225 insertions(+), 1 deletions(-)
block/blk-ioc.c +3 -0
@@ -95,6 +95,9 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node)spin_lock_init (&ret->lock); ret->ioprio_changed =0 ; ret->ioprio =0 ; +#ifdef CONFIG_GROUP_IOSCHED + ret->cgroup_changed =0 ; +#endif ret->last_waited = jiffies;/* doesn't matter... */ ret->nr_batch_requests =0 ;/* because this is 0 */ ret->aic =NULL ;
block/elevator-fq.c +174 -0
186 lines not on this page · raw message
block/elevator-fq.h +37 -1
@@ -13,11 +13,13 @@*/ #include <linux/blkdev.h> +#include <linux/cgroup.h> #ifndef _BFQ_SCHED_H#define _BFQ_SCHED_H#define IO_IOPRIO_CLASSES 3 +#define WEIGHT_MAX 1000struct io_entity ;struct io_queue ;
@@ -88,7 +90,7 @@ struct io_sched_data {* this entity; used for O(log N) lookups into active trees. * @service: service received during the last round of service. * @budget: budget used to calculate F_i; F_i = S_i + @budget / @weight. -* @weight: weight of the queue, calculated as IOPRIO_BE_NR - @ioprio. +* @weight: the weight in use. * @new_weight: when a weight change is requested, the new weight value * @parent: parent entity, for hierarchical scheduling. * @my_sched_data: for non-leaf nodes in the cgroup hierarchy, the
@@ -178,8 +180,10 @@ struct io_queue {void *sched_queue; }; +#ifdef CONFIG_GROUP_IOSCHED struct io_group { struct io_entity entity; + struct hlist_node group_node; struct io_sched_data sched_data; struct io_entity *my_entity;
@@ -190,8 +194,40 @@ struct io_group {struct io_queue *async_queue[2 ][IOPRIO_BE_NR ];struct io_queue *async_idle_queue; +unsigned short iocg_id; }; +/** +* struct io_cgroup - io cgroup data structure. +* @css: subsystem state for io in the containing cgroup. +* @weight: cgroup weight. +* @ioprio_class: cgroup ioprio_class. +* @lock: spinlock that protects @weight, @ioprio_class and @group_data. +* @group_data: list containing the io_group belonging to this cgroup. +* +* @group_data is accessed using RCU, with @lock protecting the updates, +* @weight and @ioprio_class are protected by @lock. +*/ +struct io_cgroup { +struct cgroup_subsys_state css; + +unsigned int weight; +unsigned short ioprio_class; + +spinlock_t lock; +struct hlist_head group_data; +}; +#else +struct io_group { +struct io_sched_data sched_data; + +/* async_queue and idle_queue are used only for cfq */ +struct io_queue *async_queue[2 ][IOPRIO_BE_NR ]; +struct io_queue *async_idle_queue; +}; +#endif /* CONFIG_GROUP_IOSCHED */ + +struct elv_fq_data {struct io_group *root_group;
include/linux/cgroup_subsys.h +6 -0
@@ -60,3 +60,9 @@ SUBSYS(net_cls)#endif /* */ + +#ifdef CONFIG_GROUP_IOSCHED +SUBSYS(io) +#endif + +/* */
include/linux/iocontext.h +5 -0
@@ -73,6 +73,11 @@ struct io_context {unsigned short ioprio;unsigned short ioprio_changed; +#ifdef CONFIG_GROUP_IOSCHED +/* If task changes the cgroup, elevator processes it asynchronously */ +unsigned short cgroup_changed; +#endif +/* * For request batching */
Signature · 1 line
1.6.0.6
PATCH 8/24 io-controller: Common hierarchical fair queuing code in elevaotor layer
In reply to a message not in the archiveo This patch enables hierarchical fair queuing in common layer. It is controlled by config option CONFIG_GROUP_IOSCHED.
o Requests keep a reference on ioq and ioq keeps keep a reference on groups. For async queues in CFQ, and single ioq in other schedulers, io_group also keeps are reference on io_queue. This reference on ioq is dropped when the queue is released (elv_release_ioq). So the queue can be freed.
When a queue is released, it puts the reference to io_group and the io_group is released after all the queues are released. Child groups also take reference on parent groups, and release it when they are destroyed.
o Reads of iocg->group_data are not always iocg->lock; so all the operations on that list are still protected by RCU. All modifications to iocg->group_data should always done under iocg->lock.
Whenever iocg->lock and queue_lock can both be held, queue_lock should be held first. This avoids all deadlocks. In order to avoid race between cgroup deletion and elevator switch the following algorithm is used:
- Cgroup deletion path holds iocg->lock and removes iog entry to iocg->group_data list. Then it drops iocg->lock, holds queue_lock and destroys iog. So in this path, we never hold iocg->lock and queue_lock at the same time. Also, since we remove iog from iocg->group_data under iocg->lock, we can't race with elevator switch.
- Elevator switch path does not remove iog from iocg->group_data list directly. It first hold iocg->lock, scans iocg->group_data again to see if iog is still there; it removes iog only if it finds iog there. Otherwise, cgroup deletion must have removed it from the list, and cgroup deletion is responsible for removing iog.
So the path which removes iog from iocg->group_data list does the final removal of iog by calling __io_destroy_group() function.
--- block/cfq-iosched.c | 3 + block/elevator-fq.c | 890 ++++++++++++++++++++++++++++++++++++++++++++++----- block/elevator-fq.h | 91 +++++- block/elevator.c | 4 + 4 files changed, 911 insertions(+), 77 deletions(-)
block/cfq-iosched.c +3 -0
@@ -1354,6 +1354,9 @@ alloc_cfqq: cfqq->ioq = ioq;cfq_init_cfqq (cfqd, cfqq, current->pid, is_sync);cfq_init_prio_data (cfqq, ioc); + +/* ioq reference on iog */ +elv_get_iog (iog);cfq_log_cfqq (cfqd, cfqq,"alloced" ); }else { cfqq = &cfqd->oom_cfqq;
block/elevator-fq.c +815 -75
1,050 lines not on this page · raw message
block/elevator-fq.h +89 -2
139 lines not on this page · raw message
block/elevator.c +4 -0
@@ -113,6 +113,10 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio) !bio_failfast_driver(bio) != !blk_failfast_driver(rq))return 0 ; +/* If rq and bio belongs to different groups, dont allow merging */ +if (!io_group_allow_merge (rq, bio)) +return 0 ; +if (!elv_iosched_allow_merge (rq, bio))return 0 ;
Signature · 1 line
1.6.0.6
PATCH 9/24 io-controller: cfq changes to use hierarchical fair queuing code in elevaotor layer
In reply to a message not in the archiveMake cfq hierarhical.
--- block/Kconfig.iosched | 8 ++++++ block/cfq-iosched.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++- init/Kconfig | 2 +- 3 files changed, 69 insertions(+), 3 deletions(-)
block/Kconfig.iosched +8 -0
@@ -54,6 +54,14 @@ config IOSCHED_CFQ working environment, suitable for desktop systems. This is the default I/O scheduler. +config IOSCHED_CFQ_HIER + bool "CFQ Hierarchical Scheduling support" + depends on IOSCHED_CFQ && CGROUPS + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in cfq. + choice prompt "Default I/O scheduler" default DEFAULT_CFQ
block/cfq-iosched.c +60 -2
86 lines not on this page · raw message
init/Kconfig +1 -1
@@ -613,7 +613,7 @@ config CGROUP_MEM_RES_CTLR_SWAP size is 4096bytes, 512k per 1Gbytes of swap. config GROUP_IOSCHED - bool "Group IO Scheduler" + bool depends on CGROUPS && ELV_FAIR_QUEUING default n ---help---
Signature · 1 line
1.6.0.6
PATCH 11/24 io-controller: Debug hierarchical IO scheduling
In reply to a message not in the archiveo Littile debugging aid for hierarchical IO scheduling.
o Enabled under CONFIG_DEBUG_GROUP_IOSCHED
o Currently it outputs more debug messages in blktrace output which helps a great deal in debugging in hierarchical setup. It also creates additional cgroup interfaces io.disk_queue and io.disk_dequeue to output some more debugging data.
--- block/Kconfig.iosched | 8 ++ block/elevator-fq.c | 300 ++++++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 38 ++++++- 3 files changed, 339 insertions(+), 7 deletions(-)
block/Kconfig.iosched +8 -0
@@ -90,6 +90,14 @@ config DEFAULT_IOSCHED default "cfq" if DEFAULT_CFQ default "noop" if DEFAULT_NOOP +config DEBUG_GROUP_IOSCHED + bool "Debug Hierarchical Scheduling support" + depends on CGROUPS && GROUP_IOSCHED + default n + ---help--- + Enable some debugging hooks for hierarchical scheduling support. + Currently it just outputs more information in blktrace output. + endmenu endif
block/elevator-fq.c +294 -6
427 lines not on this page · raw message
block/elevator-fq.h +37 -1
@@ -75,6 +75,7 @@ struct io_service_tree {struct io_sched_data {struct io_entity *active_entity;struct io_entity *next_active; +int nr_active;struct io_service_tree service_tree[IO_IOPRIO_CLASSES ]; };
@@ -243,6 +244,23 @@ struct io_group {/* The device MKDEV(major, minor), this group has been created for */ dev_t dev; + +#ifdef CONFIG_DEBUG_GROUP_IOSCHED +/* How many times this group has been added to active tree */ +unsigned long queue; + +/* How long this group remained on active tree, in ms */ +unsigned long queue_duration; + +/* When was this group added to active tree */ +unsigned long queue_start; + +/* How many times this group has been removed from active tree */ +unsigned long dequeue; + +/* Store cgroup path */ +char path[128 ]; +#endif };/**
@@ -303,10 +321,29 @@ struct elv_fq_data { };/* Logging facilities. */ +#ifdef CONFIG_DEBUG_GROUP_IOSCHED +#define elv_log_ioq(efqd, ioq, fmt, args...) \ +{ \ + blk_add_trace_msg((efqd)->queue, "elv%d%c %s " fmt, (ioq)->pid, \ + elv_ioq_sync(ioq) ? 'S' : 'A', \ + ioq_to_io_group(ioq)->path, ##args); \ +} + +#define elv_log_iog(efqd, iog, fmt, args...) \ +{ \ + blk_add_trace_msg((efqd)->queue, "elv %s " fmt, (iog)->path, ##args); \ +} + +#else #define elv_log_ioq(efqd, ioq, fmt, args...) \ blk_add_trace_msg((efqd)->queue, "elv%d%c " fmt, (ioq)->pid, \ elv_ioq_sync(ioq) ? 'S' : 'A', ##args) +#define elv_log_iog(efqd, iog, fmt, args...) \ + blk_add_trace_msg((efqd)->queue, "elv " fmt, ##args) + +#endif + #define elv_log(efqd, fmt, args...) \ blk_add_trace_msg((efqd)->queue, "elv " fmt, ##args)
@@ -443,7 +480,6 @@ static inline struct io_group *ioq_to_io_group(struct io_queue *ioq)#ifdef CONFIG_GROUP_IOSCHED extern int io_group_allow_merge (struct request *rq,struct bio *bio);extern void elv_put_iog (struct io_group *iog); -static inline void elv_get_iog (struct io_group *iog) {atomic_inc (&iog->ref);
Signature · 1 line
1.6.0.6
PATCH 12/24 io-controller: Introduce group idling
In reply to a message not in the archiveo It is not always that IO from a process or group is continuous. There are cases of dependent reads where next read is not issued till previous read has finished. For such cases, CFQ introduced the notion of slice_idle, where we idle on the queue for sometime hoping next request will come and that's how fairness is provided otherwise queue will be deleted immediately from the service tree and this process will not get the fair share.
o This patch introduces the similar concept at group level. Idle on the group for a period of "group_idle" which is tunable through sysfs interface. So if a group is empty and about to be deleted, we idle for the next request.
o This patch also introduces the notion of wait busy where we wait for one extra group_idle period even if queue has consumed its time slice. The reason being that group will loose its share upon removal from service tree as some other entity will be picked for dispatch and vtime jump will take place.
--- block/cfq-iosched.c | 3 + block/elevator-fq.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++--- block/elevator-fq.h | 42 ++++++++++++ 3 files changed, 213 insertions(+), 9 deletions(-)
block/cfq-iosched.c +3 -0
@@ -2124,6 +2124,9 @@ static struct elv_fs_entry cfq_attrs[] = {CFQ_ATTR (slice_idle),ELV_ATTR (slice_sync),ELV_ATTR (slice_async), +#ifdef CONFIG_GROUP_IOSCHED +ELV_ATTR (group_idle), +#endif __ATTR_NULL };
block/elevator-fq.c +168 -9
316 lines not on this page · raw message
block/elevator-fq.h +42 -0
66 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 13/24 io-controller: Wait for requests to complete from last queue before new queue is scheduled
In reply to a message not in the archiveo Currently one can dispatch requests from multiple queues to the disk. This is true for hardware which supports queuing. So if a disk support queue depth of 31 it is possible that 20 requests are dispatched from queue 1 and then next queue is scheduled in which dispatches more requests.
o This multiple queue dispatch introduces issues for accurate accounting of disk time consumed by a particular queue. For example, if one async queue is scheduled in, it can dispatch 31 requests to the disk and then it will be expired and a new sync queue might get scheduled in. These 31 requests might take a long time to finish but this time is never accounted to the async queue which dispatched these requests.
o This patch introduces the functionality where we wait for all the requests to finish from previous queue before next queue is scheduled in. That way a queue is more accurately accounted for disk time it has consumed. Note this still does not take care of errors introduced by disk write caching.
o Because above behavior can result in reduced throughput, this behavior will be enabled only if user sets "fairness" tunable to 1.
o This patch helps in achieving more isolation between reads and buffered writes in different cgroups. buffered writes typically utilize full queue depth and then expire the queue. On the contarary, sequential reads typicaly driver queue depth of 1. So despite the fact that writes are using more disk time it is never accounted to write queue because we don't wait for requests to finish after dispatching these. This patch helps do more accurate accounting of disk time, especially for buffered writes hence providing better fairness hence better isolation between two cgroups running read and write workloads.
--- block/cfq-iosched.c | 1 + block/elevator-fq.c | 33 +++++++++++++++++++++++++++++++++ block/elevator-fq.h | 10 +++++++++- 3 files changed, 43 insertions(+), 1 deletions(-)
block/cfq-iosched.c +1 -0
@@ -2126,6 +2126,7 @@ static struct elv_fs_entry cfq_attrs[] = { ELV_ATTR(slice_async),#ifdef CONFIG_GROUP_IOSCHED ELV_ATTR (group_idle), +ELV_ATTR (fairness), #endif __ATTR_NULL };
block/elevator-fq.c +33 -0
@@ -2224,6 +2224,8 @@ SHOW_FUNCTION(elv_slice_sync_show, efqd->elv_slice[1], 1);EXPORT_SYMBOL (elv_slice_sync_show);SHOW_FUNCTION (elv_slice_async_show, efqd->elv_slice[0 ],1 );EXPORT_SYMBOL (elv_slice_async_show); +SHOW_FUNCTION (elv_fairness_show, efqd->fairness,0 ); +EXPORT_SYMBOL (elv_fairness_show);#undef SHOW_FUNCTION#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) \
@@ -2248,6 +2250,8 @@ STORE_FUNCTION(elv_slice_sync_store, &efqd->elv_slice[1], 1, UINT_MAX, 1);EXPORT_SYMBOL (elv_slice_sync_store);STORE_FUNCTION (elv_slice_async_store, &efqd->elv_slice[0 ],1 ,UINT_MAX ,1 );EXPORT_SYMBOL (elv_slice_async_store); +STORE_FUNCTION (elv_fairness_store, &efqd->fairness,0 ,1 ,0 ); +EXPORT_SYMBOL (elv_fairness_store);#undef STORE_FUNCTIONvoid elv_schedule_dispatch (struct request_queue *q)
@@ -3093,6 +3097,24 @@ void *elv_fq_select_ioq(struct request_queue *q, int force) } expire: +if (efqd->fairness && !force && ioq && ioq->dispatched) { +/* +* If there are request dispatched from this queue, don't +* dispatch requests from new queue till all the requests from +* this queue have completed. +* +* This helps in attributing right amount of disk time consumed +* by a particular queue when hardware allows queuing. +* +* Set ioq = NULL so that no more requests are dispatched from +* this queue. +*/ +elv_log_ioq (efqd, ioq,"select: wait for requests to finish" +" disp=%lu" , ioq->dispatched); + ioq =NULL ; + goto keep_queue; + } +elv_ioq_slice_expired (q); new_queue: ioq =elv_set_active_ioq (q, new_ioq);
@@ -3216,6 +3238,17 @@ void elv_ioq_completed_request(struct request_queue *q, struct request *rq) goto done; } +/* If fairness is set and there are requests +* dispatched from this queue, don't dispatch +* new requests from a different queue till +* all requests from this queue have finished. +* This helps in attributing right disk time +* to a queue when hardware supports queuing. +*/ + +if (efqd->fairness && ioq->dispatched) + goto done; +/* Expire the queue */ elv_ioq_slice_expired (q); } else if (!ioq->nr_queued && !elv_close_cooperator(q, ioq)
block/elevator-fq.h +9 -1
@@ -321,6 +321,12 @@ struct elv_fq_data {* Fallback dummy ioq for extreme OOM conditions */ struct io_queue oom_ioq; + +/* +* If set to 1, waits for all request completions from current +* queue before new queue is scheduled in +*/ +unsigned int fairness; };/* Logging facilities. */
@@ -564,7 +570,9 @@ extern ssize_t elv_slice_sync_store(struct elevator_queue *q, const char *name,extern ssize_t elv_slice_async_show (struct elevator_queue *q,char *name);extern ssize_t elv_slice_async_store (struct elevator_queue *q,const char *name,size_t count); - +extern ssize_t elv_fairness_show (struct elevator_queue *q,char *name); +extern ssize_t elv_fairness_store (struct elevator_queue *q,const char *name, +size_t count);/* Functions used by elevator.c */ extern int elv_init_fq_data (struct request_queue *q,struct elevator_queue *e);extern void elv_exit_fq_data (struct elevator_queue *e);
Signature · 1 line
1.6.0.6
PATCH 14/24 io-controller: Separate out queue and data
In reply to a message not in the archiveo So far noop, deadline and AS had one common structure called *_data which contained both the queue information where requests are queued and also common data used for scheduling. This patch breaks down this common structure in two parts, *_queue and *_data. This is along the lines of cfq where all the reuquests are queued in queue and common data and tunables are part of data.
o It does not change the functionality but this re-organization helps once noop, deadline and AS are changed to use hierarchical fair queuing.
o looks like queue_empty function is not required and we can check for q->nr_sorted in elevator layer to see if ioscheduler queues are empty or not.
--- block/as-iosched.c | 208 ++++++++++++++++++++++++++-------------------- block/deadline-iosched.c | 117 ++++++++++++++++---------- block/elevator.c | 111 +++++++++++++++++++++---- block/noop-iosched.c | 59 ++++++------- include/linux/elevator.h | 9 ++- 5 files changed, 320 insertions(+), 184 deletions(-)
block/as-iosched.c +118 -90
@@ -76,13 +76,7 @@ enum anticipation_status {* or timed out */ }; -struct as_data { -/* -* run time data -*/ - -struct request_queue *q;/* the "owner" queue */ - +struct as_queue {/* * requests (as_rq s) are present on both sort_list and fifo_list */
@@ -90,6 +84,14 @@ struct as_data {struct list_head fifo_list[2 ];struct request *next_rq[2 ];/* next in sort order */ +unsigned long last_check_fifo[2 ]; +int write_batch_count;/* max # of reqs in a write batch */ +int current_write_count;/* how many requests left this batch */ +int write_batch_idled;/* has the write batch gone idle? */ +}; + +struct as_data { +struct request_queue *q;/* the "owner" queue */ sector_t last_sector[2 ];/* last SYNC & ASYNC sectors */ unsigned long exit_prob;/* probability a task will exit while
@@ -103,21 +105,17 @@ struct as_data {sector_t new_seek_mean;unsigned long current_batch_expires; -unsigned long last_check_fifo[2 ];int changed_batch;/* 1: waiting for old batch to end */ int new_batch;/* 1: waiting on first read complete */ -int batch_data_dir;/* current batch SYNC / ASYNC */ -int write_batch_count;/* max # of reqs in a write batch */ -int current_write_count;/* how many requests left this batch */ -int write_batch_idled;/* has the write batch gone idle? */ enum anticipation_status antic_status;unsigned long antic_start;/* jiffies: when it started */ struct timer_list antic_timer;/* anticipatory scheduling timer */ -struct work_struct antic_work;/* Deferred unplugging */ +struct work_struct antic_work;/* Deferred unplugging */ struct io_context *io_context;/* Identify the expected process */ int ioc_finished;/* IO associated with io_context is finished */ int nr_dispatched; +int batch_data_dir;/* current batch SYNC / ASYNC */ /* * settings that change how the i/o scheduler behaves
@@ -258,13 +256,14 @@ static void as_put_io_context(struct request *rq)/* * rb tree support functions */ -#define RQ_RB_ROOT (ad, rq) (&(ad)->sort_list[rq_is_sync((rq))]) +#define RQ_RB_ROOT (asq, rq) (&(asq)->sort_list[rq_is_sync((rq))])static void as_add_rq_rb (struct as_data *ad,struct request *rq) {struct request *alias; +struct as_queue *asq =elv_get_sched_queue (ad->q, rq); -while ((unlikely (alias =elv_rb_add (RQ_RB_ROOT (ad, rq), rq)))) { +while ((unlikely (alias =elv_rb_add (RQ_RB_ROOT (asq, rq), rq)))) {as_move_to_dispatch (ad, alias);as_antic_stop (ad); }
@@ -272,7 +271,9 @@ static void as_add_rq_rb(struct as_data *ad, struct request *rq)static inline void as_del_rq_rb (struct as_data *ad,struct request *rq) { -elv_rb_del (RQ_RB_ROOT (ad, rq), rq); +struct as_queue *asq =elv_get_sched_queue (ad->q, rq); + +elv_rb_del (RQ_RB_ROOT (asq, rq), rq); }/*
@@ -366,7 +367,7 @@ as_choose_req(struct as_data *ad, struct request *rq1, struct request *rq2)* what request to process next. Anticipation works on top of this. */ static struct request * -as_find_next_rq (struct as_data *ad,struct request *last) +as_find_next_rq (struct as_data *ad,struct as_queue *asq,struct request *last) {struct rb_node *rbnext =rb_next (&last->rb_node);struct rb_node *rbprev =rb_prev (&last->rb_node);
@@ -382,7 +383,7 @@ as_find_next_rq(struct as_data *ad, struct request *last)else {const int data_dir =rq_is_sync (last); - rbnext =rb_first (&ad->sort_list[data_dir]); + rbnext =rb_first (&asq->sort_list[data_dir]);if (rbnext && rbnext != &last->rb_node) next =rb_entry_rq (rbnext); }
@@ -789,9 +790,10 @@ static int as_can_anticipate(struct as_data *ad, struct request *rq)static void as_update_rq (struct as_data *ad,struct request *rq) {const int data_dir =rq_is_sync (rq); +struct as_queue *asq =elv_get_sched_queue (ad->q, rq);/* keep the next_rq cache up to date */ - ad->next_rq[data_dir] =as_choose_req (ad, rq, ad->next_rq[data_dir]); + asq->next_rq[data_dir] =as_choose_req (ad, rq, asq->next_rq[data_dir]);/* * have we been anticipating this request?
@@ -812,25 +814,26 @@ static void update_write_batch(struct as_data *ad) {unsigned long batch = ad->batch_expire[BLK_RW_ASYNC ];long write_time; +struct as_queue *asq =elv_get_sched_queue (ad->q,NULL ); write_time = (jiffies - ad->current_batch_expires) + batch;if (write_time <0 ) write_time =0 ; -if (write_time > batch && !ad->write_batch_idled) { +if (write_time > batch && !asq->write_batch_idled) {if (write_time > batch *3 ) - ad->write_batch_count /=2 ; + asq->write_batch_count /=2 ;else - ad->write_batch_count--; - }else if (write_time < batch && ad->current_write_count ==0 ) { + asq->write_batch_count--; + }else if (write_time < batch && asq->current_write_count ==0 ) {if (batch > write_time *3 ) - ad->write_batch_count *=2 ; + asq->write_batch_count *=2 ;else - ad->write_batch_count++; + asq->write_batch_count++; } -if (ad->write_batch_count <1 ) - ad->write_batch_count =1 ; +if (asq->write_batch_count <1 ) + asq->write_batch_count =1 ; }/*
@@ -901,6 +904,7 @@ static void as_remove_queued_request(struct request_queue *q,const int data_dir =rq_is_sync (rq);struct as_data *ad = q->elevator->elevator_data;struct io_context *ioc; +struct as_queue *asq =elv_get_sched_queue (q, rq);WARN_ON (RQ_STATE (rq) !=AS_RQ_QUEUED );
@@ -914,8 +918,8 @@ static void as_remove_queued_request(struct request_queue *q,* Update the "next_rq" cache if we are about to remove its * entry */ -if (ad->next_rq[data_dir] == rq) - ad->next_rq[data_dir] =as_find_next_rq (ad, rq); +if (asq->next_rq[data_dir] == rq) + asq->next_rq[data_dir] =as_find_next_rq (ad, asq, rq);rq_fifo_clear (rq);as_del_rq_rb (ad, rq);
@@ -929,23 +933,23 @@ static void as_remove_queued_request(struct request_queue *q,* * See as_antic_expired comment. */ -static int as_fifo_expired (struct as_data *ad,int adir) +static int as_fifo_expired (struct as_data *ad,struct as_queue *asq,int adir) {struct request *rq;long delta_jif; - delta_jif = jiffies - ad->last_check_fifo[adir]; + delta_jif = jiffies - asq->last_check_fifo[adir];if (unlikely (delta_jif <0 )) delta_jif = -delta_jif;if (delta_jif < ad->fifo_expire[adir])return 0 ; - ad->last_check_fifo[adir] = jiffies; + asq->last_check_fifo[adir] = jiffies; -if (list_empty (&ad->fifo_list[adir])) +if (list_empty (&asq->fifo_list[adir]))return 0 ; - rq =rq_entry_fifo (ad->fifo_list[adir].next); + rq =rq_entry_fifo (asq->fifo_list[adir].next);return time_after (jiffies,rq_fifo_time (rq)); }
@@ -954,7 +958,7 @@ static int as_fifo_expired(struct as_data *ad, int adir)* as_batch_expired returns true if the current batch has expired. A batch * is a set of reads or a set of writes. */ -static inline int as_batch_expired (struct as_data *ad) +static inline int as_batch_expired (struct as_data *ad,struct as_queue *asq) {if (ad->changed_batch || ad->new_batch)return 0 ;
@@ -964,7 +968,7 @@ static inline int as_batch_expired(struct as_data *ad)return time_after (jiffies, ad->current_batch_expires);return time_after (jiffies, ad->current_batch_expires) - || ad->current_write_count ==0 ; + || asq->current_write_count ==0 ; }/*
@@ -973,6 +977,7 @@ static inline int as_batch_expired(struct as_data *ad)static void as_move_to_dispatch (struct as_data *ad,struct request *rq) {const int data_dir =rq_is_sync (rq); +struct as_queue *asq =elv_get_sched_queue (ad->q, rq);BUG_ON (RB_EMPTY_NODE (&rq->rb_node));
@@ -995,12 +1000,12 @@ static void as_move_to_dispatch(struct as_data *ad, struct request *rq) ad->io_context =NULL ; } -if (ad->current_write_count !=0 ) - ad->current_write_count--; +if (asq->current_write_count !=0 ) + asq->current_write_count--; } ad->ioc_finished =0 ; - ad->next_rq[data_dir] =as_find_next_rq (ad, rq); + asq->next_rq[data_dir] =as_find_next_rq (ad, asq, rq);/* * take it off the sort and fifo list, add to dispatch queue
@@ -1024,9 +1029,16 @@ static void as_move_to_dispatch(struct as_data *ad, struct request *rq)static int as_dispatch_request (struct request_queue *q,int force) {struct as_data *ad = q->elevator->elevator_data; -const int reads = !list_empty (&ad->fifo_list[BLK_RW_SYNC ]); -const int writes = !list_empty (&ad->fifo_list[BLK_RW_ASYNC ]);struct request *rq; +struct as_queue *asq =elv_select_sched_queue (q, force); +int reads, writes; + +if (!asq) +return 0 ; + + reads = !list_empty (&asq->fifo_list[BLK_RW_SYNC ]); + writes = !list_empty (&asq->fifo_list[BLK_RW_ASYNC ]); +if (unlikely (force)) {/*
@@ -1042,25 +1054,25 @@ static int as_dispatch_request(struct request_queue *q, int force) ad->changed_batch =0 ; ad->new_batch =0 ; -while (ad->next_rq[BLK_RW_SYNC ]) { -as_move_to_dispatch (ad, ad->next_rq[BLK_RW_SYNC ]); +while (asq->next_rq[BLK_RW_SYNC ]) { +as_move_to_dispatch (ad, asq->next_rq[BLK_RW_SYNC ]); dispatched++; } - ad->last_check_fifo[BLK_RW_SYNC ] = jiffies; + asq->last_check_fifo[BLK_RW_SYNC ] = jiffies; -while (ad->next_rq[BLK_RW_ASYNC ]) { -as_move_to_dispatch (ad, ad->next_rq[BLK_RW_ASYNC ]); +while (asq->next_rq[BLK_RW_ASYNC ]) { +as_move_to_dispatch (ad, asq->next_rq[BLK_RW_ASYNC ]); dispatched++; } - ad->last_check_fifo[BLK_RW_ASYNC ] = jiffies; + asq->last_check_fifo[BLK_RW_ASYNC ] = jiffies;return dispatched; }/* Signal that the write batch was uncontended, so we can't time it */ if (ad->batch_data_dir ==BLK_RW_ASYNC && !reads) { -if (ad->current_write_count ==0 || !writes) - ad->write_batch_idled =1 ; +if (asq->current_write_count ==0 || !writes) + asq->write_batch_idled =1 ; } if (!(reads || writes)
@@ -1069,14 +1081,14 @@ static int as_dispatch_request(struct request_queue *q, int force) || ad->changed_batch)return 0 ; -if (!(reads && writes &&as_batch_expired (ad))) { +if (!(reads && writes &&as_batch_expired (ad, asq))) {/* * batch is still running or no reads or no writes */ - rq = ad->next_rq[ad->batch_data_dir]; + rq = asq->next_rq[ad->batch_data_dir];if (ad->batch_data_dir ==BLK_RW_SYNC && ad->antic_expire) { -if (as_fifo_expired (ad,BLK_RW_SYNC )) +if (as_fifo_expired (ad, asq,BLK_RW_SYNC )) goto fifo_expired;if (as_can_anticipate (ad, rq)) {
@@ -1100,7 +1112,7 @@ static int as_dispatch_request(struct request_queue *q, int force)*/ if (reads) { -BUG_ON (RB_EMPTY_ROOT (&ad->sort_list[BLK_RW_SYNC ])); +BUG_ON (RB_EMPTY_ROOT (&asq->sort_list[BLK_RW_SYNC ]));if (writes && ad->batch_data_dir ==BLK_RW_SYNC )/*
@@ -1113,8 +1125,8 @@ static int as_dispatch_request(struct request_queue *q, int force) ad->changed_batch =1 ; } ad->batch_data_dir =BLK_RW_SYNC ; - rq =rq_entry_fifo (ad->fifo_list[BLK_RW_SYNC ].next); - ad->last_check_fifo[ad->batch_data_dir] = jiffies; + rq =rq_entry_fifo (asq->fifo_list[BLK_RW_SYNC ].next); + asq->last_check_fifo[ad->batch_data_dir] = jiffies; goto dispatch_request; }
@@ -1124,7 +1136,7 @@ static int as_dispatch_request(struct request_queue *q, int force)if (writes) { dispatch_writes: -BUG_ON (RB_EMPTY_ROOT (&ad->sort_list[BLK_RW_ASYNC ])); +BUG_ON (RB_EMPTY_ROOT (&asq->sort_list[BLK_RW_ASYNC ]));if (ad->batch_data_dir ==BLK_RW_SYNC ) { ad->changed_batch =1 ;
@@ -1137,10 +1149,10 @@ dispatch_writes: ad->new_batch =0 ; } ad->batch_data_dir =BLK_RW_ASYNC ; - ad->current_write_count = ad->write_batch_count; - ad->write_batch_idled =0 ; - rq =rq_entry_fifo (ad->fifo_list[BLK_RW_ASYNC ].next); - ad->last_check_fifo[BLK_RW_ASYNC ] = jiffies; + asq->current_write_count = asq->write_batch_count; + asq->write_batch_idled =0 ; + rq =rq_entry_fifo (asq->fifo_list[BLK_RW_ASYNC ].next); + asq->last_check_fifo[BLK_RW_ASYNC ] = jiffies; goto dispatch_request; }
@@ -1152,9 +1164,9 @@ dispatch_request:* If a request has expired, service it. */ -if (as_fifo_expired (ad, ad->batch_data_dir)) { +if (as_fifo_expired (ad, asq, ad->batch_data_dir)) { fifo_expired: - rq =rq_entry_fifo (ad->fifo_list[ad->batch_data_dir].next); + rq =rq_entry_fifo (asq->fifo_list[ad->batch_data_dir].next); }if (ad->changed_batch) {
@@ -1187,6 +1199,7 @@ static void as_add_request(struct request_queue *q, struct request *rq) {struct as_data *ad = q->elevator->elevator_data;int data_dir; +struct as_queue *asq =elv_get_sched_queue (q, rq);RQ_SET_STATE (rq,AS_RQ_NEW );
@@ -1205,7 +1218,7 @@ static void as_add_request(struct request_queue *q, struct request *rq)* set expire time and add to fifo list */ rq_set_fifo_time (rq, jiffies + ad->fifo_expire[data_dir]); -list_add_tail (&rq->queuelist, &ad->fifo_list[data_dir]); +list_add_tail (&rq->queuelist, &asq->fifo_list[data_dir]);as_update_rq (ad, rq);/* keep state machine up to date */ RQ_SET_STATE (rq,AS_RQ_QUEUED );
@@ -1227,31 +1240,20 @@ static void as_deactivate_request(struct request_queue *q, struct request *rq)atomic_inc (&RQ_IOC (rq)->aic->nr_dispatched); } -/* -* as_queue_empty tells us if there are requests left in the device. It may -* not be the case that a driver can get the next request even if the queue -* is not empty - it is used in the block layer to check for plugging and -* merging opportunities -*/ -static int as_queue_empty (struct request_queue *q) -{ -struct as_data *ad = q->elevator->elevator_data; - -return list_empty (&ad->fifo_list[BLK_RW_ASYNC ]) - &&list_empty (&ad->fifo_list[BLK_RW_SYNC ]); -} -static int as_merge (struct request_queue *q,struct request **req,struct bio *bio) { -struct as_data *ad = q->elevator->elevator_data;sector_t rb_key = bio->bi_sector +bio_sectors (bio);struct request *__rq; +struct as_queue *asq =elv_get_sched_queue_current (q); + +if (!asq) +return ELEVATOR_NO_MERGE ;/* * check for front merge */ - __rq =elv_rb_find (&ad->sort_list[bio_data_dir (bio)], rb_key); + __rq =elv_rb_find (&asq->sort_list[bio_data_dir (bio)], rb_key);if (__rq &&elv_rq_merge_ok (__rq, bio)) { *req = __rq;return ELEVATOR_FRONT_MERGE ;
@@ -1334,6 +1336,41 @@ static int as_may_queue(struct request_queue *q, int rw)return ret; } +/* Called with queue lock held */ +static void *as_alloc_as_queue (struct request_queue *q, +struct elevator_queue *eq,gfp_t gfp_mask) +{ +struct as_queue *asq; +struct as_data *ad = eq->elevator_data; + + asq =kmalloc_node (sizeof (*asq), gfp_mask | __GFP_ZERO, q->node); +if (asq ==NULL ) + goto out; + +INIT_LIST_HEAD (&asq->fifo_list[BLK_RW_SYNC ]); +INIT_LIST_HEAD (&asq->fifo_list[BLK_RW_ASYNC ]); + asq->sort_list[BLK_RW_SYNC ] =RB_ROOT ; + asq->sort_list[BLK_RW_ASYNC ] =RB_ROOT ; +if (ad) + asq->write_batch_count = ad->batch_expire[BLK_RW_ASYNC ] /10 ; +else + asq->write_batch_count = default_write_batch_expire /10 ; + +if (asq->write_batch_count <2 ) + asq->write_batch_count =2 ; +out: +return asq; +} + +static void as_free_as_queue (struct elevator_queue *e,void *sched_queue) +{ +struct as_queue *asq = sched_queue; + +BUG_ON (!list_empty (&asq->fifo_list[BLK_RW_SYNC ])); +BUG_ON (!list_empty (&asq->fifo_list[BLK_RW_ASYNC ])); +kfree (asq); +} +static void as_exit_queue (struct elevator_queue *e) {struct as_data *ad = e->elevator_data;
@@ -1341,9 +1378,6 @@ static void as_exit_queue(struct elevator_queue *e)del_timer_sync (&ad->antic_timer);cancel_work_sync (&ad->antic_work); -BUG_ON (!list_empty (&ad->fifo_list[BLK_RW_SYNC ])); -BUG_ON (!list_empty (&ad->fifo_list[BLK_RW_ASYNC ])); -put_io_context (ad->io_context);kfree (ad); }
@@ -1367,10 +1401,6 @@ static void *as_init_queue(struct request_queue *q, struct elevator_queue *eq)init_timer (&ad->antic_timer);INIT_WORK (&ad->antic_work, as_work_handler); -INIT_LIST_HEAD (&ad->fifo_list[BLK_RW_SYNC ]); -INIT_LIST_HEAD (&ad->fifo_list[BLK_RW_ASYNC ]); - ad->sort_list[BLK_RW_SYNC ] =RB_ROOT ; - ad->sort_list[BLK_RW_ASYNC ] =RB_ROOT ; ad->fifo_expire[BLK_RW_SYNC ] = default_read_expire; ad->fifo_expire[BLK_RW_ASYNC ] = default_write_expire; ad->antic_expire = default_antic_expire;
@@ -1378,9 +1408,6 @@ static void *as_init_queue(struct request_queue *q, struct elevator_queue *eq) ad->batch_expire[BLK_RW_ASYNC ] = default_write_batch_expire; ad->current_batch_expires = jiffies + ad->batch_expire[BLK_RW_SYNC ]; - ad->write_batch_count = ad->batch_expire[BLK_RW_ASYNC ] /10 ; -if (ad->write_batch_count <2 ) - ad->write_batch_count =2 ;return ad; }
@@ -1478,7 +1505,6 @@ static struct elevator_type iosched_as = { .elevator_add_req_fn = as_add_request, .elevator_activate_req_fn = as_activate_request, .elevator_deactivate_req_fn = as_deactivate_request, - .elevator_queue_empty_fn = as_queue_empty, .elevator_completed_req_fn = as_completed_request, .elevator_former_req_fn = elv_rb_former_request, .elevator_latter_req_fn = elv_rb_latter_request,
@@ -1486,6 +1512,8 @@ static struct elevator_type iosched_as = { .elevator_init_fn = as_init_queue, .elevator_exit_fn = as_exit_queue, .trim = as_trim, + .elevator_alloc_sched_queue_fn = as_alloc_as_queue, + .elevator_free_sched_queue_fn = as_free_as_queue, }, .elevator_attrs = as_attrs,
block/deadline-iosched.c +71 -46
266 lines not on this page · raw message
block/elevator.c +96 -15
179 lines not on this page · raw message
block/noop-iosched.c +28 -31
111 lines not on this page · raw message
include/linux/elevator.h +7 -2
@@ -31,8 +31,10 @@ typedef void (elevator_deactivate_req_fn) (struct request_queue *, struct requestypedef void *(elevator_init_fn ) (struct request_queue *,struct elevator_queue *);typedef void (elevator_exit_fn ) (struct elevator_queue *); -#ifdef CONFIG_ELV_FAIR_QUEUING +typedef void * (elevator_alloc_sched_queue_fn ) (struct request_queue *q, +struct elevator_queue *eq,gfp_t );typedef void (elevator_free_sched_queue_fn ) (struct elevator_queue *,void *); +#ifdef CONFIG_ELV_FAIR_QUEUING typedef void (elevator_active_ioq_set_fn ) (struct request_queue *,void *,int );typedef void (elevator_active_ioq_reset_fn ) (struct request_queue *,void *);typedef void (elevator_arm_slice_timer_fn ) (struct request_queue *,void *);
@@ -69,8 +71,9 @@ struct elevator_opselevator_exit_fn *elevator_exit_fn;void (*trim)(struct io_context *); -#ifdef CONFIG_ELV_FAIR_QUEUING +elevator_alloc_sched_queue_fn *elevator_alloc_sched_queue_fn;elevator_free_sched_queue_fn *elevator_free_sched_queue_fn; +#ifdef CONFIG_ELV_FAIR_QUEUING elevator_active_ioq_set_fn *elevator_active_ioq_set_fn;elevator_active_ioq_reset_fn *elevator_active_ioq_reset_fn;
@@ -110,6 +113,7 @@ struct elevator_queue {struct elevator_ops *ops;void *elevator_data; +void *sched_queue;struct kobject kobj;struct elevator_type *elevator_type;struct mutex sysfs_lock;
@@ -256,5 +260,6 @@ static inline int elv_iosched_fair_queuing_enabled(struct elevator_queue *e)#endif /* ELV_IOSCHED_FAIR_QUEUING */ extern void *elv_get_sched_queue (struct request_queue *q,struct request *rq);extern void *elv_select_sched_queue (struct request_queue *q,int force); +extern void *elv_get_sched_queue_current (struct request_queue *q);#endif /* CONFIG_BLOCK */ #endif
Signature · 1 line
1.6.0.6
PATCH 15/24 io-conroller: Prepare elevator layer for single queue schedulers
In reply to a message not in the archiveElevator layer now has support for hierarchical fair queuing. cfq has been migrated to make use of it and now it is time to do groundwork for noop, deadline and AS.
noop deadline and AS don't maintain separate queues for different processes. There is only one single queue. Effectively one can think that in hierarchical setup, there will be one queue per cgroup where requests from all the processes in the cgroup will be queued.
Generally io scheduler takes care of creating queues. Because there is only one queue here, we have modified common layer to take care of queue creation and some other functionality. This special casing helps in keeping the changes to noop, deadline and AS to the minimum.
--- block/as-iosched.c | 2 +- block/deadline-iosched.c | 2 +- block/elevator-fq.c | 208 +++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 54 ++++++++++++ block/elevator.c | 37 ++++++++- block/noop-iosched.c | 2 +- include/linux/elevator.h | 18 ++++- 7 files changed, 315 insertions(+), 8 deletions(-)
block/as-iosched.c +1 -1
@@ -1338,7 +1338,7 @@ static int as_may_queue(struct request_queue *q, int rw)/* Called with queue lock held */ static void *as_alloc_as_queue (struct request_queue *q, -struct elevator_queue *eq,gfp_t gfp_mask) +struct elevator_queue *eq,gfp_t gfp_mask,struct io_queue *ioq) {struct as_queue *asq;struct as_data *ad = eq->elevator_data;
block/deadline-iosched.c +1 -1
@@ -341,7 +341,7 @@ dispatch_request: }static void *deadline_alloc_deadline_queue (struct request_queue *q, -struct elevator_queue *eq,gfp_t gfp_mask) +struct elevator_queue *eq,gfp_t gfp_mask,struct io_queue *ioq) {struct deadline_queue *dq;
block/elevator-fq.c +207 -1
250 lines not on this page · raw message
block/elevator-fq.h +54 -0
77 lines not on this page · raw message
block/elevator.c +35 -2
@@ -219,9 +219,17 @@ elevator_alloc_sched_queue(struct request_queue *q, struct elevator_queue *eq) {void *sched_queue =NULL ; +/* +* If fair queuing is enabled, then queue allocation takes place +* during set_request() functions when request actually comes +* in. +*/ +if (elv_iosched_fair_queuing_enabled (eq)) +return NULL ; +if (eq->ops->elevator_alloc_sched_queue_fn) { sched_queue = eq->ops->elevator_alloc_sched_queue_fn (q, eq, -GFP_KERNEL ); +GFP_KERNEL ,NULL );if (!sched_queue)return ERR_PTR (-ENOMEM );
@@ -842,6 +850,13 @@ int elv_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask) {struct elevator_queue *e = q->elevator; +/* +* Optimization for noop, deadline and AS which maintain only single +* ioq per io group +*/ +if (elv_iosched_single_ioq (e)) +return elv_fq_set_request_ioq (q, rq, gfp_mask); +if (e->ops->elevator_set_req_fn)return e->ops->elevator_set_req_fn (q, rq, gfp_mask);
@@ -853,6 +868,15 @@ void elv_put_request(struct request_queue *q, struct request *rq) {struct elevator_queue *e = q->elevator; +/* +* Optimization for noop, deadline and AS which maintain only single +* ioq per io group +*/ +if (elv_iosched_single_ioq (e)) { +elv_fq_unset_request_ioq (q, rq); +return ; + } +if (e->ops->elevator_put_req_fn) e->ops->elevator_put_req_fn (rq); }
@@ -1237,9 +1261,18 @@ EXPORT_SYMBOL(elv_select_sched_queue);/* * Get the io scheduler queue pointer for current task. +* +* If fair queuing is enabled, determine the io group of task and retrieve +* the ioq pointer from that. This is used by only single queue ioschedulers +* for retrieving the queue associated with the group to decide whether the +* new bio can do a front merge or not. */ void *elv_get_sched_queue_current (struct request_queue *q) { -return q->elevator->sched_queue; +/* Fair queuing is not enabled. There is only one queue. */ +if (!elv_iosched_fair_queuing_enabled (q->elevator)) +return q->elevator->sched_queue; + +return ioq_sched_queue (elv_lookup_ioq_current (q)); }EXPORT_SYMBOL (elv_get_sched_queue_current);
block/noop-iosched.c +1 -1
@@ -62,7 +62,7 @@ noop_latter_request(struct request_queue *q, struct request *rq) }static void *noop_alloc_noop_queue (struct request_queue *q, -struct elevator_queue *eq,gfp_t gfp_mask) +struct elevator_queue *eq,gfp_t gfp_mask,struct io_queue *ioq) {struct noop_queue *nq;
include/linux/elevator.h +16 -2
@@ -31,9 +31,9 @@ typedef void (elevator_deactivate_req_fn) (struct request_queue *, struct requestypedef void *(elevator_init_fn ) (struct request_queue *,struct elevator_queue *);typedef void (elevator_exit_fn ) (struct elevator_queue *); -typedef void * (elevator_alloc_sched_queue_fn ) (struct request_queue *q, -struct elevator_queue *eq,gfp_t );typedef void (elevator_free_sched_queue_fn ) (struct elevator_queue *,void *); +typedef void * (elevator_alloc_sched_queue_fn ) (struct request_queue *q, +struct elevator_queue *eq,gfp_t ,struct io_queue *ioq);#ifdef CONFIG_ELV_FAIR_QUEUING typedef void (elevator_active_ioq_set_fn ) (struct request_queue *,void *,int );typedef void (elevator_active_ioq_reset_fn ) (struct request_queue *,void *);
@@ -246,17 +246,31 @@ enum {/* iosched wants to use fair queuing logic of elevator layer */ #define ELV_IOSCHED_NEED_FQ 1 +/* iosched maintains only single ioq per group.*/ +#define ELV_IOSCHED_SINGLE_IOQ 2 +static inline int elv_iosched_fair_queuing_enabled (struct elevator_queue *e) {return (e->elevator_type->elevator_features) &ELV_IOSCHED_NEED_FQ ; } +static inline int elv_iosched_single_ioq (struct elevator_queue *e) +{ +return (e->elevator_type->elevator_features) &ELV_IOSCHED_SINGLE_IOQ ; +} +#else /* ELV_IOSCHED_FAIR_QUEUING */ static inline int elv_iosched_fair_queuing_enabled (struct elevator_queue *e) {return 0 ; } + +static inline int elv_iosched_single_ioq (struct elevator_queue *e) +{ +return 0 ; +} +#endif /* ELV_IOSCHED_FAIR_QUEUING */ extern void *elv_get_sched_queue (struct request_queue *q,struct request *rq);extern void *elv_select_sched_queue (struct request_queue *q,int force);
Signature · 1 line
1.6.0.6
PATCH 16/24 io-controller: noop changes for hierarchical fair queuing
In reply to a message not in the archiveThis patch changes noop to use queue scheduling code from elevator layer. One can go back to old noop by deselecting CONFIG_IOSCHED_NOOP_HIER.
--- block/Kconfig.iosched | 11 +++++++++++ block/noop-iosched.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
block/Kconfig.iosched +11 -0
@@ -25,6 +25,17 @@ config IOSCHED_NOOP that do their own scheduling and require only minimal assistance from the kernel. +config IOSCHED_NOOP_HIER + bool "Noop Hierarchical Scheduling support" + depends on IOSCHED_NOOP && CGROUPS + select ELV_FAIR_QUEUING + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in noop. In this mode noop keeps + one IO queue per cgroup instead of a global queue. Elevator + fair queuing logic ensures fairness among various queues. + config IOSCHED_AS tristate "Anticipatory I/O scheduler" default y
block/noop-iosched.c +13 -0
@@ -82,6 +82,15 @@ static void noop_free_noop_queue(struct elevator_queue *e, void *sched_queue)kfree (nq); } +#ifdef CONFIG_IOSCHED_NOOP_HIER +static struct elv_fs_entry noop_attrs[] = { +ELV_ATTR (fairness), +ELV_ATTR (slice_sync), +ELV_ATTR (group_idle), + __ATTR_NULL +}; +#endif +static struct elevator_type elevator_noop = { .ops = { .elevator_merge_req_fn = noop_merged_requests,
@@ -92,6 +101,10 @@ static struct elevator_type elevator_noop = { .elevator_alloc_sched_queue_fn = noop_alloc_noop_queue, .elevator_free_sched_queue_fn = noop_free_noop_queue, }, +#ifdef CONFIG_IOSCHED_NOOP_HIER + .elevator_features = ELV_IOSCHED_NEED_FQ | ELV_IOSCHED_SINGLE_IOQ, + .elevator_attrs = noop_attrs, +#endif .elevator_name = "noop", .elevator_owner = THIS_MODULE, };
Signature · 1 line
1.6.0.6
PATCH 17/24 io-controller: deadline changes for hierarchical fair queuing
In reply to a message not in the archiveThis patch changes deadline to use queue scheduling code from elevator layer. One can go back to old deadline by selecting CONFIG_IOSCHED_DEADLINE_HIER.
--- block/Kconfig.iosched | 11 +++++++++++ block/deadline-iosched.c | 8 ++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
block/Kconfig.iosched +11 -0
@@ -55,6 +55,17 @@ config IOSCHED_DEADLINE a disk at any one time, its behaviour is almost identical to the anticipatory I/O scheduler and so is a good choice. +config IOSCHED_DEADLINE_HIER + bool "Deadline Hierarchical Scheduling support" + depends on IOSCHED_DEADLINE && CGROUPS + select ELV_FAIR_QUEUING + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in deadline. In this mode deadline keeps + one IO queue per cgroup instead of a global queue. Elevator + fair queuing logic ensures fairness among various queues. + config IOSCHED_CFQ tristate "CFQ I/O scheduler" select ELV_FAIR_QUEUING
block/deadline-iosched.c +8 -0
@@ -461,6 +461,11 @@ static struct elv_fs_entry deadline_attrs[] = {DD_ATTR (writes_starved),DD_ATTR (front_merges),DD_ATTR (fifo_batch), +#ifdef CONFIG_IOSCHED_DEADLINE_HIER +ELV_ATTR (fairness), +ELV_ATTR (slice_sync), +ELV_ATTR (group_idle), +#endif __ATTR_NULL };
@@ -478,6 +483,9 @@ static struct elevator_type iosched_deadline = { .elevator_alloc_sched_queue_fn = deadline_alloc_deadline_queue, .elevator_free_sched_queue_fn = deadline_free_deadline_queue, }, +#ifdef CONFIG_IOSCHED_DEADLINE_HIER + .elevator_features = ELV_IOSCHED_NEED_FQ | ELV_IOSCHED_SINGLE_IOQ, +#endif .elevator_attrs = deadline_attrs, .elevator_name = "deadline", .elevator_owner = THIS_MODULE,
Signature · 1 line
1.6.0.6
PATCH 18/24 io-controller: anticipatory changes for hierarchical fair queuing
In reply to a message not in the archiveThis patch changes anticipatory scheduler to use queue scheduling code from elevator layer. One can go back to old as by deselecting CONFIG_IOSCHED_AS_HIER. Even with CONFIG_IOSCHED_AS_HIER=y, with-out any other cgroup created, AS behavior should remain the same as old.
o AS is a single queue ioschduler, that means there is one AS queue per group.
o common layer code select the queue to dispatch from based on fairness, and then AS code selects the request with-in group.
o AS runs reads and writes batches with-in group. So common layer runs timed group queues and with-in group time, AS runs timed batches of reads and writes.
o Note: Previously AS write batch length was adjusted synamically whenever a W->R batch data direction took place and when first request from the read batch completed.
Now write batch updation takes place when last request from the write batch has finished during W->R transition.
o AS runs its own anticipation logic to anticipate on reads. common layer also does the anticipation on the group if think time of the group is with-in slice_idle.
o Introduced few debugging messages in AS.
--- block/Kconfig.iosched | 12 ++ block/as-iosched.c | 294 +++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.c | 93 +++++++++++++-- block/elevator-fq.h | 3 + include/linux/elevator.h | 2 + 5 files changed, 386 insertions(+), 18 deletions(-)
block/Kconfig.iosched +12 -0
@@ -45,6 +45,18 @@ config IOSCHED_AS deadline I/O scheduler, it can also be slower in some cases especially some database loads. +config IOSCHED_AS_HIER + bool "Anticipatory Hierarchical Scheduling support" + depends on IOSCHED_AS && CGROUPS + select ELV_FAIR_QUEUING + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in anticipatory. In this mode + anticipatory keeps one IO queue per cgroup instead of a global + queue. Elevator fair queuing logic ensures fairness among various + queues. + config IOSCHED_DEADLINE tristate "Deadline I/O scheduler" default y
block/as-iosched.c +288 -6
496 lines not on this page · raw message
block/elevator-fq.c +81 -12
162 lines not on this page · raw message
block/elevator-fq.h +3 -0
@@ -370,6 +370,8 @@ enum elv_queue_state_flags { ELV_QUEUE_FLAG_wait_request,/* waiting for a request */ ELV_QUEUE_FLAG_must_dispatch,/* must be allowed a dispatch */ ELV_QUEUE_FLAG_slice_new,/* no requests dispatched in slice */ + ELV_QUEUE_FLAG_must_expire, /* Expire this queue even if it has + * request and time slice left */ };#define ELV_IO_QUEUE_FLAG_FNS (name) \
@@ -392,6 +394,7 @@ ELV_IO_QUEUE_FLAG_FNS(wait_request) ELV_IO_QUEUE_FLAG_FNS(must_dispatch) ELV_IO_QUEUE_FLAG_FNS(idle_window) ELV_IO_QUEUE_FLAG_FNS(slice_new) +ELV_IO_QUEUE_FLAG_FNS(must_expire)#ifdef CONFIG_GROUP_IOSCHED
include/linux/elevator.h +2 -0
@@ -42,6 +42,7 @@ typedef int (elevator_should_preempt_fn) (struct request_queue*, void*, struct request*);typedef struct io_queue * (elevator_close_cooperator_fn ) (struct request_queue *,void *); +typedef int (elevator_expire_ioq_fn ) (struct request_queue *,void *,int ,int );#endif struct elevator_ops
@@ -80,6 +81,7 @@ struct elevator_opselevator_arm_slice_timer_fn *elevator_arm_slice_timer_fn;elevator_should_preempt_fn *elevator_should_preempt_fn;elevator_close_cooperator_fn *elevator_close_cooperator_fn; +elevator_expire_ioq_fn *elevator_expire_ioq_fn;#endif };
Signature · 1 line
1.6.0.6
PATCH 19/24 blkio_cgroup patches from Ryo to track async bios.
In reply to a message not in the archiveo blkio_cgroup patches from Ryo to track async bios.
o Fernando is also working on another IO tracking mechanism. We are not particular about any IO tracking mechanism. This patchset can make use of any mechanism which makes it to upstream. For the time being making use of Ryo's posting.
Based on 2.6.30-rc3-git3
--- block/blk-ioc.c | 36 +++-- fs/buffer.c | 2 + fs/direct-io.c | 2 + include/linux/biotrack.h | 103 +++++++++++++ include/linux/cgroup_subsys.h | 6 + include/linux/iocontext.h | 1 + include/linux/memcontrol.h | 6 + include/linux/mmzone.h | 4 +- include/linux/page_cgroup.h | 31 ++++- init/Kconfig | 15 ++ mm/Makefile | 4 +- mm/biotrack.c | 321 +++++++++++++++++++++++++++++++++++++++++ mm/bounce.c | 2 + mm/filemap.c | 2 + mm/memcontrol.c | 6 + mm/memory.c | 5 + mm/page-writeback.c | 2 + mm/page_cgroup.c | 17 ++- mm/swap_state.c | 2 + 19 files changed, 537 insertions(+), 30 deletions(-) create mode 100644 include/linux/biotrack.h create mode 100644 mm/biotrack.c
block/blk-ioc.c +20 -16
@@ -84,27 +84,31 @@ void exit_io_context(void) } } +void init_io_context (struct io_context *ioc) +{ +atomic_long_set (&ioc->refcount,1 ); +atomic_set (&ioc->nr_tasks,1 ); +spin_lock_init (&ioc->lock); + ioc->ioprio_changed =0 ; + ioc->ioprio =0 ; +#ifdef CONFIG_GROUP_IOSCHED + ioc->cgroup_changed =0 ; +#endif + ioc->last_waited = jiffies;/* doesn't matter... */ + ioc->nr_batch_requests =0 ;/* because this is 0 */ + ioc->aic =NULL ; +INIT_RADIX_TREE (&ioc->radix_root,GFP_ATOMIC | __GFP_HIGH); +INIT_HLIST_HEAD (&ioc->cic_list); + ioc->ioc_data =NULL ; +} +struct io_context *alloc_io_context (gfp_t gfp_flags,int node) {struct io_context *ret; ret =kmem_cache_alloc_node (iocontext_cachep, gfp_flags, node); -if (ret) { -atomic_long_set (&ret->refcount,1 ); -atomic_set (&ret->nr_tasks,1 ); -spin_lock_init (&ret->lock); - ret->ioprio_changed =0 ; - ret->ioprio =0 ; -#ifdef CONFIG_GROUP_IOSCHED - ret->cgroup_changed =0 ; -#endif - ret->last_waited = jiffies;/* doesn't matter... */ - ret->nr_batch_requests =0 ;/* because this is 0 */ - ret->aic =NULL ; -INIT_RADIX_TREE (&ret->radix_root,GFP_ATOMIC | __GFP_HIGH); -INIT_HLIST_HEAD (&ret->cic_list); - ret->ioc_data =NULL ; - } +if (ret) +init_io_context (ret);return ret; }
fs/buffer.c +2 -0
@@ -36,6 +36,7 @@#include <linux/buffer_head.h> #include <linux/task_io_accounting_ops.h> #include <linux/bio.h> +#include <linux/biotrack.h> #include <linux/notifier.h> #include <linux/cpu.h> #include <linux/bitops.h>
@@ -668,6 +669,7 @@ static void __set_page_dirty(struct page *page,if (page->mapping) {/* Race with truncate? */ WARN_ON_ONCE (warn && !PageUptodate (page));account_page_dirtied (page, mapping); +blkio_cgroup_reset_owner_pagedirty (page, current->mm);radix_tree_tag_set (&mapping->page_tree,page_index (page),PAGECACHE_TAG_DIRTY ); }
fs/direct-io.c +2 -0
@@ -33,6 +33,7 @@#include <linux/err.h> #include <linux/blkdev.h> #include <linux/buffer_head.h> +#include <linux/biotrack.h> #include <linux/rwsem.h> #include <linux/uio.h> #include <asm/atomic.h>
@@ -797,6 +798,7 @@ static int do_direct_IO(struct dio *dio) ret =PTR_ERR (page); goto out; } +blkio_cgroup_reset_owner (page, current->mm);while (block_in_page < blocks_per_page) {unsigned offset_in_page = block_in_page << blkbits;
include/linux/biotrack.h new file +103 -0
103 lines not on this page · raw message
include/linux/cgroup_subsys.h +6 -0
@@ -43,6 +43,12 @@ SUBSYS(mem_cgroup)/* */ +#ifdef CONFIG_CGROUP_BLKIO +SUBSYS(blkio_cgroup) +#endif + +/* */ +#ifdef CONFIG_CGROUP_DEVICE SUBSYS(devices)#endif
include/linux/iocontext.h +1 -0
@@ -109,6 +109,7 @@ int put_io_context(struct io_context *ioc);void exit_io_context (void );struct io_context *get_io_context (gfp_t gfp_flags,int node);struct io_context *alloc_io_context (gfp_t gfp_flags,int node); +void init_io_context (struct io_context *ioc);void copy_io_context (struct io_context **pdst,struct io_context **psrc);#else static inline void exit_io_context (void )
include/linux/memcontrol.h +6 -0
@@ -37,6 +37,8 @@ struct mm_struct;* (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.) */ +extern void __init_mem_page_cgroup (struct page_cgroup *pc); +extern int mem_cgroup_newpage_charge (struct page *page,struct mm_struct *mm,gfp_t gfp_mask);/* for swap handling */
@@ -121,6 +123,10 @@ void mem_cgroup_update_mapped_file_stat(struct page *page, int val);#else /* CONFIG_CGROUP_MEM_RES_CTLR */ struct mem_cgroup ; +static inline void __init_mem_page_cgroup (struct page_cgroup *pc) +{ +} +static inline int mem_cgroup_newpage_charge (struct page *page,struct mm_struct *mm,gfp_t gfp_mask) {
include/linux/mmzone.h +2 -2
@@ -605,7 +605,7 @@ typedef struct pglist_data {int nr_zones;#ifdef CONFIG_FLAT_NODE_MEM_MAP /* means !SPARSEMEM */ struct page *node_mem_map; -#ifdef CONFIG_CGROUP_MEM_RES_CTLR +#ifdef CONFIG_CGROUP_PAGE struct page_cgroup *node_page_cgroup;#endif #endif
@@ -956,7 +956,7 @@ struct mem_section {/* See declaration of similar field in struct zone */ unsigned long *pageblock_flags; -#ifdef CONFIG_CGROUP_MEM_RES_CTLR +#ifdef CONFIG_CGROUP_PAGE /* * If !SPARSEMEM, pgdat doesn't have page_cgroup pointer. We use * section. (see memcontrol.h/page_cgroup.h about this.)
include/linux/page_cgroup.h +28 -3
@@ -1,7 +1,7 @@#ifndef __LINUX_PAGE_CGROUP_H#define __LINUX_PAGE_CGROUP_H -#ifdef CONFIG_CGROUP_MEM_RES_CTLR +#ifdef CONFIG_CGROUP_PAGE #include <linux/bit_spinlock.h> /* * Page Cgroup can be considered as an extended mem_map.
@@ -12,9 +12,11 @@*/ struct page_cgroup {unsigned long flags; -struct mem_cgroup *mem_cgroup;struct page *page; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR +struct mem_cgroup *mem_cgroup;struct list_head lru;/* per cgroup LRU list */ +#endif };void __meminit pgdat_page_cgroup_init (struct pglist_data *pgdat);
@@ -83,7 +85,7 @@ static inline void unlock_page_cgroup(struct page_cgroup *pc) bit_spin_unlock(PCG_LOCK, &pc->flags); } -#else /* CONFIG_CGROUP_MEM_RES_CTLR */ +#else /* CONFIG_CGROUP_PAGE */ struct page_cgroup ;static inline void __meminit pgdat_page_cgroup_init (struct pglist_data *pgdat)
@@ -138,4 +140,27 @@ static inline void swap_cgroup_swapoff(int type) }#endif + +#ifdef CONFIG_CGROUP_BLKIO +/* +* use lower 16 bits for flags and reserve the rest for the page tracking id +*/ +#define PCG_TRACKING_ID_SHIFT (16) +#define PCG_TRACKING_ID_BITS \ + (8 * sizeof(unsigned long) - PCG_TRACKING_ID_SHIFT) + +/* NOTE: must be called with page_cgroup() held */ +static inline unsigned long page_cgroup_get_id (struct page_cgroup *pc) +{ +return pc->flags >>PCG_TRACKING_ID_SHIFT ; +} + +/* NOTE: must be called with page_cgroup() held */ +static inline void page_cgroup_set_id (struct page_cgroup *pc,unsigned long id) +{ +WARN_ON (id >= (1UL <<PCG_TRACKING_ID_BITS )); + pc->flags &= (1UL <<PCG_TRACKING_ID_SHIFT ) -1 ; + pc->flags |= (unsigned long )(id <<PCG_TRACKING_ID_SHIFT ); +} +#endif #endif
init/Kconfig +15 -0
@@ -622,6 +622,21 @@ config GROUP_IOSCHED endif # CGROUPS +config CGROUP_BLKIO + bool "Block I/O cgroup subsystem" + depends on CGROUPS && BLOCK + select MM_OWNER + help + Provides a Resource Controller which enables to track the onwner + of every Block I/O requests. + The information this subsystem provides can be used from any + kind of module such as dm-ioband device mapper modules or + the cfq-scheduler. + +config CGROUP_PAGE + def_bool y + depends on CGROUP_MEM_RES_CTLR || CGROUP_BLKIO + config MM_OWNER bool
mm/Makefile +3 -1
@@ -39,6 +39,8 @@ else obj-$(CONFIG_SMP) += allocpercpu.o endif obj-$(CONFIG_QUICKLIST) += quicklist.o -obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o page_cgroup.o +obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o +obj-$(CONFIG_CGROUP_PAGE) += page_cgroup.o +obj-$(CONFIG_CGROUP_BLKIO) += biotrack.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
mm/biotrack.c new file +321 -0
321 lines not on this page · raw message
mm/bounce.c +2 -0
@@ -14,6 +14,7 @@#include <linux/hash.h> #include <linux/highmem.h> #include <asm/tlbflush.h> +#include <linux/biotrack.h> #include <trace/events/block.h>
@@ -210,6 +211,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, to->bv_len = from->bv_len; to->bv_offset = from->bv_offset;inc_zone_page_state (to->bv_page,NR_BOUNCE ); +blkio_cgroup_copy_owner (to->bv_page, page);if (rw ==WRITE ) {char *vto, *vfrom;
mm/filemap.c +2 -0
@@ -33,6 +33,7 @@#include <linux/cpuset.h> #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */ #include <linux/memcontrol.h> +#include <linux/biotrack.h> #include <linux/mm_inline.h> /* for page_is_file_cache() */ #include "internal.h"
@@ -464,6 +465,7 @@ int add_to_page_cache_locked(struct page *page, struct address_space *mapping, gfp_mask & GFP_RECLAIM_MASK);if (error) goto out; +blkio_cgroup_set_owner (page, current->mm); error =radix_tree_preload (gfp_mask & ~__GFP_HIGHMEM);if (error ==0 ) {
mm/memcontrol.c +6 -0
@@ -129,6 +129,12 @@ struct mem_cgroup_lru_info {struct mem_cgroup_per_node *nodeinfo[MAX_NUMNODES ]; }; +void __meminit __init_mem_page_cgroup (struct page_cgroup *pc) +{ + pc->mem_cgroup =NULL ; +INIT_LIST_HEAD (&pc->lru); +} +/* * The memory controller data structure. The memory controller controls both * page cache and RSS per cgroup. We would eventually like to provide
mm/memory.c +5 -0
@@ -51,6 +51,7 @@#include <linux/init.h> #include <linux/writeback.h> #include <linux/memcontrol.h> +#include <linux/biotrack.h> #include <linux/mmu_notifier.h> #include <linux/kallsyms.h> #include <linux/swapops.h>
@@ -2115,6 +2116,7 @@ gotten:*/ ptep_clear_flush_notify (vma, address, page_table);page_add_new_anon_rmap (new_page, vma, address); +blkio_cgroup_set_owner (new_page, mm);set_pte_at (mm, address, page_table, entry);update_mmu_cache (vma, address, entry);if (old_page) {
@@ -2580,6 +2582,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,flush_icache_page (vma, page);set_pte_at (mm, address, page_table, pte);page_add_anon_rmap (page, vma, address); +blkio_cgroup_reset_owner (page, mm);/* It's better to call commit-charge after rmap is established */ mem_cgroup_commit_charge_swapin (page, ptr);
@@ -2644,6 +2647,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma, goto release;inc_mm_counter (mm, anon_rss);page_add_new_anon_rmap (page, vma, address); +blkio_cgroup_set_owner (page, mm);set_pte_at (mm, address, page_table, entry);/* No need to invalidate - it was non-present before */
@@ -2791,6 +2795,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,if (anon) {inc_mm_counter (mm, anon_rss);page_add_new_anon_rmap (page, vma, address); +blkio_cgroup_set_owner (page, mm); }else {inc_mm_counter (mm, file_rss);page_add_file_rmap (page);
mm/page-writeback.c +2 -0
@@ -23,6 +23,7 @@#include <linux/init.h> #include <linux/backing-dev.h> #include <linux/task_io_accounting_ops.h> +#include <linux/biotrack.h> #include <linux/blkdev.h> #include <linux/mpage.h> #include <linux/rmap.h>
@@ -1247,6 +1248,7 @@ int __set_page_dirty_nobuffers(struct page *page)BUG_ON (mapping2 != mapping);WARN_ON_ONCE (!PagePrivate (page) && !PageUptodate (page));account_page_dirtied (page, mapping); +blkio_cgroup_reset_owner_pagedirty (page, current->mm);radix_tree_tag_set (&mapping->page_tree,page_index (page),PAGECACHE_TAG_DIRTY ); }
mm/page_cgroup.c +9 -8
@@ -9,14 +9,15 @@#include <linux/vmalloc.h> #include <linux/cgroup.h> #include <linux/swapops.h> +#include <linux/biotrack.h> static void __meminit __init_page_cgroup (struct page_cgroup *pc,unsigned long pfn) { pc->flags =0 ; - pc->mem_cgroup =NULL ; pc->page =pfn_to_page (pfn); -INIT_LIST_HEAD (&pc->lru); +__init_mem_page_cgroup (pc); +__init_blkio_page_cgroup (pc); }static unsigned long total_usage;
@@ -74,7 +75,7 @@ void __init page_cgroup_init_flatmem(void)int nid, fail; -if (mem_cgroup_disabled ()) +if (mem_cgroup_disabled () &&blkio_cgroup_disabled ())return ;for_each_online_node (nid) {
@@ -83,12 +84,12 @@ void __init page_cgroup_init_flatmem(void) goto fail; }printk (KERN_INFO "allocated %ld bytes of page_cgroup\n" , total_usage); -printk (KERN_INFO "please try 'cgroup_disable=memory' option if you" +printk (KERN_INFO "please try cgroup_disable=memory,blkio option if you" " don't want memory cgroups\n" );return ; fail:printk (KERN_CRIT "allocation of page_cgroup failed.\n" ); -printk (KERN_CRIT "please try 'cgroup_disable=memory' boot option\n" ); +printk (KERN_CRIT "please try cgroup_disable=memory,blkio boot options\n" );panic ("Out of memory" ); }
@@ -245,7 +246,7 @@ void __init page_cgroup_init(void)unsigned long pfn;int fail =0 ; -if (mem_cgroup_disabled ()) +if (mem_cgroup_disabled () &&blkio_cgroup_disabled ())return ;for (pfn =0 ; !fail && pfn < max_pfn; pfn +=PAGES_PER_SECTION ) {
@@ -260,8 +261,8 @@ void __init page_cgroup_init(void)hotplug_memory_notifier (page_cgroup_callback,0 ); }printk (KERN_INFO "allocated %ld bytes of page_cgroup\n" , total_usage); -printk (KERN_INFO "please try 'cgroup_disable=memory' option if you don't" -" want memory cgroups\n" ); +printk (KERN_INFO "please try cgroup_disable=memory,blkio option" +" if you don't want memory and io cgroups\n" ); }void __meminit pgdat_page_cgroup_init (struct pglist_data *pgdat)
mm/swap_state.c +2 -0
@@ -18,6 +18,7 @@#include <linux/pagevec.h> #include <linux/migrate.h> #include <linux/page_cgroup.h> +#include <linux/biotrack.h> #include <asm/pgtable.h>
@@ -307,6 +308,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,*/ __set_page_locked (new_page);SetPageSwapBacked (new_page); +blkio_cgroup_set_owner (new_page, current->mm); err =add_to_swap_cache (new_page, entry, gfp_mask &GFP_KERNEL );if (likely (!err)) {/*
Signature · 1 line
1.6.0.6
PATCH 20/24 io-controller: map async requests to appropriate cgroup
In reply to a message not in the archiveo So far we were assuming that a bio/rq belongs to the task who is submitting it. It did not hold good in case of async writes. This patch makes use of blkio_cgroup pataches to attribute the aysnc writes to right group instead of task submitting the bio.
o For sync requests, we continue to assume that io belongs to the task submitting it. Only in case of async requests, we make use of io tracking patches to track the owner cgroup.
o So far cfq always caches the async queue pointer. With async requests now not necessarily being tied to submitting task io context, caching the pointer will not help for async queues. This patch introduces a new config option CONFIG_TRACK_ASYNC_CONTEXT. If this option is not set, cfq retains old behavior where async queue pointer is cached in task context. If it is set, async queue pointer is not cached and we take help of bio tracking patches to determine group bio belongs to and then map it to async queue of that group.
--- block/Kconfig.iosched | 16 +++++ block/as-iosched.c | 2 +- block/blk-core.c | 7 +- block/cfq-iosched.c | 151 ++++++++++++++++++++++++++++++++++++---------- block/deadline-iosched.c | 2 +- block/elevator-fq.c | 119 +++++++++++++++++++++++++++++++----- block/elevator-fq.h | 20 ++++-- block/elevator.c | 15 +++-- include/linux/elevator.h | 22 ++++++- 9 files changed, 284 insertions(+), 70 deletions(-)
block/Kconfig.iosched +16 -0
@@ -132,6 +132,22 @@ config DEBUG_GROUP_IOSCHED Enable some debugging hooks for hierarchical scheduling support. Currently it just outputs more information in blktrace output. +config TRACK_ASYNC_CONTEXT + bool "Determine async request context from bio" + depends on GROUP_IOSCHED + select CGROUP_BLKIO + default n + ---help--- + Normally async request is attributed to the task submitting the + request. With group ioscheduling, for accurate accounting of + async writes, one needs to map the request to original task/cgroup + which originated the request and not the submitter of the request. + + Currently there are generic io tracking patches to provide facility + to map bio to original owner. If this option is set, for async + request, original owner of the bio is decided by using io tracking + patches otherwise we continue to attribute the request to the + submitting thread. endmenu endif
block/as-iosched.c +1 -1
@@ -1514,7 +1514,7 @@ as_merge(struct request_queue *q, struct request **req, struct bio *bio) {sector_t rb_key = bio->bi_sector +bio_sectors (bio);struct request *__rq; -struct as_queue *asq =elv_get_sched_queue_current (q); +struct as_queue *asq =elv_get_sched_queue_bio (q, bio);if (!asq)return ELEVATOR_NO_MERGE ;
block/blk-core.c +4 -3
@@ -626,7 +626,8 @@ static inline void blk_free_request(struct request_queue *q, struct request *rq) }static struct request * -blk_alloc_request (struct request_queue *q,int flags,int priv,gfp_t gfp_mask) +blk_alloc_request (struct request_queue *q,struct bio *bio,int flags,int priv, +gfp_t gfp_mask) {struct request *rq =mempool_alloc (q->rq.rq_pool, gfp_mask);
@@ -638,7 +639,7 @@ blk_alloc_request(struct request_queue *q, int flags, int priv, gfp_t gfp_mask) rq->cmd_flags = flags |REQ_ALLOCED ;if (priv) { -if (unlikely (elv_set_request (q, rq, gfp_mask))) { +if (unlikely (elv_set_request (q, rq, bio, gfp_mask))) {mempool_free (rq, q->rq.rq_pool);return NULL ; }
@@ -779,7 +780,7 @@ static struct request *get_request(struct request_queue *q, int rw_flags, rw_flags |=REQ_IO_STAT ;spin_unlock_irq (q->queue_lock); - rq =blk_alloc_request (q, rw_flags, priv, gfp_mask); + rq =blk_alloc_request (q, bio, rw_flags, priv, gfp_mask);if (unlikely (!rq)) {/* * Allocation failed presumably due to memory. Undo anything
block/cfq-iosched.c +119 -32
251 lines not on this page · raw message
block/deadline-iosched.c +1 -1
@@ -133,7 +133,7 @@ deadline_merge(struct request_queue *q, struct request **req, struct bio *bio)int ret;struct deadline_queue *dq; - dq =elv_get_sched_queue_current (q); + dq =elv_get_sched_queue_bio (q, bio);if (!dq)return ELEVATOR_NO_MERGE ;
block/elevator-fq.c +103 -16
209 lines not on this page · raw message
block/elevator-fq.h +13 -7
@@ -550,10 +550,11 @@ static inline int update_requeue(struct io_queue *ioq, int requeue) }extern int elv_fq_set_request_ioq (struct request_queue *q,struct request *rq, -gfp_t gfp_mask); +struct bio *bio,gfp_t gfp_mask);extern void elv_fq_unset_request_ioq (struct request_queue *q,struct request *rq); -extern struct io_queue *elv_lookup_ioq_current (struct request_queue *q); +extern struct io_queue *elv_lookup_ioq_bio (struct request_queue *q, +struct bio *bio);/* Sets the single ioq associated with the io group. (noop, deadline, AS) */ static inline void io_group_set_ioq (struct io_group *iog,struct io_queue *ioq)
@@ -588,7 +589,7 @@ static inline void io_group_set_ioq(struct io_group *iog, struct io_queue *ioq) }static inline int elv_fq_set_request_ioq (struct request_queue *q, -struct request *rq,gfp_t gfp_mask) +struct request *rq,struct bio *bio,gfp_t gfp_mask) {return 0 ; }
@@ -598,7 +599,8 @@ static inline void elv_fq_unset_request_ioq(struct request_queue *q, { } -static inline struct io_queue *elv_lookup_ioq_current (struct request_queue *q) +static inline struct io_queue *elv_lookup_ioq_bio (struct request_queue *q, +struct bio *bio) {return NULL ; }
@@ -655,7 +657,10 @@ extern void *io_group_async_queue_prio(struct io_group *iog, int ioprio_class, int ioprio);extern void io_group_set_async_queue (struct io_group *iog,int ioprio_class,int ioprio,struct io_queue *ioq); -extern struct io_group *io_get_io_group (struct request_queue *q,int create); +extern struct io_group *io_get_io_group (struct request_queue *q, +struct page *page,int create); +extern struct io_group *io_get_io_group_bio (struct request_queue *q, +struct bio *bio,int create);extern int elv_nr_busy_ioq (struct elevator_queue *e);extern int elv_rq_in_driver (struct elevator_queue *e);extern struct io_queue *elv_alloc_ioq (struct request_queue *q,gfp_t gfp_mask);
@@ -714,7 +719,7 @@ static inline int io_group_allow_merge(struct request *rq, struct bio *bio)return 1 ; }static inline int elv_fq_set_request_ioq (struct request_queue *q, -struct request *rq,gfp_t gfp_mask) +struct request *rq,struct bio *bio,gfp_t gfp_mask) {return 0 ; }
@@ -724,7 +729,8 @@ static inline void elv_fq_unset_request_ioq(struct request_queue *q, { } -static inline struct io_queue *elv_lookup_ioq_current (struct request_queue *q) +static inline struct io_queue *elv_lookup_ioq_bio (struct request_queue *q, +struct bio *bio) {return NULL ; }
block/elevator.c +8 -7
@@ -846,7 +846,8 @@ struct request *elv_former_request(struct request_queue *q, struct request *rq)return NULL ; } -int elv_set_request (struct request_queue *q,struct request *rq,gfp_t gfp_mask) +int elv_set_request (struct request_queue *q,struct request *rq, +struct bio *bio,gfp_t gfp_mask) {struct elevator_queue *e = q->elevator;
@@ -855,10 +856,10 @@ int elv_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask)* ioq per io group */ if (elv_iosched_single_ioq (e)) -return elv_fq_set_request_ioq (q, rq, gfp_mask); +return elv_fq_set_request_ioq (q, rq, bio, gfp_mask);if (e->ops->elevator_set_req_fn) -return e->ops->elevator_set_req_fn (q, rq, gfp_mask); +return e->ops->elevator_set_req_fn (q, rq, bio, gfp_mask); rq->elevator_private =NULL ;return 0 ;
@@ -1260,19 +1261,19 @@ void *elv_select_sched_queue(struct request_queue *q, int force)EXPORT_SYMBOL (elv_select_sched_queue);/* -* Get the io scheduler queue pointer for current task. +* Get the io scheduler queue pointer for the group bio belongs to. * * If fair queuing is enabled, determine the io group of task and retrieve * the ioq pointer from that. This is used by only single queue ioschedulers * for retrieving the queue associated with the group to decide whether the * new bio can do a front merge or not. */ -void *elv_get_sched_queue_current (struct request_queue *q) +void *elv_get_sched_queue_bio (struct request_queue *q,struct bio *bio) {/* Fair queuing is not enabled. There is only one queue. */ if (!elv_iosched_fair_queuing_enabled (q->elevator))return q->elevator->sched_queue; -return ioq_sched_queue (elv_lookup_ioq_current (q)); +return ioq_sched_queue (elv_lookup_ioq_bio (q, bio)); } -EXPORT_SYMBOL (elv_get_sched_queue_current); +EXPORT_SYMBOL (elv_get_sched_queue_bio);
include/linux/elevator.h +19 -3
@@ -23,7 +23,8 @@ typedef struct request *(elevator_request_list_fn) (struct request_queue *, strutypedef void (elevator_completed_req_fn ) (struct request_queue *,struct request *);typedef int (elevator_may_queue_fn ) (struct request_queue *,int ); -typedef int (elevator_set_req_fn ) (struct request_queue *,struct request *,gfp_t ); +typedef int (elevator_set_req_fn ) (struct request_queue *,struct request *, +struct bio *bio,gfp_t );typedef void (elevator_put_req_fn ) (struct request *);typedef void (elevator_activate_req_fn ) (struct request_queue *,struct request *);typedef void (elevator_deactivate_req_fn ) (struct request_queue *,struct request *);
@@ -147,7 +148,8 @@ extern void elv_unregister_queue(struct request_queue *q);extern int elv_may_queue (struct request_queue *,int );extern void elv_abort_queue (struct request_queue *);extern void elv_completed_request (struct request_queue *,struct request *); -extern int elv_set_request (struct request_queue *,struct request *,gfp_t ); +extern int elv_set_request (struct request_queue *,struct request *, +struct bio *bio,gfp_t );extern void elv_put_request (struct request_queue *,struct request *);extern void elv_drain_elevator (struct request_queue *);
@@ -276,6 +278,20 @@ static inline int elv_iosched_single_ioq(struct elevator_queue *e)#endif /* ELV_IOSCHED_FAIR_QUEUING */ extern void *elv_get_sched_queue (struct request_queue *q,struct request *rq);extern void *elv_select_sched_queue (struct request_queue *q,int force); -extern void *elv_get_sched_queue_current (struct request_queue *q); +extern void *elv_get_sched_queue_bio (struct request_queue *q,struct bio *bio); + +/* +* This is equivalent of rq_is_sync()/cfq_bio_sync() function where we +* determine whether an rq/bio is sync or not. There are cases like during +* merging and during * request allocation, where we don't have rq but bio +* and needs to find out * if this bio will be considered as sync or async by +* elevator/iosched. This function is useful in such cases. +*/ +static inline int elv_bio_sync (struct bio *bio) +{ +if ((bio_data_dir (bio) ==READ ) ||bio_sync (bio)) +return 1 ; +return 0 ; +}#endif /* CONFIG_BLOCK */ #endif
Signature · 1 line
1.6.0.6
PATCH 21/24 io-controller: Per cgroup request descriptor support
In reply to a message not in the archiveo Currently a request queue has got fixed number of request descriptors for sync and async requests. Once the request descriptors are consumed, new processes are put to sleep and they effectively become serialized. Because sync and async queues are separate, async requests don't impact sync ones but if one is looking for fairness between async requests, that is not achievable if request queue descriptors become bottleneck.
o Make request descriptor's per io group so that if there is lots of IO going on in one cgroup, it does not impact the IO of other group.
o This is just one relatively simple way of doing things. This patch will probably change after the feedback. Folks have raised concerns that in hierchical setup, child's request descriptors should be capped by parent's request descriptors. May be we need to have per cgroup per device files in cgroups where one can specify the upper limit of request descriptors and whenever a cgroup is created one needs to assign request descritor limit making sure total sum of child's request descriptor is not more than of parent.
I guess something like memory controller. Anyway, that would be the next step. For the time being, we have implemented something simpler as follows.
o This patch implements the per cgroup request descriptors. request pool per queue is still common but every group will have its own wait list and its own count of request descriptors allocated to that group for sync and async queues. So effectively request_list becomes per io group property and not a global request queue feature.
o Currently one can define q->nr_requests to limit request descriptors allocated for the queue. Now there is another tunable q->nr_group_requests which controls the requests descriptr limit per group. q->nr_requests supercedes q->nr_group_requests to make sure if there are lots of groups present, we don't end up allocating too many request descriptors on the queue.
--- block/blk-core.c | 305 +++++++++++++++++++++++++++++++++++++---------- block/blk-settings.c | 1 + block/blk-sysfs.c | 73 ++++++++++-- block/elevator-fq.c | 14 +++ block/elevator-fq.h | 5 + block/elevator.c | 7 +- include/linux/blkdev.h | 87 +++++++++++++- 7 files changed, 410 insertions(+), 82 deletions(-)
block/blk-core.c +241 -66
@@ -460,20 +460,30 @@ void blk_cleanup_queue(struct request_queue *q) }EXPORT_SYMBOL (blk_cleanup_queue); -static int blk_init_free_list (struct request_queue *q) +void blk_init_request_list (struct request_list *rl) { -struct request_list *rl = &q->rq; rl->count[BLK_RW_SYNC ] = rl->count[BLK_RW_ASYNC ] =0 ; - rl->starved[BLK_RW_SYNC ] = rl->starved[BLK_RW_ASYNC ] =0 ; - rl->elvpriv =0 ;init_waitqueue_head (&rl->wait[BLK_RW_SYNC ]);init_waitqueue_head (&rl->wait[BLK_RW_ASYNC ]); +} - rl->rq_pool =mempool_create_node (BLKDEV_MIN_RQ , mempool_alloc_slab, - mempool_free_slab, request_cachep, q->node); +static int blk_init_free_list (struct request_queue *q) +{ +/* +* Initialize the queue request list in case there are non-hiearchical +* io schedulers not making use of fair queuing infrastructure. +* +* For ioschedulers making use of fair queuing infrastructure, request +* list is inside the associated group and when that group is +* instanciated, it takes care of initializing the request list also. +*/ +blk_init_request_list (&q->rq); + q->rq_data.rq_pool =mempool_create_node (BLKDEV_MIN_RQ , + mempool_alloc_slab, mempool_free_slab, + request_cachep, q->node); -if (!rl->rq_pool) +if (!q->rq_data.rq_pool)return -ENOMEM ;return 0 ;
@@ -575,6 +585,9 @@ blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id)return NULL ; } +/* init starved waiter wait queue */ +init_waitqueue_head (&q->rq_data.starved_wait); +/* * if caller didn't supply a lock, they get per-queue locking with * our embedded lock
@@ -622,14 +635,14 @@ static inline void blk_free_request(struct request_queue *q, struct request *rq) {if (rq->cmd_flags &REQ_ELVPRIV )elv_put_request (q, rq); -mempool_free (rq, q->rq.rq_pool); +mempool_free (rq, q->rq_data.rq_pool); }static struct request *blk_alloc_request (struct request_queue *q,struct bio *bio,int flags,int priv,gfp_t gfp_mask) { -struct request *rq =mempool_alloc (q->rq.rq_pool, gfp_mask); +struct request *rq =mempool_alloc (q->rq_data.rq_pool, gfp_mask);if (!rq)return NULL ;
@@ -640,7 +653,7 @@ blk_alloc_request(struct request_queue *q, struct bio *bio, int flags, int priv,if (priv) {if (unlikely (elv_set_request (q, rq, bio, gfp_mask))) { -mempool_free (rq, q->rq.rq_pool); +mempool_free (rq, q->rq_data.rq_pool);return NULL ; } rq->cmd_flags |=REQ_ELVPRIV ;
@@ -683,18 +696,18 @@ static void ioc_set_batching(struct request_queue *q, struct io_context *ioc) ioc->last_waited = jiffies; } -static void __freed_request (struct request_queue *q,int sync) +static void __freed_request (struct request_queue *q,int sync, +struct request_list *rl) { -struct request_list *rl = &q->rq; - -if (rl->count[sync] <queue_congestion_off_threshold (q)) +if (q->rq_data.count[sync] <queue_congestion_off_threshold (q))blk_clear_queue_congested (q, sync); -if (rl->count[sync] +1 <= q->nr_requests) { +if (q->rq_data.count[sync] +1 <= q->nr_requests) +blk_clear_queue_full (q, sync); + +if (rl->count[sync] +1 <= q->nr_group_requests) {if (waitqueue_active (&rl->wait[sync]))wake_up (&rl->wait[sync]); - -blk_clear_queue_full (q, sync); } }
@@ -702,63 +715,133 @@ static void __freed_request(struct request_queue *q, int sync)* A request has just been released. Account for it, update the full and * congestion status, wake up any waiters. Called under q->queue_lock. */ -static void freed_request (struct request_queue *q,int sync,int priv) -{ -struct request_list *rl = &q->rq; +static void freed_request (struct request_queue *q,int sync,int priv, +struct request_list *rl) +{ +/* There is a window during request allocation where request is +* mapped to one group but by the time a queue for the group is +* allocated, it is possible that original cgroup/io group has been +* deleted and now io queue is allocated in a different group (root) +* altogether. +* +* One solution to the problem is that rq should take io group +* reference. But it looks too much to do that to solve this issue. +* The only side affect to the hard to hit issue seems to be that +* we will try to decrement the rl->count for a request list which +* did not allocate that request. Chcek for rl->count going less than +* zero and do not decrement it if that's the case. +*/ + +if (priv && rl->count[sync] >0 ) + rl->count[sync]--; + +BUG_ON (!q->rq_data.count[sync]); + q->rq_data.count[sync]--; - rl->count[sync]--;if (priv) - rl->elvpriv--; + q->rq_data.elvpriv--; -__freed_request (q, sync); +__freed_request (q, sync, rl);if (unlikely (rl->starved[sync ^1 ])) -__freed_request (q, sync ^1 ); +__freed_request (q, sync ^1 , rl); + +/* Wake up the starved process on global list, if any */ +if (unlikely (q->rq_data.starved)) { +if (waitqueue_active (&q->rq_data.starved_wait)) +wake_up (&q->rq_data.starved_wait); + q->rq_data.starved--; + } +} + +/* +* Returns whether one can sleep on this request list or not. There are +* cases (elevator switch) where request list might not have allocated +* any request descriptor but we deny request allocation due to gloabl +* limits. In that case one should sleep on global list as on this request +* list no wakeup will take place. +* +* Also sets the request list starved flag if there are no requests pending +* in the direction of rq. +* +* Return 1 --> sleep on request list, 0 --> sleep on global list +*/ +static int can_sleep_on_request_list (struct request_list *rl,int is_sync) +{ +if (unlikely (rl->count[is_sync] ==0 )) { +/* +* If there is a request pending in other direction +* in same io group, then set the starved flag of +* the group request list. Otherwise, we need to +* make this process sleep in global starved list +* to make sure it will not sleep indefinitely. +*/ +if (rl->count[is_sync ^1 ] !=0 ) { + rl->starved[is_sync] =1 ; +return 1 ; + }else +return 0 ; + } + +return 1 ; }/* * Get a free request, queue_lock must be held. -* Returns NULL on failure, with queue_lock held. +* Returns NULL on failure, with queue_lock held. Also sets the "reason" field +* in case of failure. This reason field helps caller decide to whether sleep +* on per group list or global per queue list. +* reason = 0 sleep on per group list +* reason = 1 sleep on global list +* * Returns !NULL on success, with queue_lock *not held*. */ static struct request *get_request (struct request_queue *q,int rw_flags, -struct bio *bio,gfp_t gfp_mask) +struct bio *bio,gfp_t gfp_mask, +struct request_list *rl,int *reason) {struct request *rq =NULL ; -struct request_list *rl = &q->rq;struct io_context *ioc =NULL ;const bool is_sync =rw_is_sync (rw_flags) !=0 ;int may_queue, priv; +int sleep_on_global =0 ; may_queue =elv_may_queue (q, rw_flags);if (may_queue ==ELV_MQUEUE_NO ) goto rq_starved; -if (rl->count[is_sync]+1 >=queue_congestion_on_threshold (q)) { -if (rl->count[is_sync]+1 >= q->nr_requests) { - ioc =current_io_context (GFP_ATOMIC , q->node); -/* -* The queue will fill after this allocation, so set -* it as full, and mark this process as "batching". -* This process will be allowed to complete a batch of -* requests, others will be blocked. -*/ -if (!blk_queue_full (q, is_sync)) { -ioc_set_batching (q, ioc); -blk_set_queue_full (q, is_sync); - }else { -if (may_queue !=ELV_MQUEUE_MUST - && !ioc_batching (q, ioc)) { -/* -* The queue is full and the allocating -* process is not a "batcher", and not -* exempted by the IO scheduler -*/ - goto out; - } +if (q->rq_data.count[is_sync]+1 >=queue_congestion_on_threshold (q)) +blk_set_queue_congested (q, is_sync); + +/* +* Looks like there is no user of queue full now. +* Keeping it for time being. +*/ +if (q->rq_data.count[is_sync]+1 >= q->nr_requests) +blk_set_queue_full (q, is_sync); + +if (rl->count[is_sync]+1 >= q->nr_group_requests) { + ioc =current_io_context (GFP_ATOMIC , q->node); +/* +* The queue request descriptor group will fill after this +* allocation, so set +* it as full, and mark this process as "batching". +* This process will be allowed to complete a batch of +* requests, others will be blocked. +*/ +if (rl->count[is_sync] <= q->nr_group_requests) +ioc_set_batching (q, ioc); +else { +if (may_queue !=ELV_MQUEUE_MUST + && !ioc_batching (q, ioc)) { +/* +* The queue is full and the allocating +* process is not a "batcher", and not +* exempted by the IO scheduler +*/ + goto out; } } -blk_set_queue_congested (q, is_sync); }/*
@@ -766,21 +849,60 @@ static struct request *get_request(struct request_queue *q, int rw_flags,* limit of requests, otherwise we could have thousands of requests * allocated with any setting of ->nr_requests */ -if (rl->count[is_sync] >= (3 * q->nr_requests /2 )) + +if (q->rq_data.count[is_sync] >= (3 * q->nr_requests /2 )) { +/* +* Queue is too full for allocation. On which request queue +* the task should sleep? Generally it should sleep on its +* request list but if elevator switch is happening, in that +* window, request descriptors are allocated from global +* pool and are not accounted against any particular request +* list as group is going away. +* +* So it might happen that request list does not have any +* requests allocated at all and if process sleeps on per +* group request list, it will not be woken up. In such case, +* make it sleep on global starved list. +*/ +if (test_bit (QUEUE_FLAG_ELVSWITCH , &q->queue_flags) + || !can_sleep_on_request_list (rl, is_sync)) + sleep_on_global =1 ; + goto out; + } + +/* +* Allocation of request is allowed from queue perspective. Now check +* from per group request list +*/ + +if (rl->count[is_sync] >= (3 * q->nr_group_requests /2 )) goto out; - rl->count[is_sync]++; rl->starved[is_sync] =0 ; + q->rq_data.count[is_sync]++; + priv = !test_bit (QUEUE_FLAG_ELVSWITCH , &q->queue_flags); -if (priv) - rl->elvpriv++; +if (priv) { + q->rq_data.elvpriv++; +/* +* Account the request to request list only if request is +* going to elevator. During elevator switch, there will +* be small window where group is going away and new group +* will not be allocated till elevator switch is complete. +* So till then instead of slowing down the application, +* we will continue to allocate request from total common +* pool instead of per group limit +*/ + rl->count[is_sync]++; + }if (blk_queue_io_stat (q)) rw_flags |=REQ_IO_STAT ;spin_unlock_irq (q->queue_lock); rq =blk_alloc_request (q, bio, rw_flags, priv, gfp_mask); +if (unlikely (!rq)) {/* * Allocation failed presumably due to memory. Undo anything
@@ -790,7 +912,7 @@ static struct request *get_request(struct request_queue *q, int rw_flags,* wait queue, but this is pretty rare. */ spin_lock_irq (q->queue_lock); -freed_request (q, is_sync, priv); +freed_request (q, is_sync, priv, rl);/* * in the very unlikely event that allocation failed and no
@@ -800,9 +922,8 @@ static struct request *get_request(struct request_queue *q, int rw_flags,* rq mempool into READ and WRITE */ rq_starved: -if (unlikely (rl->count[is_sync] ==0 )) - rl->starved[is_sync] =1 ; - +if (!can_sleep_on_request_list (rl, is_sync)) + sleep_on_global =1 ; goto out; }
@@ -817,6 +938,8 @@ rq_starved:trace_block_getrq (q, bio, rw_flags &1 ); out: +if (reason && sleep_on_global) + *reason =1 ;return rq; }
@@ -830,16 +953,44 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags, struct bio *bio) {const bool is_sync =rw_is_sync (rw_flags) !=0 ; +int sleep_on_global =0 ;struct request *rq; +struct request_list *rl =blk_get_request_list (q, bio); +struct io_group *iog =NULL ; - rq =get_request (q, rw_flags, bio,GFP_NOIO ); + rq =get_request (q, rw_flags, bio,GFP_NOIO , rl, &sleep_on_global);while (!rq) {DEFINE_WAIT (wait);struct io_context *ioc; -struct request_list *rl = &q->rq; -prepare_to_wait_exclusive (&rl->wait[is_sync], &wait, -TASK_UNINTERRUPTIBLE ); +if (sleep_on_global) { +/* +* Task failed allocation and needs to wait and +* try again. There are no requests pending from +* the io group hence need to sleep on global +* wait queue. Most likely the allocation failed +* because of memory issues. +*/ + + q->rq_data.starved++; +prepare_to_wait_exclusive (&q->rq_data.starved_wait, + &wait,TASK_UNINTERRUPTIBLE ); + }else { +/* +* We are about to sleep on a request list and we +* drop queue lock. After waking up, we will do +* finish_wait() on request list and in the mean +* time group might be gone. Take a reference to +* the group now. +*/ +prepare_to_wait_exclusive (&rl->wait[is_sync], &wait, +TASK_UNINTERRUPTIBLE ); +#ifdef CONFIG_GROUP_IOSCHED + iog =rl_iog (rl); +if (iog) +elv_get_iog (iog); +#endif + }trace_block_sleeprq (q, bio, rw_flags &1 );
@@ -857,9 +1008,30 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags,ioc_set_batching (q, ioc);spin_lock_irq (q->queue_lock); -finish_wait (&rl->wait[is_sync], &wait); - rq =get_request (q, rw_flags, bio,GFP_NOIO ); +if (sleep_on_global) { +finish_wait (&q->rq_data.starved_wait, &wait); + sleep_on_global =0 ; + }else { +finish_wait (&rl->wait[is_sync], &wait); +#ifdef CONFIG_GROUP_IOSCHED +/* +* We had taken a reference to the rl/iog. +* Put that now +*/ + iog =rl_iog (rl); +if (iog) +elv_put_iog (iog); +#endif + } + +/* +* After the sleep check the rl again in case cgrop bio +* belonged to is gone and it is mapped to root group now +*/ + rl =blk_get_request_list (q, bio); + rq =get_request (q, rw_flags, bio,GFP_NOIO , rl, + &sleep_on_global); };return rq;
@@ -868,14 +1040,16 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags,struct request *blk_get_request (struct request_queue *q,int rw,gfp_t gfp_mask) {struct request *rq; +struct request_list *rl;BUG_ON (rw !=READ && rw !=WRITE );spin_lock_irq (q->queue_lock); + rl =blk_get_request_list (q,NULL );if (gfp_mask & __GFP_WAIT) { rq =get_request_wait (q, rw,NULL ); }else { - rq =get_request (q, rw,NULL , gfp_mask); + rq =get_request (q, rw,NULL , gfp_mask, rl,NULL );if (!rq)spin_unlock_irq (q->queue_lock); }
@@ -1092,12 +1266,13 @@ void __blk_put_request(struct request_queue *q, struct request *req)if (req->cmd_flags &REQ_ALLOCED ) {int is_sync =rq_is_sync (req) !=0 ;int priv = req->cmd_flags &REQ_ELVPRIV ; +struct request_list *rl =rq_rl (q, req);BUG_ON (!list_empty (&req->queuelist));BUG_ON (!hlist_unhashed (&req->hash));blk_free_request (q, req); -freed_request (q, is_sync, priv); +freed_request (q, is_sync, priv, rl); } }EXPORT_SYMBOL_GPL (__blk_put_request);
block/blk-settings.c +1 -0
@@ -148,6 +148,7 @@ void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)* set defaults */ q->nr_requests =BLKDEV_MAX_RQ ; + q->nr_group_requests =BLKDEV_MAX_GROUP_RQ ; q->make_request_fn = mfn;blk_queue_dma_alignment (q,511 );
block/blk-sysfs.c +61 -12
127 lines not on this page · raw message
block/elevator-fq.c +14 -0
@@ -1228,6 +1228,16 @@ static struct io_cgroup *cgroup_to_io_cgroup(struct cgroup *cgroup) struct io_cgroup, css); } +struct request_list *io_group_get_request_list (struct request_queue *q, +struct bio *bio) +{ +struct io_group *iog; + + iog =io_get_io_group_bio (q, bio,1 ); +BUG_ON (!iog); +return &iog->rl; +} +/* * Search the io_group for efqd into the hash table (by now only a list) * of bgrp. Must be called under rcu_read_lock().
@@ -1603,6 +1613,8 @@ io_group_chain_alloc(struct request_queue *q, void *key, struct cgroup *cgroup)#endif +blk_init_request_list (&iog->rl); +if (leaf ==NULL ) { leaf = iog; prev = leaf;
@@ -1880,6 +1892,8 @@ static struct io_group *io_alloc_root_group(struct request_queue *q,for (i =0 ; i <IO_IOPRIO_CLASSES ; i++) iog->sched_data.service_tree[i] =IO_SERVICE_TREE_INIT ; +blk_init_request_list (&iog->rl); + iocg = &io_root_cgroup;spin_lock_irq (&iocg->lock);rcu_assign_pointer (iog->key, key);
block/elevator-fq.h +5 -0
@@ -265,6 +265,9 @@ struct io_group {/* Single ioq per group, used for noop, deadline, anticipatory */ struct io_queue *ioq; + +/* request list associated with the group */ +struct request_list rl; };/**
@@ -555,6 +558,8 @@ extern void elv_fq_unset_request_ioq(struct request_queue *q, struct request *rq);extern struct io_queue *elv_lookup_ioq_bio (struct request_queue *q,struct bio *bio); +extern struct request_list *io_group_get_request_list (struct request_queue *q, +struct bio *bio);/* Sets the single ioq associated with the io group. (noop, deadline, AS) */ static inline void io_group_set_ioq (struct io_group *iog,struct io_queue *ioq)
block/elevator.c +4 -3
@@ -659,7 +659,7 @@ void elv_quiesce_start(struct request_queue *q)* make sure we don't have any requests in flight */ elv_drain_elevator (q); -while (q->rq.elvpriv) { +while (q->rq_data.elvpriv) {__blk_run_queue (q);spin_unlock_irq (q->queue_lock);msleep (10 );
@@ -758,8 +758,9 @@ void elv_insert(struct request_queue *q, struct request *rq, int where) }if (unplug_it &&blk_queue_plugged (q)) { -int nrq = q->rq.count[BLK_RW_SYNC ] + q->rq.count[BLK_RW_ASYNC ] - -queue_in_flight (q); +int nrq = q->rq_data.count[BLK_RW_SYNC ] + + q->rq_data.count[BLK_RW_ASYNC ] - +queue_in_flight (q);if (nrq >= q->unplug_thresh)__generic_unplug_device (q);
include/linux/blkdev.h +85 -2
124 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 22/24 io-controller: Per io group bdi congestion interface
In reply to a message not in the archiveo So far there used to be only one pair or queue of request descriptors (one for sync and one for async) per device and number of requests allocated used to decide whether associated bdi is congested or not.
Now with per io group request descriptor infrastructure, there is a pair of request descriptor queue per io group per device. So it might happen that overall request queue is not congested but a particular io group bio belongs to is congested.
Or, it could be otherwise that group is not congested but overall queue is congested. This can happen if user has not properly set the request descriptors limits for queue and groups.
(q->nr_requests < nr_groups * q->nr_group_requests)
Hence there is a need for new interface which can query deivce congestion status per group. This group is determined by the "struct page" IO will be done for. If page is null, then group is determined from the current task context.
o This patch introduces new set of function bdi_*_congested_group(), which take "struct page" as addition argument. These functions will call the block layer and in trun elevator to find out if the io group the page will go into is congested or not.
o Currently I have introduced the core functions and migrated most of the users. But there might be still some left. This is an ongoing TODO item.
o There are some io_get_io_group() related changes which should be pushed into higher patches. Still testing this patch. Will push these changes up in next posting.
--- block/blk-core.c | 21 ++++++++++++++ block/elevator-fq.c | 62 +++++++++++++++++++++++++++++++++++++++++++ block/elevator-fq.h | 6 ++++ drivers/md/dm-table.c | 11 +++++--- drivers/md/dm.c | 7 +++-- drivers/md/dm.h | 3 +- drivers/md/linear.c | 7 +++- drivers/md/multipath.c | 7 +++- drivers/md/raid0.c | 6 +++- drivers/md/raid1.c | 9 ++++-- drivers/md/raid10.c | 6 +++- drivers/md/raid5.c | 2 +- fs/afs/write.c | 8 +++++- fs/btrfs/disk-io.c | 6 +++- fs/btrfs/extent_io.c | 12 ++++++++ fs/btrfs/volumes.c | 8 ++++- fs/cifs/file.c | 11 +++++++ fs/ext2/ialloc.c | 2 +- fs/gfs2/aops.c | 12 ++++++++ fs/nilfs2/segbuf.c | 3 +- fs/xfs/linux-2.6/xfs_aops.c | 2 +- fs/xfs/linux-2.6/xfs_buf.c | 2 +- include/linux/backing-dev.h | 61 ++++++++++++++++++++++++++++++++++++++++- include/linux/blkdev.h | 5 +++ mm/backing-dev.c | 62 +++++++++++++++++++++++++++++++++++++++++++ mm/page-writeback.c | 11 +++++++ mm/readahead.c | 2 +- 27 files changed, 322 insertions(+), 32 deletions(-)
block/blk-core.c +21 -0
@@ -90,6 +90,27 @@ void blk_queue_congestion_threshold(struct request_queue *q) q->nr_congestion_off = nr; } +#ifdef CONFIG_GROUP_IOSCHED +int blk_queue_io_group_congested (struct backing_dev_info *bdi,int bdi_bits, +struct page *page) +{ +int ret =0 ; +struct request_queue *q = bdi->unplug_io_data; + +if (!q || !q->elevator) +return bdi_congested (bdi, bdi_bits); + +/* Do we need to hold queue lock? */ +if (bdi_bits & (1 << BDI_sync_congested)) + ret |=elv_io_group_congested (q, page,1 ); + +if (bdi_bits & (1 << BDI_async_congested)) + ret |=elv_io_group_congested (q, page,0 ); + +return ret; +} +#endif +/** * blk_get_backing_dev_info - get the address of a queue's backing_dev_info * @bdev: device
block/elevator-fq.c +62 -0
86 lines not on this page · raw message
block/elevator-fq.h +6 -0
@@ -266,6 +266,10 @@ struct io_group {/* Single ioq per group, used for noop, deadline, anticipatory */ struct io_queue *ioq; +/* io group congestion on and off threshold for request descriptors */ +unsigned int nr_congestion_on; +unsigned int nr_congestion_off; +/* request list associated with the group */ struct request_list rl; };
@@ -560,6 +564,8 @@ extern struct io_queue *elv_lookup_ioq_bio(struct request_queue *q, struct bio *bio);extern struct request_list *io_group_get_request_list (struct request_queue *q,struct bio *bio); +extern int elv_io_group_congested (struct request_queue *q,struct page *page, +int sync);/* Sets the single ioq associated with the io group. (noop, deadline, AS) */ static inline void io_group_set_ioq (struct io_group *iog,struct io_queue *ioq)
drivers/md/dm-table.c +7 -4
@@ -1175,7 +1175,8 @@ int dm_table_resume_targets(struct dm_table *t)return 0 ; } -int dm_table_any_congested (struct dm_table *t,int bdi_bits) +int dm_table_any_congested (struct dm_table *t,int bdi_bits,struct page *page, +int group) {struct dm_dev_internal *dd;struct list_head *devices =dm_table_get_devices (t);
@@ -1185,9 +1186,11 @@ int dm_table_any_congested(struct dm_table *t, int bdi_bits)struct request_queue *q =bdev_get_queue (dd->dm_dev.bdev);char b[BDEVNAME_SIZE ]; -if (likely (q)) - r |=bdi_congested (&q->backing_dev_info, bdi_bits); -else +if (likely (q)) { +struct backing_dev_info *bdi = &q->backing_dev_info; + r |= group ?bdi_congested_group (bdi, bdi_bits, page) + :bdi_congested (bdi, bdi_bits); + }else DMWARN_LIMIT ("%s: any_congested: nonexistent device %s" ,dm_device_name (t->md),bdevname (dd->dm_dev.bdev, b));
drivers/md/dm.c +4 -3
@@ -1608,7 +1608,8 @@ static void dm_unplug_all(struct request_queue *q) } } -static int dm_any_congested (void *congested_data,int bdi_bits) +static int dm_any_congested (void *congested_data,int bdi_bits, +struct page *page,int group) {int r = bdi_bits;struct mapped_device *md = congested_data;
@@ -1625,8 +1626,8 @@ static int dm_any_congested(void *congested_data, int bdi_bits) r = md->queue->backing_dev_info.state & bdi_bits; else - r =dm_table_any_congested (map, bdi_bits); - + r =dm_table_any_congested (map, bdi_bits, page, + group);dm_table_put (map); } }
drivers/md/dm.h +2 -1
@@ -57,7 +57,8 @@ struct list_head *dm_table_get_devices(struct dm_table *t);void dm_table_presuspend_targets (struct dm_table *t);void dm_table_postsuspend_targets (struct dm_table *t);int dm_table_resume_targets (struct dm_table *t); -int dm_table_any_congested (struct dm_table *t,int bdi_bits); +int dm_table_any_congested (struct dm_table *t,int bdi_bits,struct page *page, +int group);int dm_table_any_busy_target (struct dm_table *t);int dm_table_set_type (struct dm_table *t);unsigned dm_table_get_type (struct dm_table *t);
drivers/md/linear.c +5 -2
@@ -102,7 +102,7 @@ static void linear_unplug(struct request_queue *q)rcu_read_unlock (); } -static int linear_congested (void *data,int bits) +static int linear_congested (void *data,int bits,struct page *page,int group) {mddev_t *mddev = data;linear_conf_t *conf;
@@ -113,7 +113,10 @@ static int linear_congested(void *data, int bits)for (i =0 ; i < mddev->raid_disks && !ret ; i++) {struct request_queue *q =bdev_get_queue (conf->disks[i].rdev->bdev); - ret |=bdi_congested (&q->backing_dev_info, bits); +struct backing_dev_info *bdi = &q->backing_dev_info; + + ret |= group ?bdi_congested_group (bdi, bits, page) : +bdi_congested (bdi, bits); }rcu_read_unlock ();
drivers/md/multipath.c +5 -2
@@ -192,7 +192,8 @@ static void multipath_status (struct seq_file *seq, mddev_t *mddev)seq_printf (seq,"]" ); } -static int multipath_congested (void *data,int bits) +static int multipath_congested (void *data,int bits,struct page *page, +int group) {mddev_t *mddev = data;multipath_conf_t *conf = mddev->private;
@@ -203,8 +204,10 @@ static int multipath_congested(void *data, int bits)mdk_rdev_t *rdev =rcu_dereference (conf->multipaths[i].rdev);if (rdev && !test_bit (Faulty, &rdev->flags)) {struct request_queue *q =bdev_get_queue (rdev->bdev); +struct backing_dev_info *bdi = &q->backing_dev_info; - ret |=bdi_congested (&q->backing_dev_info, bits); + ret |= group ?bdi_congested_group (bdi, bits, page) + :bdi_congested (bdi, bits);/* Just like multipath_map, we just check the * first available device */
drivers/md/raid0.c +4 -2
@@ -37,7 +37,7 @@ static void raid0_unplug(struct request_queue *q) } } -static int raid0_congested (void *data,int bits) +static int raid0_congested (void *data,int bits,struct page *page,int group) {mddev_t *mddev = data;raid0_conf_t *conf = mddev->private;
@@ -46,8 +46,10 @@ static int raid0_congested(void *data, int bits)for (i =0 ; i < mddev->raid_disks && !ret ; i++) {struct request_queue *q =bdev_get_queue (devlist[i]->bdev); +struct backing_dev_info *bdi = &q->backing_dev_info; - ret |=bdi_congested (&q->backing_dev_info, bits); + ret |= group ?bdi_congested_group (bdi, bits, page) + :bdi_congested (bdi, bits); }return ret; }
drivers/md/raid1.c +6 -3
@@ -570,7 +570,7 @@ static void raid1_unplug(struct request_queue *q)md_wakeup_thread (mddev->thread); } -static int raid1_congested (void *data,int bits) +static int raid1_congested (void *data,int bits,struct page *page,int group) {mddev_t *mddev = data;conf_t *conf = mddev->private;
@@ -581,14 +581,17 @@ static int raid1_congested(void *data, int bits)mdk_rdev_t *rdev =rcu_dereference (conf->mirrors[i].rdev);if (rdev && !test_bit (Faulty, &rdev->flags)) {struct request_queue *q =bdev_get_queue (rdev->bdev); +struct backing_dev_info *bdi = &q->backing_dev_info;/* Note the '|| 1' - when read_balance prefers * non-congested targets, it can be removed */ if ((bits & (1 <<BDI_async_congested)) ||1 ) - ret |=bdi_congested (&q->backing_dev_info, bits); + ret |= group ?bdi_congested_group (bdi, bits, + page) :bdi_congested (bdi, bits);else - ret &=bdi_congested (&q->backing_dev_info, bits); + ret &= group ?bdi_congested_group (bdi, bits, + page) :bdi_congested (bdi, bits); } }rcu_read_unlock ();
drivers/md/raid10.c +4 -2
@@ -625,7 +625,7 @@ static void raid10_unplug(struct request_queue *q)md_wakeup_thread (mddev->thread); } -static int raid10_congested (void *data,int bits) +static int raid10_congested (void *data,int bits,struct page *page,int group) {mddev_t *mddev = data;conf_t *conf = mddev->private;
@@ -636,8 +636,10 @@ static int raid10_congested(void *data, int bits)mdk_rdev_t *rdev =rcu_dereference (conf->mirrors[i].rdev);if (rdev && !test_bit (Faulty, &rdev->flags)) {struct request_queue *q =bdev_get_queue (rdev->bdev); +struct backing_dev_info *bdi = &q->backing_dev_info; - ret |=bdi_congested (&q->backing_dev_info, bits); + ret |= group ?bdi_congested_group (bdi, bits, page) + :bdi_congested (bdi, bits); } }rcu_read_unlock ();
drivers/md/raid5.c +1 -1
@@ -3323,7 +3323,7 @@ static void raid5_unplug_device(struct request_queue *q)unplug_slaves (mddev); } -static int raid5_congested (void *data,int bits) +static int raid5_congested (void *data,int bits,struct page *page,int group) {mddev_t *mddev = data;raid5_conf_t *conf = mddev->private;
fs/afs/write.c +7 -1
@@ -455,7 +455,7 @@ int afs_writepage(struct page *page, struct writeback_control *wbc) } wbc->nr_to_write -= ret; -if (wbc->nonblocking &&bdi_write_congested (bdi)) +if (wbc->nonblocking &&bdi_or_group_write_congested (bdi, page)) wbc->encountered_congestion =1 ;_leave (" = 0" );
@@ -491,6 +491,12 @@ static int afs_writepages_region(struct address_space *mapping,return 0 ; } +if (wbc->nonblocking &&bdi_write_congested_group (bdi, page)) { + wbc->encountered_congestion =1 ; +page_cache_release (page); +break ; + } +/* at this point we hold neither mapping->tree_lock nor lock on * the page itself: the page may be truncated or invalidated * (changing page->mapping to NULL), or even swizzled back from
fs/btrfs/disk-io.c +4 -2
@@ -1249,7 +1249,8 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,return root; } -static int btrfs_congested_fn (void *congested_data,int bdi_bits) +static int btrfs_congested_fn (void *congested_data,int bdi_bits, +struct page *page,int group) {struct btrfs_fs_info *info = (struct btrfs_fs_info *)congested_data;int ret =0 ;
@@ -1260,7 +1261,8 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)if (!device->bdev)continue ; bdi =blk_get_backing_dev_info (device->bdev); -if (bdi &&bdi_congested (bdi, bdi_bits)) { +if (bdi && (group ?bdi_congested_group (bdi, bdi_bits, page) : +bdi_congested (bdi, bdi_bits))) { ret =1 ;break ; }
fs/btrfs/extent_io.c +12 -0
@@ -2368,6 +2368,18 @@ retry:unsigned i; scanned =1 ; + +/* +* If the io group page will go into is congested, bail out. +*/ +if (wbc->nonblocking + &&bdi_write_congested_group (bdi, pvec.pages[0 ])) { + wbc->encountered_congestion =1 ; + done =1 ; +pagevec_release (&pvec); +break ; + } +for (i =0 ; i < nr_pages; i++) {struct page *page = pvec.pages[i];
fs/btrfs/volumes.c +6 -2
@@ -165,6 +165,7 @@ static noinline int run_scheduled_bios(struct btrfs_device *device)unsigned long limit;unsigned long last_waited =0 ;int force_reg =0 ; +struct page *page; bdi =blk_get_backing_dev_info (device->bdev); fs_info = device->dev_root->fs_info;
@@ -276,8 +277,11 @@ loop_lock:* is now congested. Back off and let other work structs * run instead */ -if (pending &&bdi_write_congested (bdi) && batch_run >32 && - fs_info->fs_devices->open_devices >1 ) { +if (pending) + page =bio_iovec_idx (pending,0 )->bv_page; + +if (pending &&bdi_or_group_write_congested (bdi, page) && + num_run >32 && fs_info->fs_devices->open_devices >1 ) {struct io_context *ioc; ioc = current->io_context;
fs/cifs/file.c +11 -0
@@ -1470,6 +1470,17 @@ retry: n_iov =0 ; bytes_to_write =0 ; +/* +* If the io group page will go into is congested, bail out. +*/ +if (wbc->nonblocking && +bdi_write_congested_group (bdi, pvec.pages[0 ])) { + wbc->encountered_congestion =1 ; + done =1 ; +pagevec_release (&pvec); +break ; + } +for (i =0 ; i < nr_pages; i++) { page = pvec.pages[i];/*
fs/ext2/ialloc.c +1 -1
@@ -179,7 +179,7 @@ static void ext2_preread_inode(struct inode *inode)struct backing_dev_info *bdi; bdi = inode->i_mapping->backing_dev_info; -if (bdi_read_congested (bdi)) +if (bdi_or_group_read_congested (bdi,NULL ))return ;if (bdi_write_congested (bdi))return ;
fs/gfs2/aops.c +12 -0
@@ -371,6 +371,18 @@ retry: PAGECACHE_TAG_DIRTY, min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) { scanned =1 ; + +/* +* If io group page belongs to is congested. bail out. +*/ +if (wbc->nonblocking + &&bdi_write_congested_group (bdi, pvec.pages[0 ])) { + wbc->encountered_congestion =1 ; + done =1 ; +pagevec_release (&pvec); +break ; + } + ret =gfs2_write_jdata_pagevec (mapping, wbc, &pvec, nr_pages, end);if (ret) done =1 ;
fs/nilfs2/segbuf.c +2 -1
@@ -266,8 +266,9 @@ static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode) {struct bio *bio = wi->bio;int err; +struct page *page =bio_iovec_idx (bio,0 )->bv_page; -if (wi->nbio >0 &&bdi_write_congested (wi->bdi)) { +if (wi->nbio >0 &&bdi_or_group_write_congested (wi->bdi, page)) {wait_for_completion (&wi->bio_event); wi->nbio--;if (unlikely (atomic_read (&wi->err))) {
fs/xfs/linux-2.6/xfs_aops.c +1 -1
@@ -891,7 +891,7 @@ xfs_convert_page( bdi = inode->i_mapping->backing_dev_info; wbc->nr_to_write--; -if (bdi_write_congested (bdi)) { +if (bdi_or_group_write_congested (bdi, page)) { wbc->encountered_congestion =1 ; done =1 ; }else if (wbc->nr_to_write <=0 ) {
fs/xfs/linux-2.6/xfs_buf.c +1 -1
@@ -714,7 +714,7 @@ xfs_buf_readahead(struct backing_dev_info *bdi; bdi = target->bt_mapping->backing_dev_info; -if (bdi_read_congested (bdi)) +if (bdi_or_group_read_congested (bdi,NULL ))return ; flags |= (XBF_TRYLOCK |XBF_ASYNC |XBF_READ_AHEAD );
include/linux/backing-dev.h +59 -2
79 lines not on this page · raw message
include/linux/blkdev.h +5 -0
@@ -886,6 +886,11 @@ static inline void blk_set_queue_congested(struct request_queue *q, int sync)set_bdi_congested (&q->backing_dev_info, sync); } +#ifdef CONFIG_GROUP_IOSCHED +extern int blk_queue_io_group_congested (struct backing_dev_info *bdi, +int bdi_bits,struct page *page); +#endif +extern void blk_start_queue (struct request_queue *q);extern void blk_stop_queue (struct request_queue *q);extern void blk_sync_queue (struct request_queue *q);
mm/backing-dev.c +62 -0
71 lines not on this page · raw message
mm/page-writeback.c +11 -0
@@ -985,6 +985,17 @@ retry:if (nr_pages ==0 )break ; +/* +* If the io group page will go into is congested, bail out. +*/ +if (wbc->nonblocking + &&bdi_write_congested_group (bdi, pvec.pages[0 ])) { + wbc->encountered_congestion =1 ; + done =1 ; +pagevec_release (&pvec); +break ; + } +for (i =0 ; i < nr_pages; i++) {struct page *page = pvec.pages[i];
mm/readahead.c +1 -1
@@ -542,7 +542,7 @@ page_cache_async_readahead(struct address_space *mapping,/* * Defer asynchronous read-ahead on IO congestion. */ -if (bdi_read_congested (mapping->backing_dev_info)) +if (bdi_or_group_read_congested (mapping->backing_dev_info,NULL ))return ;/* do read-ahead */
Signature · 1 line
1.6.0.6
PATCH 23/24 io-controller: Support per cgroup per device weights and io class
In reply to a message not in the archiveThis patch enables per-cgroup per-device weight and ioprio_class handling. A new cgroup interface "policy" is introduced. You can make use of this file to configure weight and ioprio_class for each device in a given cgroup. The original "weight" and "ioprio_class" files are still available. If you don't do special configuration for a particular device, "weight" and "ioprio_class" are used as default values in this device.
You can use the following format to play with the new interface. #echo dev_major:dev_minor weight ioprio_class > /patch/to/cgroup/policy weight=0 means removing the policy for device.
Examples:
Configure weight=300 ioprio_class=2 on /dev/hdb (8:16) in this cgroup
# echo "8:16 300 2" > io.policy # cat io.policy dev weight class 8:16 300 2
Configure weight=500 ioprio_class=1 on /dev/hda (8:0) in this cgroup
# echo "8:0 500 1" > io.policy # cat io.policy dev weight class 8:0 500 1 8:16 300 2
Remove the policy for /dev/hda in this cgroup
# echo 8:0 0 1 > io.policy # cat io.policy dev weight class 8:16 300 2
Changelog (v1 -> v2)
- Rename some structures
- Use spin_lock_irqsave() and spin_lock_irqrestore() version to prevent from enabling the interrupts unconditionally.
- Fix policy setup bug when switching to another io scheduler.
- If a policy is available for a specific device, don't update weight and io class when writing "weight" and "iprio_class".
- Fix a bug when parsing policy string.
--- block/elevator-fq.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 10 ++ 2 files changed, 271 insertions(+), 4 deletions(-)
block/elevator-fq.c +261 -4
@@ -17,6 +17,7 @@#include <linux/blktrace_api.h> #include <linux/seq_file.h> #include <linux/biotrack.h> +#include <linux/genhd.h> /* Values taken from cfq */ const int elv_slice_sync =HZ /10 ;
@@ -1189,12 +1190,30 @@ bfq_init_entity(struct io_entity *entity, struct io_group *iog) entity->sched_data = &iog->sched_data; } -static void io_group_init_entity (struct io_cgroup *iocg,struct io_group *iog) +static struct io_policy_node *policy_search_node (const struct io_cgroup *iocg, +dev_t dev); + +static void +io_group_init_entity (struct io_cgroup *iocg,struct io_group *iog,dev_t dev) {struct io_entity *entity = &iog->entity; +struct io_policy_node *pn; +unsigned long flags; - entity->weight = iocg->weight; - entity->ioprio_class = entity->new_ioprio_class = iocg->ioprio_class; +spin_lock_irqsave (&iocg->lock, flags); + pn =policy_search_node (iocg, dev); +if (pn) { + entity->weight = pn->weight; + entity->new_weight = pn->weight; + entity->ioprio_class = pn->ioprio_class; + entity->new_ioprio_class = pn->ioprio_class; + }else { + entity->weight = iocg->weight; + entity->new_weight = iocg->weight; + entity->ioprio_class = iocg->ioprio_class; + entity->new_ioprio_class = iocg->ioprio_class; + } +spin_unlock_irqrestore (&iocg->lock, flags); entity->ioprio_changed =1 ; entity->my_sched_data = &iog->sched_data; }
@@ -1314,6 +1333,227 @@ io_cgroup_lookup_group(struct io_cgroup *iocg, void *key)return NULL ; } +static int io_cgroup_policy_read (struct cgroup *cgrp,struct cftype *cft, +struct seq_file *m) +{ +struct io_cgroup *iocg; +struct io_policy_node *pn; + + iocg =cgroup_to_io_cgroup (cgrp); + +if (list_empty (&iocg->policy_list)) + goto out; + +seq_printf (m,"dev\tweight\tclass\n" ); + +spin_lock_irq (&iocg->lock); +list_for_each_entry (pn, &iocg->policy_list, node) { +seq_printf (m,"%u:%u\t%u\t%hu\n" ,MAJOR (pn->dev), +MINOR (pn->dev), pn->weight, pn->ioprio_class); + } +spin_unlock_irq (&iocg->lock); +out: +return 0 ; +} + +static inline void policy_insert_node (struct io_cgroup *iocg, +struct io_policy_node *pn) +{ +list_add (&pn->node, &iocg->policy_list); +} + +/* Must be called with iocg->lock held */ +static inline void policy_delete_node (struct io_policy_node *pn) +{ +list_del (&pn->node); +} + +/* Must be called with iocg->lock held */ +static struct io_policy_node *policy_search_node (const struct io_cgroup *iocg, +dev_t dev) +{ +struct io_policy_node *pn; + +if (list_empty (&iocg->policy_list)) +return NULL ; + +list_for_each_entry (pn, &iocg->policy_list, node) { +if (pn->dev == dev) +return pn; + } + +return NULL ; +} + +static int check_dev_num (dev_t dev) +{ +int part =0 ; +struct gendisk *disk; + + disk =get_gendisk (dev, &part); +if (!disk || part) +return -ENODEV ; + +return 0 ; +} + +static int policy_parse_and_set (char *buf,struct io_policy_node *newpn) +{ +char *s[4 ], *p, *major_s =NULL , *minor_s =NULL ; +int ret; +unsigned long major, minor, temp; +int i =0 ; +dev_t dev; + +memset (s,0 ,sizeof (s)); +while ((p =strsep (&buf," " )) !=NULL ) { +if (!*p) +continue ; + s[i++] = p; + +/* Prevent from inputing too many things */ +if (i ==4 ) +break ; + } + +if (i !=3 ) +return -EINVAL ; + + p =strsep (&s[0 ],":" ); +if (p !=NULL ) + major_s = p; +else +return -EINVAL ; + + minor_s = s[0 ]; +if (!minor_s) +return -EINVAL ; + + ret =strict_strtoul (major_s,10 , &major); +if (ret) +return -EINVAL ; + + ret =strict_strtoul (minor_s,10 , &minor); +if (ret) +return -EINVAL ; + + dev =MKDEV (major, minor); + + ret =check_dev_num (dev); +if (ret) +return ret; + + newpn->dev = dev; + +if (s[1 ] ==NULL ) +return -EINVAL ; + + ret =strict_strtoul (s[1 ],10 , &temp); +if (ret || temp >WEIGHT_MAX ) +return -EINVAL ; + + newpn->weight = temp; + +if (s[2 ] ==NULL ) +return -EINVAL ; + + ret =strict_strtoul (s[2 ],10 , &temp); +if (ret || temp <IOPRIO_CLASS_RT || temp >IOPRIO_CLASS_IDLE ) +return -EINVAL ; + newpn->ioprio_class = temp; + +return 0 ; +} + +static int io_cgroup_policy_write (struct cgroup *cgrp,struct cftype *cft, +const char *buffer) +{ +struct io_cgroup *iocg; +struct io_policy_node *newpn, *pn; +char *buf; +int ret =0 ; +int keep_newpn =0 ; +struct hlist_node *n; +struct io_group *iog; + + buf =kstrdup (buffer,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + newpn =kzalloc (sizeof (*newpn),GFP_KERNEL ); +if (!newpn) { + ret = -ENOMEM ; + goto free_buf; + } + + ret =policy_parse_and_set (buf, newpn); +if (ret) + goto free_newpn; + +if (!cgroup_lock_live_group (cgrp)) { + ret = -ENODEV ; + goto free_newpn; + } + + iocg =cgroup_to_io_cgroup (cgrp); +spin_lock_irq (&iocg->lock); + + pn =policy_search_node (iocg, newpn->dev); +if (!pn) { +if (newpn->weight !=0 ) { +policy_insert_node (iocg, newpn); + keep_newpn =1 ; + } + goto update_io_group; + } + +if (newpn->weight ==0 ) { +/* weight == 0 means deleteing a policy */ +policy_delete_node (pn); + goto update_io_group; + } + + pn->weight = newpn->weight; + pn->ioprio_class = newpn->ioprio_class; + +update_io_group: +hlist_for_each_entry (iog, n, &iocg->group_data, group_node) { +if (iog->dev == newpn->dev) { +if (newpn->weight) { + iog->entity.new_weight = newpn->weight; + iog->entity.new_ioprio_class = + newpn->ioprio_class; +/* +* iog weight and ioprio_class updating +* actually happens if ioprio_changed is set. +* So ensure ioprio_changed is not set until +* new weight and new ioprio_class are updated. +*/ +smp_wmb (); + iog->entity.ioprio_changed =1 ; + }else { + iog->entity.new_weight = iocg->weight; + iog->entity.new_ioprio_class = + iocg->ioprio_class; + +/* The same as above */ +smp_wmb (); + iog->entity.ioprio_changed =1 ; + } + } + } +spin_unlock_irq (&iocg->lock); + +cgroup_unlock (); + +free_newpn: +if (!keep_newpn) +kfree (newpn); +free_buf: +kfree (buf); +return ret; +} +#define SHOW_FUNCTION (__VAR) \ static u64 io_cgroup_##__VAR##_read(struct cgroup *cgroup, \ struct cftype *cftype) \
@@ -1346,6 +1586,7 @@ static int io_cgroup_##__VAR##_write(struct cgroup *cgroup, \struct io_cgroup *iocg; \struct io_group *iog; \struct hlist_node *n; \ +struct io_policy_node *pn; \ \if (val < (__MIN) || val > (__MAX)) \return -EINVAL ; \
@@ -1358,6 +1599,9 @@ static int io_cgroup_##__VAR##_write(struct cgroup *cgroup, \spin_lock_irq (&iocg->lock); \ iocg->__VAR = (unsigned long )val; \ hlist_for_each_entry(iog, n, &iocg->group_data, group_node) { \ + pn =policy_search_node (iocg, iog->dev); \ +if (pn) \ +continue ; \ iog->entity.new_##__VAR = (unsigned long)val; \smp_wmb (); \ iog->entity.ioprio_changed =1 ; \
@@ -1496,6 +1740,12 @@ static int io_cgroup_disk_dequeue_read(struct cgroup *cgroup,struct cftype bfqio_files[] = { { + .name ="policy" , + .read_seq_string = io_cgroup_policy_read, + .write_string = io_cgroup_policy_write, + .max_write_len =256 , + }, + { .name ="weight" , .read_u64 = io_cgroup_weight_read, .write_u64 = io_cgroup_weight_write,
@@ -1547,6 +1797,7 @@ static struct cgroup_subsys_state *iocg_create(struct cgroup_subsys *subsys,INIT_HLIST_HEAD (&iocg->group_data); iocg->weight =IO_DEFAULT_GRP_WEIGHT ; iocg->ioprio_class =IO_DEFAULT_GRP_CLASS ; +INIT_LIST_HEAD (&iocg->policy_list);return &iocg->css; }
@@ -1649,7 +1900,7 @@ io_group_chain_alloc(struct request_queue *q, void *key, struct cgroup *cgroup)sscanf (dev_name (bdi->dev),"%u:%u" , &major, &minor); iog->dev =MKDEV (major, minor); -io_group_init_entity (iocg, iog); +io_group_init_entity (iocg, iog, iog->dev); iog->my_entity = &iog->entity;atomic_set (&iog->ref,0 );
@@ -2121,6 +2372,7 @@ static void iocg_destroy(struct cgroup_subsys *subsys, struct cgroup *cgroup)struct io_group *iog;struct elv_fq_data *efqd;unsigned long uninitialized_var (flags ); +struct io_policy_node *pn, *pntmp;/* * io groups are linked in two lists. One list is maintained
@@ -2160,6 +2412,11 @@ remove_entry: goto remove_entry; done: +list_for_each_entry_safe (pn, pntmp, &iocg->policy_list, node) { +policy_delete_node (pn); +kfree (pn); + } +free_css_id (&io_subsys, &iocg->css);rcu_read_unlock ();BUG_ON (!hlist_empty (&iocg->group_data));
block/elevator-fq.h +10 -0
@@ -274,6 +274,13 @@ struct io_group {struct request_list rl; }; +struct io_policy_node { +struct list_head node; +dev_t dev; +unsigned int weight; +unsigned short ioprio_class; +}; +/** * struct io_cgroup - io cgroup data structure. * @css: subsystem state for io in the containing cgroup.
@@ -291,6 +298,9 @@ struct io_cgroup {unsigned int weight;unsigned short ioprio_class; +/* list of io_policy_node */ +struct list_head policy_list; +spinlock_t lock;struct hlist_head group_data; };
Signature · 1 line
1.6.0.6
PATCH 24/24 map sync requests to group using bio tracking info
In reply to a message not in the archiveo sync requests are mapped to the cgroup submitting tasks belongs to. This is an experimental patch where sync requets can be mapped to the group using bio tracking information and not submitting task's context.
o This patch implements this functionality only for noop, deadline and AS.
o Introducing this patch for experimental purposes to see if it is really meaningful or not.
o This behavior is turned on by setting /sys/block/<disk>/queue/iosched/map_sync varibale.
--- block/as-iosched.c | 1 + block/deadline-iosched.c | 1 + block/elevator-fq.c | 7 ++++++- block/elevator-fq.h | 9 +++++++++ block/noop-iosched.c | 1 + 5 files changed, 18 insertions(+), 1 deletions(-)
block/as-iosched.c +1 -0
@@ -1768,6 +1768,7 @@ static struct elv_fs_entry as_attrs[] = {ELV_ATTR (fairness),ELV_ATTR (slice_sync),ELV_ATTR (group_idle), +ELV_ATTR (map_sync), #endif __ATTR_NULL };
block/deadline-iosched.c +1 -0
@@ -465,6 +465,7 @@ static struct elv_fs_entry deadline_attrs[] = {ELV_ATTR (fairness),ELV_ATTR (slice_sync),ELV_ATTR (group_idle), +ELV_ATTR (map_sync), #endif __ATTR_NULL };
block/elevator-fq.c +6 -1
@@ -2073,6 +2073,7 @@ struct io_group *io_get_io_group_bio(struct request_queue *q, struct bio *bio, int create) {struct page *page =NULL ; +struct elv_fq_data *efqd = &q->elevator->efqd;/* * Determine the group from task context. Even calls from
@@ -2091,7 +2092,7 @@ struct io_group *io_get_io_group_bio(struct request_queue *q, struct bio *bio, }/* Map the sync bio to the right group using task context */ -if (elv_bio_sync (bio)) +if (elv_bio_sync (bio) && !efqd->map_sync) goto sync;#ifdef CONFIG_TRACK_ASYNC_CONTEXT
@@ -2812,6 +2813,8 @@ SHOW_FUNCTION(elv_slice_async_show, efqd->elv_slice[0], 1);EXPORT_SYMBOL (elv_slice_async_show);SHOW_FUNCTION (elv_fairness_show, efqd->fairness,0 );EXPORT_SYMBOL (elv_fairness_show); +SHOW_FUNCTION (elv_map_sync_show, efqd->map_sync,0 ); +EXPORT_SYMBOL (elv_map_sync_show);#undef SHOW_FUNCTION#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) \
@@ -2838,6 +2841,8 @@ STORE_FUNCTION(elv_slice_async_store, &efqd->elv_slice[0], 1, UINT_MAX, 1);EXPORT_SYMBOL (elv_slice_async_store);STORE_FUNCTION (elv_fairness_store, &efqd->fairness,0 ,1 ,0 );EXPORT_SYMBOL (elv_fairness_store); +STORE_FUNCTION (elv_map_sync_store, &efqd->map_sync,0 ,1 ,0 ); +EXPORT_SYMBOL (elv_map_sync_store);#undef STORE_FUNCTIONvoid elv_schedule_dispatch (struct request_queue *q)
block/elevator-fq.h +9 -0
@@ -347,6 +347,12 @@ struct elv_fq_data {* queue before new queue is scheduled in */ unsigned int fairness; + +/* +* Get io group bio belongs to from bio and not from submitting task +* context +*/ +unsigned int map_sync; };/* Logging facilities. */
@@ -551,6 +557,9 @@ extern void elv_put_iog(struct io_group *iog);extern ssize_t elv_group_idle_show (struct elevator_queue *q,char *name);extern ssize_t elv_group_idle_store (struct elevator_queue *q,const char *name,size_t count); +extern ssize_t elv_map_sync_show (struct elevator_queue *q,char *name); +extern ssize_t elv_map_sync_store (struct elevator_queue *q,const char *name, +size_t count);static inline void elv_get_iog (struct io_group *iog) {atomic_inc (&iog->ref);
block/noop-iosched.c +1 -0
@@ -87,6 +87,7 @@ static struct elv_fs_entry noop_attrs[] = {ELV_ATTR (fairness),ELV_ATTR (slice_sync),ELV_ATTR (group_idle), +ELV_ATTR (map_sync), __ATTR_NULL };#endif
Signature · 1 line
1.6.0.6
Hi Vivek,
Here are some test results for normal reads and write for IO Controller V7 by fio. Tested with "fairness == 0". It seems performance gets better comparing with V6.
Mode Normal read | Random read | Normal write | Random write | Direct read | Direct Write
2.6.31-rc1 71,613KiB/s 3,606KiB/s 66,250KiB/s 9,420KiB/s 51,535KiB/s 55,752KiB/s
V7 70,540KiB/s 3,551KiB/s 64,548KiB/s 9,677KiB/s 53,530KiB/s 54,145KiB/s
Performance -1.5% -1.5% -2.6% +2.7% +3.9% -2.9%
Quoted 402 lines · Vivek Goyal
Hi All,
Here is the V7 of the IO controller patches generated on top of 2.6.31-rc4.
For ease of patching, a consolidated patch is available here.
http://people.redhat.com/~vgoyal/io-controller/io-scheduler-based-io-controller-v7.patch
Previous versions of the patches was posted here.
(V1) http://lkml.org/lkml/2009/3/11/486
(V2) http://lkml.org/lkml/2009/5/5/275
(V3) http://lkml.org/lkml/2009/5/26/472
(V4) http://lkml.org/lkml/2009/6/8/580
(V5) http://lkml.org/lkml/2009/6/19/279
(V6) http://lkml.org/lkml/2009/7/2/369Changes from V6
===============
- Introduced the notion ofgroup_idlingwhere we idle for next request to come from the same group before we expire it. It is along the lines of cfq'sslice_idlething to provide fairness. Switching to group idling now helps in the sense that we don't have to rely whether queue idling was turned on or not by CFQ. It becomes too much of debugging pain with different work loads and different kind of storage media. Introduction ofgroup_idleshould help.- Moved some of the code like dynamic queue idling update, arming queue idling timer, keeping track of average think time etc back to CFQ. With group idling we don't need it now. Reduce the amount of change.
- Enabled cfq's close cooperator functionality in groups. So far this worked only in root group. Now it should work in non-root groups also.
- Got rid of the patch where we calculated disk time based on average disk rate in some circumstances. It was giving bad numbers in early queue deletion cases. Also did not think that it was helping a lot. Remvoed it for the time being.
- Added an experimental patch to map sync requests using bio tracking info and not task context. This is only for noop, deadline and AS.
- Got rid of experimental patch of idling for async queues. Don't think it was helping.
- Got rid of
wait_busyandwait_busy_donelogic from queue. Instead implemented it for groups.- Introduced
oom_ioqto accomodateoom_cfqqchange recently.- Broke-up
elv_init_ioq()fn into smaller functions. It had 7 arguments and looked complicated.- Fixed a bug in
blk_queue_io_group_congested(). Thanks to Munehiro Ikeda.- Merged gui's patch to fix the cgroup file format issue.
- Merged gui's patch to update per group congestion limit when
q->nr_group_requestsis updated.- Fixed a bug where close cooperation will not work if we wait for all the requests to finish from previous queue.
- Fixed group deletion accouting where deletion from idle tree were also appearing in the log.
- Got rid of
busy_rt_queuesinfrastructure.- Got rid of
elv_ioq_request_dispatched(). An helper function just to increment a variable.Limitations
===========- This IO controller provides the bandwidth control at the IO scheduler level (leaf node in stacked hiearchy of logical devices). So there can be cases (depending on configuration) where application does not see proportional BW division at higher logical level device.
LWN has written an article about the issue here.
http://lwn.net/Articles/332839/How to solve the issue of fairness at higher level logical devices
==================================================================
(Do we really need it? That's not where the contention for resources is.)Couple of suggestions have come forward.
- Implement IO control at IO scheduler layer and then with the help of some daemon, adjust the weight on underlying devices dynamiclly, depending on what kind of BW gurantees are to be achieved at higher level logical block devices.
- Also implement a higher level IO controller along with IO scheduler based controller and let user choose one depending on his needs.
A higher level controller does not know about the assumptions/policies of unerldying IO scheduler, hence it has the potential to break down the IO scheduler's policy with-in cgroup. A lower level controller can work with IO scheduler much more closely and efficiently.
Other active IO controller developments
=======================================IO throttling
-------------This is a max bandwidth controller and not the proportional one. Secondly it is a second level controller which can break the IO scheduler's policy/assumtions with-in cgroup.
dm-ioband
---------This is a proportional bandwidth controller implemented as device mapper driver. It is also a second level controller which can break the IO scheduler's policy/assumptions with-in cgroup.
TODO
====
- code cleanups, testing, bug fixing, optimizations, benchmarking etc...Testing
=======I have been able to do some testing as follows. All my testing is with ext3 file system with a SATA drive which supports queue depth of 31.
Test1 (Isolation between two KVM virtual machines)
==================================================
Created two KVM virtual machines. Partitioned a disk on host in two partitions and gave one partition to each virtual machine. Put both the virtual machines in two different cgroup of weight 1000 and 500 each. Virtual machines created ext3 file system on the partitions exported from host and did buffered writes. Host seems writes as synchronous and virtual machine with higher weight gets double the disk time of virtual machine of lower weight. Used deadline scheduler in this test case.Some more details about configuration are in documentation patch.
Test2 (Fairness for synchronous reads)
======================================
- Two dd in two cgroups with cgrop weights 1000 and 500. Ran two "dd" in those cgroups (With CFQ scheduler and /sys/block/<device>/queue/fairness = 1)Higher weight dd finishes first and at that point of time my script takes care of reading cgroup files io.disk_time and io.disk_sectors for both the groups and display the results.
dd if=/mnt/$BLOCKDEV/zerofile1 of=/dev/null &
dd if=/mnt/$BLOCKDEV/zerofile2 of=/dev/null &234179072 bytes (234 MB) copied, 3.9065 s, 59.9 MB/s 234179072 bytes (234 MB) copied, 5.19232 s, 45.1 MB/s
group1 time=8 16 2471 group1 sectors=8 16 457840 group2 time=8 16 1220 group2 sectors=8 16 225736
First two fields in time and sectors statistics represent major and minor number of the device. Third field represents disk time in milliseconds and number of sectors transferred respectively.
This patchset tries to provide fairness in terms of disk time received. group1 got almost double of group2 disk time (At the time of first dd finish). These time and sectors statistics can be read using io.disk_time and io.disk_sector files in cgroup. More about it in documentation file.
Test3 (Reader Vs Buffered Writes)
================================
Buffered writes can be problematic and can overwhelm readers, especially with noop and deadline. IO controller can provide isolation between readers and buffered (async) writers.First I ran the test without io controller to see the severity of the issue. Ran a hostile writer and then after 10 seconds started a reader and then monitored the completion time of reader. Reader reads a 256 MB file. Tested this with noop scheduler.
sample script
------------
sync
echo 3 >/proc/sys/vm/drop_caches
time dd if=/dev/zero of=/mnt/sdb/reader-writer-zerofile bs=4K count=2097152 conv=fdatasync &
sleep 10
time dd if=/mnt/sdb/256M-file of=/dev/null &Results
-------
8589934592 bytes (8.6 GB) copied, 106.045 s, 81.0 MB/s (Writer) 268435456 bytes (268 MB) copied, 96.5237 s, 2.8 MB/s (Reader)Now it was time to test io controller whether it can provide isolation between readers and writers with noop. I created two cgroups of weight 1000 each and put reader in group1 and writer in group 2 and ran the test again. Upon comletion of reader, my scripts read io.dis_time and io.disk_group cgroup files to get an estimate how much disk time each group got and how many sectors each group did IO for.
For more accurate accounting of disk time for buffered writes with queuing hardware I had to set /sys/block/<disk>/queue/iosched/fairness to "1".
sample script
-------------
echo $$ > /cgroup/bfqio/test2/tasks
dd if=/dev/zero of=/mnt/$BLOCKDEV/testzerofile bs=4K count=2097152 & sleep 10
echo noop >/sys/block/$BLOCKDEV/queue/scheduler
echo 1 >/sys/block/$BLOCKDEV/queue/iosched/fairnessecho $$ > /cgroup/bfqio/test1/tasks
dd if=/mnt/$BLOCKDEV/256M-file of=/dev/null &
wait $!
# Some code for reading cgroup files upon completion of reader.
-------------------------Results
=======
268435456 bytes (268 MB) copied, 6.65819 s, 40.3 MB/s (Reader)group1 time=8 16 3063 group1 sectors=8 16 524808
group2 time=8 16 3071 group2 sectors=8 16 441752Note, reader finishes now much lesser time and both group1 and group2 got almost 3 seconds of disk time. Hence io-controller provides isolation from buffered writes.
Test4 (AIO)
===========AIO reads
-----------
Set up two fio, AIO read jobs in two cgroup with weight 1000 and 500 respectively. I am using cfq scheduler. Following are some lines from my test script.---------------------------------------------------------------
echo 1000 > /cgroup/bfqio/test1/io.weight
echo 500 > /cgroup/bfqio/test2/io.weightfio_args="--ioengine=libaio --rw=read --size=512M --direct=1" echo 1 >
/sys/block/$BLOCKDEV/queue/iosched/fairnessecho $$ > /cgroup/bfqio/test1/tasks
fio $fio_args --name=test1 --directory=/mnt/$BLOCKDEV/fio1/ --output=/mnt/$BLOCKDEV/fio1/test1.log --exec_postrun="../read-and-display-group-stats.sh $maj_dev $minor_dev" &echo $$ > /cgroup/bfqio/test2/tasks
fio $fio_args --name=test2 --directory=/mnt/$BLOCKDEV/fio2/ --output=/mnt/$BLOCKDEV/fio2/test2.log &
----------------------------------------------------------------test1 and test2 are two groups with weight 1000 and 500 respectively. "
read-and-display-group-stats.sh" is one small script which reads the test1 and test2 cgroup files to determine how much disk time each group got till first fio job finished.Results
------
test1 statistics: time=8 16 22403 sectors=8 16 1049640
test2 statistics: time=8 16 11400 sectors=8 16 552864Above shows that by the time first fio (higher weight), finished, group test1 got 22403 ms of disk time and group test2 got 11400 ms of disk time. similarly the statistics for number of sectors transferred are also shown.
Note that disk time given to group test1 is almost double of group2 disk time.
AIO writes
----------
Set up two fio, AIO direct write jobs in two cgroup with weight 1000 and 500 respectively. I am using cfq scheduler. Following are some lines from my test script.------------------------------------------------
echo 1000 > /cgroup/bfqio/test1/io.weight
echo 500 > /cgroup/bfqio/test2/io.weight fio_args="--ioengine=libaio --rw=write --size=512M --direct=1"echo 1 >
/sys/block/$BLOCKDEV/queue/iosched/fairnessecho $$ > /cgroup/bfqio/test1/tasks
fio $fio_args --name=test1 --directory=/mnt/$BLOCKDEV/fio1/ --output=/mnt/$BLOCKDEV/fio1/test1.log --exec_postrun="../read-and-display-group-stats.sh $maj_dev $minor_dev" &echo $$ > /cgroup/bfqio/test2/tasks
fio $fio_args --name=test2 --directory=/mnt/$BLOCKDEV/fio2/ --output=/mnt/$BLOCKDEV/fio2/test2.log &
-------------------------------------------------test1 and test2 are two groups with weight 1000 and 500 respectively. "
read-and-display-group-stats.sh" is one small script which reads the test1 and test2 cgroup files to determine how much disk time each group got till first fio job finished.Following are the results.
test1 statistics: time=8 16 29085 sectors=8 16 1049656
test2 statistics: time=8 16 14652 sectors=8 16 516728Above shows that by the time first fio (higher weight), finished, group test1 got 28085 ms of disk time and group test2 got 14652 ms of disk time. similarly the statistics for number of sectors transferred are also shown.
Note that disk time given to group test1 is almost double of group2 disk time.
Test5 (Fairness for async writes, Buffered Write Vs Buffered Write)
===================================================================
Fairness for async writes is tricky and biggest reason is that async writes are cached in higher layers (page cahe) as well as possibly in file system layer also (btrfs, xfs etc), and are dispatched to lower layers not necessarily in proportional manner.For example, consider two dd threads reading
/dev/zeroas input file and doing writes of huge files. Very soon we will crossvm_dirty_ratioand dd thread will be forced to write out some pages to disk before more pages can be dirtied. But not necessarily dirty pages of same thread are picked. It can very well pick the inode of lesser priority dd thread and do some writeout. So effectively higher weight dd is doing writeouts of lower weight dd pages and we don't see service differentation.IOW, the core problem with async write fairness is that higher weight thread does not throw enought IO traffic at IO controller to keep the queue continuously backlogged. In my testing, there are many .2 to .8 second intervals where higher weight queue is empty and in that duration lower weight queue get lots of job done giving the impression that there was no service differentiation.
In summary, from IO controller point of view async writes support is there. Because page cache has not been designed in such a manner that higher prio/weight writer can do more write out as compared to lower prio/weight writer, gettting service differentiation is hard and it is visible in some cases and not visible in some cases.
Do we really care that much for fairness among two writer cgroups? One can choose to do direct writes or sync writes if fairness for writes really matters for him.
Following is the only case where it is hard to ensure fairness between cgroups.
- Buffered writes Vs Buffered Writes.
So to test async writes I created two partitions on a disk and created ext3 file systems on both the partitions. Also created two cgroups and generated lots of write traffic in two cgroups (50 fio threads) and watched the disk time statistics in respective cgroups at the interval of 2 seconds. Thanks to ryo tsuruta for the test case.
*****************************************************************
sync
echo 3 >/proc/sys/vm/drop_cachesfio_args="--size=64m --rw=write --numjobs=50 --group_reporting"
echo $$ > /cgroup/bfqio/test1/tasks
fio $fio_args --name=test1 --directory=/mnt/sdd1/fio/ --output=/mnt/sdd1/fio/test1.log &echo $$ > /cgroup/bfqio/test2/tasks
fio $fio_args --name=test2 --directory=/mnt/sdd2/fio/ --output=/mnt/sdd2/fio/test2.log &
***********************************************************************And watched the disk time and sector statistics for the both the cgroups every 2 seconds using a script. How is snippet from output.
test1 statistics: time=8 48 1315 sectors=8 48 55776 dq=8 48 1
test2 statistics: time=8 48 633 sectors=8 48 14720 dq=8 48 2test1 statistics: time=8 48 5586 sectors=8 48 339064 dq=8 48 2
test2 statistics: time=8 48 2985 sectors=8 48 146656 dq=8 48 3test1 statistics: time=8 48 9935 sectors=8 48 628728 dq=8 48 3
test2 statistics: time=8 48 5265 sectors=8 48 278688 dq=8 48 4test1 statistics: time=8 48 14156 sectors=8 48 932488 dq=8 48 6
test2 statistics: time=8 48 7646 sectors=8 48 412704 dq=8 48 7test1 statistics: time=8 48 18141 sectors=8 48 1231488 dq=8 48 10
test2 statistics: time=8 48 9820 sectors=8 48 548400 dq=8 48 8test1 statistics: time=8 48 21953 sectors=8 48 1485632 dq=8 48 13
test2 statistics: time=8 48 12394 sectors=8 48 698288 dq=8 48 10test1 statistics: time=8 48 25167 sectors=8 48 1705264 dq=8 48 13
test2 statistics: time=8 48 14042 sectors=8 48 817808 dq=8 48 10First two fields in time and sectors statistics represent major and minor number of the device. Third field represents disk time in milliseconds and number of sectors transferred respectively.
So disk time consumed by group1 is almost double of group2 in this case.
Your feedback is welcome.
Thanks
Vivek
Signature · 2 lines
Regards Gui Jianfeng
PATCH 2/24 io-controller: Core of the B-WF2Q+ scheduler
In reply to Vivek GoyalThis is core of the BFQ(B-WF2Q+) scheduler originally implemented by Paolo and Fabio in BFQ patches. Since then I have taken relevant pieces from BFQ and continued the work on IO controller. It is not the full patch. Just pulled out the some bits to show how core scheduler looks like and it becomes easier to review.
Originally BFQ code was hierarchical. This patch only shows non-hierarchical bits. Hierarhical code comes in later patches.
This code is the building base of introducing fair queuing logic in common elevator layer so that it can be used by all the four IO schedulers. In later patches, CFQ's weighted round robin scheduler will be replaced with B-WF2Q+ scheduler.
Also note that BFQ originally provided fairness in-terms of number of sectors of IO done by the queue. It has been modified to provide fairness in terms of disk time (like CFQ allocate disk time slices proportionate to prio/weight).
B-WF2Q+ is based on WF2Q+, that is described in [2], together with H-WF2Q+, while the augmented tree used to implement B-WF2Q+ with O(log N) complexity derives from the one introduced with EEVDF in [3].
[1] P. Valente and F. Checconi, ``High Throughput Disk Scheduling with Deterministic Guarantees on Bandwidth Distribution,'' to be published.
http://algo.ing.unimo.it/people/paolo/disk_sched/bfq.pdf
[2] Jon C.R. Bennett and H. Zhang, ``Hierarchical Packet Fair Queueing
Algorithms,'' IEEE/ACM Transactions on Networking, 5(5):675-689,
Oct 1997.
http://www.cs.cmu.edu/~hzhang/papers/TON-97-Oct.ps.gz[3] I. Stoica and H. Abdel-Wahab, ``Earliest Eligible Virtual Deadline
First: A Flexible and Accurate Mechanism for Proportional Share Resource Allocation,'' technical report.
http://www.cs.berkeley.edu/~istoica/papers/eevdf-tr-95.pdf
--- block/elevator-fq.c | 715 +++++++++++++++++++++++++++++++++++++++++++++++++++ block/elevator-fq.h | 172 ++++++++++++ 2 files changed, 887 insertions(+), 0 deletions(-) create mode 100644 block/elevator-fq.c create mode 100644 block/elevator-fq.h
block/elevator-fq.c new file +715 -0
@@ -0,0 +1,715 @@ +/* +* elevator fair queuing Layer. Uses B-WF2Q+ hierarchical scheduler for +* fair queuing. +* +* Based on ideas and code from CFQ: +* Copyright (C) 2003 Jens Axboe <[email protected]> +* +* Copyright (C) 2008 Fabio Checconi <[email protected]> +* Paolo Valente <[email protected]> +* +* Copyright (C) 2009 Vivek Goyal <[email protected]> +* Nauman Rafique <[email protected]> +*/ + +#include <linux/blkdev.h> +#include "elevator-fq.h" + +#define IO_SERVICE_TREE_INIT ((struct io_service_tree) \ + { RB_ROOT, RB_ROOT, NULL, NULL, 0, 0 }) + +/* Mainly the BFQ scheduling code Follows */ + +/* +* Shift for timestamp calculations. This actually limits the maximum +* service allowed in one timestamp delta (small shift values increase it), +* the maximum total weight that can be used for the queues in the system +* (big shift values increase it), and the period of virtual time wraparounds. +*/ +#define WFQ_SERVICE_SHIFT 22 + +/** +* bfq_gt - compare two timestamps. +* @a: first ts. +* @b: second ts. +* +* Return @a > @b, dealing with wrapping correctly. +*/ +static inline int bfq_gt (u64 a,u64 b) +{ +return (s64)(a - b) >0 ; +} + +/** +* bfq_delta - map service into the virtual time domain. +* @service: amount of service. +* @weight: scale factor. +*/ +static inline u64 bfq_delta (unsigned long service,unsigned int weight) +{ +u64 d = (u64 )service <<WFQ_SERVICE_SHIFT ; + +do_div (d, weight); +return d; +} + +/** +* bfq_calc_finish - assign the finish time to an entity. +* @entity: the entity to act upon. +* @service: the service to be charged to the entity. +*/ +static inline void bfq_calc_finish (struct io_entity *entity, +unsigned long service) +{ +BUG_ON (entity->weight ==0 ); + + entity->finish = entity->start +bfq_delta (service, entity->weight); +} + +static inline struct io_queue *io_entity_to_ioq (struct io_entity *entity) +{ +struct io_queue *ioq =NULL ; + +BUG_ON (entity ==NULL ); +if (entity->my_sched_data ==NULL ) + ioq = container_of(entity, struct io_queue, entity); +return ioq; +} + +/** +* io_entity_of - get an entity from a node. +* @node: the node field of the entity. +* +* Convert a node pointer to the relative entity. This is used only +* to simplify the logic of some functions and not as the generic +* conversion mechanism because, e.g., in the tree walking functions, +* the check for a %NULL value would be redundant. +*/ +static inline struct io_entity *io_entity_of (struct rb_node *node) +{ +struct io_entity *entity =NULL ; + +if (node !=NULL ) + entity = rb_entry(node, struct io_entity, rb_node); + +return entity; +} + +/** +* bfq_remove - remove an entity from a tree. +* @root: the tree root. +* @entity: the entity to remove. +*/ +static inline void bfq_remove (struct rb_root *root,struct io_entity *entity) +{ +BUG_ON (entity->tree != root); + + entity->tree =NULL ; +rb_erase (&entity->rb_node, root); +} + +/** +* bfq_idle_remove - remove an entity from the idle tree. +* @st: the service tree of the owning @entity. +* @entity: the entity being removed. +*/ +static void bfq_idle_remove (struct io_service_tree *st, +struct io_entity *entity) +{ +struct rb_node *next; + +BUG_ON (entity->tree != &st->idle); + +if (entity == st->first_idle) { + next =rb_next (&entity->rb_node); + st->first_idle =io_entity_of (next); + } + +if (entity == st->last_idle) { + next =rb_prev (&entity->rb_node); + st->last_idle =io_entity_of (next); + } + +bfq_remove (&st->idle, entity); +} + +/** +* bfq_insert - generic tree insertion. +* @root: tree root. +* @entity: entity to insert. +* +* This is used for the idle and the active tree, since they are both +* ordered by finish time. +*/ +static void bfq_insert (struct rb_root *root,struct io_entity *entity) +{ +struct io_entity *entry; +struct rb_node **node = &root->rb_node; +struct rb_node *parent =NULL ; + +BUG_ON (entity->tree !=NULL ); + +while (*node !=NULL ) { + parent = *node; + entry = rb_entry(parent, struct io_entity, rb_node); + +if (bfq_gt (entry->finish, entity->finish)) + node = &parent->rb_left; +else + node = &parent->rb_right; + } + +rb_link_node (&entity->rb_node, parent, node); +rb_insert_color (&entity->rb_node, root); + + entity->tree = root; +} + +/** +* bfq_update_min - update the min_start field of a entity. +* @entity: the entity to update. +* @node: one of its children. +* +* This function is called when @entity may store an invalid value for +* min_start due to updates to the active tree. The function assumes +* that the subtree rooted at @node (which may be its left or its right +* child) has a valid min_start value. +*/ +static inline void bfq_update_min (struct io_entity *entity, +struct rb_node *node) +{ +struct io_entity *child; + +if (node !=NULL ) { + child = rb_entry(node, struct io_entity, rb_node); +if (bfq_gt (entity->min_start, child->min_start)) + entity->min_start = child->min_start; + } +} + +/** +* bfq_update_active_node - recalculate min_start. +* @node: the node to update. +* +* @node may have changed position or one of its children may have moved, +* this function updates its min_start value. The left and right subtrees +* are assumed to hold a correct min_start value. +*/ +static inline void bfq_update_active_node (struct rb_node *node) +{ + struct io_entity *entity = rb_entry(node, struct io_entity, rb_node); + + entity->min_start = entity->start; +bfq_update_min (entity, node->rb_right); +bfq_update_min (entity, node->rb_left); +} + +/** +* bfq_update_active_tree - update min_start for the whole active tree. +* @node: the starting node. +* +* @node must be the deepest modified node after an update. This function +* updates its min_start using the values held by its children, assuming +* that they did not change, and then updates all the nodes that may have +* changed in the path to the root. The only nodes that may have changed +* are the ones in the path or their siblings. +*/ +static void bfq_update_active_tree (struct rb_node *node) +{ +struct rb_node *parent; + +up: +bfq_update_active_node (node); + + parent =rb_parent (node); +if (parent ==NULL ) +return ; + +if (node == parent->rb_left && parent->rb_right !=NULL ) +bfq_update_active_node (parent->rb_right); +else if (parent->rb_left !=NULL ) +bfq_update_active_node (parent->rb_left); + + node = parent; + goto up; +} + +/** +* bfq_active_insert - insert an entity in the active tree of its group/device. +* @st: the service tree of the entity. +* @entity: the entity being inserted. +* +* The active tree is ordered by finish time, but an extra key is kept +* per each node, containing the minimum value for the start times of +* its children (and the node itself), so it's possible to search for +* the eligible node with the lowest finish time in logarithmic time. +*/ +static void bfq_active_insert (struct io_service_tree *st, +struct io_entity *entity) +{ +struct rb_node *node = &entity->rb_node; + +bfq_insert (&st->active, entity); + +if (node->rb_left !=NULL ) + node = node->rb_left; +else if (node->rb_right !=NULL ) + node = node->rb_right; + +bfq_update_active_tree (node); +} + +static void bfq_get_entity (struct io_entity *entity) +{ +struct io_queue *ioq =io_entity_to_ioq (entity); + +if (ioq) +elv_get_ioq (ioq); +} + +static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +{ + entity->sched_data = &iog->sched_data; +} + +/** +* bfq_find_deepest - find the deepest node that an extraction can modify. +* @node: the node being removed. +* +* Do the first step of an extraction in an rb tree, looking for the +* node that will replace @node, and returning the deepest node that +* the following modifications to the tree can touch. If @node is the +* last node in the tree return %NULL. +*/ +static struct rb_node *bfq_find_deepest (struct rb_node *node) +{ +struct rb_node *deepest; + +if (node->rb_right ==NULL && node->rb_left ==NULL ) + deepest =rb_parent (node); +else if (node->rb_right ==NULL ) + deepest = node->rb_left; +else if (node->rb_left ==NULL ) + deepest = node->rb_right; +else { + deepest =rb_next (node); +if (deepest->rb_right !=NULL ) + deepest = deepest->rb_right; +else if (rb_parent (deepest) != node) + deepest =rb_parent (deepest); + } + +return deepest; +} + +/** +* bfq_active_remove - remove an entity from the active tree. +* @st: the service_tree containing the tree. +* @entity: the entity being removed. +*/ +static void bfq_active_remove (struct io_service_tree *st, +struct io_entity *entity) +{ +struct rb_node *node; + + node =bfq_find_deepest (&entity->rb_node); +bfq_remove (&st->active, entity); + +if (node !=NULL ) +bfq_update_active_tree (node); +} + +/** +* bfq_idle_insert - insert an entity into the idle tree. +* @st: the service tree containing the tree. +* @entity: the entity to insert. +*/ +static void bfq_idle_insert (struct io_service_tree *st, +struct io_entity *entity) +{ +struct io_entity *first_idle = st->first_idle; +struct io_entity *last_idle = st->last_idle; + +if (first_idle ==NULL ||bfq_gt (first_idle->finish, entity->finish)) + st->first_idle = entity; +if (last_idle ==NULL ||bfq_gt (entity->finish, last_idle->finish)) + st->last_idle = entity; + +bfq_insert (&st->idle, entity); +} + +/** +* bfq_forget_entity - remove an entity from the wfq trees. +* @st: the service tree. +* @entity: the entity being removed. +* +* Update the device status and forget everything about @entity, putting +* the device reference to it, if it is a queue. Entities belonging to +* groups are not refcounted. +*/ +static void bfq_forget_entity (struct io_service_tree *st, +struct io_entity *entity) +{ +struct io_queue *ioq =NULL ; + +BUG_ON (!entity->on_st); + entity->on_st =0 ; + st->wsum -= entity->weight; + ioq =io_entity_to_ioq (entity); +if (!ioq) +return ; +elv_put_ioq (ioq); +} + +/** +* bfq_put_idle_entity - release the idle tree ref of an entity. +* @st: service tree for the entity. +* @entity: the entity being released. +*/ +static void bfq_put_idle_entity (struct io_service_tree *st, +struct io_entity *entity) +{ +bfq_idle_remove (st, entity); +bfq_forget_entity (st, entity); +} + +/** +* bfq_forget_idle - update the idle tree if necessary. +* @st: the service tree to act upon. +* +* To preserve the global O(log N) complexity we only remove one entry here; +* as the idle tree will not grow indefinitely this can be done safely. +*/ +static void bfq_forget_idle (struct io_service_tree *st) +{ +struct io_entity *first_idle = st->first_idle; +struct io_entity *last_idle = st->last_idle; + +if (RB_EMPTY_ROOT (&st->active) && last_idle !=NULL && + !bfq_gt (last_idle->finish, st->vtime)) { +/* +* Active tree is empty. Pull back vtime to finish time of +* last idle entity on idle tree. +* Rational seems to be that it reduces the possibility of +* vtime wraparound (bfq_gt(V-F) < 0). +*/ + st->vtime = last_idle->finish; + } + +if (first_idle !=NULL && !bfq_gt (first_idle->finish, st->vtime)) +bfq_put_idle_entity (st, first_idle); +} + + +static struct io_service_tree * +__bfq_entity_update_prio (struct io_service_tree *old_st, +struct io_entity *entity) +{ +struct io_service_tree *new_st = old_st; +struct io_queue *ioq =io_entity_to_ioq (entity); + +if (entity->ioprio_changed) { + old_st->wsum -= entity->weight; + entity->ioprio = entity->new_ioprio; + entity->ioprio_class = entity->new_ioprio_class; + entity->weight = entity->new_weight; + entity->ioprio_changed =0 ; + +/* +* Also update the scaled budget for ioq. Group will get the +* updated budget once ioq is selected to run next. +*/ +if (ioq) { +struct elv_fq_data *efqd = ioq->efqd; +/* +* elv_prio_to_slice() is defined in later patches +* where a slice length is calculated from the +* ioprio of the queue. +*/ + entity->budget =elv_prio_to_slice (efqd, ioq); + } + +/* +* NOTE: here we may be changing the weight too early, +* this will cause unfairness. The correct approach +* would have required additional complexity to defer +* weight changes to the proper time instants (i.e., +* when entity->finish <= old_st->vtime). +*/ + new_st =io_entity_service_tree (entity); + new_st->wsum += entity->weight; + +if (new_st != old_st) + entity->start = new_st->vtime; + } + +return new_st; +} + +/** +* bfq_update_vtime - update vtime if necessary. +* @st: the service tree to act upon. +* +* If necessary update the service tree vtime to have at least one +* eligible entity, skipping to its start time. Assumes that the +* active tree of the device is not empty. +* +* NOTE: this hierarchical implementation updates vtimes quite often, +* we may end up with reactivated tasks getting timestamps after a +* vtime skip done because we needed a ->first_active entity on some +* intermediate node. +*/ +static void bfq_update_vtime (struct io_service_tree *st) +{ +struct io_entity *entry; +struct rb_node *node = st->active.rb_node; + + entry = rb_entry(node, struct io_entity, rb_node); +if (bfq_gt (entry->min_start, st->vtime)) { + st->vtime = entry->min_start; +bfq_forget_idle (st); + } +} + +/** +* bfq_first_active - find the eligible entity with the smallest finish time +* @st: the service tree to select from. +* +* This function searches the first schedulable entity, starting from the +* root of the tree and going on the left every time on this side there is +* a subtree with at least one eligible (start <= vtime) entity. The path +* on the right is followed only if a) the left subtree contains no eligible +* entities and b) no eligible entity has been found yet. +*/ +static struct io_entity *bfq_first_active_entity (struct io_service_tree *st) +{ +struct io_entity *entry, *first =NULL ; +struct rb_node *node = st->active.rb_node; + +while (node !=NULL ) { + entry = rb_entry(node, struct io_entity, rb_node); +left: +if (!bfq_gt (entry->start, st->vtime)) + first = entry; + +BUG_ON (bfq_gt (entry->min_start, st->vtime)); + +if (node->rb_left !=NULL ) { + entry =rb_entry (node->rb_left, + struct io_entity, rb_node); +if (!bfq_gt (entry->min_start, st->vtime)) { + node = node->rb_left; + goto left; + } + } +if (first !=NULL ) +break ; + node = node->rb_right; + } + +BUG_ON (first ==NULL && !RB_EMPTY_ROOT (&st->active)); +return first; +} + +/** +* __bfq_lookup_next_entity - return the first eligible entity in @st. +* @st: the service tree. +* +* Update the virtual time in @st and return the first eligible entity +* it contains. +*/ +static struct io_entity *__bfq_lookup_next_entity (struct io_service_tree *st) +{ +struct io_entity *entity; + +if (RB_EMPTY_ROOT (&st->active)) +return NULL ; + +bfq_update_vtime (st); + entity =bfq_first_active_entity (st); +BUG_ON (bfq_gt (entity->start, st->vtime)); + +return entity; +} + +/** +* bfq_lookup_next_entity - return the first eligible entity in @sd. +* @sd: the sched_data. +* @extract: if true the returned entity will be also extracted from @sd. +* +* NOTE: since we cache the next_active entity at each level of the +* hierarchy, the complexity of the lookup can be decreased with +* absolutely no effort just returning the cached next_active value; +* we prefer to do full lookups to test the consistency of * the data +* structures. +*/ +static struct io_entity *bfq_lookup_next_entity (struct io_sched_data *sd, +int extract) +{ +struct io_service_tree *st = sd->service_tree; +struct io_entity *entity; +int i; + +/* +* We should not call lookup when an entity is active, as doing lookup +* can result in an erroneous vtime jump. +*/ +BUG_ON (sd->active_entity !=NULL ); + +for (i =0 ; i <IO_IOPRIO_CLASSES ; i++, st++) { + entity =__bfq_lookup_next_entity (st); +if (entity !=NULL ) { +if (extract) { +bfq_active_remove (st, entity); + sd->active_entity = entity; + } +break ; + } + } + +return entity; +} + +/** +* __bfq_activate_entity - activate an entity. +* @entity: the entity being activated. +* +* Called whenever an entity is activated, i.e., it is not active and one +* of its children receives a new request, or has to be reactivated due to +* budget exhaustion. It uses the current budget of the entity (and the +* service received if @entity is active) of the queue to calculate its +* timestamps. +*/ +static void __bfq_activate_entity (struct io_entity *entity) +{ +struct io_sched_data *sd = entity->sched_data; +struct io_service_tree *st =io_entity_service_tree (entity); + +if (entity == sd->active_entity) { +BUG_ON (entity->tree !=NULL ); +/* +* If we are requeueing the current entity we have +* to take care of not charging to it service it has +* not received. +*/ +bfq_calc_finish (entity, entity->service); + entity->start = entity->finish; + sd->active_entity =NULL ; + }else if (entity->tree == &st->active) { +/* +* Requeueing an entity due to a change of some +* next_active entity below it. We reuse the old +* start time. +*/ +bfq_active_remove (st, entity); + }else if (entity->tree == &st->idle) { +/* +* Must be on the idle tree, bfq_idle_remove() will +* check for that. +*/ +bfq_idle_remove (st, entity); + entity->start =bfq_gt (st->vtime, entity->finish) ? + st->vtime : entity->finish; + }else { +/* +* The finish time of the entity may be invalid, and +* it is in the past for sure, otherwise the queue +* would have been on the idle tree. +*/ + entity->start = st->vtime; + st->wsum += entity->weight; +bfq_get_entity (entity); + +BUG_ON (entity->on_st); + entity->on_st =1 ; + } + + st =__bfq_entity_update_prio (st, entity); +bfq_calc_finish (entity, entity->budget); +bfq_active_insert (st, entity); +} + +/** +* bfq_activate_entity - activate an entity. +* @entity: the entity to activate. +*/ +static void bfq_activate_entity (struct io_entity *entity) +{ +__bfq_activate_entity (entity); +} + +/** +* __bfq_deactivate_entity - deactivate an entity from its service tree. +* @entity: the entity to deactivate. +* @requeue: if false, the entity will not be put into the idle tree. +* +* Deactivate an entity, independently from its previous state. If the +* entity was not on a service tree just return, otherwise if it is on +* any scheduler tree, extract it from that tree, and if necessary +* and if the caller did not specify @requeue, put it on the idle tree. +* +*/ +static int __bfq_deactivate_entity (struct io_entity *entity,int requeue) +{ +struct io_sched_data *sd = entity->sched_data; +struct io_service_tree *st =io_entity_service_tree (entity); +int was_active = entity == sd->active_entity; +int ret =0 ; + +if (!entity->on_st) +return 0 ; + +BUG_ON (was_active && entity->tree !=NULL ); + +if (was_active) { +bfq_calc_finish (entity, entity->service); + sd->active_entity =NULL ; + }else if (entity->tree == &st->active) +bfq_active_remove (st, entity); +else if (entity->tree == &st->idle) +bfq_idle_remove (st, entity); +else if (entity->tree !=NULL ) +BUG (); + +if (!requeue || !bfq_gt (entity->finish, st->vtime)) +bfq_forget_entity (st, entity); +else +bfq_idle_insert (st, entity); + +BUG_ON (sd->active_entity == entity); + +return ret; +} + +/** +* bfq_deactivate_entity - deactivate an entity. +* @entity: the entity to deactivate. +* @requeue: true if the entity can be put on the idle tree +*/ +static void bfq_deactivate_entity (struct io_entity *entity,int requeue) +{ +__bfq_deactivate_entity (entity, requeue); +} + +static void entity_served (struct io_entity *entity,unsigned long served) +{ +struct io_service_tree *st; + + st =io_entity_service_tree (entity); + entity->service += served; +BUG_ON (st->wsum ==0 ); + st->vtime +=bfq_delta (served, st->wsum); +bfq_forget_idle (st); +} + +/** +* io_flush_idle_tree - deactivate any entity on the idle tree of @st. +* @st: the service tree being flushed. +*/ +static void io_flush_idle_tree (struct io_service_tree *st) +{ +struct io_entity *entity = st->first_idle; + +for (; entity !=NULL ; entity = st->first_idle) +__bfq_deactivate_entity (entity,0 ); +}
block/elevator-fq.h new file +172 -0
172 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 3/24 io-controller: bfq support of in-class preemption
In reply to Vivek Goyalo Generally preemption is associated with cross class where if an request from RT class is pending it will preempt the ongoing BE or IDLE class request.
o CFQ also does in-class preemtions like a sync request queue preempting the async request queue. In that case it looks like preempting queue gains share and it is not fair.
o Implement the similar functionality in bfq so that we can retain the existing CFQ behavior.
o This patch creates a bypass path so that a queue can be put at the front of the service tree (add_front, similar to CFQ), so that it will be selected next to run. That's a different thing that in the process this queue gains share.
--- block/elevator-fq.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 5 deletions(-)
block/elevator-fq.c +41 -5
@@ -267,7 +267,8 @@ static void bfq_get_entity(struct io_entity *entity)elv_get_ioq (ioq); } -static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +static inline void +bfq_init_entity (struct io_entity *entity,struct io_group *iog) { entity->sched_data = &iog->sched_data; }
@@ -580,7 +581,7 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd,* service received if @entity is active) of the queue to calculate its * timestamps. */ -static void __bfq_activate_entity (struct io_entity *entity) +static void __bfq_activate_entity (struct io_entity *entity,int add_front) {struct io_sched_data *sd = entity->sched_data;struct io_service_tree *st =io_entity_service_tree (entity);
@@ -625,7 +626,42 @@ static void __bfq_activate_entity(struct io_entity *entity) } st =__bfq_entity_update_prio (st, entity); -bfq_calc_finish (entity, entity->budget); +/* +* This is to emulate cfq like functionality where preemption can +* happen with-in same class, like sync queue preempting async queue +* May be this is not a very good idea from fairness point of view +* as preempting queue gains share. Keeping it for now. +*/ +if (add_front) { +struct io_entity *next_entity; + +/* +* Determine the entity which will be dispatched next +* Use sd->next_active once hierarchical patch is applied +*/ + next_entity =bfq_lookup_next_entity (sd,0 ); + +if (next_entity && next_entity != entity) { +struct io_service_tree *new_st; +u64 delta; + + new_st =io_entity_service_tree (next_entity); + +/* +* At this point, both entities should belong to +* same service tree as cross service tree preemption +* is automatically taken care by algorithm +*/ +BUG_ON (new_st != st); + entity->finish = next_entity->finish -1 ; + delta =bfq_delta (entity->budget, entity->weight); + entity->start = entity->finish - delta; +if (bfq_gt (entity->start, st->vtime)) + entity->start = st->vtime; + } + }else { +bfq_calc_finish (entity, entity->budget); + }bfq_active_insert (st, entity); }
@@ -633,9 +669,9 @@ static void __bfq_activate_entity(struct io_entity *entity)* bfq_activate_entity - activate an entity. * @entity: the entity to activate. */ -static void bfq_activate_entity (struct io_entity *entity) +static void bfq_activate_entity (struct io_entity *entity,int add_front) { -__bfq_activate_entity (entity); +__bfq_activate_entity (entity, add_front); }/**
Signature · 1 line
1.6.0.6
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 66 lines · Vivek Goyal
o Generally preemption is associated with cross class where if an request from RT class is pending it will preempt the ongoing BE or IDLE class request.
o CFQ also does in-class preemtions like a sync request queue preempting the async request queue. In that case it looks like preempting queue gains share and it is not fair.
o Implement the similar functionality in bfq so that we can retain the existing CFQ behavior.
o This patch creates a bypass path so that a queue can be put at the front of the service tree (
add_front, similar to CFQ), so that it will be selected next to run. That's a different thing that in the process this queue gains share.Signed-off-by Vivek Goyal <[email protected]>--- block/elevator-fq.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 5 deletions(-)block/elevator-fq.c +20
-3@@ -267,7 +267,8 @@ static void bfq_get_entity(struct io_entity *entity)elv_get_ioq (ioq); } -static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +static inline void +bfq_init_entity (struct io_entity *entity,struct io_group *iog) { entity->sched_data = &iog->sched_data; }@@ -580,7 +581,7 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd,* service received if @entity is active) of the queue to calculate its * timestamps. */ -static void __bfq_activate_entity (struct io_entity *entity) +static void __bfq_activate_entity (struct io_entity *entity,int add_front) {struct io_sched_data *sd = entity->sched_data;struct io_service_tree *st =io_entity_service_tree (entity);@@ -625,7 +626,42 @@ static void __bfq_activate_entity(struct io_entity *entity) } st =__bfq_entity_update_prio (st, entity); -bfq_calc_finish (entity, entity->budget); +/* +* This is to emulate cfq like functionality where preemption can +* happen with-in same class, like sync queue preempting async queue +* May be this is not a very good idea from fairness point of view +* as preempting queue gains share. Keeping it for now. +*/ +if (add_front) { +struct io_entity *next_entity; + +/* +* Determine the entity which will be dispatched next +* Use sd->next_active once hierarchical patch is applied +*/ + next_entity =bfq_lookup_next_entity (sd,0 ); + +if (next_entity && next_entity != entity) { +struct io_service_tree *new_st;
block/elevator-fq.c static void __bfq_activate_entity(struct io_entity *entity) · line 655
Quoted 10 lines
block/elevator-fq.c +10
-0+u64 delta; + + new_st =io_entity_service_tree (next_entity); + +/* +* At this point, both entities should belong to +* same service tree as cross service tree preemption +* is automatically taken care by algorithm +*/ +BUG_ON (new_st != st);
Hi Vivek,
I don't quite understand how cross service tree preemption is taken care by algorithm, but I've hit this bug while doing some RT I/O and then killing it.
$ ionice -c 1 dd if=/dev/zero of=/tmp/foo bs=1M count=1000 & $ killall dd
------------[ cut here ]------------ kernel BUG at block/elevator-fq.c:963! invalid opcode: 0000 [#1] SMP last sysfs file: /sys/block/sdb/size Modules linked in: usb_storage netconsole ipt_REJECT xt_tcpudp iptable_filter ip_tables x_tables bridge stp ipv6 autofs4 hidp rfcomm l2cap bluetooth rfkill sunrpc dm_mirror dm_region_hash dm_log dm_multipath scsi_dh dm_mod video output sbs sbshc battery ac lp snd_hda_codec_analog snd_hda_intel sg dcdbas snd_hda_codec snd_seq_dummy sr_mod snd_seq_oss snd_seq_midi_event snd_seq cdrom snd_seq_device snd_pcm_oss snd_mixer_oss serio_raw snd_pcm snd_timer button parport_pc snd tg3 libphy rtc_cmos i2c_i801 soundcore snd_page_alloc i2c_core pcspkr parport rtc_core rtc_lib ata_piix libata sd_mod scsi_mod ext3 jbd uhci_hcd ohci_hcdehci_hcd [last unloaded: microcode]
Pid: 5627, comm: crond Not tainted (2.6.31-rc4-io-controller-v7 #62) OptiPlex 745
EIP: 0060:[<c0535194>] EFLAGS: 00010012 CPU: 0
EIP is at __bfq_activate_entity+0x1f6/0x370
EAX: f6af607c EBX: f6af6098 ECX: f6af6070 EDX: f5d1f84c
ESI: f6af6070 EDI: f5d1f3a8 EBP: f387bcd4 ESP: f387bca4
DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process crond (pid: 5627, ti=f387b000 task=f38942b0 task.ti=f387b000)
Stack: f6af6070 00000001 f6af6098 00000000 00000001 f6ab4a00 000b3614 00000000 <0> 00000001 f5d1f3a8 c05323fe f5d1f3a8 f387bce0 c0535cf4 f5d1f3a8 f387bd10 <0> c05372ff f644fdf4 f71ab368 00000000 f6af6070 00000000 f5d1f84c f6ab4a00 Call Trace: [<c05323fe>] ? cfq_should_preempt+0x0/0xfc [<c0535cf4>] ? elv_activate_ioq+0xf/0x27 [<c05372ff>] ? elv_ioq_request_add+0x2d3/0x30b [<c0522b51>] ? elv_insert+0x12c/0x1c0 [<c0522c74>] ? __elv_add_request+0x8f/0x94 [<c0528b8d>] ? __make_request+0x303/0x372 [<c044d23f>] ? mark_held_locks+0x43/0x5b [<c052687e>] ? generic_make_request+0x260/0x29c [<c0484ca1>] ? mempool_alloc_slab+0xe/0x10 [<c0484f10>] ? mempool_alloc+0x42/0xe0 [<c052696f>] ? submit_bio+0xb5/0xbd [<c04c5cf1>] ? bio_alloc_bioset+0x25/0xbd [<c04c2937>] ? submit_bh+0xdf/0xfc [<c04c3fe1>] ? ll_rw_block+0xa4/0xd8 [<f80bd73c>] ? ext3_bread+0x35/0x5b [ext3] [<f80c182f>] ? htree_dirblock_to_tree+0x1f/0x118 [ext3] [<f80c198a>] ? ext3_htree_fill_tree+0x62/0x1ac [ext3] [<c044d483>] ? trace_hardirqs_on_caller+0xff/0x120 [<c044d4af>] ? trace_hardirqs_on+0xb/0xd [<f80b9a1b>] ? ext3_readdir+0x18f/0x5fe [ext3] [<c04b33b5>] ? filldir+0x0/0xb7 [<c044d483>] ? trace_hardirqs_on_caller+0xff/0x120 [<c069c632>] ? __mutex_lock_common+0x293/0x2d2 [<c069c6d4>] ? mutex_lock_killable_nested+0x2e/0x35 [<c04b3591>] ? vfs_readdir+0x68/0x94 [<c04b33b5>] ? filldir+0x0/0xb7 [<c04b36bf>] ? sys_getdents+0x62/0xa1 [<c04029b4>] ? sysenter_do_call+0x12/0x32 Code: 00 0f b7 42 4c 8b 4a 44 48 83 f8 02 76 04 0f 0b eb fe 85 c9 75 04 0f 0b eb fe 6b c0 1c 8d 04 01 8945 d0 83 c0 0c 39 45 d8 74 04 <0f> 0b eb fe 8b 5a 10 8b 72 14 8b 47 30 8b 57 34 83 c3 ff 83 d6 EIP: [<c0535194>] __bfq_activate_entity+0x1f6/0x370 SS:ESP 0068:f387bca4 ---[ end trace 048abafbc8ce5bf7 ]---
Regards,
Jerome
Quoted 24 lines
block/elevator-fq.c +11
-2+ entity->finish = next_entity->finish -1 ; + delta =bfq_delta (entity->budget, entity->weight); + entity->start = entity->finish - delta; +if (bfq_gt (entity->start, st->vtime)) + entity->start = st->vtime; + } + }else { +bfq_calc_finish (entity, entity->budget); + }bfq_active_insert (st, entity); }@@ -633,9 +669,9 @@ static void __bfq_activate_entity(struct io_entity *entity)* bfq_activate_entity - activate an entity. * @entity: the entity to activate. */ -static void bfq_activate_entity (struct io_entity *entity) +static void bfq_activate_entity (struct io_entity *entity,int add_front) { -__bfq_activate_entity (entity); +__bfq_activate_entity (entity, add_front); }/**
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 80 lines · Jerome Marchand
Quoted 66 lines · Vivek Goyal
o Generally preemption is associated with cross class where if an request from RT class is pending it will preempt the ongoing BE or IDLE class request.
o CFQ also does in-class preemtions like a sync request queue preempting the async request queue. In that case it looks like preempting queue gains share and it is not fair.
o Implement the similar functionality in bfq so that we can retain the existing CFQ behavior.
o This patch creates a bypass path so that a queue can be put at the front of the service tree (
add_front, similar to CFQ), so that it will be selected next to run. That's a different thing that in the process this queue gains share.Signed-off-by Vivek Goyal <[email protected]>--- block/elevator-fq.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 5 deletions(-)block/elevator-fq.c +20
-3@@ -267,7 +267,8 @@ static void bfq_get_entity(struct io_entity *entity)elv_get_ioq (ioq); } -static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +static inline void +bfq_init_entity (struct io_entity *entity,struct io_group *iog) { entity->sched_data = &iog->sched_data; }@@ -580,7 +581,7 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd,* service received if @entity is active) of the queue to calculate its * timestamps. */ -static void __bfq_activate_entity (struct io_entity *entity) +static void __bfq_activate_entity (struct io_entity *entity,int add_front) {struct io_sched_data *sd = entity->sched_data;struct io_service_tree *st =io_entity_service_tree (entity);@@ -625,7 +626,42 @@ static void __bfq_activate_entity(struct io_entity *entity) } st =__bfq_entity_update_prio (st, entity); -bfq_calc_finish (entity, entity->budget); +/* +* This is to emulate cfq like functionality where preemption can +* happen with-in same class, like sync queue preempting async queue +* May be this is not a very good idea from fairness point of view +* as preempting queue gains share. Keeping it for now. +*/ +if (add_front) { +struct io_entity *next_entity; + +/* +* Determine the entity which will be dispatched next +* Use sd->next_active once hierarchical patch is applied +*/ + next_entity =bfq_lookup_next_entity (sd,0 ); + +if (next_entity && next_entity != entity) { +struct io_service_tree *new_st;block/elevator-fq.c static void __bfq_activate_entity(struct io_entity *entity) · line 655
Quoted 10 lines
block/elevator-fq.c +10
-0+u64 delta; + + new_st =io_entity_service_tree (next_entity); + +/* +* At this point, both entities should belong to +* same service tree as cross service tree preemption +* is automatically taken care by algorithm +*/ +BUG_ON (new_st != st);Hi Vivek,
Quoted 7 lines
I don't quite understand how cross service tree preemption is taken care by algorithm, but I've hit this bug while doing some RT I/O and then killing it.
$ ionice -c 1 dd if=/dev/zero of=/tmp/foo bs=1M count=1000 & $ killall dd
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the sd->next_entity will point to itself and any queue which is preempting it has to be on same service tree.
But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see BUG_ON() hitting.
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
In this patch, we just check next entity on same class service tree and if one is present, stick new queue in front of it. We don't rely on sd->next_active, which could be pointing to a queue of different class in same group (scheduling_data).
--- block/elevator-fq.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
block/elevator-fq.c +5 -11
@@ -946,21 +946,15 @@ static void __bfq_activate_entity(structif (add_front) {struct io_entity *next_entity; -/* Determine the entity which will be dispatched next */ - next_entity = sd->next_active; +/* +* Determine the entity which will be dispatched next on +* same service tree. +*/ + next_entity =__bfq_lookup_next_entity (st);if (next_entity && next_entity != entity) { -struct io_service_tree *new_st;u64 delta; - new_st =io_entity_service_tree (next_entity); - -/* -* At this point, both entities should belong to -* same service tree as cross service tree preemption -* is automatically taken care by algorithm -*/ -BUG_ON (new_st != st); entity->finish = next_entity->finish -1 ; delta =bfq_delta (entity->budget, entity->weight); entity->start = entity->finish - delta;
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.
Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.
Jerome
Quoted 41 lines
In this patch, we just check next entity on same class service tree and if one is present, stick new queue in front of it. We don't rely on
sd->next_active, which could be pointing to a queue of different class in same group (scheduling_data).--- block/elevator-fq.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)Index:
linux8/block/elevator-fq.c
===================================================================block/elevator-fq.c +5
-11@@ -946,21 +946,15 @@ static void __bfq_activate_entity(structif (add_front) {struct io_entity *next_entity; -/* Determine the entity which will be dispatched next */ - next_entity = sd->next_active; +/* +* Determine the entity which will be dispatched next on +* same service tree. +*/ + next_entity =__bfq_lookup_next_entity (st);if (next_entity && next_entity != entity) { -struct io_service_tree *new_st;u64 delta; - new_st =io_entity_service_tree (next_entity); - -/* -* At this point, both entities should belong to -* same service tree as cross service tree preemption -* is automatically taken care by algorithm -*/ -BUG_ON (new_st != st); entity->finish = next_entity->finish -1 ; delta =bfq_delta (entity->budget, entity->weight); entity->start = entity->finish - delta;
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 22 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936
Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Thanks
Vivek
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 33 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.
Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 4 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
Quoted 8 lines
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weight
Test:
$ echo 3 > /proc/sys/vm/drop_caches
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks
$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks
$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasks
Quoted 3 lines
Thanks
Vivek
Jerome
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 66 lines · Jerome Marchand
Quoted 33 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 4 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
Quoted 8 lines
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weightTest:
$ echo 3 > /proc/sys/vm/drop_caches
Quoted 9 lines
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasks
Ok, got it. So you have created three BE class groups and with-in those groups you are running job of RT, BE and IDLE type.
From group scheduling point of view, because the tree groups have got same class and same weight, they should get equal access to disk and with-in group how bandwidth is divided is left to CFQ.
Because in this case, only one task is present in each group, it should get all the BW available to the group. Hence, in above test case, all the three dd processes should get equal amount of disk time.
You mentioned that RT and BE task are getting fair share but not IDLE task. This is a bug and probably I know where the bug is. I will debug it and fix it soon.
Thanks
Vivek
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 76 lines · Vivek Goyal
Quoted 62 lines · Jerome Marchand
Quoted 32 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 11 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weightTest:
$ echo 3 > /proc/sys/vm/drop_cachesQuoted 9 lines
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasksOk, got it. So you have created three BE class groups and with-in those groups you are running job of RT, BE and IDLE type.
Quoted 7 lines
From group scheduling point of view, because the tree groups have got same class and same weight, they should get equal access to disk and with-in group how bandwidth is divided is left to CFQ.
Because in this case, only one task is present in each group, it should get all the BW available to the group. Hence, in above test case, all the three dd processes should get equal amount of disk time.
OK. That's how I understood it, but I wanted your confirmation.
Quoted 4 lines
You mentioned that RT and BE task are getting fair share but not IDLE task. This is a bug and probably I know where the bug is. I will debug it and fix it soon.
I've tested it with the last version of your patchset (v6) and the problem was less acute (the IDLE task got about 5 times less time that RT and BE against 50 times less with v7 patchset). I hope that helps you.
Jerome
Quoted 3 lines
Thanks
Vivek
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 88 lines · Jerome Marchand
Quoted 76 lines · Vivek Goyal
Quoted 62 lines · Jerome Marchand
Quoted 32 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 11 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weightTest:
$ echo 3 > /proc/sys/vm/drop_cachesQuoted 9 lines
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasksOk, got it. So you have created three BE class groups and with-in those groups you are running job of RT, BE and IDLE type.
Quoted 7 lines
From group scheduling point of view, because the tree groups have got same class and same weight, they should get equal access to disk and with-in group how bandwidth is divided is left to CFQ.
Because in this case, only one task is present in each group, it should get all the BW available to the group. Hence, in above test case, all the three dd processes should get equal amount of disk time.
OK. That's how I understood it, but I wanted your confirmation.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
You mentioned that RT and BE task are getting fair share but not IDLE task. This is a bug and probably I know where the bug is. I will debug it and fix it soon.
I've tested it with the last version of your patchset (v6) and the problem was less acute (the IDLE task got about 5 times less time that RT and BE against 50 times less with v7 patchset). I hope that helps you.
Hi Jerome,
Can you please try attached patch. It should fix the issue of group in which idle task is running is not getting its fair share.
The primary issue here is that for such groups, we were not doing group idle, which will lead to queue and group deletion immediately after dispatching one request and it will not get its fair share.
Attached patch should fix the problem.
Thanks
Vivek
--- block/cfq-iosched.c | 5 ++- block/elevator-fq.c | 70 ++++++++++++++++++++++++++++++++++++---------------- block/elevator-fq.h | 1 3 files changed, 54 insertions(+), 22 deletions(-)
block/elevator-fq.c +49 -21
@@ -1212,6 +1212,30 @@ io_group_init_entity(struct io_cgroup *i entity->my_sched_data = &iog->sched_data; } +/* Check if we plan to idle on the group associated with this queue or not */ +int elv_iog_should_idle (struct io_queue *ioq) +{ +struct io_group *iog =ioq_to_io_group (ioq); +struct elv_fq_data *efqd = ioq->efqd; + +/* +* No idling on group if group idle is disabled or idling is disabled +* for this group. Currently for root group idling is disabled. +*/ +if (!efqd->elv_group_idle || !elv_iog_idle_window (iog)) +return 0 ; + +/* +* If this is last active queue in group with no request queued, we +* need to idle on group before expiring the queue to make sure group +* does not loose its share. +*/ +if ((elv_iog_nr_active (iog) <=1 ) && !ioq->nr_queued) +return 1 ; + +return 0 ; +} +static void io_group_set_parent (struct io_group *iog,struct io_group *parent) {struct io_entity *entity;
@@ -2708,6 +2732,10 @@ static inline int is_only_root_group(voi {return 1 ; } + +/* No group idling in flat mode */ +int elv_iog_should_idle (struct io_queue *ioq) {return 0 ; } +#endif /* GROUP_IOSCHED */ /* Elevator fair queuing function */
@@ -3308,12 +3336,18 @@ void __elv_ioq_slice_expired(struct requif (time_after (ioq->slice_end, jiffies)) { slice_unused = ioq->slice_end - jiffies;if (slice_unused == entity->budget) { -/* -* queue got expired immediately after -* completing first request. Charge 1/2 of -* time consumed in completing first request. +/* Queue got expired immediately after completing +* first request. It happens with idle class queues +* as well as can happen with closely cooperating +* queues or with queues for which idling is not +* enabled. +* +* Charge the full time since slice was started. This +* will include the seek cost also on rotational media. +* This is bit unfair but don't know what's the better +* way to handle such cases. */ - slice_used = (slice_used +1 )/2 ; + slice_used = jiffies - ioq->slice_start; }else slice_used = entity->budget - slice_unused; }else {
@@ -3686,7 +3720,8 @@ void *elv_fq_select_ioq(struct request_q/* * The active queue has run out of time, expire it and select new. */ -if (elv_ioq_slice_used (ioq) && !elv_ioq_must_dispatch (ioq)) { +if ((elv_ioq_slice_used (ioq) ||elv_ioq_class_idle (ioq)) + && !elv_ioq_must_dispatch (ioq)) {/* * Queue has used up its slice. Wait busy is not on otherwise * we wouldn't have been here. If this group will be deleted
@@ -3711,9 +3746,7 @@ void *elv_fq_select_ioq(struct request_q* from queue and is not proportional to group's weight, it * harms the fairness of the group. */ -if ((elv_iog_nr_active (iog) <=1 ) && !ioq->nr_queued - && !elv_iog_wait_busy_done (iog) && efqd->elv_group_idle - &&elv_iog_idle_window (iog)) { +if (elv_iog_should_idle (ioq) && !elv_iog_wait_busy_done (iog)) { ioq =NULL ; goto keep_queue; }else
@@ -3893,12 +3926,6 @@ void elv_ioq_completed_request(struct reelv_clear_ioq_slice_new (ioq); } -if (elv_ioq_class_idle (ioq)) { -if (elv_iosched_expire_ioq (q,1 ,0 )) -elv_ioq_slice_expired (q); - goto done; - } -/* * If there is only root group present, don't expire the queue * for single queue ioschedulers (noop, deadline, AS). It is
@@ -3919,14 +3946,14 @@ void elv_ioq_completed_request(struct re* mean seek distance, give them a chance to run instead * of idling. */ -if (elv_ioq_slice_used (ioq)) { +if (elv_ioq_slice_used (ioq) ||elv_ioq_class_idle (ioq)) {/* This is the last empty queue in the group and it * has consumed its slice. If we expire it right away * group might loose its share. Wait for an extra * group_idle period for a request before queue * expires. */ -if ((elv_iog_nr_active (iog) <=1 ) && !ioq->nr_queued) { +if (elv_iog_should_idle (ioq)) {elv_iog_arm_slice_timer (q, iog,1 ); goto done; }
@@ -3943,8 +3970,10 @@ void elv_ioq_completed_request(struct re goto done;/* Expire the queue */ -if (elv_iosched_expire_ioq (q,1 ,0 )) +if (elv_iosched_expire_ioq (q,1 ,0 )) {elv_ioq_slice_expired (q); + goto done; + } }else if (!ioq->nr_queued && !elv_close_cooperator (q, ioq) && sync && !rq_noidle (rq))elv_ioq_arm_slice_timer (q);
@@ -3953,9 +3982,8 @@ void elv_ioq_completed_request(struct re* If this is the last queue in the group and we did not * decide to idle on queue, idle on group. */ -if (elv_active_ioq (q->elevator) && !ioq->nr_queued && - !ioq->dispatched && !timer_pending (&efqd->idle_slice_timer) - && (elv_iog_nr_active (iog) <=1 )) { +if (elv_iog_should_idle (ioq) && !ioq->dispatched + && !timer_pending (&efqd->idle_slice_timer)) {/* * If queue has used up its slice, wait for the * one extra group_idle period to let the group
block/elevator-fq.h +1 -0
@@ -695,6 +695,7 @@ extern int elv_nr_busy_ioq(struct elevatextern int elv_rq_in_driver (struct elevator_queue *e);extern struct io_queue *elv_alloc_ioq (struct request_queue *q,gfp_t gfp_mask);extern void elv_free_ioq (struct io_queue *ioq); +extern int elv_iog_should_idle (struct io_queue *ioq);#else /* CONFIG_ELV_FAIR_QUEUING */
block/cfq-iosched.c +4 -1
@@ -1007,10 +1007,13 @@ static int cfq_dispatch_requests(struct/* * expire an async queue immediately if it has used up its slice. idle * queue always expire after 1 dispatch round. +* +* Also do not expire the queue if we plan to do group idling on it. +* In that case it will be expired later. */ if (elv_nr_busy_ioq (q->elevator) >1 && ((!cfq_cfqq_sync (cfqq) && cfqq->slice_dispatch >=cfq_prio_to_maxrq (cfqd, cfqq)) || -cfq_class_idle (cfqq))) { + (cfq_class_idle (cfqq) && !elv_iog_should_idle (cfqq->ioq)))) {cfq_slice_expired (cfqd); }
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 88 lines · Jerome Marchand
Quoted 76 lines · Vivek Goyal
Quoted 62 lines · Jerome Marchand
Quoted 32 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 11 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weightTest:
$ echo 3 > /proc/sys/vm/drop_cachesQuoted 9 lines
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasksOk, got it. So you have created three BE class groups and with-in those groups you are running job of RT, BE and IDLE type.
Quoted 7 lines
From group scheduling point of view, because the tree groups have got same class and same weight, they should get equal access to disk and with-in group how bandwidth is divided is left to CFQ.
Because in this case, only one task is present in each group, it should get all the BW available to the group. Hence, in above test case, all the three dd processes should get equal amount of disk time.
OK. That's how I understood it, but I wanted your confirmation.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
You mentioned that RT and BE task are getting fair share but not IDLE task. This is a bug and probably I know where the bug is. I will debug it and fix it soon.
I've tested it with the last version of your patchset (v6) and the problem was less acute (the IDLE task got about 5 times less time that RT and BE against 50 times less with v7 patchset). I hope that helps you.
Hi Jerome,
Can you please try attached patch. It should fix the issue of group in which idle task is running is not getting its fair share.
The primary issue here is that for such groups, we were not doing group idle, which will lead to queue and group deletion immediately after dispatching one request and it will not get its fair share.
Attached patch should fix the problem.
Thanks
Vivek
--- block/cfq-iosched.c | 5 ++- block/elevator-fq.c | 70 ++++++++++++++++++++++++++++++++++++---------------- block/elevator-fq.h | 1 3 files changed, 54 insertions(+), 22 deletions(-)
block/elevator-fq.c +49 -21
@@ -1212,6 +1212,30 @@ io_group_init_entity(struct io_cgroup *i entity->my_sched_data = &iog->sched_data; } +/* Check if we plan to idle on the group associated with this queue or not */ +int elv_iog_should_idle (struct io_queue *ioq) +{ +struct io_group *iog =ioq_to_io_group (ioq); +struct elv_fq_data *efqd = ioq->efqd; + +/* +* No idling on group if group idle is disabled or idling is disabled +* for this group. Currently for root group idling is disabled. +*/ +if (!efqd->elv_group_idle || !elv_iog_idle_window (iog)) +return 0 ; + +/* +* If this is last active queue in group with no request queued, we +* need to idle on group before expiring the queue to make sure group +* does not loose its share. +*/ +if ((elv_iog_nr_active (iog) <=1 ) && !ioq->nr_queued) +return 1 ; + +return 0 ; +} +static void io_group_set_parent (struct io_group *iog,struct io_group *parent) {struct io_entity *entity;
@@ -2708,6 +2732,10 @@ static inline int is_only_root_group(voi {return 1 ; } + +/* No group idling in flat mode */ +int elv_iog_should_idle (struct io_queue *ioq) {return 0 ; } +#endif /* GROUP_IOSCHED */ /* Elevator fair queuing function */
@@ -3308,12 +3336,18 @@ void __elv_ioq_slice_expired(struct requif (time_after (ioq->slice_end, jiffies)) { slice_unused = ioq->slice_end - jiffies;if (slice_unused == entity->budget) { -/* -* queue got expired immediately after -* completing first request. Charge 1/2 of -* time consumed in completing first request. +/* Queue got expired immediately after completing +* first request. It happens with idle class queues +* as well as can happen with closely cooperating +* queues or with queues for which idling is not +* enabled. +* +* Charge the full time since slice was started. This +* will include the seek cost also on rotational media. +* This is bit unfair but don't know what's the better +* way to handle such cases. */ - slice_used = (slice_used +1 )/2 ; + slice_used = jiffies - ioq->slice_start; }else slice_used = entity->budget - slice_unused; }else {
@@ -3686,7 +3720,8 @@ void *elv_fq_select_ioq(struct request_q/* * The active queue has run out of time, expire it and select new. */ -if (elv_ioq_slice_used (ioq) && !elv_ioq_must_dispatch (ioq)) { +if ((elv_ioq_slice_used (ioq) ||elv_ioq_class_idle (ioq)) + && !elv_ioq_must_dispatch (ioq)) {/* * Queue has used up its slice. Wait busy is not on otherwise * we wouldn't have been here. If this group will be deleted
@@ -3711,9 +3746,7 @@ void *elv_fq_select_ioq(struct request_q* from queue and is not proportional to group's weight, it * harms the fairness of the group. */ -if ((elv_iog_nr_active (iog) <=1 ) && !ioq->nr_queued - && !elv_iog_wait_busy_done (iog) && efqd->elv_group_idle - &&elv_iog_idle_window (iog)) { +if (elv_iog_should_idle (ioq) && !elv_iog_wait_busy_done (iog)) { ioq =NULL ; goto keep_queue; }else
@@ -3893,12 +3926,6 @@ void elv_ioq_completed_request(struct reelv_clear_ioq_slice_new (ioq); } -if (elv_ioq_class_idle (ioq)) { -if (elv_iosched_expire_ioq (q,1 ,0 )) -elv_ioq_slice_expired (q); - goto done; - } -/* * If there is only root group present, don't expire the queue * for single queue ioschedulers (noop, deadline, AS). It is
@@ -3919,14 +3946,14 @@ void elv_ioq_completed_request(struct re* mean seek distance, give them a chance to run instead * of idling. */ -if (elv_ioq_slice_used (ioq)) { +if (elv_ioq_slice_used (ioq) ||elv_ioq_class_idle (ioq)) {/* This is the last empty queue in the group and it * has consumed its slice. If we expire it right away * group might loose its share. Wait for an extra * group_idle period for a request before queue * expires. */ -if ((elv_iog_nr_active (iog) <=1 ) && !ioq->nr_queued) { +if (elv_iog_should_idle (ioq)) {elv_iog_arm_slice_timer (q, iog,1 ); goto done; }
@@ -3943,8 +3970,10 @@ void elv_ioq_completed_request(struct re goto done;/* Expire the queue */ -if (elv_iosched_expire_ioq (q,1 ,0 )) +if (elv_iosched_expire_ioq (q,1 ,0 )) {elv_ioq_slice_expired (q); + goto done; + } }else if (!ioq->nr_queued && !elv_close_cooperator (q, ioq) && sync && !rq_noidle (rq))elv_ioq_arm_slice_timer (q);
@@ -3953,9 +3982,8 @@ void elv_ioq_completed_request(struct re* If this is the last queue in the group and we did not * decide to idle on queue, idle on group. */ -if (elv_active_ioq (q->elevator) && !ioq->nr_queued && - !ioq->dispatched && !timer_pending (&efqd->idle_slice_timer) - && (elv_iog_nr_active (iog) <=1 )) { +if (elv_iog_should_idle (ioq) && !ioq->dispatched + && !timer_pending (&efqd->idle_slice_timer)) {/* * If queue has used up its slice, wait for the * one extra group_idle period to let the group
block/elevator-fq.h +1 -0
@@ -695,6 +695,7 @@ extern int elv_nr_busy_ioq(struct elevatextern int elv_rq_in_driver (struct elevator_queue *e);extern struct io_queue *elv_alloc_ioq (struct request_queue *q,gfp_t gfp_mask);extern void elv_free_ioq (struct io_queue *ioq); +extern int elv_iog_should_idle (struct io_queue *ioq);#else /* CONFIG_ELV_FAIR_QUEUING */
block/cfq-iosched.c +4 -1
@@ -1007,10 +1007,13 @@ static int cfq_dispatch_requests(struct/* * expire an async queue immediately if it has used up its slice. idle * queue always expire after 1 dispatch round. +* +* Also do not expire the queue if we plan to do group idling on it. +* In that case it will be expired later. */ if (elv_nr_busy_ioq (q->elevator) >1 && ((!cfq_cfqq_sync (cfqq) && cfqq->slice_dispatch >=cfq_prio_to_maxrq (cfqd, cfqq)) || -cfq_class_idle (cfqq))) { + (cfq_class_idle (cfqq) && !elv_iog_should_idle (cfqq->ioq)))) {cfq_slice_expired (cfqd); }
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 76 lines · Vivek Goyal
Quoted 62 lines · Jerome Marchand
Quoted 32 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 11 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weightTest:
$ echo 3 > /proc/sys/vm/drop_cachesQuoted 9 lines
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasksOk, got it. So you have created three BE class groups and with-in those groups you are running job of RT, BE and IDLE type.
Quoted 7 lines
From group scheduling point of view, because the tree groups have got same class and same weight, they should get equal access to disk and with-in group how bandwidth is divided is left to CFQ.
Because in this case, only one task is present in each group, it should get all the BW available to the group. Hence, in above test case, all the three dd processes should get equal amount of disk time.
OK. That's how I understood it, but I wanted your confirmation.
Quoted 4 lines
You mentioned that RT and BE task are getting fair share but not IDLE task. This is a bug and probably I know where the bug is. I will debug it and fix it soon.
I've tested it with the last version of your patchset (v6) and the problem was less acute (the IDLE task got about 5 times less time that RT and BE against 50 times less with v7 patchset). I hope that helps you.
Jerome
Quoted 3 lines
Thanks
Vivek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 66 lines · Jerome Marchand
Quoted 33 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 4 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
Quoted 8 lines
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weightTest:
$ echo 3 > /proc/sys/vm/drop_caches
Quoted 9 lines
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasks
Ok, got it. So you have created three BE class groups and with-in those groups you are running job of RT, BE and IDLE type.
From group scheduling point of view, because the tree groups have got same class and same weight, they should get equal access to disk and with-in group how bandwidth is divided is left to CFQ.
Because in this case, only one task is present in each group, it should get all the BW available to the group. Hence, in above test case, all the three dd processes should get equal amount of disk time.
You mentioned that RT and BE task are getting fair share but not IDLE task. This is a bug and probably I know where the bug is. I will debug it and fix it soon.
Thanks
Vivek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 33 lines · Vivek Goyal
Quoted 21 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.
Quoted 4 lines
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I wasn't clear enough. I meant the class of the process as set by ionice, not the class of the cgroup. That is, of course, only an issue when using CFQ.
Quoted 4 lines
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
Quoted 8 lines
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Setup:
$ mount -t cgroup -o io,blkio none /cgroup $ mkdir /cgroup/test1 /cgroup/test2 /cgroup/test3 $ echo 1000 > /cgroup/test1/io.weight $ echo 1000 > /cgroup/test2/io.weight $ echo 1000 > /cgroup/test3/io.weight
Test:
$ echo 3 > /proc/sys/vm/drop_caches
$ ionice -c 1 dd if=/tmp/io-controller-test3 of=/dev/null & $ echo $! > /cgroup/test1/tasks
$ ionice -c 2 dd if=/tmp/io-controller-test1 of=/dev/null & $ echo $! > /cgroup/test2/tasks
$ ionice -c 3 dd if=/tmp/io-controller-test2 of=/dev/null & $ echo $! > /cgroup/test3/tasks
Quoted 3 lines
Thanks
Vivek
Jerome
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 22 lines · Jerome Marchand
Quoted 15 lines · Vivek Goyal
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the
sd->next_entitywill point to itself and any queue which is preempting it has to be on same service tree.But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see
BUG_ON()hitting.Quoted 5 lines
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
Quoted 10 lines
I've tried it: I can't reproduce the issue anymore and I haven't seen any other problem so far.
By the way, what is the expected result regarding fairness among different groups when IO from different classes are run on each group? For instance, if we have RT IO going on on one group, BE IO on an other and Idle IO on a third group, what is the expected result: should the IO time been shared fairly between the groups or should RT IO have priority? As it is now, the time is shared fairly between BE and RT groups and the last group running Idle IO hardly get any time.
Hi Jerome,
If there are two groups RT and BE, I would expect RT group to get all the bandwidth as long as it is backlogged and starve the BE group.
I ran quick test of two dd readers. One reader is in RT group and other is in BE group. I do see that RT group runs away with almost all the BW.
group1 time=8:16 2479 group1 sectors=8:16 457848
group2 time=8:16 103 group2 sectors=8:16 18936
Note that when group1 (RT) finished it had got 2479 ms of disk time while group2 (BE) got only 103 ms.
Can you send details of your test. It should not be fair sharing between RT and BE group.
Thanks
Vivek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 80 lines · Jerome Marchand
Quoted 66 lines · Vivek Goyal
o Generally preemption is associated with cross class where if an request from RT class is pending it will preempt the ongoing BE or IDLE class request.
o CFQ also does in-class preemtions like a sync request queue preempting the async request queue. In that case it looks like preempting queue gains share and it is not fair.
o Implement the similar functionality in bfq so that we can retain the existing CFQ behavior.
o This patch creates a bypass path so that a queue can be put at the front of the service tree (
add_front, similar to CFQ), so that it will be selected next to run. That's a different thing that in the process this queue gains share.Signed-off-by Vivek Goyal <[email protected]>--- block/elevator-fq.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 5 deletions(-)block/elevator-fq.c +20
-3@@ -267,7 +267,8 @@ static void bfq_get_entity(struct io_entity *entity)elv_get_ioq (ioq); } -static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +static inline void +bfq_init_entity (struct io_entity *entity,struct io_group *iog) { entity->sched_data = &iog->sched_data; }@@ -580,7 +581,7 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd,* service received if @entity is active) of the queue to calculate its * timestamps. */ -static void __bfq_activate_entity (struct io_entity *entity) +static void __bfq_activate_entity (struct io_entity *entity,int add_front) {struct io_sched_data *sd = entity->sched_data;struct io_service_tree *st =io_entity_service_tree (entity);@@ -625,7 +626,42 @@ static void __bfq_activate_entity(struct io_entity *entity) } st =__bfq_entity_update_prio (st, entity); -bfq_calc_finish (entity, entity->budget); +/* +* This is to emulate cfq like functionality where preemption can +* happen with-in same class, like sync queue preempting async queue +* May be this is not a very good idea from fairness point of view +* as preempting queue gains share. Keeping it for now. +*/ +if (add_front) { +struct io_entity *next_entity; + +/* +* Determine the entity which will be dispatched next +* Use sd->next_active once hierarchical patch is applied +*/ + next_entity =bfq_lookup_next_entity (sd,0 ); + +if (next_entity && next_entity != entity) { +struct io_service_tree *new_st;block/elevator-fq.c static void __bfq_activate_entity(struct io_entity *entity) · line 655
Quoted 10 lines
block/elevator-fq.c +10
-0+u64 delta; + + new_st =io_entity_service_tree (next_entity); + +/* +* At this point, both entities should belong to +* same service tree as cross service tree preemption +* is automatically taken care by algorithm +*/ +BUG_ON (new_st != st);Hi Vivek,
Quoted 7 lines
I don't quite understand how cross service tree preemption is taken care by algorithm, but I've hit this bug while doing some RT I/O and then killing it.
$ ionice -c 1 dd if=/dev/zero of=/tmp/foo bs=1M count=1000 & $ killall dd
Hi Jerome,
Thanks for testing it out. I could also reproduce the issue.
I had assumed that RT queue will always preempt non-RT queue and hence if there is an RT ioq/request pending, the sd->next_entity will point to itself and any queue which is preempting it has to be on same service tree.
But in your test case it looks like that RT async queue is pending and there is some sync BE class IO going on. It looks like that CFQ allows sync queue preempting async queue irrespective of class, so in this case sync BE class reader will preempt async RT queue and that's where my assumption is broken and we see BUG_ON() hitting.
Can you please tryout following patch. It is a quick patch and requires more testing. It solves the crash but still does not solve the issue of sync queue always preempting async queues irrespective of class. In current scheduler we always schedule the RT queue first (whether it be sync or async). This problem requires little more thought.
In this patch, we just check next entity on same class service tree and if one is present, stick new queue in front of it. We don't rely on sd->next_active, which could be pointing to a queue of different class in same group (scheduling_data).
--- block/elevator-fq.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
block/elevator-fq.c +5 -11
@@ -946,21 +946,15 @@ static void __bfq_activate_entity(structif (add_front) {struct io_entity *next_entity; -/* Determine the entity which will be dispatched next */ - next_entity = sd->next_active; +/* +* Determine the entity which will be dispatched next on +* same service tree. +*/ + next_entity =__bfq_lookup_next_entity (st);if (next_entity && next_entity != entity) { -struct io_service_tree *new_st;u64 delta; - new_st =io_entity_service_tree (next_entity); - -/* -* At this point, both entities should belong to -* same service tree as cross service tree preemption -* is automatically taken care by algorithm -*/ -BUG_ON (new_st != st); entity->finish = next_entity->finish -1 ; delta =bfq_delta (entity->budget, entity->weight); entity->start = entity->finish - delta;
A message that is not in the archive (sent off-list or not yet received): 1248467274-32073-4-git-send-email-vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [PATCH 03/24] io-controller: bfq support of in-class preemption
Quoted 66 lines · Vivek Goyal
o Generally preemption is associated with cross class where if an request from RT class is pending it will preempt the ongoing BE or IDLE class request.
o CFQ also does in-class preemtions like a sync request queue preempting the async request queue. In that case it looks like preempting queue gains share and it is not fair.
o Implement the similar functionality in bfq so that we can retain the existing CFQ behavior.
o This patch creates a bypass path so that a queue can be put at the front of the service tree (
add_front, similar to CFQ), so that it will be selected next to run. That's a different thing that in the process this queue gains share.Signed-off-by Vivek Goyal <[email protected]>--- block/elevator-fq.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 5 deletions(-)block/elevator-fq.c +20
-3@@ -267,7 +267,8 @@ static void bfq_get_entity(struct io_entity *entity)elv_get_ioq (ioq); } -static void bfq_init_entity (struct io_entity *entity,struct io_group *iog) +static inline void +bfq_init_entity (struct io_entity *entity,struct io_group *iog) { entity->sched_data = &iog->sched_data; }@@ -580,7 +581,7 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd,* service received if @entity is active) of the queue to calculate its * timestamps. */ -static void __bfq_activate_entity (struct io_entity *entity) +static void __bfq_activate_entity (struct io_entity *entity,int add_front) {struct io_sched_data *sd = entity->sched_data;struct io_service_tree *st =io_entity_service_tree (entity);@@ -625,7 +626,42 @@ static void __bfq_activate_entity(struct io_entity *entity) } st =__bfq_entity_update_prio (st, entity); -bfq_calc_finish (entity, entity->budget); +/* +* This is to emulate cfq like functionality where preemption can +* happen with-in same class, like sync queue preempting async queue +* May be this is not a very good idea from fairness point of view +* as preempting queue gains share. Keeping it for now. +*/ +if (add_front) { +struct io_entity *next_entity; + +/* +* Determine the entity which will be dispatched next +* Use sd->next_active once hierarchical patch is applied +*/ + next_entity =bfq_lookup_next_entity (sd,0 ); + +if (next_entity && next_entity != entity) { +struct io_service_tree *new_st;
block/elevator-fq.c static void __bfq_activate_entity(struct io_entity *entity) · line 655
Quoted 10 lines
block/elevator-fq.c +10
-0+u64 delta; + + new_st =io_entity_service_tree (next_entity); + +/* +* At this point, both entities should belong to +* same service tree as cross service tree preemption +* is automatically taken care by algorithm +*/ +BUG_ON (new_st != st);
Hi Vivek,
I don't quite understand how cross service tree preemption is taken care by algorithm, but I've hit this bug while doing some RT I/O and then killing it.
$ ionice -c 1 dd if=/dev/zero of=/tmp/foo bs=1M count=1000 & $ killall dd
------------[ cut here ]------------ kernel BUG at block/elevator-fq.c:963! invalid opcode: 0000 [#1] SMP last sysfs file: /sys/block/sdb/size Modules linked in: usb_storage netconsole ipt_REJECT xt_tcpudp iptable_filter ip_tables x_tables bridge stp ipv6 autofs4 hidp rfcomm l2cap bluetooth rfkill sunrpc dm_mirror dm_region_hash dm_log dm_multipath scsi_dh dm_mod video output sbs sbshc battery ac lp snd_hda_codec_analog snd_hda_intel sg dcdbas snd_hda_codec snd_seq_dummy sr_mod snd_seq_oss snd_seq_midi_event snd_seq cdrom snd_seq_device snd_pcm_oss snd_mixer_oss serio_raw snd_pcm snd_timer button parport_pc snd tg3 libphy rtc_cmos i2c_i801 soundcore snd_page_alloc i2c_core pcspkr parport rtc_core rtc_lib ata_piix libata sd_mod scsi_mod ext3 jbd uhci_hcd ohci_hcdehci_hcd [last unloaded: microcode]
Pid: 5627, comm: crond Not tainted (2.6.31-rc4-io-controller-v7 #62) OptiPlex 745
EIP: 0060:[<c0535194>] EFLAGS: 00010012 CPU: 0
EIP is at __bfq_activate_entity+0x1f6/0x370
EAX: f6af607c EBX: f6af6098 ECX: f6af6070 EDX: f5d1f84c
ESI: f6af6070 EDI: f5d1f3a8 EBP: f387bcd4 ESP: f387bca4
DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process crond (pid: 5627, ti=f387b000 task=f38942b0 task.ti=f387b000)
Stack: f6af6070 00000001 f6af6098 00000000 00000001 f6ab4a00 000b3614 00000000 <0> 00000001 f5d1f3a8 c05323fe f5d1f3a8 f387bce0 c0535cf4 f5d1f3a8 f387bd10 <0> c05372ff f644fdf4 f71ab368 00000000 f6af6070 00000000 f5d1f84c f6ab4a00 Call Trace: [<c05323fe>] ? cfq_should_preempt+0x0/0xfc [<c0535cf4>] ? elv_activate_ioq+0xf/0x27 [<c05372ff>] ? elv_ioq_request_add+0x2d3/0x30b [<c0522b51>] ? elv_insert+0x12c/0x1c0 [<c0522c74>] ? __elv_add_request+0x8f/0x94 [<c0528b8d>] ? __make_request+0x303/0x372 [<c044d23f>] ? mark_held_locks+0x43/0x5b [<c052687e>] ? generic_make_request+0x260/0x29c [<c0484ca1>] ? mempool_alloc_slab+0xe/0x10 [<c0484f10>] ? mempool_alloc+0x42/0xe0 [<c052696f>] ? submit_bio+0xb5/0xbd [<c04c5cf1>] ? bio_alloc_bioset+0x25/0xbd [<c04c2937>] ? submit_bh+0xdf/0xfc [<c04c3fe1>] ? ll_rw_block+0xa4/0xd8 [<f80bd73c>] ? ext3_bread+0x35/0x5b [ext3] [<f80c182f>] ? htree_dirblock_to_tree+0x1f/0x118 [ext3] [<f80c198a>] ? ext3_htree_fill_tree+0x62/0x1ac [ext3] [<c044d483>] ? trace_hardirqs_on_caller+0xff/0x120 [<c044d4af>] ? trace_hardirqs_on+0xb/0xd [<f80b9a1b>] ? ext3_readdir+0x18f/0x5fe [ext3] [<c04b33b5>] ? filldir+0x0/0xb7 [<c044d483>] ? trace_hardirqs_on_caller+0xff/0x120 [<c069c632>] ? __mutex_lock_common+0x293/0x2d2 [<c069c6d4>] ? mutex_lock_killable_nested+0x2e/0x35 [<c04b3591>] ? vfs_readdir+0x68/0x94 [<c04b33b5>] ? filldir+0x0/0xb7 [<c04b36bf>] ? sys_getdents+0x62/0xa1 [<c04029b4>] ? sysenter_do_call+0x12/0x32 Code: 00 0f b7 42 4c 8b 4a 44 48 83 f8 02 76 04 0f 0b eb fe 85 c9 75 04 0f 0b eb fe 6b c0 1c 8d 04 01 8945 d0 83 c0 0c 39 45 d8 74 04 <0f> 0b eb fe 8b 5a 10 8b 72 14 8b 47 30 8b 57 34 83 c3 ff 83 d6 EIP: [<c0535194>] __bfq_activate_entity+0x1f6/0x370 SS:ESP 0068:f387bca4 ---[ end trace 048abafbc8ce5bf7 ]---
Regards,
Jerome
Quoted 24 lines
block/elevator-fq.c +11
-2+ entity->finish = next_entity->finish -1 ; + delta =bfq_delta (entity->budget, entity->weight); + entity->start = entity->finish - delta; +if (bfq_gt (entity->start, st->vtime)) + entity->start = st->vtime; + } + }else { +bfq_calc_finish (entity, entity->budget); + }bfq_active_insert (st, entity); }@@ -633,9 +669,9 @@ static void __bfq_activate_entity(struct io_entity *entity)* bfq_activate_entity - activate an entity. * @entity: the entity to activate. */ -static void bfq_activate_entity (struct io_entity *entity) +static void bfq_activate_entity (struct io_entity *entity,int add_front) { -__bfq_activate_entity (entity); +__bfq_activate_entity (entity, add_front); }/**
PATCH 4/24 io-controller: Common flat fair queuing code in elevaotor layer
In reply to Vivek GoyalThis is common fair queuing code in elevator layer. This is controlled by config option CONFIG_ELV_FAIR_QUEUING. This patch initially only introduces flat fair queuing support where there is only one group, "root group" and all the tasks belong to root group.
This elevator layer changes are backward compatible. That means any ioscheduler using old interfaces will continue to work.
This code is essentially the CFQ code for fair queuing. The primary difference is that flat rounding robin algorithm of CFQ has been replaced with BFQ (WF2Q+).
--- block/Kconfig.iosched | 13 + block/Makefile | 1 + block/as-iosched.c | 2 +- block/blk.h | 4 + block/cfq-iosched.c | 2 +- block/deadline-iosched.c | 3 +- block/elevator-fq.c | 1112 +++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 281 ++++++++++++ block/elevator.c | 44 ++- block/noop-iosched.c | 2 +- include/linux/blkdev.h | 14 + include/linux/elevator.h | 51 ++- 12 files changed, 1507 insertions(+), 22 deletions(-)
block/Kconfig.iosched +13 -0
@@ -2,6 +2,19 @@ if BLOCK menu "IO Schedulers" +config ELV_FAIR_QUEUING + bool "Elevator Fair Queuing Support" + default n + ---help--- + Traditionally only cfq had notion of multiple queues and it did + fair queuing at its own. With the cgroups and need of controlling + IO, now even the simple io schedulers like noop, deadline, as will + have one queue per cgroup and will need hierarchical fair queuing. + Instead of every io scheduler implementing its own fair queuing + logic, this option enables fair queuing in elevator layer so that + other ioschedulers can make use of it. + If unsure, say N. + config IOSCHED_NOOP bool default y
block/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o obj-$(CONFIG_BLK_DEV_INTEGRITY) += blk-integrity.o +obj-$(CONFIG_ELV_FAIR_QUEUING) += elevator-fq.o
block/as-iosched.c +1 -1
@@ -1351,7 +1351,7 @@ static void as_exit_queue(struct elevator_queue *e)/* * initialize elevator private data (as_data). */ -static void *as_init_queue (struct request_queue *q) +static void *as_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct as_data *ad;
block/blk.h +4 -0
@@ -71,6 +71,8 @@ static inline void elv_activate_rq(struct request_queue *q, struct request *rq) {struct elevator_queue *e = q->elevator; +elv_fq_activate_rq (q, rq); +if (e->ops->elevator_activate_req_fn) e->ops->elevator_activate_req_fn (q, rq); }
@@ -79,6 +81,8 @@ static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq {struct elevator_queue *e = q->elevator; +elv_fq_deactivate_rq (q, rq); +if (e->ops->elevator_deactivate_req_fn) e->ops->elevator_deactivate_req_fn (q, rq); }
block/cfq-iosched.c +1 -1
@@ -2448,7 +2448,7 @@ static void cfq_exit_queue(struct elevator_queue *e)kfree (cfqd); } -static void *cfq_init_queue (struct request_queue *q) +static void *cfq_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct cfq_data *cfqd;int i;
block/deadline-iosched.c +2 -1
@@ -347,7 +347,8 @@ static void deadline_exit_queue(struct elevator_queue *e)/* * initialize elevator private data (deadline_data). */ -static void *deadline_init_queue (struct request_queue *q) +static void * +deadline_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct deadline_data *dd;
block/elevator-fq.c +1107 -5
1,139 lines not on this page · raw message
block/elevator-fq.h +281 -0
306 lines not on this page · raw message
block/elevator.c +32 -12
108 lines not on this page · raw message
block/noop-iosched.c +1 -1
@@ -65,7 +65,7 @@ noop_latter_request(struct request_queue *q, struct request *rq) return list_entry(rq->queuelist.next, struct request, queuelist); } -static void *noop_init_queue (struct request_queue *q) +static void *noop_init_queue (struct request_queue *q,struct elevator_queue *eq) {struct noop_data *nd;
include/linux/blkdev.h +14 -0
@@ -229,6 +229,11 @@ struct request {/* for bidi */ struct request *next_rq; + +#ifdef CONFIG_ELV_FAIR_QUEUING +/* io queue request belongs to */ +struct io_queue *ioq; +#endif };static inline unsigned short req_get_ioprio (struct request *req)
@@ -236,6 +241,15 @@ static inline unsigned short req_get_ioprio(struct request *req)return req->ioprio; } +static inline struct io_queue *req_ioq (struct request *req) +{ +#ifdef CONFIG_ELV_FAIR_QUEUING +return req->ioq; +#else +return NULL ; +#endif +} +/* * State information carried for REQ_TYPE_PM_SUSPEND and REQ_TYPE_PM_RESUME * requests. Some step values could eventually be made generic.
include/linux/elevator.h +50 -1
87 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 5/24 io-controller: Modify cfq to make use of flat elevator fair queuing
In reply to Vivek GoyalThis patch changes cfq to use fair queuing code from elevator layer.
--- block/Kconfig.iosched | 3 +- block/cfq-iosched.c | 1007 +++++++++++-------------------------------------- 2 files changed, 231 insertions(+), 779 deletions(-)
block/Kconfig.iosched +2 -1
@@ -3,7 +3,7 @@ if BLOCK menu "IO Schedulers" config ELV_FAIR_QUEUING - bool "Elevator Fair Queuing Support" + bool default n ---help--- Traditionally only cfq had notion of multiple queues and it did
@@ -46,6 +46,7 @@ config IOSCHED_DEADLINE config IOSCHED_CFQ tristate "CFQ I/O scheduler" + select ELV_FAIR_QUEUING default y ---help--- The CFQ I/O scheduler tries to distribute bandwidth equally
block/cfq-iosched.c +229 -778
1,659 lines not on this page · raw message
Signature · 1 line
1.6.0.6
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
Vivek Goyal wrote:
...
Quoted 30 lines
/*
* Check ifnew_cfqqshould preempt the currently active queue. Return 0 for
- * no or if we aren't sure, a 1 will cause a preempt.
+ * no or if we aren't sure, a 1 will cause a preemption attempt.
+ * Some of the preemption logic has been moved to common layer. Only cfq
+ * specific parts are left here.
*/
static intblock/cfq-iosched.c +4
-6-cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, - struct request *rq) +cfq_should_preempt(struct request_queue *q, void *new_cfqq, struct request *rq) { - struct cfq_queue *cfqq; + struct cfq_data *cfqd = q->elevator->elevator_data; +struct cfq_queue *cfqq =elv_active_sched_queue (q->elevator); - cfqq = cfqd->active_queue;if (!cfqq)return 0 ; -if (cfq_slice_used (cfqq)) +if (elv_ioq_slice_used (cfqq->ioq))return 1 ;if (cfq_class_idle (new_cfqq))@@ -2018,13 +1661,7 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,if (rq_is_meta (rq) && !cfqq->meta_pending)return 1 ; -/*
block/cfq-iosched.c cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, · line 1667
Quoted 10 lines
block/cfq-iosched.c +1
-6-* Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice. -*/ -if (cfq_class_rt (new_cfqq) && !cfq_class_rt (cfqq)) -return 1 ; - -if (!cfqd->active_cic || !cfq_cfqq_wait_request (cfqq)) +if (!cfqd->active_cic || !elv_ioq_wait_request (cfqq->ioq))return 0 ;/*
Hi Vivek,
cfq_should_preempt() will do the check "if (cfq_rq_close(cfqd, rq)) to see whether it should preempt the current cfqq. From fairness point of view, should we also check "fairness" value, if it's set fairness == 1, don't allow to preempt the current cfqq?
Signature · 2 lines
Regards Gui Jianfeng
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
Quoted 41 lines · Gui Jianfeng
Vivek Goyal wrote:
...Quoted 39 lines
/*
* Check ifnew_cfqqshould preempt the currently active queue. Return 0 for
- * no or if we aren't sure, a 1 will cause a preempt.
+ * no or if we aren't sure, a 1 will cause a preemption attempt.
+ * Some of the preemption logic has been moved to common layer. Only cfq
+ * specific parts are left here.
*/
static intblock/cfq-iosched.c +5
-12-cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, - struct request *rq) +cfq_should_preempt(struct request_queue *q, void *new_cfqq, struct request *rq) { - struct cfq_queue *cfqq; + struct cfq_data *cfqd = q->elevator->elevator_data; +struct cfq_queue *cfqq =elv_active_sched_queue (q->elevator); - cfqq = cfqd->active_queue;if (!cfqq)return 0 ; -if (cfq_slice_used (cfqq)) +if (elv_ioq_slice_used (cfqq->ioq))return 1 ;if (cfq_class_idle (new_cfqq))@@ -2018,13 +1661,7 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,if (rq_is_meta (rq) && !cfqq->meta_pending)return 1 ; -/* -* Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice. -*/ -if (cfq_class_rt (new_cfqq) && !cfq_class_rt (cfqq)) -return 1 ; - -if (!cfqd->active_cic || !cfq_cfqq_wait_request (cfqq)) +if (!cfqd->active_cic || !elv_ioq_wait_request (cfqq->ioq))return 0 ;
Quoted 8 lines
Review cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, · line 1667
Quoted 1 line
(quoted diff) +0
-0/*Hi Vivek,
cfq_should_preempt()will do the check "if (cfq_rq_close(cfqd, rq)) to see whether it should preempt the current cfqq. From fairness point of view, should we also check "fairness" value, if it's set fairness == 1, don't allow to preempt the current cfqq?
Hi Gui,
In V7, fairness=1 means that we try to dispatch request only from one queue at a time and wait for requests to finish from that queue before next queue is scheduled in. This helps in better disk time accounting for the queue.
But currently this is not true for preemption path. So if we decide to preempt the current queue (either by elevator layer or by cfq), we expire the queue immediately and bring in the new one. So this is just not cfq_rq_close() but the whole preemption path.
Currently I will leave it as it is but if we run into significant issues, then we can fix it. It will require extra logic of keeping track that current queue has been preempted. Also keep track who preempted etc and as soon as last request from queue completes, expire it.
Thanks
Vivek
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
Quoted 41 lines · Gui Jianfeng
Vivek Goyal wrote:
...Quoted 39 lines
/*
* Check ifnew_cfqqshould preempt the currently active queue. Return 0 for
- * no or if we aren't sure, a 1 will cause a preempt.
+ * no or if we aren't sure, a 1 will cause a preemption attempt.
+ * Some of the preemption logic has been moved to common layer. Only cfq
+ * specific parts are left here.
*/
static intblock/cfq-iosched.c +5
-12-cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, - struct request *rq) +cfq_should_preempt(struct request_queue *q, void *new_cfqq, struct request *rq) { - struct cfq_queue *cfqq; + struct cfq_data *cfqd = q->elevator->elevator_data; +struct cfq_queue *cfqq =elv_active_sched_queue (q->elevator); - cfqq = cfqd->active_queue;if (!cfqq)return 0 ; -if (cfq_slice_used (cfqq)) +if (elv_ioq_slice_used (cfqq->ioq))return 1 ;if (cfq_class_idle (new_cfqq))@@ -2018,13 +1661,7 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,if (rq_is_meta (rq) && !cfqq->meta_pending)return 1 ; -/* -* Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice. -*/ -if (cfq_class_rt (new_cfqq) && !cfq_class_rt (cfqq)) -return 1 ; - -if (!cfqd->active_cic || !cfq_cfqq_wait_request (cfqq)) +if (!cfqd->active_cic || !elv_ioq_wait_request (cfqq->ioq))return 0 ;
Quoted 8 lines
Review cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, · line 1667
Quoted 1 line
(quoted diff) +0
-0/*Hi Vivek,
cfq_should_preempt()will do the check "if (cfq_rq_close(cfqd, rq)) to see whether it should preempt the current cfqq. From fairness point of view, should we also check "fairness" value, if it's set fairness == 1, don't allow to preempt the current cfqq?
Hi Gui,
In V7, fairness=1 means that we try to dispatch request only from one queue at a time and wait for requests to finish from that queue before next queue is scheduled in. This helps in better disk time accounting for the queue.
But currently this is not true for preemption path. So if we decide to preempt the current queue (either by elevator layer or by cfq), we expire the queue immediately and bring in the new one. So this is just not cfq_rq_close() but the whole preemption path.
Currently I will leave it as it is but if we run into significant issues, then we can fix it. It will require extra logic of keeping track that current queue has been preempted. Also keep track who preempted etc and as soon as last request from queue completes, expire it.
Thanks
Vivek
A message that is not in the archive (sent off-list or not yet received): 1248467274-32073-6-git-send-email-vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
Vivek Goyal wrote:
...
Quoted 30 lines
/*
* Check ifnew_cfqqshould preempt the currently active queue. Return 0 for
- * no or if we aren't sure, a 1 will cause a preempt.
+ * no or if we aren't sure, a 1 will cause a preemption attempt.
+ * Some of the preemption logic has been moved to common layer. Only cfq
+ * specific parts are left here.
*/
static intblock/cfq-iosched.c +4
-6-cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, - struct request *rq) +cfq_should_preempt(struct request_queue *q, void *new_cfqq, struct request *rq) { - struct cfq_queue *cfqq; + struct cfq_data *cfqd = q->elevator->elevator_data; +struct cfq_queue *cfqq =elv_active_sched_queue (q->elevator); - cfqq = cfqd->active_queue;if (!cfqq)return 0 ; -if (cfq_slice_used (cfqq)) +if (elv_ioq_slice_used (cfqq->ioq))return 1 ;if (cfq_class_idle (new_cfqq))@@ -2018,13 +1661,7 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,if (rq_is_meta (rq) && !cfqq->meta_pending)return 1 ; -/*
block/cfq-iosched.c cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, · line 1667
Quoted 10 lines
block/cfq-iosched.c +1
-6-* Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice. -*/ -if (cfq_class_rt (new_cfqq) && !cfq_class_rt (cfqq)) -return 1 ; - -if (!cfqd->active_cic || !cfq_cfqq_wait_request (cfqq)) +if (!cfqd->active_cic || !elv_ioq_wait_request (cfqq->ioq))return 0 ;/*
Hi Vivek,
cfq_should_preempt() will do the check "if (cfq_rq_close(cfqd, rq)) to see whether it should preempt the current cfqq. From fairness point of view, should we also check "fairness" value, if it's set fairness == 1, don't allow to preempt the current cfqq?
Signature · 2 lines
Regards Gui Jianfeng
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
In reply to a message not in the archiveReview static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) · line 1237
Quoted 5 lines · Vivek Goyal
(quoted diff) +1
-0@@ -1616,11 +1234,12 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) struct cfq_data *cfqd = cic->key; struct cfq_queue *cfqq; unsigned long flags; + struct request_queue *q = cfqd->queue;
cfqd may be NULL here. We'd better test it before using it.
Quoted 10 lines
(quoted diff) +1
-1if (unlikely(!cfqd)) return; - spin_lock_irqsave(cfqd->queue->queue_lock, flags); + spin_lock_irqsave(q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC]; if (cfqq) {
Review static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) · line 1262
Quoted 8 lines
(quoted diff) +1
-1@@ -1637,7 +1256,7 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) if (cfqq) cfq_mark_cfqq_prio_changed(cfqq); - spin_unlock_irqrestore(cfqd->queue->queue_lock, flags); + spin_unlock_irqrestore(q->queue_lock, flags); } static void cfq_ioc_set_ioprio(struct io_context *ioc)
cfq-iosched.c renamed from cfq-iosched.c.orig +2 -1
@@ -1271,11 +1271,12 @@ static void changed_ioprio(struct io_construct cfq_data *cfqd = cic->key;struct cfq_queue *cfqq;unsigned long flags; -struct request_queue *q = cfqd->queue; +struct request_queue *q;if (unlikely (!cfqd))return ; + q = cfqd->queue;spin_lock_irqsave (q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC ];
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
In reply to Vivek GoyalReview static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) · line 1237
Quoted 5 lines · Vivek Goyal
(quoted diff) +1
-0@@ -1616,11 +1234,12 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) struct cfq_data *cfqd = cic->key; struct cfq_queue *cfqq; unsigned long flags; + struct request_queue *q = cfqd->queue;
cfqd may be NULL here. We'd better test it before using it.
Quoted 10 lines
(quoted diff) +1
-1if (unlikely(!cfqd)) return; - spin_lock_irqsave(cfqd->queue->queue_lock, flags); + spin_lock_irqsave(q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC]; if (cfqq) {
Review static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) · line 1262
Quoted 8 lines
(quoted diff) +1
-1@@ -1637,7 +1256,7 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) if (cfqq) cfq_mark_cfqq_prio_changed(cfqq); - spin_unlock_irqrestore(cfqd->queue->queue_lock, flags); + spin_unlock_irqrestore(q->queue_lock, flags); } static void cfq_ioc_set_ioprio(struct io_context *ioc)
cfq-iosched.c renamed from cfq-iosched.c.orig +2 -1
@@ -1271,11 +1271,12 @@ static void changed_ioprio(struct io_construct cfq_data *cfqd = cic->key;struct cfq_queue *cfqq;unsigned long flags; -struct request_queue *q = cfqd->queue; +struct request_queue *q;if (unlikely (!cfqd))return ; + q = cfqd->queue;spin_lock_irqsave (q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC ];
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
Quoted 9 lines · Jerome Marchand
cfq-iosched.c static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) · line 1237
Quoted 5 lines · Vivek Goyal
cfq-iosched.c renamed from cfq-iosched.c.orig +1
-0@@ -1616,11 +1234,12 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic)struct cfq_data *cfqd = cic->key;struct cfq_queue *cfqq;unsigned long flags; +struct request_queue *q = cfqd->queue;cfqd may be NULL here. We'd better test it before using it.
Thanks Jerome.
Actually I will drop this chage altogether. This is not required. I don't know why did I change original code to introduce another local variable.
Thanks
Vivek
Quoted 36 lines
Quoted 18 lines
cfq-iosched.c renamed from cfq-iosched.c.orig +2
-2if (unlikely (!cfqd))return ; -spin_lock_irqsave (cfqd->queue->queue_lock, flags); +spin_lock_irqsave (q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC ];if (cfqq) {@@ -1637,7 +1256,7 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic)if (cfqq)cfq_mark_cfqq_prio_changed (cfqq); -spin_unlock_irqrestore (cfqd->queue->queue_lock, flags); +spin_unlock_irqrestore (q->queue_lock, flags); }static void cfq_ioc_set_ioprio (struct io_context *ioc)cfq-iosched.c renamed from cfq-iosched.c.orig +2
-1@@ -1271,11 +1271,12 @@ static void changed_ioprio(struct io_construct cfq_data *cfqd = cic->key;struct cfq_queue *cfqq;unsigned long flags; -struct request_queue *q = cfqd->queue; +struct request_queue *q;if (unlikely (!cfqd))return ; + q = cfqd->queue;spin_lock_irqsave (q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC ];
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 05/24] io-controller: Modify cfq to make use of flat elevator fair queuing
Quoted 9 lines · Jerome Marchand
cfq-iosched.c static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic) · line 1237
Quoted 5 lines · Vivek Goyal
cfq-iosched.c renamed from cfq-iosched.c.orig +1
-0@@ -1616,11 +1234,12 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic)struct cfq_data *cfqd = cic->key;struct cfq_queue *cfqq;unsigned long flags; +struct request_queue *q = cfqd->queue;cfqd may be NULL here. We'd better test it before using it.
Thanks Jerome.
Actually I will drop this chage altogether. This is not required. I don't know why did I change original code to introduce another local variable.
Thanks
Vivek
Quoted 36 lines
Quoted 18 lines
cfq-iosched.c renamed from cfq-iosched.c.orig +2
-2if (unlikely (!cfqd))return ; -spin_lock_irqsave (cfqd->queue->queue_lock, flags); +spin_lock_irqsave (q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC ];if (cfqq) {@@ -1637,7 +1256,7 @@ static void changed_ioprio(struct io_context *ioc, struct cfq_io_context *cic)if (cfqq)cfq_mark_cfqq_prio_changed (cfqq); -spin_unlock_irqrestore (cfqd->queue->queue_lock, flags); +spin_unlock_irqrestore (q->queue_lock, flags); }static void cfq_ioc_set_ioprio (struct io_context *ioc)cfq-iosched.c renamed from cfq-iosched.c.orig +2
-1@@ -1271,11 +1271,12 @@ static void changed_ioprio(struct io_construct cfq_data *cfqd = cic->key;struct cfq_queue *cfqq;unsigned long flags; -struct request_queue *q = cfqd->queue; +struct request_queue *q;if (unlikely (!cfqd))return ; + q = cfqd->queue;spin_lock_irqsave (q->queue_lock, flags); cfqq = cic->cfqq[BLK_RW_ASYNC ];
PATCH 6/24 io-controller: core bfq scheduler changes for hierarchical setup
In reply to Vivek Goyalo Some of the core bfq scheduler changes for hiearchical groups.
--- block/elevator-fq.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++----- block/elevator-fq.h | 4 + init/Kconfig | 8 +++ 3 files changed, 165 insertions(+), 16 deletions(-)
block/elevator-fq.c +153 -16
@@ -38,6 +38,69 @@ static struct kmem_cache *elv_ioq_pool;*/ #define WFQ_SERVICE_SHIFT 22 +#ifdef CONFIG_GROUP_IOSCHED +#define for_each_entity (entity) \ + for (; entity != NULL; entity = entity->parent) + +#define for_each_entity_safe (entity, parent) \ + for (; entity && ({ parent = entity->parent; 1; }); entity = parent) + + +static struct io_entity *bfq_lookup_next_entity (struct io_sched_data *sd, +int extract); + +static int bfq_update_next_active (struct io_sched_data *sd) +{ +struct io_group *iog; +struct io_entity *entity, *next_active; + +if (sd->active_entity !=NULL ) +/* will update/requeue at the end of service */ +return 0 ; + +/* +* NOTE: this can be improved in may ways, such as returning +* 1 (and thus propagating upwards the update) only when the +* budget changes, or caching the bfqq that will be scheduled +* next from this subtree. By now we worry more about +* correctness than about performance... +*/ + next_active =bfq_lookup_next_entity (sd,0 ); + sd->next_active = next_active; + +if (next_active !=NULL ) { + iog = container_of(sd, struct io_group, sched_data); + entity = iog->my_entity; +if (entity !=NULL ) + entity->budget = next_active->budget; + } + +return 1 ; +} + +static inline void bfq_check_next_active (struct io_sched_data *sd, +struct io_entity *entity) +{ +BUG_ON (sd->next_active != entity); +} +#else /* GROUP_IOSCHED */ +#define for_each_entity (entity) \ + for (; entity != NULL; entity = NULL) + +#define for_each_entity_safe (entity, parent) \ + for (parent = NULL; entity != NULL; entity = parent) + +static inline int bfq_update_next_active (struct io_sched_data *sd) +{ +return 0 ; +} + +static inline void bfq_check_next_active (struct io_sched_data *sd, +struct io_entity *entity) +{ +} +#endif /* GROUP_IOSCHED */ +static inline int elv_prio_slice (struct elv_fq_data *efqd,int sync,unsigned short prio) {
@@ -582,8 +645,10 @@ static struct io_entity *bfq_lookup_next_entity(struct io_sched_data *sd, entity =__bfq_lookup_next_entity (st);if (entity !=NULL ) {if (extract) { +bfq_check_next_active (sd, entity);bfq_active_remove (st, entity); sd->active_entity = entity; + sd->next_active =NULL ; }break ; }
@@ -660,11 +725,8 @@ static void __bfq_activate_entity(struct io_entity *entity, int add_front)if (add_front) {struct io_entity *next_entity; -/* -* Determine the entity which will be dispatched next -* Use sd->next_active once hierarchical patch is applied -*/ - next_entity =bfq_lookup_next_entity (sd,0 ); +/* Determine the entity which will be dispatched next */ + next_entity = sd->next_active;if (next_entity && next_entity != entity) {struct io_service_tree *new_st;
@@ -696,7 +758,21 @@ static void __bfq_activate_entity(struct io_entity *entity, int add_front)*/ static void bfq_activate_entity (struct io_entity *entity,int add_front) { -__bfq_activate_entity (entity, add_front); +struct io_sched_data *sd; + +for_each_entity (entity) { +__bfq_activate_entity (entity, add_front); + + add_front =0 ; + sd = entity->sched_data; +if (!bfq_update_next_active (sd)) +/* +* No need to propagate the activation to the +* upper entities, as they will be updated when +* the active entity is rescheduled. +*/ +break ; + } }/**
@@ -731,6 +807,8 @@ static int __bfq_deactivate_entity(struct io_entity *entity, int requeue)bfq_idle_remove (st, entity); else if (entity->tree != NULL) BUG(); +if (was_active || sd->next_active == entity) + ret =bfq_update_next_active (sd);if (!requeue || !bfq_gt (entity->finish, st->vtime))bfq_forget_entity (st, entity);
@@ -738,6 +816,7 @@ static int __bfq_deactivate_entity(struct io_entity *entity, int requeue)bfq_idle_insert (st, entity);BUG_ON (sd->active_entity == entity); +BUG_ON (sd->next_active == entity);return ret; }
@@ -749,18 +828,62 @@ static int __bfq_deactivate_entity(struct io_entity *entity, int requeue)*/ static void bfq_deactivate_entity (struct io_entity *entity,int requeue) { -__bfq_deactivate_entity (entity, requeue); +struct io_sched_data *sd; +struct io_entity *parent; + +for_each_entity_safe (entity, parent) { + sd = entity->sched_data; + +if (!__bfq_deactivate_entity (entity, requeue)) +/* +* The parent entity is still backlogged, and +* we don't need to update it as it is still +* under service. +*/ +break ; + +if (sd->next_active !=NULL ) { +/* +* The parent entity is still backlogged and +* the budgets on the path towards the root +* need to be updated. +*/ + goto update; + } + +/* +* If we reach there the parent is no more backlogged and +* we want to propagate the dequeue upwards. +* +*/ + + requeue =1 ; + } + +return ; + +update: + entity = parent; +for_each_entity (entity) { +__bfq_activate_entity (entity,0 ); + + sd = entity->sched_data; +if (!bfq_update_next_active (sd)) +break ; + } }static void entity_served (struct io_entity *entity,unsigned long served) {struct io_service_tree *st; - st =io_entity_service_tree (entity); - entity->service += served; -BUG_ON (st->wsum ==0 ); - st->vtime +=bfq_delta (served, st->wsum); -bfq_forget_idle (st); +for_each_entity (entity) { + st =io_entity_service_tree (entity); + entity->service += served; +BUG_ON (st->wsum ==0 ); + st->vtime +=bfq_delta (served, st->wsum); +bfq_forget_idle (st); + } }/**
@@ -1068,11 +1191,25 @@ static struct io_queue *elv_get_next_ioq(struct request_queue *q, int extract)return NULL ; sd = &efqd->root_group->sched_data; - entity =bfq_lookup_next_entity (sd,1 ); -BUG_ON (!entity); -if (extract) - entity->service =0 ; +for (; sd !=NULL ; sd = entity->my_sched_data) { + entity =bfq_lookup_next_entity (sd,1 ); +/* +* entity can be null despite the fact that there are busy +* queues. if all the busy queues are under a group which is +* currently under service. +* So if we are just looking for next ioq while something is +* being served, null entity is not an error. +*/ +BUG_ON (!entity && extract); + +if (extract) + entity->service =0 ; + +if (!entity) +return NULL ; + } + ioq =io_entity_to_ioq (entity);return ioq;
block/elevator-fq.h +4 -0
@@ -72,6 +72,7 @@ struct io_service_tree {*/ struct io_sched_data {struct io_entity *active_entity; +struct io_entity *next_active;struct io_service_tree service_tree[IO_IOPRIO_CLASSES ]; };
@@ -178,7 +179,10 @@ struct io_queue { };struct io_group { +struct io_entity entity;struct io_sched_data sched_data; +struct io_entity *my_entity; +/* * async queue for each priority case for RT and BE class. * Used only for cfq.
init/Kconfig +8 -0
@@ -612,6 +612,14 @@ config CGROUP_MEM_RES_CTLR_SWAP Now, memory usage of swap_cgroup is 2 bytes per entry. If swap page size is 4096bytes, 512k per 1Gbytes of swap. +config GROUP_IOSCHED + bool "Group IO Scheduler" + depends on CGROUPS && ELV_FAIR_QUEUING + default n + ---help--- + This feature lets IO scheduler recognize task groups and control + disk bandwidth allocation to such task groups. + endif # CGROUPS config MM_OWNER
Signature · 1 line
1.6.0.6
PATCH 7/24 io-controller: cgroup related changes for hierarchical group support
In reply to Vivek Goyalo This patch introduces some of the cgroup related code for io controller.
--- block/blk-ioc.c | 3 + block/elevator-fq.c | 174 +++++++++++++++++++++++++++++++++++++++++ block/elevator-fq.h | 38 +++++++++- include/linux/cgroup_subsys.h | 6 ++ include/linux/iocontext.h | 5 + 5 files changed, 225 insertions(+), 1 deletions(-)
block/blk-ioc.c +3 -0
@@ -95,6 +95,9 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node)spin_lock_init (&ret->lock); ret->ioprio_changed =0 ; ret->ioprio =0 ; +#ifdef CONFIG_GROUP_IOSCHED + ret->cgroup_changed =0 ; +#endif ret->last_waited = jiffies;/* doesn't matter... */ ret->nr_batch_requests =0 ;/* because this is 0 */ ret->aic =NULL ;
block/elevator-fq.c +174 -0
186 lines not on this page · raw message
block/elevator-fq.h +37 -1
@@ -13,11 +13,13 @@*/ #include <linux/blkdev.h> +#include <linux/cgroup.h> #ifndef _BFQ_SCHED_H#define _BFQ_SCHED_H#define IO_IOPRIO_CLASSES 3 +#define WEIGHT_MAX 1000struct io_entity ;struct io_queue ;
@@ -88,7 +90,7 @@ struct io_sched_data {* this entity; used for O(log N) lookups into active trees. * @service: service received during the last round of service. * @budget: budget used to calculate F_i; F_i = S_i + @budget / @weight. -* @weight: weight of the queue, calculated as IOPRIO_BE_NR - @ioprio. +* @weight: the weight in use. * @new_weight: when a weight change is requested, the new weight value * @parent: parent entity, for hierarchical scheduling. * @my_sched_data: for non-leaf nodes in the cgroup hierarchy, the
@@ -178,8 +180,10 @@ struct io_queue {void *sched_queue; }; +#ifdef CONFIG_GROUP_IOSCHED struct io_group { struct io_entity entity; + struct hlist_node group_node; struct io_sched_data sched_data; struct io_entity *my_entity;
@@ -190,8 +194,40 @@ struct io_group {struct io_queue *async_queue[2 ][IOPRIO_BE_NR ];struct io_queue *async_idle_queue; +unsigned short iocg_id; }; +/** +* struct io_cgroup - io cgroup data structure. +* @css: subsystem state for io in the containing cgroup. +* @weight: cgroup weight. +* @ioprio_class: cgroup ioprio_class. +* @lock: spinlock that protects @weight, @ioprio_class and @group_data. +* @group_data: list containing the io_group belonging to this cgroup. +* +* @group_data is accessed using RCU, with @lock protecting the updates, +* @weight and @ioprio_class are protected by @lock. +*/ +struct io_cgroup { +struct cgroup_subsys_state css; + +unsigned int weight; +unsigned short ioprio_class; + +spinlock_t lock; +struct hlist_head group_data; +}; +#else +struct io_group { +struct io_sched_data sched_data; + +/* async_queue and idle_queue are used only for cfq */ +struct io_queue *async_queue[2 ][IOPRIO_BE_NR ]; +struct io_queue *async_idle_queue; +}; +#endif /* CONFIG_GROUP_IOSCHED */ + +struct elv_fq_data {struct io_group *root_group;
include/linux/cgroup_subsys.h +6 -0
@@ -60,3 +60,9 @@ SUBSYS(net_cls)#endif /* */ + +#ifdef CONFIG_GROUP_IOSCHED +SUBSYS(io) +#endif + +/* */
include/linux/iocontext.h +5 -0
@@ -73,6 +73,11 @@ struct io_context {unsigned short ioprio;unsigned short ioprio_changed; +#ifdef CONFIG_GROUP_IOSCHED +/* If task changes the cgroup, elevator processes it asynchronously */ +unsigned short cgroup_changed; +#endif +/* * For request batching */
Signature · 1 line
1.6.0.6
PATCH 8/24 io-controller: Common hierarchical fair queuing code in elevaotor layer
In reply to Vivek Goyalo This patch enables hierarchical fair queuing in common layer. It is controlled by config option CONFIG_GROUP_IOSCHED.
o Requests keep a reference on ioq and ioq keeps keep a reference on groups. For async queues in CFQ, and single ioq in other schedulers, io_group also keeps are reference on io_queue. This reference on ioq is dropped when the queue is released (elv_release_ioq). So the queue can be freed.
When a queue is released, it puts the reference to io_group and the io_group is released after all the queues are released. Child groups also take reference on parent groups, and release it when they are destroyed.
o Reads of iocg->group_data are not always iocg->lock; so all the operations on that list are still protected by RCU. All modifications to iocg->group_data should always done under iocg->lock.
Whenever iocg->lock and queue_lock can both be held, queue_lock should be held first. This avoids all deadlocks. In order to avoid race between cgroup deletion and elevator switch the following algorithm is used:
- Cgroup deletion path holds iocg->lock and removes iog entry to iocg->group_data list. Then it drops iocg->lock, holds queue_lock and destroys iog. So in this path, we never hold iocg->lock and queue_lock at the same time. Also, since we remove iog from iocg->group_data under iocg->lock, we can't race with elevator switch.
- Elevator switch path does not remove iog from iocg->group_data list directly. It first hold iocg->lock, scans iocg->group_data again to see if iog is still there; it removes iog only if it finds iog there. Otherwise, cgroup deletion must have removed it from the list, and cgroup deletion is responsible for removing iog.
So the path which removes iog from iocg->group_data list does the final removal of iog by calling __io_destroy_group() function.
--- block/cfq-iosched.c | 3 + block/elevator-fq.c | 890 ++++++++++++++++++++++++++++++++++++++++++++++----- block/elevator-fq.h | 91 +++++- block/elevator.c | 4 + 4 files changed, 911 insertions(+), 77 deletions(-)
block/cfq-iosched.c +3 -0
@@ -1354,6 +1354,9 @@ alloc_cfqq: cfqq->ioq = ioq;cfq_init_cfqq (cfqd, cfqq, current->pid, is_sync);cfq_init_prio_data (cfqq, ioc); + +/* ioq reference on iog */ +elv_get_iog (iog);cfq_log_cfqq (cfqd, cfqq,"alloced" ); }else { cfqq = &cfqd->oom_cfqq;
block/elevator-fq.c +815 -75
1,050 lines not on this page · raw message
block/elevator-fq.h +89 -2
139 lines not on this page · raw message
block/elevator.c +4 -0
@@ -113,6 +113,10 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio) !bio_failfast_driver(bio) != !blk_failfast_driver(rq))return 0 ; +/* If rq and bio belongs to different groups, dont allow merging */ +if (!io_group_allow_merge (rq, bio)) +return 0 ; +if (!elv_iosched_allow_merge (rq, bio))return 0 ;
Signature · 1 line
1.6.0.6
PATCH 9/24 io-controller: cfq changes to use hierarchical fair queuing code in elevaotor layer
In reply to Vivek GoyalMake cfq hierarhical.
--- block/Kconfig.iosched | 8 ++++++ block/cfq-iosched.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++- init/Kconfig | 2 +- 3 files changed, 69 insertions(+), 3 deletions(-)
block/Kconfig.iosched +8 -0
@@ -54,6 +54,14 @@ config IOSCHED_CFQ working environment, suitable for desktop systems. This is the default I/O scheduler. +config IOSCHED_CFQ_HIER + bool "CFQ Hierarchical Scheduling support" + depends on IOSCHED_CFQ && CGROUPS + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in cfq. + choice prompt "Default I/O scheduler" default DEFAULT_CFQ
block/cfq-iosched.c +60 -2
86 lines not on this page · raw message
init/Kconfig +1 -1
@@ -613,7 +613,7 @@ config CGROUP_MEM_RES_CTLR_SWAP size is 4096bytes, 512k per 1Gbytes of swap. config GROUP_IOSCHED - bool "Group IO Scheduler" + bool depends on CGROUPS && ELV_FAIR_QUEUING default n ---help---
Signature · 1 line
1.6.0.6
PATCH 10/24 io-controller: Export disk time used and nr sectors dipatched through cgroups
In reply to Vivek Goyalo This patch exports some statistics through cgroup interface. Two of the statistics currently exported are actual disk time assigned to the cgroup and actual number of sectors dispatched to disk on behalf of this cgroup.
--- block/elevator-fq.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 10 ++++++ 2 files changed, 89 insertions(+), 2 deletions(-)
block/elevator-fq.c +79 -2
@@ -15,6 +15,7 @@#include <linux/blkdev.h> #include "elevator-fq.h" #include <linux/blktrace_api.h> +#include <linux/seq_file.h> /* Values taken from cfq */ const int elv_slice_sync =HZ /10 ;
@@ -977,13 +978,16 @@ update: } } -static void entity_served (struct io_entity *entity,unsigned long served) +void entity_served (struct io_entity *entity,unsigned long served, +unsigned long nr_sectors) {struct io_service_tree *st;for_each_entity (entity) { st =io_entity_service_tree (entity); entity->service += served; + entity->total_service += served; + entity->total_sector_service += nr_sectors;BUG_ON (st->wsum ==0 ); st->vtime +=bfq_delta (served, st->wsum);bfq_forget_idle (st);
@@ -1144,6 +1148,66 @@ STORE_FUNCTION(weight, 1, WEIGHT_MAX);STORE_FUNCTION (ioprio_class,IOPRIO_CLASS_RT ,IOPRIO_CLASS_IDLE );#undef STORE_FUNCTION +static int io_cgroup_disk_time_read (struct cgroup *cgroup, +struct cftype *cftype,struct seq_file *m) +{ +struct io_cgroup *iocg; +struct io_group *iog; +struct hlist_node *n; + +if (!cgroup_lock_live_group (cgroup)) +return -ENODEV ; + + iocg =cgroup_to_io_cgroup (cgroup); + +rcu_read_lock (); +hlist_for_each_entry_rcu (iog, n, &iocg->group_data, group_node) { +/* +* There might be groups which are not functional and +* waiting to be reclaimed upon cgoup deletion. +*/ +if (iog->key) { +seq_printf (m,"%u:%u %lu\n" ,MAJOR (iog->dev), +MINOR (iog->dev), + iog->entity.total_service); + } + } +rcu_read_unlock (); +cgroup_unlock (); + +return 0 ; +} + +static int io_cgroup_disk_sectors_read (struct cgroup *cgroup, +struct cftype *cftype,struct seq_file *m) +{ +struct io_cgroup *iocg; +struct io_group *iog; +struct hlist_node *n; + +if (!cgroup_lock_live_group (cgroup)) +return -ENODEV ; + + iocg =cgroup_to_io_cgroup (cgroup); + +rcu_read_lock (); +hlist_for_each_entry_rcu (iog, n, &iocg->group_data, group_node) { +/* +* There might be groups which are not functional and +* waiting to be reclaimed upon cgoup deletion. +*/ +if (iog->key) { +seq_printf (m,"%u:%u %lu\n" ,MAJOR (iog->dev), +MINOR (iog->dev), + iog->entity.total_sector_service); + } + } +rcu_read_unlock (); +cgroup_unlock (); + +return 0 ; +} +struct cftype bfqio_files[] = { { .name ="weight" ,
@@ -1155,6 +1219,14 @@ struct cftype bfqio_files[] = { .read_u64 = io_cgroup_ioprio_class_read, .write_u64 = io_cgroup_ioprio_class_write, }, + { + .name = "disk_time", + .read_seq_string = io_cgroup_disk_time_read, + }, + { + .name = "disk_sectors", + .read_seq_string = io_cgroup_disk_sectors_read, + }, };static int iocg_populate (struct cgroup_subsys *subsys,struct cgroup *cgroup)
@@ -1256,6 +1328,8 @@ io_group_chain_alloc(struct request_queue *q, void *key, struct cgroup *cgroup)struct io_cgroup *iocg;struct io_group *iog, *leaf =NULL , *prev =NULL ;gfp_t flags =GFP_ATOMIC | __GFP_ZERO; +unsigned int major, minor; +struct backing_dev_info *bdi = &q->backing_dev_info;for (; cgroup !=NULL ; cgroup = cgroup->parent) { iocg =cgroup_to_io_cgroup (cgroup);
@@ -1276,6 +1350,9 @@ io_group_chain_alloc(struct request_queue *q, void *key, struct cgroup *cgroup) iog->iocg_id =css_id (&iocg->css); +sscanf (dev_name (bdi->dev),"%u:%u" , &major, &minor); + iog->dev =MKDEV (major, minor); +io_group_init_entity (iocg, iog); iog->my_entity = &iog->entity;
@@ -1869,7 +1946,7 @@ EXPORT_SYMBOL(elv_del_idle_slice_timer);static void elv_ioq_served (struct io_queue *ioq,unsigned long served) { -entity_served (&ioq->entity, served); +entity_served (&ioq->entity, served, ioq->nr_sectors); }/*
block/elevator-fq.h +10 -0
@@ -147,6 +147,13 @@ struct io_entity {unsigned short ioprio_class, new_ioprio_class;int ioprio_changed; + +/* +* Keep track of total service received by this entity. Keep the +* stats both for time slices and number of sectors dispatched +*/ +unsigned long total_service; +unsigned long total_sector_service; };/*
@@ -233,6 +240,9 @@ struct io_group {struct rcu_head rcu_head;int deleting;unsigned short iocg_id; + +/* The device MKDEV(major, minor), this group has been created for */ +dev_t dev; };/**
Signature · 1 line
1.6.0.6
PATCH 11/24 io-controller: Debug hierarchical IO scheduling
In reply to Vivek Goyalo Littile debugging aid for hierarchical IO scheduling.
o Enabled under CONFIG_DEBUG_GROUP_IOSCHED
o Currently it outputs more debug messages in blktrace output which helps a great deal in debugging in hierarchical setup. It also creates additional cgroup interfaces io.disk_queue and io.disk_dequeue to output some more debugging data.
--- block/Kconfig.iosched | 8 ++ block/elevator-fq.c | 300 ++++++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 38 ++++++- 3 files changed, 339 insertions(+), 7 deletions(-)
block/Kconfig.iosched +8 -0
@@ -90,6 +90,14 @@ config DEFAULT_IOSCHED default "cfq" if DEFAULT_CFQ default "noop" if DEFAULT_NOOP +config DEBUG_GROUP_IOSCHED + bool "Debug Hierarchical Scheduling support" + depends on CGROUPS && GROUP_IOSCHED + default n + ---help--- + Enable some debugging hooks for hierarchical scheduling support. + Currently it just outputs more information in blktrace output. + endmenu endif
block/elevator-fq.c +294 -6
427 lines not on this page · raw message
block/elevator-fq.h +37 -1
@@ -75,6 +75,7 @@ struct io_service_tree {struct io_sched_data {struct io_entity *active_entity;struct io_entity *next_active; +int nr_active;struct io_service_tree service_tree[IO_IOPRIO_CLASSES ]; };
@@ -243,6 +244,23 @@ struct io_group {/* The device MKDEV(major, minor), this group has been created for */ dev_t dev; + +#ifdef CONFIG_DEBUG_GROUP_IOSCHED +/* How many times this group has been added to active tree */ +unsigned long queue; + +/* How long this group remained on active tree, in ms */ +unsigned long queue_duration; + +/* When was this group added to active tree */ +unsigned long queue_start; + +/* How many times this group has been removed from active tree */ +unsigned long dequeue; + +/* Store cgroup path */ +char path[128 ]; +#endif };/**
@@ -303,10 +321,29 @@ struct elv_fq_data { };/* Logging facilities. */ +#ifdef CONFIG_DEBUG_GROUP_IOSCHED +#define elv_log_ioq(efqd, ioq, fmt, args...) \ +{ \ + blk_add_trace_msg((efqd)->queue, "elv%d%c %s " fmt, (ioq)->pid, \ + elv_ioq_sync(ioq) ? 'S' : 'A', \ + ioq_to_io_group(ioq)->path, ##args); \ +} + +#define elv_log_iog(efqd, iog, fmt, args...) \ +{ \ + blk_add_trace_msg((efqd)->queue, "elv %s " fmt, (iog)->path, ##args); \ +} + +#else #define elv_log_ioq(efqd, ioq, fmt, args...) \ blk_add_trace_msg((efqd)->queue, "elv%d%c " fmt, (ioq)->pid, \ elv_ioq_sync(ioq) ? 'S' : 'A', ##args) +#define elv_log_iog(efqd, iog, fmt, args...) \ + blk_add_trace_msg((efqd)->queue, "elv " fmt, ##args) + +#endif + #define elv_log(efqd, fmt, args...) \ blk_add_trace_msg((efqd)->queue, "elv " fmt, ##args)
@@ -443,7 +480,6 @@ static inline struct io_group *ioq_to_io_group(struct io_queue *ioq)#ifdef CONFIG_GROUP_IOSCHED extern int io_group_allow_merge (struct request *rq,struct bio *bio);extern void elv_put_iog (struct io_group *iog); -static inline void elv_get_iog (struct io_group *iog) {atomic_inc (&iog->ref);
Signature · 1 line
1.6.0.6
PATCH 12/24 io-controller: Introduce group idling
In reply to Vivek Goyalo It is not always that IO from a process or group is continuous. There are cases of dependent reads where next read is not issued till previous read has finished. For such cases, CFQ introduced the notion of slice_idle, where we idle on the queue for sometime hoping next request will come and that's how fairness is provided otherwise queue will be deleted immediately from the service tree and this process will not get the fair share.
o This patch introduces the similar concept at group level. Idle on the group for a period of "group_idle" which is tunable through sysfs interface. So if a group is empty and about to be deleted, we idle for the next request.
o This patch also introduces the notion of wait busy where we wait for one extra group_idle period even if queue has consumed its time slice. The reason being that group will loose its share upon removal from service tree as some other entity will be picked for dispatch and vtime jump will take place.
--- block/cfq-iosched.c | 3 + block/elevator-fq.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++--- block/elevator-fq.h | 42 ++++++++++++ 3 files changed, 213 insertions(+), 9 deletions(-)
block/cfq-iosched.c +3 -0
@@ -2124,6 +2124,9 @@ static struct elv_fs_entry cfq_attrs[] = {CFQ_ATTR (slice_idle),ELV_ATTR (slice_sync),ELV_ATTR (slice_async), +#ifdef CONFIG_GROUP_IOSCHED +ELV_ATTR (group_idle), +#endif __ATTR_NULL };
block/elevator-fq.c +168 -9
316 lines not on this page · raw message
block/elevator-fq.h +42 -0
66 lines not on this page · raw message
Signature · 1 line
1.6.0.6
PATCH 13/24 io-controller: Wait for requests to complete from last queue before new queue is scheduled
In reply to Vivek Goyalo Currently one can dispatch requests from multiple queues to the disk. This is true for hardware which supports queuing. So if a disk support queue depth of 31 it is possible that 20 requests are dispatched from queue 1 and then next queue is scheduled in which dispatches more requests.
o This multiple queue dispatch introduces issues for accurate accounting of disk time consumed by a particular queue. For example, if one async queue is scheduled in, it can dispatch 31 requests to the disk and then it will be expired and a new sync queue might get scheduled in. These 31 requests might take a long time to finish but this time is never accounted to the async queue which dispatched these requests.
o This patch introduces the functionality where we wait for all the requests to finish from previous queue before next queue is scheduled in. That way a queue is more accurately accounted for disk time it has consumed. Note this still does not take care of errors introduced by disk write caching.
o Because above behavior can result in reduced throughput, this behavior will be enabled only if user sets "fairness" tunable to 1.
o This patch helps in achieving more isolation between reads and buffered writes in different cgroups. buffered writes typically utilize full queue depth and then expire the queue. On the contarary, sequential reads typicaly driver queue depth of 1. So despite the fact that writes are using more disk time it is never accounted to write queue because we don't wait for requests to finish after dispatching these. This patch helps do more accurate accounting of disk time, especially for buffered writes hence providing better fairness hence better isolation between two cgroups running read and write workloads.
--- block/cfq-iosched.c | 1 + block/elevator-fq.c | 33 +++++++++++++++++++++++++++++++++ block/elevator-fq.h | 10 +++++++++- 3 files changed, 43 insertions(+), 1 deletions(-)
block/cfq-iosched.c +1 -0
@@ -2126,6 +2126,7 @@ static struct elv_fs_entry cfq_attrs[] = { ELV_ATTR(slice_async),#ifdef CONFIG_GROUP_IOSCHED ELV_ATTR (group_idle), +ELV_ATTR (fairness), #endif __ATTR_NULL };
block/elevator-fq.c +33 -0
@@ -2224,6 +2224,8 @@ SHOW_FUNCTION(elv_slice_sync_show, efqd->elv_slice[1], 1);EXPORT_SYMBOL (elv_slice_sync_show);SHOW_FUNCTION (elv_slice_async_show, efqd->elv_slice[0 ],1 );EXPORT_SYMBOL (elv_slice_async_show); +SHOW_FUNCTION (elv_fairness_show, efqd->fairness,0 ); +EXPORT_SYMBOL (elv_fairness_show);#undef SHOW_FUNCTION#define STORE_FUNCTION (__FUNC, __PTR,MIN ,MAX , __CONV) \
@@ -2248,6 +2250,8 @@ STORE_FUNCTION(elv_slice_sync_store, &efqd->elv_slice[1], 1, UINT_MAX, 1);EXPORT_SYMBOL (elv_slice_sync_store);STORE_FUNCTION (elv_slice_async_store, &efqd->elv_slice[0 ],1 ,UINT_MAX ,1 );EXPORT_SYMBOL (elv_slice_async_store); +STORE_FUNCTION (elv_fairness_store, &efqd->fairness,0 ,1 ,0 ); +EXPORT_SYMBOL (elv_fairness_store);#undef STORE_FUNCTIONvoid elv_schedule_dispatch (struct request_queue *q)
@@ -3093,6 +3097,24 @@ void *elv_fq_select_ioq(struct request_queue *q, int force) } expire: +if (efqd->fairness && !force && ioq && ioq->dispatched) { +/* +* If there are request dispatched from this queue, don't +* dispatch requests from new queue till all the requests from +* this queue have completed. +* +* This helps in attributing right amount of disk time consumed +* by a particular queue when hardware allows queuing. +* +* Set ioq = NULL so that no more requests are dispatched from +* this queue. +*/ +elv_log_ioq (efqd, ioq,"select: wait for requests to finish" +" disp=%lu" , ioq->dispatched); + ioq =NULL ; + goto keep_queue; + } +elv_ioq_slice_expired (q); new_queue: ioq =elv_set_active_ioq (q, new_ioq);
@@ -3216,6 +3238,17 @@ void elv_ioq_completed_request(struct request_queue *q, struct request *rq) goto done; } +/* If fairness is set and there are requests +* dispatched from this queue, don't dispatch +* new requests from a different queue till +* all requests from this queue have finished. +* This helps in attributing right disk time +* to a queue when hardware supports queuing. +*/ + +if (efqd->fairness && ioq->dispatched) + goto done; +/* Expire the queue */ elv_ioq_slice_expired (q); } else if (!ioq->nr_queued && !elv_close_cooperator(q, ioq)
block/elevator-fq.h +9 -1
@@ -321,6 +321,12 @@ struct elv_fq_data {* Fallback dummy ioq for extreme OOM conditions */ struct io_queue oom_ioq; + +/* +* If set to 1, waits for all request completions from current +* queue before new queue is scheduled in +*/ +unsigned int fairness; };/* Logging facilities. */
@@ -564,7 +570,9 @@ extern ssize_t elv_slice_sync_store(struct elevator_queue *q, const char *name,extern ssize_t elv_slice_async_show (struct elevator_queue *q,char *name);extern ssize_t elv_slice_async_store (struct elevator_queue *q,const char *name,size_t count); - +extern ssize_t elv_fairness_show (struct elevator_queue *q,char *name); +extern ssize_t elv_fairness_store (struct elevator_queue *q,const char *name, +size_t count);/* Functions used by elevator.c */ extern int elv_init_fq_data (struct request_queue *q,struct elevator_queue *e);extern void elv_exit_fq_data (struct elevator_queue *e);
Signature · 1 line
1.6.0.6
PATCH 14/24 io-controller: Separate out queue and data
In reply to Vivek Goyalo So far noop, deadline and AS had one common structure called *_data which contained both the queue information where requests are queued and also common data used for scheduling. This patch breaks down this common structure in two parts, *_queue and *_data. This is along the lines of cfq where all the reuquests are queued in queue and common data and tunables are part of data.
o It does not change the functionality but this re-organization helps once noop, deadline and AS are changed to use hierarchical fair queuing.
o looks like queue_empty function is not required and we can check for q->nr_sorted in elevator layer to see if ioscheduler queues are empty or not.
--- block/as-iosched.c | 208 ++++++++++++++++++++++++++-------------------- block/deadline-iosched.c | 117 ++++++++++++++++---------- block/elevator.c | 111 +++++++++++++++++++++---- block/noop-iosched.c | 59 ++++++------- include/linux/elevator.h | 9 ++- 5 files changed, 320 insertions(+), 184 deletions(-)
block/as-iosched.c +118 -90
@@ -76,13 +76,7 @@ enum anticipation_status {* or timed out */ }; -struct as_data { -/* -* run time data -*/ - -struct request_queue *q;/* the "owner" queue */ - +struct as_queue {/* * requests (as_rq s) are present on both sort_list and fifo_list */
@@ -90,6 +84,14 @@ struct as_data {struct list_head fifo_list[2 ];struct request *next_rq[2 ];/* next in sort order */ +unsigned long last_check_fifo[2 ]; +int write_batch_count;/* max # of reqs in a write batch */ +int current_write_count;/* how many requests left this batch */ +int write_batch_idled;/* has the write batch gone idle? */ +}; + +struct as_data { +struct request_queue *q;/* the "owner" queue */ sector_t last_sector[2 ];/* last SYNC & ASYNC sectors */ unsigned long exit_prob;/* probability a task will exit while
@@ -103,21 +105,17 @@ struct as_data {sector_t new_seek_mean;unsigned long current_batch_expires; -unsigned long last_check_fifo[2 ];int changed_batch;/* 1: waiting for old batch to end */ int new_batch;/* 1: waiting on first read complete */ -int batch_data_dir;/* current batch SYNC / ASYNC */ -int write_batch_count;/* max # of reqs in a write batch */ -int current_write_count;/* how many requests left this batch */ -int write_batch_idled;/* has the write batch gone idle? */ enum anticipation_status antic_status;unsigned long antic_start;/* jiffies: when it started */ struct timer_list antic_timer;/* anticipatory scheduling timer */ -struct work_struct antic_work;/* Deferred unplugging */ +struct work_struct antic_work;/* Deferred unplugging */ struct io_context *io_context;/* Identify the expected process */ int ioc_finished;/* IO associated with io_context is finished */ int nr_dispatched; +int batch_data_dir;/* current batch SYNC / ASYNC */ /* * settings that change how the i/o scheduler behaves
@@ -258,13 +256,14 @@ static void as_put_io_context(struct request *rq)/* * rb tree support functions */ -#define RQ_RB_ROOT (ad, rq) (&(ad)->sort_list[rq_is_sync((rq))]) +#define RQ_RB_ROOT (asq, rq) (&(asq)->sort_list[rq_is_sync((rq))])static void as_add_rq_rb (struct as_data *ad,struct request *rq) {struct request *alias; +struct as_queue *asq =elv_get_sched_queue (ad->q, rq); -while ((unlikely (alias =elv_rb_add (RQ_RB_ROOT (ad, rq), rq)))) { +while ((unlikely (alias =elv_rb_add (RQ_RB_ROOT (asq, rq), rq)))) {as_move_to_dispatch (ad, alias);as_antic_stop (ad); }
@@ -272,7 +271,9 @@ static void as_add_rq_rb(struct as_data *ad, struct request *rq)static inline void as_del_rq_rb (struct as_data *ad,struct request *rq) { -elv_rb_del (RQ_RB_ROOT (ad, rq), rq); +struct as_queue *asq =elv_get_sched_queue (ad->q, rq); + +elv_rb_del (RQ_RB_ROOT (asq, rq), rq); }/*
@@ -366,7 +367,7 @@ as_choose_req(struct as_data *ad, struct request *rq1, struct request *rq2)* what request to process next. Anticipation works on top of this. */ static struct request * -as_find_next_rq (struct as_data *ad,struct request *last) +as_find_next_rq (struct as_data *ad,struct as_queue *asq,struct request *last) {struct rb_node *rbnext =rb_next (&last->rb_node);struct rb_node *rbprev =rb_prev (&last->rb_node);
@@ -382,7 +383,7 @@ as_find_next_rq(struct as_data *ad, struct request *last)else {const int data_dir =rq_is_sync (last); - rbnext =rb_first (&ad->sort_list[data_dir]); + rbnext =rb_first (&asq->sort_list[data_dir]);if (rbnext && rbnext != &last->rb_node) next =rb_entry_rq (rbnext); }
@@ -789,9 +790,10 @@ static int as_can_anticipate(struct as_data *ad, struct request *rq)static void as_update_rq (struct as_data *ad,struct request *rq) {const int data_dir =rq_is_sync (rq); +struct as_queue *asq =elv_get_sched_queue (ad->q, rq);/* keep the next_rq cache up to date */ - ad->next_rq[data_dir] =as_choose_req (ad, rq, ad->next_rq[data_dir]); + asq->next_rq[data_dir] =as_choose_req (ad, rq, asq->next_rq[data_dir]);/* * have we been anticipating this request?
@@ -812,25 +814,26 @@ static void update_write_batch(struct as_data *ad) {unsigned long batch = ad->batch_expire[BLK_RW_ASYNC ];long write_time; +struct as_queue *asq =elv_get_sched_queue (ad->q,NULL ); write_time = (jiffies - ad->current_batch_expires) + batch;if (write_time <0 ) write_time =0 ; -if (write_time > batch && !ad->write_batch_idled) { +if (write_time > batch && !asq->write_batch_idled) {if (write_time > batch *3 ) - ad->write_batch_count /=2 ; + asq->write_batch_count /=2 ;else - ad->write_batch_count--; - }else if (write_time < batch && ad->current_write_count ==0 ) { + asq->write_batch_count--; + }else if (write_time < batch && asq->current_write_count ==0 ) {if (batch > write_time *3 ) - ad->write_batch_count *=2 ; + asq->write_batch_count *=2 ;else - ad->write_batch_count++; + asq->write_batch_count++; } -if (ad->write_batch_count <1 ) - ad->write_batch_count =1 ; +if (asq->write_batch_count <1 ) + asq->write_batch_count =1 ; }/*
@@ -901,6 +904,7 @@ static void as_remove_queued_request(struct request_queue *q,const int data_dir =rq_is_sync (rq);struct as_data *ad = q->elevator->elevator_data;struct io_context *ioc; +struct as_queue *asq =elv_get_sched_queue (q, rq);WARN_ON (RQ_STATE (rq) !=AS_RQ_QUEUED );
@@ -914,8 +918,8 @@ static void as_remove_queued_request(struct request_queue *q,* Update the "next_rq" cache if we are about to remove its * entry */ -if (ad->next_rq[data_dir] == rq) - ad->next_rq[data_dir] =as_find_next_rq (ad, rq); +if (asq->next_rq[data_dir] == rq) + asq->next_rq[data_dir] =as_find_next_rq (ad, asq, rq);rq_fifo_clear (rq);as_del_rq_rb (ad, rq);
@@ -929,23 +933,23 @@ static void as_remove_queued_request(struct request_queue *q,* * See as_antic_expired comment. */ -static int as_fifo_expired (struct as_data *ad,int adir) +static int as_fifo_expired (struct as_data *ad,struct as_queue *asq,int adir) {struct request *rq;long delta_jif; - delta_jif = jiffies - ad->last_check_fifo[adir]; + delta_jif = jiffies - asq->last_check_fifo[adir];if (unlikely (delta_jif <0 )) delta_jif = -delta_jif;if (delta_jif < ad->fifo_expire[adir])return 0 ; - ad->last_check_fifo[adir] = jiffies; + asq->last_check_fifo[adir] = jiffies; -if (list_empty (&ad->fifo_list[adir])) +if (list_empty (&asq->fifo_list[adir]))return 0 ; - rq =rq_entry_fifo (ad->fifo_list[adir].next); + rq =rq_entry_fifo (asq->fifo_list[adir].next);return time_after (jiffies,rq_fifo_time (rq)); }
@@ -954,7 +958,7 @@ static int as_fifo_expired(struct as_data *ad, int adir)* as_batch_expired returns true if the current batch has expired. A batch * is a set of reads or a set of writes. */ -static inline int as_batch_expired (struct as_data *ad) +static inline int as_batch_expired (struct as_data *ad,struct as_queue *asq) {if (ad->changed_batch || ad->new_batch)return 0 ;
@@ -964,7 +968,7 @@ static inline int as_batch_expired(struct as_data *ad)return time_after (jiffies, ad->current_batch_expires);return time_after (jiffies, ad->current_batch_expires) - || ad->current_write_count ==0 ; + || asq->current_write_count ==0 ; }/*
@@ -973,6 +977,7 @@ static inline int as_batch_expired(struct as_data *ad)static void as_move_to_dispatch (struct as_data *ad,struct request *rq) {const int data_dir =rq_is_sync (rq); +struct as_queue *asq =elv_get_sched_queue (ad->q, rq);BUG_ON (RB_EMPTY_NODE (&rq->rb_node));
@@ -995,12 +1000,12 @@ static void as_move_to_dispatch(struct as_data *ad, struct request *rq) ad->io_context =NULL ; } -if (ad->current_write_count !=0 ) - ad->current_write_count--; +if (asq->current_write_count !=0 ) + asq->current_write_count--; } ad->ioc_finished =0 ; - ad->next_rq[data_dir] =as_find_next_rq (ad, rq); + asq->next_rq[data_dir] =as_find_next_rq (ad, asq, rq);/* * take it off the sort and fifo list, add to dispatch queue
@@ -1024,9 +1029,16 @@ static void as_move_to_dispatch(struct as_data *ad, struct request *rq)static int as_dispatch_request (struct request_queue *q,int force) {struct as_data *ad = q->elevator->elevator_data; -const int reads = !list_empty (&ad->fifo_list[BLK_RW_SYNC ]); -const int writes = !list_empty (&ad->fifo_list[BLK_RW_ASYNC ]);struct request *rq; +struct as_queue *asq =elv_select_sched_queue (q, force); +int reads, writes; + +if (!asq) +return 0 ; + + reads = !list_empty (&asq->fifo_list[BLK_RW_SYNC ]); + writes = !list_empty (&asq->fifo_list[BLK_RW_ASYNC ]); +if (unlikely (force)) {/*
@@ -1042,25 +1054,25 @@ static int as_dispatch_request(struct request_queue *q, int force) ad->changed_batch =0 ; ad->new_batch =0 ; -while (ad->next_rq[BLK_RW_SYNC ]) { -as_move_to_dispatch (ad, ad->next_rq[BLK_RW_SYNC ]); +while (asq->next_rq[BLK_RW_SYNC ]) { +as_move_to_dispatch (ad, asq->next_rq[BLK_RW_SYNC ]); dispatched++; } - ad->last_check_fifo[BLK_RW_SYNC ] = jiffies; + asq->last_check_fifo[BLK_RW_SYNC ] = jiffies; -while (ad->next_rq[BLK_RW_ASYNC ]) { -as_move_to_dispatch (ad, ad->next_rq[BLK_RW_ASYNC ]); +while (asq->next_rq[BLK_RW_ASYNC ]) { +as_move_to_dispatch (ad, asq->next_rq[BLK_RW_ASYNC ]); dispatched++; } - ad->last_check_fifo[BLK_RW_ASYNC ] = jiffies; + asq->last_check_fifo[BLK_RW_ASYNC ] = jiffies;return dispatched; }/* Signal that the write batch was uncontended, so we can't time it */ if (ad->batch_data_dir ==BLK_RW_ASYNC && !reads) { -if (ad->current_write_count ==0 || !writes) - ad->write_batch_idled =1 ; +if (asq->current_write_count ==0 || !writes) + asq->write_batch_idled =1 ; } if (!(reads || writes)
@@ -1069,14 +1081,14 @@ static int as_dispatch_request(struct request_queue *q, int force) || ad->changed_batch)return 0 ; -if (!(reads && writes &&as_batch_expired (ad))) { +if (!(reads && writes &&as_batch_expired (ad, asq))) {/* * batch is still running or no reads or no writes */ - rq = ad->next_rq[ad->batch_data_dir]; + rq = asq->next_rq[ad->batch_data_dir];if (ad->batch_data_dir ==BLK_RW_SYNC && ad->antic_expire) { -if (as_fifo_expired (ad,BLK_RW_SYNC )) +if (as_fifo_expired (ad, asq,BLK_RW_SYNC )) goto fifo_expired;if (as_can_anticipate (ad, rq)) {
@@ -1100,7 +1112,7 @@ static int as_dispatch_request(struct request_queue *q, int force)*/ if (reads) { -BUG_ON (RB_EMPTY_ROOT (&ad->sort_list[BLK_RW_SYNC ])); +BUG_ON (RB_EMPTY_ROOT (&asq->sort_list[BLK_RW_SYNC ]));if (writes && ad->batch_data_dir ==BLK_RW_SYNC )/*
@@ -1113,8 +1125,8 @@ static int as_dispatch_request(struct request_queue *q, int force) ad->changed_batch =1 ; } ad->batch_data_dir =BLK_RW_SYNC ; - rq =rq_entry_fifo (ad->fifo_list[BLK_RW_SYNC ].next); - ad->last_check_fifo[ad->batch_data_dir] = jiffies; + rq =rq_entry_fifo (asq->fifo_list[BLK_RW_SYNC ].next); + asq->last_check_fifo[ad->batch_data_dir] = jiffies; goto dispatch_request; }
@@ -1124,7 +1136,7 @@ static int as_dispatch_request(struct request_queue *q, int force)if (writes) { dispatch_writes: -BUG_ON (RB_EMPTY_ROOT (&ad->sort_list[BLK_RW_ASYNC ])); +BUG_ON (RB_EMPTY_ROOT (&asq->sort_list[BLK_RW_ASYNC ]));if (ad->batch_data_dir ==BLK_RW_SYNC ) { ad->changed_batch =1 ;
@@ -1137,10 +1149,10 @@ dispatch_writes: ad->new_batch =0 ; } ad->batch_data_dir =BLK_RW_ASYNC ; - ad->current_write_count = ad->write_batch_count; - ad->write_batch_idled =0 ; - rq =rq_entry_fifo (ad->fifo_list[BLK_RW_ASYNC ].next); - ad->last_check_fifo[BLK_RW_ASYNC ] = jiffies; + asq->current_write_count = asq->write_batch_count; + asq->write_batch_idled =0 ; + rq =rq_entry_fifo (asq->fifo_list[BLK_RW_ASYNC ].next); + asq->last_check_fifo[BLK_RW_ASYNC ] = jiffies; goto dispatch_request; }
@@ -1152,9 +1164,9 @@ dispatch_request:* If a request has expired, service it. */ -if (as_fifo_expired (ad, ad->batch_data_dir)) { +if (as_fifo_expired (ad, asq, ad->batch_data_dir)) { fifo_expired: - rq =rq_entry_fifo (ad->fifo_list[ad->batch_data_dir].next); + rq =rq_entry_fifo (asq->fifo_list[ad->batch_data_dir].next); }if (ad->changed_batch) {
@@ -1187,6 +1199,7 @@ static void as_add_request(struct request_queue *q, struct request *rq) {struct as_data *ad = q->elevator->elevator_data;int data_dir; +struct as_queue *asq =elv_get_sched_queue (q, rq);RQ_SET_STATE (rq,AS_RQ_NEW );
@@ -1205,7 +1218,7 @@ static void as_add_request(struct request_queue *q, struct request *rq)* set expire time and add to fifo list */ rq_set_fifo_time (rq, jiffies + ad->fifo_expire[data_dir]); -list_add_tail (&rq->queuelist, &ad->fifo_list[data_dir]); +list_add_tail (&rq->queuelist, &asq->fifo_list[data_dir]);as_update_rq (ad, rq);/* keep state machine up to date */ RQ_SET_STATE (rq,AS_RQ_QUEUED );
@@ -1227,31 +1240,20 @@ static void as_deactivate_request(struct request_queue *q, struct request *rq)atomic_inc (&RQ_IOC (rq)->aic->nr_dispatched); } -/* -* as_queue_empty tells us if there are requests left in the device. It may -* not be the case that a driver can get the next request even if the queue -* is not empty - it is used in the block layer to check for plugging and -* merging opportunities -*/ -static int as_queue_empty (struct request_queue *q) -{ -struct as_data *ad = q->elevator->elevator_data; - -return list_empty (&ad->fifo_list[BLK_RW_ASYNC ]) - &&list_empty (&ad->fifo_list[BLK_RW_SYNC ]); -} -static int as_merge (struct request_queue *q,struct request **req,struct bio *bio) { -struct as_data *ad = q->elevator->elevator_data;sector_t rb_key = bio->bi_sector +bio_sectors (bio);struct request *__rq; +struct as_queue *asq =elv_get_sched_queue_current (q); + +if (!asq) +return ELEVATOR_NO_MERGE ;/* * check for front merge */ - __rq =elv_rb_find (&ad->sort_list[bio_data_dir (bio)], rb_key); + __rq =elv_rb_find (&asq->sort_list[bio_data_dir (bio)], rb_key);if (__rq &&elv_rq_merge_ok (__rq, bio)) { *req = __rq;return ELEVATOR_FRONT_MERGE ;
@@ -1334,6 +1336,41 @@ static int as_may_queue(struct request_queue *q, int rw)return ret; } +/* Called with queue lock held */ +static void *as_alloc_as_queue (struct request_queue *q, +struct elevator_queue *eq,gfp_t gfp_mask) +{ +struct as_queue *asq; +struct as_data *ad = eq->elevator_data; + + asq =kmalloc_node (sizeof (*asq), gfp_mask | __GFP_ZERO, q->node); +if (asq ==NULL ) + goto out; + +INIT_LIST_HEAD (&asq->fifo_list[BLK_RW_SYNC ]); +INIT_LIST_HEAD (&asq->fifo_list[BLK_RW_ASYNC ]); + asq->sort_list[BLK_RW_SYNC ] =RB_ROOT ; + asq->sort_list[BLK_RW_ASYNC ] =RB_ROOT ; +if (ad) + asq->write_batch_count = ad->batch_expire[BLK_RW_ASYNC ] /10 ; +else + asq->write_batch_count = default_write_batch_expire /10 ; + +if (asq->write_batch_count <2 ) + asq->write_batch_count =2 ; +out: +return asq; +} + +static void as_free_as_queue (struct elevator_queue *e,void *sched_queue) +{ +struct as_queue *asq = sched_queue; + +BUG_ON (!list_empty (&asq->fifo_list[BLK_RW_SYNC ])); +BUG_ON (!list_empty (&asq->fifo_list[BLK_RW_ASYNC ])); +kfree (asq); +} +static void as_exit_queue (struct elevator_queue *e) {struct as_data *ad = e->elevator_data;
@@ -1341,9 +1378,6 @@ static void as_exit_queue(struct elevator_queue *e)del_timer_sync (&ad->antic_timer);cancel_work_sync (&ad->antic_work); -BUG_ON (!list_empty (&ad->fifo_list[BLK_RW_SYNC ])); -BUG_ON (!list_empty (&ad->fifo_list[BLK_RW_ASYNC ])); -put_io_context (ad->io_context);kfree (ad); }
@@ -1367,10 +1401,6 @@ static void *as_init_queue(struct request_queue *q, struct elevator_queue *eq)init_timer (&ad->antic_timer);INIT_WORK (&ad->antic_work, as_work_handler); -INIT_LIST_HEAD (&ad->fifo_list[BLK_RW_SYNC ]); -INIT_LIST_HEAD (&ad->fifo_list[BLK_RW_ASYNC ]); - ad->sort_list[BLK_RW_SYNC ] =RB_ROOT ; - ad->sort_list[BLK_RW_ASYNC ] =RB_ROOT ; ad->fifo_expire[BLK_RW_SYNC ] = default_read_expire; ad->fifo_expire[BLK_RW_ASYNC ] = default_write_expire; ad->antic_expire = default_antic_expire;
@@ -1378,9 +1408,6 @@ static void *as_init_queue(struct request_queue *q, struct elevator_queue *eq) ad->batch_expire[BLK_RW_ASYNC ] = default_write_batch_expire; ad->current_batch_expires = jiffies + ad->batch_expire[BLK_RW_SYNC ]; - ad->write_batch_count = ad->batch_expire[BLK_RW_ASYNC ] /10 ; -if (ad->write_batch_count <2 ) - ad->write_batch_count =2 ;return ad; }
@@ -1478,7 +1505,6 @@ static struct elevator_type iosched_as = { .elevator_add_req_fn = as_add_request, .elevator_activate_req_fn = as_activate_request, .elevator_deactivate_req_fn = as_deactivate_request, - .elevator_queue_empty_fn = as_queue_empty, .elevator_completed_req_fn = as_completed_request, .elevator_former_req_fn = elv_rb_former_request, .elevator_latter_req_fn = elv_rb_latter_request,
@@ -1486,6 +1512,8 @@ static struct elevator_type iosched_as = { .elevator_init_fn = as_init_queue, .elevator_exit_fn = as_exit_queue, .trim = as_trim, + .elevator_alloc_sched_queue_fn = as_alloc_as_queue, + .elevator_free_sched_queue_fn = as_free_as_queue, }, .elevator_attrs = as_attrs,
block/deadline-iosched.c +71 -46
266 lines not on this page · raw message
block/elevator.c +96 -15
179 lines not on this page · raw message
block/noop-iosched.c +28 -31
111 lines not on this page · raw message
include/linux/elevator.h +7 -2
@@ -31,8 +31,10 @@ typedef void (elevator_deactivate_req_fn) (struct request_queue *, struct requestypedef void *(elevator_init_fn ) (struct request_queue *,struct elevator_queue *);typedef void (elevator_exit_fn ) (struct elevator_queue *); -#ifdef CONFIG_ELV_FAIR_QUEUING +typedef void * (elevator_alloc_sched_queue_fn ) (struct request_queue *q, +struct elevator_queue *eq,gfp_t );typedef void (elevator_free_sched_queue_fn ) (struct elevator_queue *,void *); +#ifdef CONFIG_ELV_FAIR_QUEUING typedef void (elevator_active_ioq_set_fn ) (struct request_queue *,void *,int );typedef void (elevator_active_ioq_reset_fn ) (struct request_queue *,void *);typedef void (elevator_arm_slice_timer_fn ) (struct request_queue *,void *);
@@ -69,8 +71,9 @@ struct elevator_opselevator_exit_fn *elevator_exit_fn;void (*trim)(struct io_context *); -#ifdef CONFIG_ELV_FAIR_QUEUING +elevator_alloc_sched_queue_fn *elevator_alloc_sched_queue_fn;elevator_free_sched_queue_fn *elevator_free_sched_queue_fn; +#ifdef CONFIG_ELV_FAIR_QUEUING elevator_active_ioq_set_fn *elevator_active_ioq_set_fn;elevator_active_ioq_reset_fn *elevator_active_ioq_reset_fn;
@@ -110,6 +113,7 @@ struct elevator_queue {struct elevator_ops *ops;void *elevator_data; +void *sched_queue;struct kobject kobj;struct elevator_type *elevator_type;struct mutex sysfs_lock;
@@ -256,5 +260,6 @@ static inline int elv_iosched_fair_queuing_enabled(struct elevator_queue *e)#endif /* ELV_IOSCHED_FAIR_QUEUING */ extern void *elv_get_sched_queue (struct request_queue *q,struct request *rq);extern void *elv_select_sched_queue (struct request_queue *q,int force); +extern void *elv_get_sched_queue_current (struct request_queue *q);#endif /* CONFIG_BLOCK */ #endif
Signature · 1 line
1.6.0.6
PATCH 15/24 io-conroller: Prepare elevator layer for single queue schedulers
In reply to Vivek GoyalElevator layer now has support for hierarchical fair queuing. cfq has been migrated to make use of it and now it is time to do groundwork for noop, deadline and AS.
noop deadline and AS don't maintain separate queues for different processes. There is only one single queue. Effectively one can think that in hierarchical setup, there will be one queue per cgroup where requests from all the processes in the cgroup will be queued.
Generally io scheduler takes care of creating queues. Because there is only one queue here, we have modified common layer to take care of queue creation and some other functionality. This special casing helps in keeping the changes to noop, deadline and AS to the minimum.
--- block/as-iosched.c | 2 +- block/deadline-iosched.c | 2 +- block/elevator-fq.c | 208 +++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.h | 54 ++++++++++++ block/elevator.c | 37 ++++++++- block/noop-iosched.c | 2 +- include/linux/elevator.h | 18 ++++- 7 files changed, 315 insertions(+), 8 deletions(-)
block/as-iosched.c +1 -1
@@ -1338,7 +1338,7 @@ static int as_may_queue(struct request_queue *q, int rw)/* Called with queue lock held */ static void *as_alloc_as_queue (struct request_queue *q, -struct elevator_queue *eq,gfp_t gfp_mask) +struct elevator_queue *eq,gfp_t gfp_mask,struct io_queue *ioq) {struct as_queue *asq;struct as_data *ad = eq->elevator_data;
block/deadline-iosched.c +1 -1
@@ -341,7 +341,7 @@ dispatch_request: }static void *deadline_alloc_deadline_queue (struct request_queue *q, -struct elevator_queue *eq,gfp_t gfp_mask) +struct elevator_queue *eq,gfp_t gfp_mask,struct io_queue *ioq) {struct deadline_queue *dq;
block/elevator-fq.c +207 -1
250 lines not on this page · raw message
block/elevator-fq.h +54 -0
77 lines not on this page · raw message
block/elevator.c +35 -2
@@ -219,9 +219,17 @@ elevator_alloc_sched_queue(struct request_queue *q, struct elevator_queue *eq) {void *sched_queue =NULL ; +/* +* If fair queuing is enabled, then queue allocation takes place +* during set_request() functions when request actually comes +* in. +*/ +if (elv_iosched_fair_queuing_enabled (eq)) +return NULL ; +if (eq->ops->elevator_alloc_sched_queue_fn) { sched_queue = eq->ops->elevator_alloc_sched_queue_fn (q, eq, -GFP_KERNEL ); +GFP_KERNEL ,NULL );if (!sched_queue)return ERR_PTR (-ENOMEM );
@@ -842,6 +850,13 @@ int elv_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask) {struct elevator_queue *e = q->elevator; +/* +* Optimization for noop, deadline and AS which maintain only single +* ioq per io group +*/ +if (elv_iosched_single_ioq (e)) +return elv_fq_set_request_ioq (q, rq, gfp_mask); +if (e->ops->elevator_set_req_fn)return e->ops->elevator_set_req_fn (q, rq, gfp_mask);
@@ -853,6 +868,15 @@ void elv_put_request(struct request_queue *q, struct request *rq) {struct elevator_queue *e = q->elevator; +/* +* Optimization for noop, deadline and AS which maintain only single +* ioq per io group +*/ +if (elv_iosched_single_ioq (e)) { +elv_fq_unset_request_ioq (q, rq); +return ; + } +if (e->ops->elevator_put_req_fn) e->ops->elevator_put_req_fn (rq); }
@@ -1237,9 +1261,18 @@ EXPORT_SYMBOL(elv_select_sched_queue);/* * Get the io scheduler queue pointer for current task. +* +* If fair queuing is enabled, determine the io group of task and retrieve +* the ioq pointer from that. This is used by only single queue ioschedulers +* for retrieving the queue associated with the group to decide whether the +* new bio can do a front merge or not. */ void *elv_get_sched_queue_current (struct request_queue *q) { -return q->elevator->sched_queue; +/* Fair queuing is not enabled. There is only one queue. */ +if (!elv_iosched_fair_queuing_enabled (q->elevator)) +return q->elevator->sched_queue; + +return ioq_sched_queue (elv_lookup_ioq_current (q)); }EXPORT_SYMBOL (elv_get_sched_queue_current);
block/noop-iosched.c +1 -1
@@ -62,7 +62,7 @@ noop_latter_request(struct request_queue *q, struct request *rq) }static void *noop_alloc_noop_queue (struct request_queue *q, -struct elevator_queue *eq,gfp_t gfp_mask) +struct elevator_queue *eq,gfp_t gfp_mask,struct io_queue *ioq) {struct noop_queue *nq;
include/linux/elevator.h +16 -2
@@ -31,9 +31,9 @@ typedef void (elevator_deactivate_req_fn) (struct request_queue *, struct requestypedef void *(elevator_init_fn ) (struct request_queue *,struct elevator_queue *);typedef void (elevator_exit_fn ) (struct elevator_queue *); -typedef void * (elevator_alloc_sched_queue_fn ) (struct request_queue *q, -struct elevator_queue *eq,gfp_t );typedef void (elevator_free_sched_queue_fn ) (struct elevator_queue *,void *); +typedef void * (elevator_alloc_sched_queue_fn ) (struct request_queue *q, +struct elevator_queue *eq,gfp_t ,struct io_queue *ioq);#ifdef CONFIG_ELV_FAIR_QUEUING typedef void (elevator_active_ioq_set_fn ) (struct request_queue *,void *,int );typedef void (elevator_active_ioq_reset_fn ) (struct request_queue *,void *);
@@ -246,17 +246,31 @@ enum {/* iosched wants to use fair queuing logic of elevator layer */ #define ELV_IOSCHED_NEED_FQ 1 +/* iosched maintains only single ioq per group.*/ +#define ELV_IOSCHED_SINGLE_IOQ 2 +static inline int elv_iosched_fair_queuing_enabled (struct elevator_queue *e) {return (e->elevator_type->elevator_features) &ELV_IOSCHED_NEED_FQ ; } +static inline int elv_iosched_single_ioq (struct elevator_queue *e) +{ +return (e->elevator_type->elevator_features) &ELV_IOSCHED_SINGLE_IOQ ; +} +#else /* ELV_IOSCHED_FAIR_QUEUING */ static inline int elv_iosched_fair_queuing_enabled (struct elevator_queue *e) {return 0 ; } + +static inline int elv_iosched_single_ioq (struct elevator_queue *e) +{ +return 0 ; +} +#endif /* ELV_IOSCHED_FAIR_QUEUING */ extern void *elv_get_sched_queue (struct request_queue *q,struct request *rq);extern void *elv_select_sched_queue (struct request_queue *q,int force);
Signature · 1 line
1.6.0.6
PATCH 16/24 io-controller: noop changes for hierarchical fair queuing
In reply to Vivek GoyalThis patch changes noop to use queue scheduling code from elevator layer. One can go back to old noop by deselecting CONFIG_IOSCHED_NOOP_HIER.
--- block/Kconfig.iosched | 11 +++++++++++ block/noop-iosched.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
block/Kconfig.iosched +11 -0
@@ -25,6 +25,17 @@ config IOSCHED_NOOP that do their own scheduling and require only minimal assistance from the kernel. +config IOSCHED_NOOP_HIER + bool "Noop Hierarchical Scheduling support" + depends on IOSCHED_NOOP && CGROUPS + select ELV_FAIR_QUEUING + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in noop. In this mode noop keeps + one IO queue per cgroup instead of a global queue. Elevator + fair queuing logic ensures fairness among various queues. + config IOSCHED_AS tristate "Anticipatory I/O scheduler" default y
block/noop-iosched.c +13 -0
@@ -82,6 +82,15 @@ static void noop_free_noop_queue(struct elevator_queue *e, void *sched_queue)kfree (nq); } +#ifdef CONFIG_IOSCHED_NOOP_HIER +static struct elv_fs_entry noop_attrs[] = { +ELV_ATTR (fairness), +ELV_ATTR (slice_sync), +ELV_ATTR (group_idle), + __ATTR_NULL +}; +#endif +static struct elevator_type elevator_noop = { .ops = { .elevator_merge_req_fn = noop_merged_requests,
@@ -92,6 +101,10 @@ static struct elevator_type elevator_noop = { .elevator_alloc_sched_queue_fn = noop_alloc_noop_queue, .elevator_free_sched_queue_fn = noop_free_noop_queue, }, +#ifdef CONFIG_IOSCHED_NOOP_HIER + .elevator_features = ELV_IOSCHED_NEED_FQ | ELV_IOSCHED_SINGLE_IOQ, + .elevator_attrs = noop_attrs, +#endif .elevator_name = "noop", .elevator_owner = THIS_MODULE, };
Signature · 1 line
1.6.0.6
PATCH 17/24 io-controller: deadline changes for hierarchical fair queuing
In reply to Vivek GoyalThis patch changes deadline to use queue scheduling code from elevator layer. One can go back to old deadline by selecting CONFIG_IOSCHED_DEADLINE_HIER.
--- block/Kconfig.iosched | 11 +++++++++++ block/deadline-iosched.c | 8 ++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
block/Kconfig.iosched +11 -0
@@ -55,6 +55,17 @@ config IOSCHED_DEADLINE a disk at any one time, its behaviour is almost identical to the anticipatory I/O scheduler and so is a good choice. +config IOSCHED_DEADLINE_HIER + bool "Deadline Hierarchical Scheduling support" + depends on IOSCHED_DEADLINE && CGROUPS + select ELV_FAIR_QUEUING + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in deadline. In this mode deadline keeps + one IO queue per cgroup instead of a global queue. Elevator + fair queuing logic ensures fairness among various queues. + config IOSCHED_CFQ tristate "CFQ I/O scheduler" select ELV_FAIR_QUEUING
block/deadline-iosched.c +8 -0
@@ -461,6 +461,11 @@ static struct elv_fs_entry deadline_attrs[] = {DD_ATTR (writes_starved),DD_ATTR (front_merges),DD_ATTR (fifo_batch), +#ifdef CONFIG_IOSCHED_DEADLINE_HIER +ELV_ATTR (fairness), +ELV_ATTR (slice_sync), +ELV_ATTR (group_idle), +#endif __ATTR_NULL };
@@ -478,6 +483,9 @@ static struct elevator_type iosched_deadline = { .elevator_alloc_sched_queue_fn = deadline_alloc_deadline_queue, .elevator_free_sched_queue_fn = deadline_free_deadline_queue, }, +#ifdef CONFIG_IOSCHED_DEADLINE_HIER + .elevator_features = ELV_IOSCHED_NEED_FQ | ELV_IOSCHED_SINGLE_IOQ, +#endif .elevator_attrs = deadline_attrs, .elevator_name = "deadline", .elevator_owner = THIS_MODULE,
Signature · 1 line
1.6.0.6
PATCH 18/24 io-controller: anticipatory changes for hierarchical fair queuing
In reply to Vivek GoyalThis patch changes anticipatory scheduler to use queue scheduling code from elevator layer. One can go back to old as by deselecting CONFIG_IOSCHED_AS_HIER. Even with CONFIG_IOSCHED_AS_HIER=y, with-out any other cgroup created, AS behavior should remain the same as old.
o AS is a single queue ioschduler, that means there is one AS queue per group.
o common layer code select the queue to dispatch from based on fairness, and then AS code selects the request with-in group.
o AS runs reads and writes batches with-in group. So common layer runs timed group queues and with-in group time, AS runs timed batches of reads and writes.
o Note: Previously AS write batch length was adjusted synamically whenever a W->R batch data direction took place and when first request from the read batch completed.
Now write batch updation takes place when last request from the write batch has finished during W->R transition.
o AS runs its own anticipation logic to anticipate on reads. common layer also does the anticipation on the group if think time of the group is with-in slice_idle.
o Introduced few debugging messages in AS.
--- block/Kconfig.iosched | 12 ++ block/as-iosched.c | 294 +++++++++++++++++++++++++++++++++++++++++++++- block/elevator-fq.c | 93 +++++++++++++-- block/elevator-fq.h | 3 + include/linux/elevator.h | 2 + 5 files changed, 386 insertions(+), 18 deletions(-)
block/Kconfig.iosched +12 -0
@@ -45,6 +45,18 @@ config IOSCHED_AS deadline I/O scheduler, it can also be slower in some cases especially some database loads. +config IOSCHED_AS_HIER + bool "Anticipatory Hierarchical Scheduling support" + depends on IOSCHED_AS && CGROUPS + select ELV_FAIR_QUEUING + select GROUP_IOSCHED + default n + ---help--- + Enable hierarhical scheduling in anticipatory. In this mode + anticipatory keeps one IO queue per cgroup instead of a global + queue. Elevator fair queuing logic ensures fairness among various + queues. + config IOSCHED_DEADLINE tristate "Deadline I/O scheduler" default y
block/as-iosched.c +288 -6
496 lines not on this page · raw message
block/elevator-fq.c +81 -12
162 lines not on this page · raw message
block/elevator-fq.h +3 -0
@@ -370,6 +370,8 @@ enum elv_queue_state_flags { ELV_QUEUE_FLAG_wait_request,/* waiting for a request */ ELV_QUEUE_FLAG_must_dispatch,/* must be allowed a dispatch */ ELV_QUEUE_FLAG_slice_new,/* no requests dispatched in slice */ + ELV_QUEUE_FLAG_must_expire, /* Expire this queue even if it has + * request and time slice left */ };#define ELV_IO_QUEUE_FLAG_FNS (name) \
@@ -392,6 +394,7 @@ ELV_IO_QUEUE_FLAG_FNS(wait_request) ELV_IO_QUEUE_FLAG_FNS(must_dispatch) ELV_IO_QUEUE_FLAG_FNS(idle_window) ELV_IO_QUEUE_FLAG_FNS(slice_new) +ELV_IO_QUEUE_FLAG_FNS(must_expire)#ifdef CONFIG_GROUP_IOSCHED
include/linux/elevator.h +2 -0
@@ -42,6 +42,7 @@ typedef int (elevator_should_preempt_fn) (struct request_queue*, void*, struct request*);typedef struct io_queue * (elevator_close_cooperator_fn ) (struct request_queue *,void *); +typedef int (elevator_expire_ioq_fn ) (struct request_queue *,void *,int ,int );#endif struct elevator_ops
@@ -80,6 +81,7 @@ struct elevator_opselevator_arm_slice_timer_fn *elevator_arm_slice_timer_fn;elevator_should_preempt_fn *elevator_should_preempt_fn;elevator_close_cooperator_fn *elevator_close_cooperator_fn; +elevator_expire_ioq_fn *elevator_expire_ioq_fn;#endif };
Signature · 1 line
1.6.0.6
PATCH 19/24 blkio_cgroup patches from Ryo to track async bios.
In reply to Vivek Goyalo blkio_cgroup patches from Ryo to track async bios.
o Fernando is also working on another IO tracking mechanism. We are not particular about any IO tracking mechanism. This patchset can make use of any mechanism which makes it to upstream. For the time being making use of Ryo's posting.
Based on 2.6.30-rc3-git3
--- block/blk-ioc.c | 36 +++-- fs/buffer.c | 2 + fs/direct-io.c | 2 + include/linux/biotrack.h | 103 +++++++++++++ include/linux/cgroup_subsys.h | 6 + include/linux/iocontext.h | 1 + include/linux/memcontrol.h | 6 + include/linux/mmzone.h | 4 +- include/linux/page_cgroup.h | 31 ++++- init/Kconfig | 15 ++ mm/Makefile | 4 +- mm/biotrack.c | 321 +++++++++++++++++++++++++++++++++++++++++ mm/bounce.c | 2 + mm/filemap.c | 2 + mm/memcontrol.c | 6 + mm/memory.c | 5 + mm/page-writeback.c | 2 + mm/page_cgroup.c | 17 ++- mm/swap_state.c | 2 + 19 files changed, 537 insertions(+), 30 deletions(-) create mode 100644 include/linux/biotrack.h create mode 100644 mm/biotrack.c
block/blk-ioc.c +20 -16
@@ -84,27 +84,31 @@ void exit_io_context(void) } } +void init_io_context (struct io_context *ioc) +{ +atomic_long_set (&ioc->refcount,1 ); +atomic_set (&ioc->nr_tasks,1 ); +spin_lock_init (&ioc->lock); + ioc->ioprio_changed =0 ; + ioc->ioprio =0 ; +#ifdef CONFIG_GROUP_IOSCHED + ioc->cgroup_changed =0 ; +#endif + ioc->last_waited = jiffies;/* doesn't matter... */ + ioc->nr_batch_requests =0 ;/* because this is 0 */ + ioc->aic =NULL ; +INIT_RADIX_TREE (&ioc->radix_root,GFP_ATOMIC | __GFP_HIGH); +INIT_HLIST_HEAD (&ioc->cic_list); + ioc->ioc_data =NULL ; +} +struct io_context *alloc_io_context (gfp_t gfp_flags,int node) {struct io_context *ret; ret =kmem_cache_alloc_node (iocontext_cachep, gfp_flags, node); -if (ret) { -atomic_long_set (&ret->refcount,1 ); -atomic_set (&ret->nr_tasks,1 ); -spin_lock_init (&ret->lock); - ret->ioprio_changed =0 ; - ret->ioprio =0 ; -#ifdef CONFIG_GROUP_IOSCHED - ret->cgroup_changed =0 ; -#endif - ret->last_waited = jiffies;/* doesn't matter... */ - ret->nr_batch_requests =0 ;/* because this is 0 */ - ret->aic =NULL ; -INIT_RADIX_TREE (&ret->radix_root,GFP_ATOMIC | __GFP_HIGH); -INIT_HLIST_HEAD (&ret->cic_list); - ret->ioc_data =NULL ; - } +if (ret) +init_io_context (ret);return ret; }
fs/buffer.c +2 -0
@@ -36,6 +36,7 @@#include <linux/buffer_head.h> #include <linux/task_io_accounting_ops.h> #include <linux/bio.h> +#include <linux/biotrack.h> #include <linux/notifier.h> #include <linux/cpu.h> #include <linux/bitops.h>
@@ -668,6 +669,7 @@ static void __set_page_dirty(struct page *page,if (page->mapping) {/* Race with truncate? */ WARN_ON_ONCE (warn && !PageUptodate (page));account_page_dirtied (page, mapping); +blkio_cgroup_reset_owner_pagedirty (page, current->mm);radix_tree_tag_set (&mapping->page_tree,page_index (page),PAGECACHE_TAG_DIRTY ); }
fs/direct-io.c +2 -0
@@ -33,6 +33,7 @@#include <linux/err.h> #include <linux/blkdev.h> #include <linux/buffer_head.h> +#include <linux/biotrack.h> #include <linux/rwsem.h> #include <linux/uio.h> #include <asm/atomic.h>
@@ -797,6 +798,7 @@ static int do_direct_IO(struct dio *dio) ret =PTR_ERR (page); goto out; } +blkio_cgroup_reset_owner (page, current->mm);while (block_in_page < blocks_per_page) {unsigned offset_in_page = block_in_page << blkbits;
include/linux/biotrack.h new file +103 -0
103 lines not on this page · raw message
include/linux/cgroup_subsys.h +6 -0
@@ -43,6 +43,12 @@ SUBSYS(mem_cgroup)/* */ +#ifdef CONFIG_CGROUP_BLKIO +SUBSYS(blkio_cgroup) +#endif + +/* */ +#ifdef CONFIG_CGROUP_DEVICE SUBSYS(devices)#endif
include/linux/iocontext.h +1 -0
@@ -109,6 +109,7 @@ int put_io_context(struct io_context *ioc);void exit_io_context (void );struct io_context *get_io_context (gfp_t gfp_flags,int node);struct io_context *alloc_io_context (gfp_t gfp_flags,int node); +void init_io_context (struct io_context *ioc);void copy_io_context (struct io_context **pdst,struct io_context **psrc);#else static inline void exit_io_context (void )
include/linux/memcontrol.h +6 -0
@@ -37,6 +37,8 @@ struct mm_struct;* (Of course, if memcg does memory allocation in future, GFP_KERNEL is sane.) */ +extern void __init_mem_page_cgroup (struct page_cgroup *pc); +extern int mem_cgroup_newpage_charge (struct page *page,struct mm_struct *mm,gfp_t gfp_mask);/* for swap handling */
@@ -121,6 +123,10 @@ void mem_cgroup_update_mapped_file_stat(struct page *page, int val);#else /* CONFIG_CGROUP_MEM_RES_CTLR */ struct mem_cgroup ; +static inline void __init_mem_page_cgroup (struct page_cgroup *pc) +{ +} +static inline int mem_cgroup_newpage_charge (struct page *page,struct mm_struct *mm,gfp_t gfp_mask) {
include/linux/mmzone.h +2 -2
@@ -605,7 +605,7 @@ typedef struct pglist_data {int nr_zones;#ifdef CONFIG_FLAT_NODE_MEM_MAP /* means !SPARSEMEM */ struct page *node_mem_map; -#ifdef CONFIG_CGROUP_MEM_RES_CTLR +#ifdef CONFIG_CGROUP_PAGE struct page_cgroup *node_page_cgroup;#endif #endif
@@ -956,7 +956,7 @@ struct mem_section {/* See declaration of similar field in struct zone */ unsigned long *pageblock_flags; -#ifdef CONFIG_CGROUP_MEM_RES_CTLR +#ifdef CONFIG_CGROUP_PAGE /* * If !SPARSEMEM, pgdat doesn't have page_cgroup pointer. We use * section. (see memcontrol.h/page_cgroup.h about this.)
include/linux/page_cgroup.h +28 -3
@@ -1,7 +1,7 @@#ifndef __LINUX_PAGE_CGROUP_H#define __LINUX_PAGE_CGROUP_H -#ifdef CONFIG_CGROUP_MEM_RES_CTLR +#ifdef CONFIG_CGROUP_PAGE #include <linux/bit_spinlock.h> /* * Page Cgroup can be considered as an extended mem_map.
@@ -12,9 +12,11 @@*/ struct page_cgroup {unsigned long flags; -struct mem_cgroup *mem_cgroup;struct page *page; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR +struct mem_cgroup *mem_cgroup;struct list_head lru;/* per cgroup LRU list */ +#endif };void __meminit pgdat_page_cgroup_init (struct pglist_data *pgdat);
@@ -83,7 +85,7 @@ static inline void unlock_page_cgroup(struct page_cgroup *pc) bit_spin_unlock(PCG_LOCK, &pc->flags); } -#else /* CONFIG_CGROUP_MEM_RES_CTLR */ +#else /* CONFIG_CGROUP_PAGE */ struct page_cgroup ;static inline void __meminit pgdat_page_cgroup_init (struct pglist_data *pgdat)
@@ -138,4 +140,27 @@ static inline void swap_cgroup_swapoff(int type) }#endif + +#ifdef CONFIG_CGROUP_BLKIO +/* +* use lower 16 bits for flags and reserve the rest for the page tracking id +*/ +#define PCG_TRACKING_ID_SHIFT (16) +#define PCG_TRACKING_ID_BITS \ + (8 * sizeof(unsigned long) - PCG_TRACKING_ID_SHIFT) + +/* NOTE: must be called with page_cgroup() held */ +static inline unsigned long page_cgroup_get_id (struct page_cgroup *pc) +{ +return pc->flags >>PCG_TRACKING_ID_SHIFT ; +} + +/* NOTE: must be called with page_cgroup() held */ +static inline void page_cgroup_set_id (struct page_cgroup *pc,unsigned long id) +{ +WARN_ON (id >= (1UL <<PCG_TRACKING_ID_BITS )); + pc->flags &= (1UL <<PCG_TRACKING_ID_SHIFT ) -1 ; + pc->flags |= (unsigned long )(id <<PCG_TRACKING_ID_SHIFT ); +} +#endif #endif
init/Kconfig +15 -0
@@ -622,6 +622,21 @@ config GROUP_IOSCHED endif # CGROUPS +config CGROUP_BLKIO + bool "Block I/O cgroup subsystem" + depends on CGROUPS && BLOCK + select MM_OWNER + help + Provides a Resource Controller which enables to track the onwner + of every Block I/O requests. + The information this subsystem provides can be used from any + kind of module such as dm-ioband device mapper modules or + the cfq-scheduler. + +config CGROUP_PAGE + def_bool y + depends on CGROUP_MEM_RES_CTLR || CGROUP_BLKIO + config MM_OWNER bool
mm/Makefile +3 -1
@@ -39,6 +39,8 @@ else obj-$(CONFIG_SMP) += allocpercpu.o endif obj-$(CONFIG_QUICKLIST) += quicklist.o -obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o page_cgroup.o +obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o +obj-$(CONFIG_CGROUP_PAGE) += page_cgroup.o +obj-$(CONFIG_CGROUP_BLKIO) += biotrack.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o
mm/biotrack.c new file +321 -0
321 lines not on this page · raw message
mm/bounce.c +2 -0
@@ -14,6 +14,7 @@#include <linux/hash.h> #include <linux/highmem.h> #include <asm/tlbflush.h> +#include <linux/biotrack.h> #include <trace/events/block.h>
@@ -210,6 +211,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, to->bv_len = from->bv_len; to->bv_offset = from->bv_offset;inc_zone_page_state (to->bv_page,NR_BOUNCE ); +blkio_cgroup_copy_owner (to->bv_page, page);if (rw ==WRITE ) {char *vto, *vfrom;
mm/filemap.c +2 -0
@@ -33,6 +33,7 @@#include <linux/cpuset.h> #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */ #include <linux/memcontrol.h> +#include <linux/biotrack.h> #include <linux/mm_inline.h> /* for page_is_file_cache() */ #include "internal.h"
@@ -464,6 +465,7 @@ int add_to_page_cache_locked(struct page *page, struct address_space *mapping, gfp_mask & GFP_RECLAIM_MASK);if (error) goto out; +blkio_cgroup_set_owner (page, current->mm); error =radix_tree_preload (gfp_mask & ~__GFP_HIGHMEM);if (error ==0 ) {
mm/memcontrol.c +6 -0
@@ -129,6 +129,12 @@ struct mem_cgroup_lru_info {struct mem_cgroup_per_node *nodeinfo[MAX_NUMNODES ]; }; +void __meminit __init_mem_page_cgroup (struct page_cgroup *pc) +{ + pc->mem_cgroup =NULL ; +INIT_LIST_HEAD (&pc->lru); +} +/* * The memory controller data structure. The memory controller controls both * page cache and RSS per cgroup. We would eventually like to provide
mm/memory.c +5 -0
@@ -51,6 +51,7 @@#include <linux/init.h> #include <linux/writeback.h> #include <linux/memcontrol.h> +#include <linux/biotrack.h> #include <linux/mmu_notifier.h> #include <linux/kallsyms.h> #include <linux/swapops.h>
@@ -2115,6 +2116,7 @@ gotten:*/ ptep_clear_flush_notify (vma, address, page_table);page_add_new_anon_rmap (new_page, vma, address); +blkio_cgroup_set_owner (new_page, mm);set_pte_at (mm, address, page_table, entry);update_mmu_cache (vma, address, entry);if (old_page) {
@@ -2580,6 +2582,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,flush_icache_page (vma, page);set_pte_at (mm, address, page_table, pte);page_add_anon_rmap (page, vma, address); +blkio_cgroup_reset_owner (page, mm);/* It's better to call commit-charge after rmap is established */ mem_cgroup_commit_charge_swapin (page, ptr);
@@ -2644,6 +2647,7 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma, goto release;inc_mm_counter (mm, anon_rss);page_add_new_anon_rmap (page, vma, address); +blkio_cgroup_set_owner (page, mm);set_pte_at (mm, address, page_table, entry);/* No need to invalidate - it was non-present before */
@@ -2791,6 +2795,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,if (anon) {inc_mm_counter (mm, anon_rss);page_add_new_anon_rmap (page, vma, address); +blkio_cgroup_set_owner (page, mm); }else {inc_mm_counter (mm, file_rss);page_add_file_rmap (page);
mm/page-writeback.c +2 -0
@@ -23,6 +23,7 @@#include <linux/init.h> #include <linux/backing-dev.h> #include <linux/task_io_accounting_ops.h> +#include <linux/biotrack.h> #include <linux/blkdev.h> #include <linux/mpage.h> #include <linux/rmap.h>
@@ -1247,6 +1248,7 @@ int __set_page_dirty_nobuffers(struct page *page)BUG_ON (mapping2 != mapping);WARN_ON_ONCE (!PagePrivate (page) && !PageUptodate (page));account_page_dirtied (page, mapping); +blkio_cgroup_reset_owner_pagedirty (page, current->mm);radix_tree_tag_set (&mapping->page_tree,page_index (page),PAGECACHE_TAG_DIRTY ); }
mm/page_cgroup.c +9 -8
@@ -9,14 +9,15 @@#include <linux/vmalloc.h> #include <linux/cgroup.h> #include <linux/swapops.h> +#include <linux/biotrack.h> static void __meminit __init_page_cgroup (struct page_cgroup *pc,unsigned long pfn) { pc->flags =0 ; - pc->mem_cgroup =NULL ; pc->page =pfn_to_page (pfn); -INIT_LIST_HEAD (&pc->lru); +__init_mem_page_cgroup (pc); +__init_blkio_page_cgroup (pc); }static unsigned long total_usage;
@@ -74,7 +75,7 @@ void __init page_cgroup_init_flatmem(void)int nid, fail; -if (mem_cgroup_disabled ()) +if (mem_cgroup_disabled () &&blkio_cgroup_disabled ())return ;for_each_online_node (nid) {
@@ -83,12 +84,12 @@ void __init page_cgroup_init_flatmem(void) goto fail; }printk (KERN_INFO "allocated %ld bytes of page_cgroup\n" , total_usage); -printk (KERN_INFO "please try 'cgroup_disable=memory' option if you" +printk (KERN_INFO "please try cgroup_disable=memory,blkio option if you" " don't want memory cgroups\n" );return ; fail:printk (KERN_CRIT "allocation of page_cgroup failed.\n" ); -printk (KERN_CRIT "please try 'cgroup_disable=memory' boot option\n" ); +printk (KERN_CRIT "please try cgroup_disable=memory,blkio boot options\n" );panic ("Out of memory" ); }
@@ -245,7 +246,7 @@ void __init page_cgroup_init(void)unsigned long pfn;int fail =0 ; -if (mem_cgroup_disabled ()) +if (mem_cgroup_disabled () &&blkio_cgroup_disabled ())return ;for (pfn =0 ; !fail && pfn < max_pfn; pfn +=PAGES_PER_SECTION ) {
@@ -260,8 +261,8 @@ void __init page_cgroup_init(void)hotplug_memory_notifier (page_cgroup_callback,0 ); }printk (KERN_INFO "allocated %ld bytes of page_cgroup\n" , total_usage); -printk (KERN_INFO "please try 'cgroup_disable=memory' option if you don't" -" want memory cgroups\n" ); +printk (KERN_INFO "please try cgroup_disable=memory,blkio option" +" if you don't want memory and io cgroups\n" ); }void __meminit pgdat_page_cgroup_init (struct pglist_data *pgdat)
mm/swap_state.c +2 -0
@@ -18,6 +18,7 @@#include <linux/pagevec.h> #include <linux/migrate.h> #include <linux/page_cgroup.h> +#include <linux/biotrack.h> #include <asm/pgtable.h>
@@ -307,6 +308,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,*/ __set_page_locked (new_page);SetPageSwapBacked (new_page); +blkio_cgroup_set_owner (new_page, current->mm); err =add_to_swap_cache (new_page, entry, gfp_mask &GFP_KERNEL );if (likely (!err)) {/*
Signature · 1 line
1.6.0.6
PATCH 20/24 io-controller: map async requests to appropriate cgroup
In reply to Vivek Goyalo So far we were assuming that a bio/rq belongs to the task who is submitting it. It did not hold good in case of async writes. This patch makes use of blkio_cgroup pataches to attribute the aysnc writes to right group instead of task submitting the bio.
o For sync requests, we continue to assume that io belongs to the task submitting it. Only in case of async requests, we make use of io tracking patches to track the owner cgroup.
o So far cfq always caches the async queue pointer. With async requests now not necessarily being tied to submitting task io context, caching the pointer will not help for async queues. This patch introduces a new config option CONFIG_TRACK_ASYNC_CONTEXT. If this option is not set, cfq retains old behavior where async queue pointer is cached in task context. If it is set, async queue pointer is not cached and we take help of bio tracking patches to determine group bio belongs to and then map it to async queue of that group.
--- block/Kconfig.iosched | 16 +++++ block/as-iosched.c | 2 +- block/blk-core.c | 7 +- block/cfq-iosched.c | 151 ++++++++++++++++++++++++++++++++++++---------- block/deadline-iosched.c | 2 +- block/elevator-fq.c | 119 +++++++++++++++++++++++++++++++----- block/elevator-fq.h | 20 ++++-- block/elevator.c | 15 +++-- include/linux/elevator.h | 22 ++++++- 9 files changed, 284 insertions(+), 70 deletions(-)
block/Kconfig.iosched +16 -0
@@ -132,6 +132,22 @@ config DEBUG_GROUP_IOSCHED Enable some debugging hooks for hierarchical scheduling support. Currently it just outputs more information in blktrace output. +config TRACK_ASYNC_CONTEXT + bool "Determine async request context from bio" + depends on GROUP_IOSCHED + select CGROUP_BLKIO + default n + ---help--- + Normally async request is attributed to the task submitting the + request. With group ioscheduling, for accurate accounting of + async writes, one needs to map the request to original task/cgroup + which originated the request and not the submitter of the request. + + Currently there are generic io tracking patches to provide facility + to map bio to original owner. If this option is set, for async + request, original owner of the bio is decided by using io tracking + patches otherwise we continue to attribute the request to the + submitting thread. endmenu endif
block/as-iosched.c +1 -1
@@ -1514,7 +1514,7 @@ as_merge(struct request_queue *q, struct request **req, struct bio *bio) {sector_t rb_key = bio->bi_sector +bio_sectors (bio);struct request *__rq; -struct as_queue *asq =elv_get_sched_queue_current (q); +struct as_queue *asq =elv_get_sched_queue_bio (q, bio);if (!asq)return ELEVATOR_NO_MERGE ;
block/blk-core.c +4 -3
@@ -626,7 +626,8 @@ static inline void blk_free_request(struct request_queue *q, struct request *rq) }static struct request * -blk_alloc_request (struct request_queue *q,int flags,int priv,gfp_t gfp_mask) +blk_alloc_request (struct request_queue *q,struct bio *bio,int flags,int priv, +gfp_t gfp_mask) {struct request *rq =mempool_alloc (q->rq.rq_pool, gfp_mask);
@@ -638,7 +639,7 @@ blk_alloc_request(struct request_queue *q, int flags, int priv, gfp_t gfp_mask) rq->cmd_flags = flags |REQ_ALLOCED ;if (priv) { -if (unlikely (elv_set_request (q, rq, gfp_mask))) { +if (unlikely (elv_set_request (q, rq, bio, gfp_mask))) {mempool_free (rq, q->rq.rq_pool);return NULL ; }
@@ -779,7 +780,7 @@ static struct request *get_request(struct request_queue *q, int rw_flags, rw_flags |=REQ_IO_STAT ;spin_unlock_irq (q->queue_lock); - rq =blk_alloc_request (q, rw_flags, priv, gfp_mask); + rq =blk_alloc_request (q, bio, rw_flags, priv, gfp_mask);if (unlikely (!rq)) {/* * Allocation failed presumably due to memory. Undo anything
block/cfq-iosched.c +119 -32
251 lines not on this page · raw message
block/deadline-iosched.c +1 -1
@@ -133,7 +133,7 @@ deadline_merge(struct request_queue *q, struct request **req, struct bio *bio)int ret;struct deadline_queue *dq; - dq =elv_get_sched_queue_current (q); + dq =elv_get_sched_queue_bio (q, bio);if (!dq)return ELEVATOR_NO_MERGE ;
block/elevator-fq.c +103 -16
209 lines not on this page · raw message
block/elevator-fq.h +13 -7
@@ -550,10 +550,11 @@ static inline int update_requeue(struct io_queue *ioq, int requeue) }extern int elv_fq_set_request_ioq (struct request_queue *q,struct request *rq, -gfp_t gfp_mask); +struct bio *bio,gfp_t gfp_mask);extern void elv_fq_unset_request_ioq (struct request_queue *q,struct request *rq); -extern struct io_queue *elv_lookup_ioq_current (struct request_queue *q); +extern struct io_queue *elv_lookup_ioq_bio (struct request_queue *q, +struct bio *bio);/* Sets the single ioq associated with the io group. (noop, deadline, AS) */ static inline void io_group_set_ioq (struct io_group *iog,struct io_queue *ioq)
@@ -588,7 +589,7 @@ static inline void io_group_set_ioq(struct io_group *iog, struct io_queue *ioq) }static inline int elv_fq_set_request_ioq (struct request_queue *q, -struct request *rq,gfp_t gfp_mask) +struct request *rq,struct bio *bio,gfp_t gfp_mask) {return 0 ; }
@@ -598,7 +599,8 @@ static inline void elv_fq_unset_request_ioq(struct request_queue *q, { } -static inline struct io_queue *elv_lookup_ioq_current (struct request_queue *q) +static inline struct io_queue *elv_lookup_ioq_bio (struct request_queue *q, +struct bio *bio) {return NULL ; }
@@ -655,7 +657,10 @@ extern void *io_group_async_queue_prio(struct io_group *iog, int ioprio_class, int ioprio);extern void io_group_set_async_queue (struct io_group *iog,int ioprio_class,int ioprio,struct io_queue *ioq); -extern struct io_group *io_get_io_group (struct request_queue *q,int create); +extern struct io_group *io_get_io_group (struct request_queue *q, +struct page *page,int create); +extern struct io_group *io_get_io_group_bio (struct request_queue *q, +struct bio *bio,int create);extern int elv_nr_busy_ioq (struct elevator_queue *e);extern int elv_rq_in_driver (struct elevator_queue *e);extern struct io_queue *elv_alloc_ioq (struct request_queue *q,gfp_t gfp_mask);
@@ -714,7 +719,7 @@ static inline int io_group_allow_merge(struct request *rq, struct bio *bio)return 1 ; }static inline int elv_fq_set_request_ioq (struct request_queue *q, -struct request *rq,gfp_t gfp_mask) +struct request *rq,struct bio *bio,gfp_t gfp_mask) {return 0 ; }
@@ -724,7 +729,8 @@ static inline void elv_fq_unset_request_ioq(struct request_queue *q, { } -static inline struct io_queue *elv_lookup_ioq_current (struct request_queue *q) +static inline struct io_queue *elv_lookup_ioq_bio (struct request_queue *q, +struct bio *bio) {return NULL ; }
block/elevator.c +8 -7
@@ -846,7 +846,8 @@ struct request *elv_former_request(struct request_queue *q, struct request *rq)return NULL ; } -int elv_set_request (struct request_queue *q,struct request *rq,gfp_t gfp_mask) +int elv_set_request (struct request_queue *q,struct request *rq, +struct bio *bio,gfp_t gfp_mask) {struct elevator_queue *e = q->elevator;
@@ -855,10 +856,10 @@ int elv_set_request(struct request_queue *q, struct request *rq, gfp_t gfp_mask)* ioq per io group */ if (elv_iosched_single_ioq (e)) -return elv_fq_set_request_ioq (q, rq, gfp_mask); +return elv_fq_set_request_ioq (q, rq, bio, gfp_mask);if (e->ops->elevator_set_req_fn) -return e->ops->elevator_set_req_fn (q, rq, gfp_mask); +return e->ops->elevator_set_req_fn (q, rq, bio, gfp_mask); rq->elevator_private =NULL ;return 0 ;
@@ -1260,19 +1261,19 @@ void *elv_select_sched_queue(struct request_queue *q, int force)EXPORT_SYMBOL (elv_select_sched_queue);/* -* Get the io scheduler queue pointer for current task. +* Get the io scheduler queue pointer for the group bio belongs to. * * If fair queuing is enabled, determine the io group of task and retrieve * the ioq pointer from that. This is used by only single queue ioschedulers * for retrieving the queue associated with the group to decide whether the * new bio can do a front merge or not. */ -void *elv_get_sched_queue_current (struct request_queue *q) +void *elv_get_sched_queue_bio (struct request_queue *q,struct bio *bio) {/* Fair queuing is not enabled. There is only one queue. */ if (!elv_iosched_fair_queuing_enabled (q->elevator))return q->elevator->sched_queue; -return ioq_sched_queue (elv_lookup_ioq_current (q)); +return ioq_sched_queue (elv_lookup_ioq_bio (q, bio)); } -EXPORT_SYMBOL (elv_get_sched_queue_current); +EXPORT_SYMBOL (elv_get_sched_queue_bio);
include/linux/elevator.h +19 -3
@@ -23,7 +23,8 @@ typedef struct request *(elevator_request_list_fn) (struct request_queue *, strutypedef void (elevator_completed_req_fn ) (struct request_queue *,struct request *);typedef int (elevator_may_queue_fn ) (struct request_queue *,int ); -typedef int (elevator_set_req_fn ) (struct request_queue *,struct request *,gfp_t ); +typedef int (elevator_set_req_fn ) (struct request_queue *,struct request *, +struct bio *bio,gfp_t );typedef void (elevator_put_req_fn ) (struct request *);typedef void (elevator_activate_req_fn ) (struct request_queue *,struct request *);typedef void (elevator_deactivate_req_fn ) (struct request_queue *,struct request *);
@@ -147,7 +148,8 @@ extern void elv_unregister_queue(struct request_queue *q);extern int elv_may_queue (struct request_queue *,int );extern void elv_abort_queue (struct request_queue *);extern void elv_completed_request (struct request_queue *,struct request *); -extern int elv_set_request (struct request_queue *,struct request *,gfp_t ); +extern int elv_set_request (struct request_queue *,struct request *, +struct bio *bio,gfp_t );extern void elv_put_request (struct request_queue *,struct request *);extern void elv_drain_elevator (struct request_queue *);
@@ -276,6 +278,20 @@ static inline int elv_iosched_single_ioq(struct elevator_queue *e)#endif /* ELV_IOSCHED_FAIR_QUEUING */ extern void *elv_get_sched_queue (struct request_queue *q,struct request *rq);extern void *elv_select_sched_queue (struct request_queue *q,int force); -extern void *elv_get_sched_queue_current (struct request_queue *q); +extern void *elv_get_sched_queue_bio (struct request_queue *q,struct bio *bio); + +/* +* This is equivalent of rq_is_sync()/cfq_bio_sync() function where we +* determine whether an rq/bio is sync or not. There are cases like during +* merging and during * request allocation, where we don't have rq but bio +* and needs to find out * if this bio will be considered as sync or async by +* elevator/iosched. This function is useful in such cases. +*/ +static inline int elv_bio_sync (struct bio *bio) +{ +if ((bio_data_dir (bio) ==READ ) ||bio_sync (bio)) +return 1 ; +return 0 ; +}#endif /* CONFIG_BLOCK */ #endif
Signature · 1 line
1.6.0.6
PATCH 21/24 io-controller: Per cgroup request descriptor support
In reply to Vivek Goyalo Currently a request queue has got fixed number of request descriptors for sync and async requests. Once the request descriptors are consumed, new processes are put to sleep and they effectively become serialized. Because sync and async queues are separate, async requests don't impact sync ones but if one is looking for fairness between async requests, that is not achievable if request queue descriptors become bottleneck.
o Make request descriptor's per io group so that if there is lots of IO going on in one cgroup, it does not impact the IO of other group.
o This is just one relatively simple way of doing things. This patch will probably change after the feedback. Folks have raised concerns that in hierchical setup, child's request descriptors should be capped by parent's request descriptors. May be we need to have per cgroup per device files in cgroups where one can specify the upper limit of request descriptors and whenever a cgroup is created one needs to assign request descritor limit making sure total sum of child's request descriptor is not more than of parent.
I guess something like memory controller. Anyway, that would be the next step. For the time being, we have implemented something simpler as follows.
o This patch implements the per cgroup request descriptors. request pool per queue is still common but every group will have its own wait list and its own count of request descriptors allocated to that group for sync and async queues. So effectively request_list becomes per io group property and not a global request queue feature.
o Currently one can define q->nr_requests to limit request descriptors allocated for the queue. Now there is another tunable q->nr_group_requests which controls the requests descriptr limit per group. q->nr_requests supercedes q->nr_group_requests to make sure if there are lots of groups present, we don't end up allocating too many request descriptors on the queue.
--- block/blk-core.c | 305 +++++++++++++++++++++++++++++++++++++---------- block/blk-settings.c | 1 + block/blk-sysfs.c | 73 ++++++++++-- block/elevator-fq.c | 14 +++ block/elevator-fq.h | 5 + block/elevator.c | 7 +- include/linux/blkdev.h | 87 +++++++++++++- 7 files changed, 410 insertions(+), 82 deletions(-)
block/blk-core.c +241 -66
@@ -460,20 +460,30 @@ void blk_cleanup_queue(struct request_queue *q) }EXPORT_SYMBOL (blk_cleanup_queue); -static int blk_init_free_list (struct request_queue *q) +void blk_init_request_list (struct request_list *rl) { -struct request_list *rl = &q->rq; rl->count[BLK_RW_SYNC ] = rl->count[BLK_RW_ASYNC ] =0 ; - rl->starved[BLK_RW_SYNC ] = rl->starved[BLK_RW_ASYNC ] =0 ; - rl->elvpriv =0 ;init_waitqueue_head (&rl->wait[BLK_RW_SYNC ]);init_waitqueue_head (&rl->wait[BLK_RW_ASYNC ]); +} - rl->rq_pool =mempool_create_node (BLKDEV_MIN_RQ , mempool_alloc_slab, - mempool_free_slab, request_cachep, q->node); +static int blk_init_free_list (struct request_queue *q) +{ +/* +* Initialize the queue request list in case there are non-hiearchical +* io schedulers not making use of fair queuing infrastructure. +* +* For ioschedulers making use of fair queuing infrastructure, request +* list is inside the associated group and when that group is +* instanciated, it takes care of initializing the request list also. +*/ +blk_init_request_list (&q->rq); + q->rq_data.rq_pool =mempool_create_node (BLKDEV_MIN_RQ , + mempool_alloc_slab, mempool_free_slab, + request_cachep, q->node); -if (!rl->rq_pool) +if (!q->rq_data.rq_pool)return -ENOMEM ;return 0 ;
@@ -575,6 +585,9 @@ blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id)return NULL ; } +/* init starved waiter wait queue */ +init_waitqueue_head (&q->rq_data.starved_wait); +/* * if caller didn't supply a lock, they get per-queue locking with * our embedded lock
@@ -622,14 +635,14 @@ static inline void blk_free_request(struct request_queue *q, struct request *rq) {if (rq->cmd_flags &REQ_ELVPRIV )elv_put_request (q, rq); -mempool_free (rq, q->rq.rq_pool); +mempool_free (rq, q->rq_data.rq_pool); }static struct request *blk_alloc_request (struct request_queue *q,struct bio *bio,int flags,int priv,gfp_t gfp_mask) { -struct request *rq =mempool_alloc (q->rq.rq_pool, gfp_mask); +struct request *rq =mempool_alloc (q->rq_data.rq_pool, gfp_mask);if (!rq)return NULL ;
@@ -640,7 +653,7 @@ blk_alloc_request(struct request_queue *q, struct bio *bio, int flags, int priv,if (priv) {if (unlikely (elv_set_request (q, rq, bio, gfp_mask))) { -mempool_free (rq, q->rq.rq_pool); +mempool_free (rq, q->rq_data.rq_pool);return NULL ; } rq->cmd_flags |=REQ_ELVPRIV ;
@@ -683,18 +696,18 @@ static void ioc_set_batching(struct request_queue *q, struct io_context *ioc) ioc->last_waited = jiffies; } -static void __freed_request (struct request_queue *q,int sync) +static void __freed_request (struct request_queue *q,int sync, +struct request_list *rl) { -struct request_list *rl = &q->rq; - -if (rl->count[sync] <queue_congestion_off_threshold (q)) +if (q->rq_data.count[sync] <queue_congestion_off_threshold (q))blk_clear_queue_congested (q, sync); -if (rl->count[sync] +1 <= q->nr_requests) { +if (q->rq_data.count[sync] +1 <= q->nr_requests) +blk_clear_queue_full (q, sync); + +if (rl->count[sync] +1 <= q->nr_group_requests) {if (waitqueue_active (&rl->wait[sync]))wake_up (&rl->wait[sync]); - -blk_clear_queue_full (q, sync); } }
@@ -702,63 +715,133 @@ static void __freed_request(struct request_queue *q, int sync)* A request has just been released. Account for it, update the full and * congestion status, wake up any waiters. Called under q->queue_lock. */ -static void freed_request (struct request_queue *q,int sync,int priv) -{ -struct request_list *rl = &q->rq; +static void freed_request (struct request_queue *q,int sync,int priv, +struct request_list *rl) +{ +/* There is a window during request allocation where request is +* mapped to one group but by the time a queue for the group is +* allocated, it is possible that original cgroup/io group has been +* deleted and now io queue is allocated in a different group (root) +* altogether. +* +* One solution to the problem is that rq should take io group +* reference. But it looks too much to do that to solve this issue. +* The only side affect to the hard to hit issue seems to be that +* we will try to decrement the rl->count for a request list which +* did not allocate that request. Chcek for rl->count going less than +* zero and do not decrement it if that's the case. +*/ + +if (priv && rl->count[sync] >0 ) + rl->count[sync]--; + +BUG_ON (!q->rq_data.count[sync]); + q->rq_data.count[sync]--; - rl->count[sync]--;if (priv) - rl->elvpriv--; + q->rq_data.elvpriv--; -__freed_request (q, sync); +__freed_request (q, sync, rl);if (unlikely (rl->starved[sync ^1 ])) -__freed_request (q, sync ^1 ); +__freed_request (q, sync ^1 , rl); + +/* Wake up the starved process on global list, if any */ +if (unlikely (q->rq_data.starved)) { +if (waitqueue_active (&q->rq_data.starved_wait)) +wake_up (&q->rq_data.starved_wait); + q->rq_data.starved--; + } +} + +/* +* Returns whether one can sleep on this request list or not. There are +* cases (elevator switch) where request list might not have allocated +* any request descriptor but we deny request allocation due to gloabl +* limits. In that case one should sleep on global list as on this request +* list no wakeup will take place. +* +* Also sets the request list starved flag if there are no requests pending +* in the direction of rq. +* +* Return 1 --> sleep on request list, 0 --> sleep on global list +*/ +static int can_sleep_on_request_list (struct request_list *rl,int is_sync) +{ +if (unlikely (rl->count[is_sync] ==0 )) { +/* +* If there is a request pending in other direction +* in same io group, then set the starved flag of +* the group request list. Otherwise, we need to +* make this process sleep in global starved list +* to make sure it will not sleep indefinitely. +*/ +if (rl->count[is_sync ^1 ] !=0 ) { + rl->starved[is_sync] =1 ; +return 1 ; + }else +return 0 ; + } + +return 1 ; }/* * Get a free request, queue_lock must be held. -* Returns NULL on failure, with queue_lock held. +* Returns NULL on failure, with queue_lock held. Also sets the "reason" field +* in case of failure. This reason field helps caller decide to whether sleep +* on per group list or global per queue list. +* reason = 0 sleep on per group list +* reason = 1 sleep on global list +* * Returns !NULL on success, with queue_lock *not held*. */ static struct request *get_request (struct request_queue *q,int rw_flags, -struct bio *bio,gfp_t gfp_mask) +struct bio *bio,gfp_t gfp_mask, +struct request_list *rl,int *reason) {struct request *rq =NULL ; -struct request_list *rl = &q->rq;struct io_context *ioc =NULL ;const bool is_sync =rw_is_sync (rw_flags) !=0 ;int may_queue, priv; +int sleep_on_global =0 ; may_queue =elv_may_queue (q, rw_flags);if (may_queue ==ELV_MQUEUE_NO ) goto rq_starved; -if (rl->count[is_sync]+1 >=queue_congestion_on_threshold (q)) { -if (rl->count[is_sync]+1 >= q->nr_requests) { - ioc =current_io_context (GFP_ATOMIC , q->node); -/* -* The queue will fill after this allocation, so set -* it as full, and mark this process as "batching". -* This process will be allowed to complete a batch of -* requests, others will be blocked. -*/ -if (!blk_queue_full (q, is_sync)) { -ioc_set_batching (q, ioc); -blk_set_queue_full (q, is_sync); - }else { -if (may_queue !=ELV_MQUEUE_MUST - && !ioc_batching (q, ioc)) { -/* -* The queue is full and the allocating -* process is not a "batcher", and not -* exempted by the IO scheduler -*/ - goto out; - } +if (q->rq_data.count[is_sync]+1 >=queue_congestion_on_threshold (q)) +blk_set_queue_congested (q, is_sync); + +/* +* Looks like there is no user of queue full now. +* Keeping it for time being. +*/ +if (q->rq_data.count[is_sync]+1 >= q->nr_requests) +blk_set_queue_full (q, is_sync); + +if (rl->count[is_sync]+1 >= q->nr_group_requests) { + ioc =current_io_context (GFP_ATOMIC , q->node); +/* +* The queue request descriptor group will fill after this +* allocation, so set +* it as full, and mark this process as "batching". +* This process will be allowed to complete a batch of +* requests, others will be blocked. +*/ +if (rl->count[is_sync] <= q->nr_group_requests) +ioc_set_batching (q, ioc); +else { +if (may_queue !=ELV_MQUEUE_MUST + && !ioc_batching (q, ioc)) { +/* +* The queue is full and the allocating +* process is not a "batcher", and not +* exempted by the IO scheduler +*/ + goto out; } } -blk_set_queue_congested (q, is_sync); }/*
@@ -766,21 +849,60 @@ static struct request *get_request(struct request_queue *q, int rw_flags,* limit of requests, otherwise we could have thousands of requests * allocated with any setting of ->nr_requests */ -if (rl->count[is_sync] >= (3 * q->nr_requests /2 )) + +if (q->rq_data.count[is_sync] >= (3 * q->nr_requests /2 )) { +/* +* Queue is too full for allocation. On which request queue +* the task should sleep? Generally it should sleep on its +* request list but if elevator switch is happening, in that +* window, request descriptors are allocated from global +* pool and are not accounted against any particular request +* list as group is going away. +* +* So it might happen that request list does not have any +* requests allocated at all and if process sleeps on per +* group request list, it will not be woken up. In such case, +* make it sleep on global starved list. +*/ +if (test_bit (QUEUE_FLAG_ELVSWITCH , &q->queue_flags) + || !can_sleep_on_request_list (rl, is_sync)) + sleep_on_global =1 ; + goto out; + } + +/* +* Allocation of request is allowed from queue perspective. Now check +* from per group request list +*/ + +if (rl->count[is_sync] >= (3 * q->nr_group_requests /2 )) goto out; - rl->count[is_sync]++; rl->starved[is_sync] =0 ; + q->rq_data.count[is_sync]++; + priv = !test_bit (QUEUE_FLAG_ELVSWITCH , &q->queue_flags); -if (priv) - rl->elvpriv++; +if (priv) { + q->rq_data.elvpriv++; +/* +* Account the request to request list only if request is +* going to elevator. During elevator switch, there will +* be small window where group is going away and new group +* will not be allocated till elevator switch is complete. +* So till then instead of slowing down the application, +* we will continue to allocate request from total common +* pool instead of per group limit +*/ + rl->count[is_sync]++; + }if (blk_queue_io_stat (q)) rw_flags |=REQ_IO_STAT ;spin_unlock_irq (q->queue_lock); rq =blk_alloc_request (q, bio, rw_flags, priv, gfp_mask); +if (unlikely (!rq)) {/* * Allocation failed presumably due to memory. Undo anything
@@ -790,7 +912,7 @@ static struct request *get_request(struct request_queue *q, int rw_flags,* wait queue, but this is pretty rare. */ spin_lock_irq (q->queue_lock); -freed_request (q, is_sync, priv); +freed_request (q, is_sync, priv, rl);/* * in the very unlikely event that allocation failed and no
@@ -800,9 +922,8 @@ static struct request *get_request(struct request_queue *q, int rw_flags,* rq mempool into READ and WRITE */ rq_starved: -if (unlikely (rl->count[is_sync] ==0 )) - rl->starved[is_sync] =1 ; - +if (!can_sleep_on_request_list (rl, is_sync)) + sleep_on_global =1 ; goto out; }
@@ -817,6 +938,8 @@ rq_starved:trace_block_getrq (q, bio, rw_flags &1 ); out: +if (reason && sleep_on_global) + *reason =1 ;return rq; }
@@ -830,16 +953,44 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags, struct bio *bio) {const bool is_sync =rw_is_sync (rw_flags) !=0 ; +int sleep_on_global =0 ;struct request *rq; +struct request_list *rl =blk_get_request_list (q, bio); +struct io_group *iog =NULL ; - rq =get_request (q, rw_flags, bio,GFP_NOIO ); + rq =get_request (q, rw_flags, bio,GFP_NOIO , rl, &sleep_on_global);while (!rq) {DEFINE_WAIT (wait);struct io_context *ioc; -struct request_list *rl = &q->rq; -prepare_to_wait_exclusive (&rl->wait[is_sync], &wait, -TASK_UNINTERRUPTIBLE ); +if (sleep_on_global) { +/* +* Task failed allocation and needs to wait and +* try again. There are no requests pending from +* the io group hence need to sleep on global +* wait queue. Most likely the allocation failed +* because of memory issues. +*/ + + q->rq_data.starved++; +prepare_to_wait_exclusive (&q->rq_data.starved_wait, + &wait,TASK_UNINTERRUPTIBLE ); + }else { +/* +* We are about to sleep on a request list and we +* drop queue lock. After waking up, we will do +* finish_wait() on request list and in the mean +* time group might be gone. Take a reference to +* the group now. +*/ +prepare_to_wait_exclusive (&rl->wait[is_sync], &wait, +TASK_UNINTERRUPTIBLE ); +#ifdef CONFIG_GROUP_IOSCHED + iog =rl_iog (rl); +if (iog) +elv_get_iog (iog); +#endif + }trace_block_sleeprq (q, bio, rw_flags &1 );
@@ -857,9 +1008,30 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags,ioc_set_batching (q, ioc);spin_lock_irq (q->queue_lock); -finish_wait (&rl->wait[is_sync], &wait); - rq =get_request (q, rw_flags, bio,GFP_NOIO ); +if (sleep_on_global) { +finish_wait (&q->rq_data.starved_wait, &wait); + sleep_on_global =0 ; + }else { +finish_wait (&rl->wait[is_sync], &wait); +#ifdef CONFIG_GROUP_IOSCHED +/* +* We had taken a reference to the rl/iog. +* Put that now +*/ + iog =rl_iog (rl); +if (iog) +elv_put_iog (iog); +#endif + } + +/* +* After the sleep check the rl again in case cgrop bio +* belonged to is gone and it is mapped to root group now +*/ + rl =blk_get_request_list (q, bio); + rq =get_request (q, rw_flags, bio,GFP_NOIO , rl, + &sleep_on_global); };return rq;
@@ -868,14 +1040,16 @@ static struct request *get_request_wait(struct request_queue *q, int rw_flags,struct request *blk_get_request (struct request_queue *q,int rw,gfp_t gfp_mask) {struct request *rq; +struct request_list *rl;BUG_ON (rw !=READ && rw !=WRITE );spin_lock_irq (q->queue_lock); + rl =blk_get_request_list (q,NULL );if (gfp_mask & __GFP_WAIT) { rq =get_request_wait (q, rw,NULL ); }else { - rq =get_request (q, rw,NULL , gfp_mask); + rq =get_request (q, rw,NULL , gfp_mask, rl,NULL );if (!rq)spin_unlock_irq (q->queue_lock); }
@@ -1092,12 +1266,13 @@ void __blk_put_request(struct request_queue *q, struct request *req)if (req->cmd_flags &REQ_ALLOCED ) {int is_sync =rq_is_sync (req) !=0 ;int priv = req->cmd_flags &REQ_ELVPRIV ; +struct request_list *rl =rq_rl (q, req);BUG_ON (!list_empty (&req->queuelist));BUG_ON (!hlist_unhashed (&req->hash));blk_free_request (q, req); -freed_request (q, is_sync, priv); +freed_request (q, is_sync, priv, rl); } }EXPORT_SYMBOL_GPL (__blk_put_request);
block/blk-settings.c +1 -0
@@ -148,6 +148,7 @@ void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)* set defaults */ q->nr_requests =BLKDEV_MAX_RQ ; + q->nr_group_requests =BLKDEV_MAX_GROUP_RQ ; q->make_request_fn = mfn;blk_queue_dma_alignment (q,511 );
block/blk-sysfs.c +61 -12
127 lines not on this page · raw message
block/elevator-fq.c +14 -0
@@ -1228,6 +1228,16 @@ static struct io_cgroup *cgroup_to_io_cgroup(struct cgroup *cgroup) struct io_cgroup, css); } +struct request_list *io_group_get_request_list (struct request_queue *q, +struct bio *bio) +{ +struct io_group *iog; + + iog =io_get_io_group_bio (q, bio,1 ); +BUG_ON (!iog); +return &iog->rl; +} +/* * Search the io_group for efqd into the hash table (by now only a list) * of bgrp. Must be called under rcu_read_lock().
@@ -1603,6 +1613,8 @@ io_group_chain_alloc(struct request_queue *q, void *key, struct cgroup *cgroup)#endif +blk_init_request_list (&iog->rl); +if (leaf ==NULL ) { leaf = iog; prev = leaf;
@@ -1880,6 +1892,8 @@ static struct io_group *io_alloc_root_group(struct request_queue *q,for (i =0 ; i <IO_IOPRIO_CLASSES ; i++) iog->sched_data.service_tree[i] =IO_SERVICE_TREE_INIT ; +blk_init_request_list (&iog->rl); + iocg = &io_root_cgroup;spin_lock_irq (&iocg->lock);rcu_assign_pointer (iog->key, key);
block/elevator-fq.h +5 -0
@@ -265,6 +265,9 @@ struct io_group {/* Single ioq per group, used for noop, deadline, anticipatory */ struct io_queue *ioq; + +/* request list associated with the group */ +struct request_list rl; };/**
@@ -555,6 +558,8 @@ extern void elv_fq_unset_request_ioq(struct request_queue *q, struct request *rq);extern struct io_queue *elv_lookup_ioq_bio (struct request_queue *q,struct bio *bio); +extern struct request_list *io_group_get_request_list (struct request_queue *q, +struct bio *bio);/* Sets the single ioq associated with the io group. (noop, deadline, AS) */ static inline void io_group_set_ioq (struct io_group *iog,struct io_queue *ioq)
block/elevator.c +4 -3
@@ -659,7 +659,7 @@ void elv_quiesce_start(struct request_queue *q)* make sure we don't have any requests in flight */ elv_drain_elevator (q); -while (q->rq.elvpriv) { +while (q->rq_data.elvpriv) {__blk_run_queue (q);spin_unlock_irq (q->queue_lock);msleep (10 );
@@ -758,8 +758,9 @@ void elv_insert(struct request_queue *q, struct request *rq, int where) }if (unplug_it &&blk_queue_plugged (q)) { -int nrq = q->rq.count[BLK_RW_SYNC ] + q->rq.count[BLK_RW_ASYNC ] - -queue_in_flight (q); +int nrq = q->rq_data.count[BLK_RW_SYNC ] + + q->rq_data.count[BLK_RW_ASYNC ] - +queue_in_flight (q);if (nrq >= q->unplug_thresh)__generic_unplug_device (q);
include/linux/blkdev.h +85 -2
124 lines not on this page · raw message
Signature · 1 line
1.6.0.6