original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1049 lines
24 KiB

tracing/events: convert block trace points to TRACE_EVENT() TRACE_EVENT is a more generic way to define tracepoints. Doing so adds these new capabilities to this tracepoint: - zero-copy and per-cpu splice() tracing - binary tracing without printf overhead - structured logging records exposed under /debug/tracing/events - trace events embedded in function tracer output and other plugins - user-defined, per tracepoint filter expressions ... Cons: - no dev_t info for the output of plug, unplug_timer and unplug_io events. no dev_t info for getrq and sleeprq events if bio == NULL. no dev_t info for rq_abort,...,rq_requeue events if rq->rq_disk == NULL. This is mainly because we can't get the deivce from a request queue. But this may change in the future. - A packet command is converted to a string in TP_assign, not TP_print. While blktrace do the convertion just before output. Since pc requests should be rather rare, this is not a big issue. - In blktrace, an event can have 2 different print formats, but a TRACE_EVENT has a unique format, which means we have some unused data in a trace entry. The overhead is minimized by using __dynamic_array() instead of __array(). I've benchmarked the ioctl blktrace vs the splice based TRACE_EVENT tracing: dd dd + ioctl blktrace dd + TRACE_EVENT (splice) 1 7.36s, 42.7 MB/s 7.50s, 42.0 MB/s 7.41s, 42.5 MB/s 2 7.43s, 42.3 MB/s 7.48s, 42.1 MB/s 7.43s, 42.4 MB/s 3 7.38s, 42.6 MB/s 7.45s, 42.2 MB/s 7.41s, 42.5 MB/s So the overhead of tracing is very small, and no regression when using those trace events vs blktrace. And the binary output of TRACE_EVENT is much smaller than blktrace: # ls -l -h -rw-r--r-- 1 root root 8.8M 06-09 13:24 sda.blktrace.0 -rw-r--r-- 1 root root 195K 06-09 13:24 sda.blktrace.1 -rw-r--r-- 1 root root 2.7M 06-09 13:25 trace_splice.out Following are some comparisons between TRACE_EVENT and blktrace: plug: kjournald-480 [000] 303.084981: block_plug: [kjournald] kjournald-480 [000] 303.084981: 8,0 P N [kjournald] unplug_io: kblockd/0-118 [000] 300.052973: block_unplug_io: [kblockd/0] 1 kblockd/0-118 [000] 300.052974: 8,0 U N [kblockd/0] 1 remap: kjournald-480 [000] 303.085042: block_remap: 8,0 W 102736992 + 8 <- (8,8) 33384 kjournald-480 [000] 303.085043: 8,0 A W 102736992 + 8 <- (8,8) 33384 bio_backmerge: kjournald-480 [000] 303.085086: block_bio_backmerge: 8,0 W 102737032 + 8 [kjournald] kjournald-480 [000] 303.085086: 8,0 M W 102737032 + 8 [kjournald] getrq: kjournald-480 [000] 303.084974: block_getrq: 8,0 W 102736984 + 8 [kjournald] kjournald-480 [000] 303.084975: 8,0 G W 102736984 + 8 [kjournald] bash-2066 [001] 1072.953770: 8,0 G N [bash] bash-2066 [001] 1072.953773: block_getrq: 0,0 N 0 + 0 [bash] rq_complete: konsole-2065 [001] 300.053184: block_rq_complete: 8,0 W () 103669040 + 16 [0] konsole-2065 [001] 300.053191: 8,0 C W 103669040 + 16 [0] ksoftirqd/1-7 [001] 1072.953811: 8,0 C N (5a 00 08 00 00 00 00 00 24 00) [0] ksoftirqd/1-7 [001] 1072.953813: block_rq_complete: 0,0 N (5a 00 08 00 00 00 00 00 24 00) 0 + 0 [0] rq_insert: kjournald-480 [000] 303.084985: block_rq_insert: 8,0 W 0 () 102736984 + 8 [kjournald] kjournald-480 [000] 303.084986: 8,0 I W 102736984 + 8 [kjournald] Changelog from v2 -> v3: - use the newly introduced __dynamic_array(). Changelog from v1 -> v2: - use __string() instead of __array() to minimize the memory required to store hex dump of rq->cmd(). - support large pc requests. - add missing blk_fill_rwbs_rq() in block_rq_requeue TRACE_EVENT. - some cleanups. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> LKML-Reference: <4A2DF669.5070905@cn.fujitsu.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
13 years ago
blkcg: shoot down blkio_groups on elevator switch Elevator switch may involve changes to blkcg policies. Implement shoot down of blkio_groups. Combined with the previous bypass updates, the end goal is updating blkcg core such that it can ensure that blkcg's being affected become quiescent and don't have any per-blkg data hanging around before commencing any policy updates. Until queues are made aware of the policies that applies to them, as an interim step, all per-policy blkg data will be shot down. * blk-throtl doesn't need this change as it can't be disabled for a live queue; however, update it anyway as the scheduled blkg unification requires this behavior change. This means that blk-throtl configuration will be unnecessarily lost over elevator switch. This oddity will be removed after blkcg learns to associate individual policies with request_queues. * blk-throtl dosen't shoot down root_tg. This is to ease transition. Unified blkg will always have persistent root group and not shooting down root_tg for now eases transition to that point by avoiding having to update td->root_tg and is safe as blk-throtl can never be disabled -v2: Vivek pointed out that group list is not guaranteed to be empty on return from clear function if it raced cgroup removal and lost. Fix it by waiting a bit and retrying. This kludge will soon be removed once locking is updated such that blkg is never in limbo state between blkcg and request_queue locks. blk-throtl no longer shoots down root_tg to avoid breaking td->root_tg. Also, Nest queue_lock inside blkio_list_lock not the other way around to avoid introduce possible deadlock via blkcg lock. -v3: blkcg_clear_queue() repositioned and renamed to blkg_destroy_all() to increase consistency with later changes. cfq_clear_queue() updated to check q->elevator before dereferencing it to avoid NULL dereference on not fully initialized queues (used by later change). Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 years ago
block: convert to pos and nr_sectors accessors With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
13 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
hlist: drop the node parameter from iterators I'm not sure why, but the hlist for each entry iterators were conceived list_for_each_entry(pos, head, member) The hlist ones were greedy and wanted an extra parameter: hlist_for_each_entry(tpos, pos, head, member) Why did they need an extra pos parameter? I'm not quite sure. Not only they don't really need it, it also prevents the iterator from looking exactly like the list iterator, which is unfortunate. Besides the semantic patch, there was some manual work required: - Fix up the actual hlist iterators in linux/list.h - Fix up the declaration of other iterators based on the hlist ones. - A very small amount of places were using the 'node' parameter, this was modified to use 'obj->member' instead. - Coccinelle didn't handle the hlist_for_each_entry_safe iterator properly, so those had to be fixed up manually. The semantic patch which is mostly the work of Peter Senna Tschudin is here: @@ iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host; type T; expression a,c,d,e; identifier b; statement S; @@ -T b; <+... when != b ( hlist_for_each_entry(a, - b, c, d) S | hlist_for_each_entry_continue(a, - b, c) S | hlist_for_each_entry_from(a, - b, c) S | hlist_for_each_entry_rcu(a, - b, c, d) S | hlist_for_each_entry_rcu_bh(a, - b, c, d) S | hlist_for_each_entry_continue_rcu_bh(a, - b, c) S | for_each_busy_worker(a, c, - b, d) S | ax25_uid_for_each(a, - b, c) S | ax25_for_each(a, - b, c) S | inet_bind_bucket_for_each(a, - b, c) S | sctp_for_each_hentry(a, - b, c) S | sk_for_each(a, - b, c) S | sk_for_each_rcu(a, - b, c) S | sk_for_each_from -(a, b) +(a) S + sk_for_each_from(a) S | sk_for_each_safe(a, - b, c, d) S | sk_for_each_bound(a, - b, c) S | hlist_for_each_entry_safe(a, - b, c, d, e) S | hlist_for_each_entry_continue_rcu(a, - b, c) S | nr_neigh_for_each(a, - b, c) S | nr_neigh_for_each_safe(a, - b, c, d) S | nr_node_for_each(a, - b, c) S | nr_node_for_each_safe(a, - b, c, d) S | - for_each_gfn_sp(a, c, d, b) S + for_each_gfn_sp(a, c, d) S | - for_each_gfn_indirect_valid_sp(a, c, d, b) S + for_each_gfn_indirect_valid_sp(a, c, d) S | for_each_host(a, - b, c) S | for_each_host_safe(a, - b, c, d) S | for_each_mesh_entry(a, - b, c, d) S ) ...+> [akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c] [akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c] [akpm@linux-foundation.org: checkpatch fixes] [akpm@linux-foundation.org: fix warnings] [akpm@linux-foudnation.org: redo intrusive kvm changes] Tested-by: Peter Senna Tschudin <peter.senna@gmail.com> Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Gleb Natapov <gleb@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
9 years ago
Merge branch 'for-3.9/core' of git://git.kernel.dk/linux-block Pull block IO core bits from Jens Axboe: "Below are the core block IO bits for 3.9. It was delayed a few days since my workstation kept crashing every 2-8h after pulling it into current -git, but turns out it is a bug in the new pstate code (divide by zero, will report separately). In any case, it contains: - The big cfq/blkcg update from Tejun and and Vivek. - Additional block and writeback tracepoints from Tejun. - Improvement of the should sort (based on queues) logic in the plug flushing. - _io() variants of the wait_for_completion() interface, using io_schedule() instead of schedule() to contribute to io wait properly. - Various little fixes. You'll get two trivial merge conflicts, which should be easy enough to fix up" Fix up the trivial conflicts due to hlist traversal cleanups (commit b67bfe0d42ca: "hlist: drop the node parameter from iterators"). * 'for-3.9/core' of git://git.kernel.dk/linux-block: (39 commits) block: remove redundant check to bd_openers() block: use i_size_write() in bd_set_size() cfq: fix lock imbalance with failed allocations drivers/block/swim3.c: fix null pointer dereference block: don't select PERCPU_RWSEM block: account iowait time when waiting for completion of IO request sched: add wait_for_completion_io[_timeout] writeback: add more tracepoints block: add block_{touch|dirty}_buffer tracepoint buffer: make touch_buffer() an exported function block: add @req to bio_{front|back}_merge tracepoints block: add missing block_bio_complete() tracepoint block: Remove should_sort judgement when flush blk_plug block,elevator: use new hashtable implementation cfq-iosched: add hierarchical cfq_group statistics cfq-iosched: collect stats from dead cfqgs cfq-iosched: separate out cfqg_stats_reset() from cfq_pd_reset_stats() blkcg: make blkcg_print_blkgs() grab q locks instead of blkcg lock block: RCU free request_queue blkcg: implement blkg_[rw]stat_recursive_sum() and blkg_[rw]stat_merge() ...
9 years ago
block: convert to pos and nr_sectors accessors With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
13 years ago
block: convert to pos and nr_sectors accessors With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
13 years ago
block: convert to pos and nr_sectors accessors With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
13 years ago
block: convert to pos and nr_sectors accessors With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
13 years ago
block: convert to pos and nr_sectors accessors With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
13 years ago
block: convert to pos and nr_sectors accessors With recent cleanups, there is no place where low level driver directly manipulates request fields. This means that the 'hard' request fields always equal the !hard fields. Convert all rq->sectors, nr_sectors and current_nr_sectors references to accessors. While at it, drop superflous blk_rq_pos() < 0 test in swim.c. [ Impact: use pos and nr_sectors accessors ] Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Tested-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Adrian McMenamin <adrian@mcmen.demon.co.uk> Acked-by: Mike Miller <mike.miller@hp.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Cc: Borislav Petkov <petkovbb@googlemail.com> Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Eric Moore <Eric.Moore@lsi.com> Cc: Alan Stern <stern@rowland.harvard.edu> Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Pete Zaitcev <zaitcev@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Paul Clements <paul.clements@steeleye.com> Cc: Tim Waugh <tim@cyberelk.net> Cc: Jeff Garzik <jgarzik@pobox.com> Cc: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Alex Dubov <oakad@yahoo.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Dario Ballabio <ballabio_dario@emc.com> Cc: David S. Miller <davem@davemloft.net> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: unsik Kim <donari75@gmail.com> Cc: Laurent Vivier <Laurent@lvivier.info> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
13 years ago
block: drop barrier ordering by queue draining Filesystems will take all the responsibilities for ordering requests around commit writes and will only indicate how the commit writes themselves should be handled by block layers. This patch drops barrier ordering by queue draining from block layer. Ordering by draining implementation was somewhat invasive to request handling. List of notable changes follow. * Each queue has 1 bit color which is flipped on each barrier issue. This is used to track whether a given request is issued before the current barrier or not. REQ_ORDERED_COLOR flag and coloring implementation in __elv_add_request() are removed. * Requests which shouldn't be processed yet for draining were stalled by returning -EAGAIN from blk_do_ordered() according to the test result between blk_ordered_req_seq() and blk_blk_ordered_cur_seq(). This logic is removed. * Draining completion logic in elv_completed_request() removed. * All barrier sequence requests were queued to request queue and then trckled to lower layer according to progress and thus maintaining request orders during requeue was necessary. This is replaced by queueing the next request in the barrier sequence only after the current one is complete from blk_ordered_complete_seq(), which removes the need for multiple proxy requests in struct request_queue and the request sorting logic in the ELEVATOR_INSERT_REQUEUE path of elv_insert(). * As barriers no longer have ordering constraints, there's no need to dump the whole elevator onto the dispatch queue on each barrier. Insert barriers at the front instead. * If other barrier requests come to the front of the dispatch queue while one is already in progress, they are stored in q->pending_barriers and restored to dispatch queue one-by-one after each barrier completion from blk_ordered_complete_seq(). Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Christoph Hellwig <hch@infradead.org> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
11 years ago
block: reimplement FLUSH/FUA to support merge The current FLUSH/FUA support has evolved from the implementation which had to perform queue draining. As such, sequencing is done queue-wide one flush request after another. However, with the draining requirement gone, there's no reason to keep the queue-wide sequential approach. This patch reimplements FLUSH/FUA support such that each FLUSH/FUA request is sequenced individually. The actual FLUSH execution is double buffered and whenever a request wants to execute one for either PRE or POSTFLUSH, it queues on the pending queue. Once certain conditions are met, a flush request is issued and on its completion all pending requests proceed to the next sequence. This allows arbitrary merging of different type of flushes. How they are merged can be primarily controlled and tuned by adjusting the above said 'conditions' used to determine when to issue the next flush. This is inspired by Darrick's patches to merge multiple zero-data flushes which helps workloads with highly concurrent fsync requests. * As flush requests are never put on the IO scheduler, request fields used for flush share space with rq->rb_node. rq->completion_data is moved out of the union. This increases the request size by one pointer. As rq->elevator_private* are used only by the iosched too, it is possible to reduce the request size further. However, to do that, we need to modify request allocation path such that iosched data is not allocated for flush requests. * FLUSH/FUA processing happens on insertion now instead of dispatch. - Comments updated as per Vivek and Mike. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: "Darrick J. Wong" <djwong@us.ibm.com> Cc: Shaohua Li <shli@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
11 years ago
block: implement bio_associate_current() IO scheduling and cgroup are tied to the issuing task via io_context and cgroup of %current. Unfortunately, there are cases where IOs need to be routed via a different task which makes scheduling and cgroup limit enforcement applied completely incorrectly. For example, all bios delayed by blk-throttle end up being issued by a delayed work item and get assigned the io_context of the worker task which happens to serve the work item and dumped to the default block cgroup. This is double confusing as bios which aren't delayed end up in the correct cgroup and makes using blk-throttle and cfq propio together impossible. Any code which punts IO issuing to another task is affected which is getting more and more common (e.g. btrfs). As both io_context and cgroup are firmly tied to task including userland visible APIs to manipulate them, it makes a lot of sense to match up tasks to bios. This patch implements bio_associate_current() which associates the specified bio with %current. The bio will record the associated ioc and blkcg at that point and block layer will use the recorded ones regardless of which task actually ends up issuing the bio. bio release puts the associated ioc and blkcg. It grabs and remembers ioc and blkcg instead of the task itself because task may already be dead by the time the bio is issued making ioc and blkcg inaccessible and those are all block layer cares about. elevator_set_req_fn() is updated such that the bio elvdata is being allocated for is available to the elevator. This doesn't update block cgroup policies yet. Further patches will implement the support. -v2: #ifdef CONFIG_BLK_CGROUP added around bio->bi_ioc dereference in rq_ioc() to fix build breakage. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Kent Overstreet <koverstreet@google.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 years ago
block: implement bio_associate_current() IO scheduling and cgroup are tied to the issuing task via io_context and cgroup of %current. Unfortunately, there are cases where IOs need to be routed via a different task which makes scheduling and cgroup limit enforcement applied completely incorrectly. For example, all bios delayed by blk-throttle end up being issued by a delayed work item and get assigned the io_context of the worker task which happens to serve the work item and dumped to the default block cgroup. This is double confusing as bios which aren't delayed end up in the correct cgroup and makes using blk-throttle and cfq propio together impossible. Any code which punts IO issuing to another task is affected which is getting more and more common (e.g. btrfs). As both io_context and cgroup are firmly tied to task including userland visible APIs to manipulate them, it makes a lot of sense to match up tasks to bios. This patch implements bio_associate_current() which associates the specified bio with %current. The bio will record the associated ioc and blkcg at that point and block layer will use the recorded ones regardless of which task actually ends up issuing the bio. bio release puts the associated ioc and blkcg. It grabs and remembers ioc and blkcg instead of the task itself because task may already be dead by the time the bio is issued making ioc and blkcg inaccessible and those are all block layer cares about. elevator_set_req_fn() is updated such that the bio elvdata is being allocated for is available to the elevator. This doesn't update block cgroup policies yet. Further patches will implement the support. -v2: #ifdef CONFIG_BLK_CGROUP added around bio->bi_ioc dereference in rq_ioc() to fix build breakage. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Kent Overstreet <koverstreet@google.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 years ago
block: reimplement FLUSH/FUA to support merge The current FLUSH/FUA support has evolved from the implementation which had to perform queue draining. As such, sequencing is done queue-wide one flush request after another. However, with the draining requirement gone, there's no reason to keep the queue-wide sequential approach. This patch reimplements FLUSH/FUA support such that each FLUSH/FUA request is sequenced individually. The actual FLUSH execution is double buffered and whenever a request wants to execute one for either PRE or POSTFLUSH, it queues on the pending queue. Once certain conditions are met, a flush request is issued and on its completion all pending requests proceed to the next sequence. This allows arbitrary merging of different type of flushes. How they are merged can be primarily controlled and tuned by adjusting the above said 'conditions' used to determine when to issue the next flush. This is inspired by Darrick's patches to merge multiple zero-data flushes which helps workloads with highly concurrent fsync requests. * As flush requests are never put on the IO scheduler, request fields used for flush share space with rq->rb_node. rq->completion_data is moved out of the union. This increases the request size by one pointer. As rq->elevator_private* are used only by the iosched too, it is possible to reduce the request size further. However, to do that, we need to modify request allocation path such that iosched data is not allocated for flush requests. * FLUSH/FUA processing happens on insertion now instead of dispatch. - Comments updated as per Vivek and Mike. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: "Darrick J. Wong" <djwong@us.ibm.com> Cc: Shaohua Li <shli@kernel.org> Cc: Christoph Hellwig <hch@lst.de> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
11 years ago
elevator: fix oops on early call to elevator_change() 2.6.36 introduces an API for drivers to switch the IO scheduler instead of manually calling the elevator exit and init functions. This API was added since q->elevator must be cleared in between those two calls. And since we already have this functionality directly from use by the sysfs interface to switch schedulers online, it was prudent to reuse it internally too. But this API needs the queue to be in a fully initialized state before it is called, or it will attempt to unregister elevator kobjects before they have been added. This results in an oops like this: BUG: unable to handle kernel NULL pointer dereference at 0000000000000051 IP: [<ffffffff8116f15e>] sysfs_create_dir+0x2e/0xc0 PGD 47ddfc067 PUD 47c6a1067 PMD 0 Oops: 0000 [#1] PREEMPT SMP last sysfs file: /sys/devices/pci0000:00/0000:00:02.0/0000:04:00.1/irq CPU 2 Modules linked in: t(+) loop hid_apple usbhid ahci ehci_hcd uhci_hcd libahci usbcore nls_base igb Pid: 7319, comm: modprobe Not tainted 2.6.36-rc6+ #132 QSSC-S4R/QSSC-S4R RIP: 0010:[<ffffffff8116f15e>] [<ffffffff8116f15e>] sysfs_create_dir+0x2e/0xc0 RSP: 0018:ffff88027da25d08 EFLAGS: 00010246 RAX: ffff88047c68c528 RBX: 00000000fffffffe RCX: 0000000000000000 RDX: 000000000000002f RSI: 000000000000002f RDI: ffff88047e196c88 RBP: ffff88027da25d38 R08: 0000000000000000 R09: d84156c5635688c0 R10: d84156c5635688c0 R11: 0000000000000000 R12: ffff88047e196c88 R13: 0000000000000000 R14: 0000000000000000 R15: ffff88047c68c528 FS: 00007fcb0b26f6e0(0000) GS:ffff880287400000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b CR2: 0000000000000051 CR3: 000000047e76e000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400 Process modprobe (pid: 7319, threadinfo ffff88027da24000, task ffff88027d377090) Stack: ffff88027da25d58 ffff88047c68c528 00000000fffffffe ffff88047e196c88 <0> ffff88047c68c528 ffff88047e05bd90 ffff88027da25d78 ffffffff8123fb77 <0> ffff88047e05bd90 0000000000000000 ffff88047e196c88 ffff88047c68c528 Call Trace: [<ffffffff8123fb77>] kobject_add_internal+0xe7/0x1f0 [<ffffffff8123fd98>] kobject_add_varg+0x38/0x60 [<ffffffff8123feb9>] kobject_add+0x69/0x90 [<ffffffff8116efe0>] ? sysfs_remove_dir+0x20/0xa0 [<ffffffff8103d48d>] ? sub_preempt_count+0x9d/0xe0 [<ffffffff8143de20>] ? _raw_spin_unlock+0x30/0x50 [<ffffffff8116efe0>] ? sysfs_remove_dir+0x20/0xa0 [<ffffffff8116eff4>] ? sysfs_remove_dir+0x34/0xa0 [<ffffffff81224204>] elv_register_queue+0x34/0xa0 [<ffffffff81224aad>] elevator_change+0xfd/0x250 [<ffffffffa007e000>] ? t_init+0x0/0x361 [t] [<ffffffffa007e000>] ? t_init+0x0/0x361 [t] [<ffffffffa007e0a8>] t_init+0xa8/0x361 [t] [<ffffffff810001de>] do_one_initcall+0x3e/0x170 [<ffffffff8108c3fd>] sys_init_module+0xbd/0x220 [<ffffffff81002f2b>] system_call_fastpath+0x16/0x1b Code: e5 41 56 41 55 41 54 49 89 fc 53 48 83 ec 10 48 85 ff 74 52 48 8b 47 18 49 c7 c5 00 46 61 81 48 85 c0 74 04 4c 8b 68 30 45 31 f6 <41> 80 7d 51 00 74 0e 49 8b 44 24 28 4c 89 e7 ff 50 20 49 89 c6 RIP [<ffffffff8116f15e>] sysfs_create_dir+0x2e/0xc0 RSP <ffff88027da25d08> CR2: 0000000000000051 ---[ end trace a6541d3bf07945df ]--- Fix this by adding a registered bit to the elevator queue, which is set when the sysfs kobjects have been registered. Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
11 years ago
blkcg: unify blkg's for blkcg policies Currently, blkg is per cgroup-queue-policy combination. This is unnatural and leads to various convolutions in partially used duplicate fields in blkg, config / stat access, and general management of blkgs. This patch make blkg's per cgroup-queue and let them serve all policies. blkgs are now created and destroyed by blkcg core proper. This will allow further consolidation of common management logic into blkcg core and API with better defined semantics and layering. As a transitional step to untangle blkg management, elvswitch and policy [de]registration, all blkgs except the root blkg are being shot down during elvswitch and bypass. This patch adds blkg_root_update() to update root blkg in place on policy change. This is hacky and racy but should be good enough as interim step until we get locking simplified and switch over to proper in-place update for all blkgs. -v2: Root blkgs need to be updated on elvswitch too and blkg_alloc() comment wasn't updated according to the function change. Fixed. Both pointed out by Vivek. -v3: v2 updated blkg_destroy_all() to invoke update_root_blkg_pd() for all policies. This freed root pd during elvswitch before the last queue finished exiting and led to oops. Directly invoke update_root_blkg_pd() only on BLKIO_POLICY_PROP from cfq_exit_queue(). This also is closer to what will be done with proper in-place blkg update. Reported by Vivek. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
10 years ago
block: don't request module during elevator init Block layer allows selecting an elevator which is built as a module to be selected as system default via kernel param "elevator=". This is achieved by automatically invoking request_module() whenever a new block device is initialized and the elevator is not available. This led to an interesting deadlock problem involving async and module init. Block device probing running off an async job invokes request_module(). While the module is being loaded, it performs async_synchronize_full() which ends up waiting for the async job which is already waiting for request_module() to finish, leading to deadlock. Invoking request_module() from deep in block device init path is already nasty in itself. It seems best to avoid these situations from the beginning by moving on-demand module loading out of block init path. The previous patch made sure that the default elevator module is loaded early during boot if available. This patch removes on-demand loading of the default elevator from elevator init path. As the module would have been loaded during boot, userland-visible behavior difference should be minimal. For more details, please refer to the following thread. http://thread.gmane.org/gmane.linux.kernel/1420814 v2: The bool parameter was named @request_module which conflicted with request_module(). This built okay w/ CONFIG_MODULES because request_module() was defined as a macro. W/o CONFIG_MODULES, it causes build breakage. Rename the parameter to @try_loading. Reported by Fengguang. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Alex Riesen <raa.lkml@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com>
9 years ago
  1. /*
  2. * Block device elevator/IO-scheduler.
  3. *
  4. * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
  5. *
  6. * 30042000 Jens Axboe <axboe@kernel.dk> :
  7. *
  8. * Split the elevator a bit so that it is possible to choose a different
  9. * one or even write a new "plug in". There are three pieces:
  10. * - elevator_fn, inserts a new request in the queue list
  11. * - elevator_merge_fn, decides whether a new buffer can be merged with
  12. * an existing request
  13. * - elevator_dequeue_fn, called when a request is taken off the active list
  14. *
  15. * 20082000 Dave Jones <davej@suse.de> :
  16. * Removed tests for max-bomb-segments, which was breaking elvtune
  17. * when run without -bN
  18. *
  19. * Jens:
  20. * - Rework again to work with bio instead of buffer_heads
  21. * - loose bi_dev comparisons, partition handling is right now
  22. * - completely modularize elevator setup and teardown
  23. *
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/fs.h>
  27. #include <linux/blkdev.h>
  28. #include <linux/elevator.h>
  29. #include <linux/bio.h>
  30. #include <linux/module.h>
  31. #include <linux/slab.h>
  32. #include <linux/init.h>
  33. #include <linux/compiler.h>
  34. #include <linux/blktrace_api.h>
  35. #include <linux/hash.h>
  36. #include <linux/uaccess.h>
  37. #include <linux/pm_runtime.h>
  38. #include <trace/events/block.h>
  39. #include "blk.h"
  40. #include "blk-cgroup.h"
  41. static DEFINE_SPINLOCK(elv_list_lock);
  42. static LIST_HEAD(elv_list);
  43. /*
  44. * Merge hash stuff.
  45. */
  46. #define rq_hash_key(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))
  47. /*
  48. * Query io scheduler to see if the current process issuing bio may be
  49. * merged with rq.
  50. */
  51. static int elv_iosched_allow_merge(struct request *rq, struct bio *bio)
  52. {
  53. struct request_queue *q = rq->q;
  54. struct elevator_queue *e = q->elevator;
  55. if (e->type->ops.elevator_allow_merge_fn)
  56. return e->type->ops.elevator_allow_merge_fn(q, rq, bio);
  57. return 1;
  58. }
  59. /*
  60. * can we safely merge with this request?
  61. */
  62. bool elv_rq_merge_ok(struct request *rq, struct bio *bio)
  63. {
  64. if (!blk_rq_merge_ok(rq, bio))
  65. return 0;
  66. if (!elv_iosched_allow_merge(rq, bio))
  67. return 0;
  68. return 1;
  69. }
  70. EXPORT_SYMBOL(elv_rq_merge_ok);
  71. static struct elevator_type *elevator_find(const char *name)
  72. {
  73. struct elevator_type *e;
  74. list_for_each_entry(e, &elv_list, list) {
  75. if (!strcmp(e->elevator_name, name))
  76. return e;
  77. }
  78. return NULL;
  79. }
  80. static void elevator_put(struct elevator_type *e)
  81. {
  82. module_put(e->elevator_owner);
  83. }
  84. static struct elevator_type *elevator_get(const char *name, bool try_loading)
  85. {
  86. struct elevator_type *e;
  87. spin_lock(&elv_list_lock);
  88. e = elevator_find(name);
  89. if (!e && try_loading) {
  90. spin_unlock(&elv_list_lock);
  91. request_module("%s-iosched", name);
  92. spin_lock(&elv_list_lock);
  93. e = elevator_find(name);
  94. }
  95. if (e && !try_module_get(e->elevator_owner))
  96. e = NULL;
  97. spin_unlock(&elv_list_lock);
  98. return e;
  99. }
  100. static char chosen_elevator[ELV_NAME_MAX];
  101. static int __init elevator_setup(char *str)
  102. {
  103. /*
  104. * Be backwards-compatible with previous kernels, so users
  105. * won't get the wrong elevator.
  106. */
  107. strncpy(chosen_elevator, str, sizeof(chosen_elevator) - 1);
  108. return 1;
  109. }
  110. __setup("elevator=", elevator_setup);
  111. /* called during boot to load the elevator chosen by the elevator param */
  112. void __init load_default_elevator_module(void)
  113. {
  114. struct elevator_type *e;
  115. if (!chosen_elevator[0])
  116. return;
  117. spin_lock(&elv_list_lock);
  118. e = elevator_find(chosen_elevator);
  119. spin_unlock(&elv_list_lock);
  120. if (!e)
  121. request_module("%s-iosched", chosen_elevator);
  122. }
  123. static struct kobj_type elv_ktype;
  124. struct elevator_queue *elevator_alloc(struct request_queue *q,
  125. struct elevator_type *e)
  126. {
  127. struct elevator_queue *eq;
  128. eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node);
  129. if (unlikely(!eq))
  130. goto err;
  131. eq->type = e;
  132. kobject_init(&eq->kobj, &elv_ktype);
  133. mutex_init(&eq->sysfs_lock);
  134. hash_init(eq->hash);
  135. return eq;
  136. err:
  137. kfree(eq);
  138. elevator_put(e);
  139. return NULL;
  140. }
  141. EXPORT_SYMBOL(elevator_alloc);
  142. static void elevator_release(struct kobject *kobj)
  143. {
  144. struct elevator_queue *e;
  145. e = container_of(kobj, struct elevator_queue, kobj);
  146. elevator_put(e->type);
  147. kfree(e);
  148. }
  149. int elevator_init(struct request_queue *q, char *name)
  150. {
  151. struct elevator_type *e = NULL;
  152. int err;
  153. if (unlikely(q->elevator))
  154. return 0;
  155. INIT_LIST_HEAD(&q->queue_head);
  156. q->last_merge = NULL;
  157. q->end_sector = 0;
  158. q->boundary_rq = NULL;
  159. if (name) {
  160. e = elevator_get(name, true);
  161. if (!e)
  162. return -EINVAL;
  163. }
  164. /*
  165. * Use the default elevator specified by config boot param or
  166. * config option. Don't try to load modules as we could be running
  167. * off async and request_module() isn't allowed from async.
  168. */
  169. if (!e && *chosen_elevator) {
  170. e = elevator_get(chosen_elevator, false);
  171. if (!e)
  172. printk(KERN_ERR "I/O scheduler %s not found\n",
  173. chosen_elevator);
  174. }
  175. if (!e) {
  176. e = elevator_get(CONFIG_DEFAULT_IOSCHED, false);
  177. if (!e) {
  178. printk(KERN_ERR
  179. "Default I/O scheduler not found. " \
  180. "Using noop.\n");
  181. e = elevator_get("noop", false);
  182. }
  183. }
  184. err = e->ops.elevator_init_fn(q, e);
  185. return 0;
  186. }
  187. EXPORT_SYMBOL(elevator_init);
  188. void elevator_exit(struct elevator_queue *e)
  189. {
  190. mutex_lock(&e->sysfs_lock);
  191. if (e->type->ops.elevator_exit_fn)
  192. e->type->ops.elevator_exit_fn(e);
  193. mutex_unlock(&e->sysfs_lock);
  194. kobject_put(&e->kobj);
  195. }
  196. EXPORT_SYMBOL(elevator_exit);
  197. static inline void __elv_rqhash_del(struct request *rq)
  198. {
  199. hash_del(&rq->hash);
  200. }
  201. static void elv_rqhash_del(struct request_queue *q, struct request *rq)
  202. {
  203. if (ELV_ON_HASH(rq))
  204. __elv_rqhash_del(rq);
  205. }
  206. static void elv_rqhash_add(struct request_queue *q, struct request *rq)
  207. {
  208. struct elevator_queue *e = q->elevator;
  209. BUG_ON(ELV_ON_HASH(rq));
  210. hash_add(e->hash, &rq->hash, rq_hash_key(rq));
  211. }
  212. static void elv_rqhash_reposition(struct request_queue *q, struct request *rq)
  213. {
  214. __elv_rqhash_del(rq);
  215. elv_rqhash_add(q, rq);
  216. }
  217. static struct request *elv_rqhash_find(struct request_queue *q, sector_t offset)
  218. {
  219. struct elevator_queue *e = q->elevator;
  220. struct hlist_node *next;
  221. struct request *rq;
  222. hash_for_each_possible_safe(e->hash, rq, next, hash, offset) {
  223. BUG_ON(!ELV_ON_HASH(rq));
  224. if (unlikely(!rq_mergeable(rq))) {
  225. __elv_rqhash_del(rq);
  226. continue;
  227. }
  228. if (rq_hash_key(rq) == offset)
  229. return rq;
  230. }
  231. return NULL;
  232. }
  233. /*
  234. * RB-tree support functions for inserting/lookup/removal of requests
  235. * in a sorted RB tree.
  236. */
  237. void elv_rb_add(struct rb_root *root, struct request *rq)
  238. {
  239. struct rb_node **p = &root->rb_node;
  240. struct rb_node *parent = NULL;
  241. struct request *__rq;
  242. while (*p) {
  243. parent = *p;
  244. __rq = rb_entry(parent, struct request, rb_node);
  245. if (blk_rq_pos(rq) < blk_rq_pos(__rq))
  246. p = &(*p)->rb_left;
  247. else if (blk_rq_pos(rq) >= blk_rq_pos(__rq))
  248. p = &(*p)->rb_right;
  249. }
  250. rb_link_node(&rq->rb_node, parent, p);
  251. rb_insert_color(&rq->rb_node, root);
  252. }
  253. EXPORT_SYMBOL(elv_rb_add);
  254. void elv_rb_del(struct rb_root *root, struct request *rq)
  255. {
  256. BUG_ON(RB_EMPTY_NODE(&rq->rb_node));
  257. rb_erase(&rq->rb_node, root);
  258. RB_CLEAR_NODE(&rq->rb_node);
  259. }
  260. EXPORT_SYMBOL(elv_rb_del);
  261. struct request *elv_rb_find(struct rb_root *root, sector_t sector)
  262. {
  263. struct rb_node *n = root->rb_node;
  264. struct request *rq;
  265. while (n) {
  266. rq = rb_entry(n, struct request, rb_node);
  267. if (sector < blk_rq_pos(rq))
  268. n = n->rb_left;
  269. else if (sector > blk_rq_pos(rq))
  270. n = n->rb_right;
  271. else
  272. return rq;
  273. }
  274. return NULL;
  275. }
  276. EXPORT_SYMBOL(elv_rb_find);
  277. /*
  278. * Insert rq into dispatch queue of q. Queue lock must be held on
  279. * entry. rq is sort instead into the dispatch queue. To be used by
  280. * specific elevators.
  281. */
  282. void elv_dispatch_sort(struct request_queue *q, struct request *rq)
  283. {
  284. sector_t boundary;
  285. struct list_head *entry;
  286. int stop_flags;
  287. if (q->last_merge == rq)
  288. q->last_merge = NULL;
  289. elv_rqhash_del(q, rq);
  290. q->nr_sorted--;
  291. boundary = q->end_sector;
  292. stop_flags = REQ_SOFTBARRIER | REQ_STARTED;
  293. list_for_each_prev(entry, &q->queue_head) {
  294. struct request *pos = list_entry_rq(entry);
  295. if ((rq->cmd_flags & REQ_DISCARD) !=
  296. (pos->cmd_flags & REQ_DISCARD))
  297. break;
  298. if (rq_data_dir(rq) != rq_data_dir(pos))
  299. break;
  300. if (pos->cmd_flags & stop_flags)
  301. break;
  302. if (blk_rq_pos(rq) >= boundary) {
  303. if (blk_rq_pos(pos) < boundary)
  304. continue;
  305. } else {
  306. if (blk_rq_pos(pos) >= boundary)
  307. break;
  308. }
  309. if (blk_rq_pos(rq) >= blk_rq_pos(pos))
  310. break;
  311. }
  312. list_add(&rq->queuelist, entry);
  313. }
  314. EXPORT_SYMBOL(elv_dispatch_sort);
  315. /*
  316. * Insert rq into dispatch queue of q. Queue lock must be held on
  317. * entry. rq is added to the back of the dispatch queue. To be used by
  318. * specific elevators.
  319. */
  320. void elv_dispatch_add_tail(struct request_queue *q, struct request *rq)
  321. {
  322. if (q->last_merge == rq)
  323. q->last_merge = NULL;
  324. elv_rqhash_del(q, rq);
  325. q->nr_sorted--;
  326. q->end_sector = rq_end_sector(rq);
  327. q->boundary_rq = rq;
  328. list_add_tail(&rq->queuelist, &q->queue_head);
  329. }
  330. EXPORT_SYMBOL(elv_dispatch_add_tail);
  331. int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
  332. {
  333. struct elevator_queue *e = q->elevator;
  334. struct request *__rq;
  335. int ret;
  336. /*
  337. * Levels of merges:
  338. * nomerges: No merges at all attempted
  339. * noxmerges: Only simple one-hit cache try
  340. * merges: All merge tries attempted
  341. */
  342. if (blk_queue_nomerges(q))
  343. return ELEVATOR_NO_MERGE;
  344. /*
  345. * First try one-hit cache.
  346. */
  347. if (q->last_merge && elv_rq_merge_ok(q->last_merge, bio)) {
  348. ret = blk_try_merge(q->last_merge, bio);
  349. if (ret != ELEVATOR_NO_MERGE) {
  350. *req = q->last_merge;
  351. return ret;
  352. }
  353. }
  354. if (blk_queue_noxmerges(q))
  355. return ELEVATOR_NO_MERGE;
  356. /*
  357. * See if our hash lookup can find a potential backmerge.
  358. */
  359. __rq = elv_rqhash_find(q, bio->bi_sector);
  360. if (__rq && elv_rq_merge_ok(__rq, bio)) {
  361. *req = __rq;
  362. return ELEVATOR_BACK_MERGE;
  363. }
  364. if (e->type->ops.elevator_merge_fn)
  365. return e->type->ops.elevator_merge_fn(q, req, bio);
  366. return ELEVATOR_NO_MERGE;
  367. }
  368. /*
  369. * Attempt to do an insertion back merge. Only check for the case where
  370. * we can append 'rq' to an existing request, so we can throw 'rq' away
  371. * afterwards.
  372. *
  373. * Returns true if we merged, false otherwise
  374. */
  375. static bool elv_attempt_insert_merge(struct request_queue *q,
  376. struct request *rq)
  377. {
  378. struct request *__rq;
  379. bool ret;
  380. if (blk_queue_nomerges(q))
  381. return false;
  382. /*
  383. * First try one-hit cache.
  384. */
  385. if (q->last_merge && blk_attempt_req_merge(q, q->last_merge, rq))
  386. return true;
  387. if (blk_queue_noxmerges(q))
  388. return false;
  389. ret = false;
  390. /*
  391. * See if our hash lookup can find a potential backmerge.
  392. */
  393. while (1) {
  394. __rq = elv_rqhash_find(q, blk_rq_pos(rq));
  395. if (!__rq || !blk_attempt_req_merge(q, __rq, rq))
  396. break;
  397. /* The merged request could be merged with others, try again */
  398. ret = true;
  399. rq = __rq;
  400. }
  401. return ret;
  402. }
  403. void elv_merged_request(struct request_queue *q, struct request *rq, int type)
  404. {
  405. struct elevator_queue *e = q->elevator;
  406. if (e->type->ops.elevator_merged_fn)
  407. e->type->ops.elevator_merged_fn(q, rq, type);
  408. if (type == ELEVATOR_BACK_MERGE)
  409. elv_rqhash_reposition(q, rq);
  410. q->last_merge = rq;
  411. }
  412. void elv_merge_requests(struct request_queue *q, struct request *rq,
  413. struct request *next)
  414. {
  415. struct elevator_queue *e = q->elevator;
  416. const int next_sorted = next->cmd_flags & REQ_SORTED;
  417. if (next_sorted && e->type->ops.elevator_merge_req_fn)
  418. e->type->ops.elevator_merge_req_fn(q, rq, next);
  419. elv_rqhash_reposition(q, rq);
  420. if (next_sorted) {
  421. elv_rqhash_del(q, next);
  422. q->nr_sorted--;
  423. }
  424. q->last_merge = rq;
  425. }
  426. void elv_bio_merged(struct request_queue *q, struct request *rq,
  427. struct bio *bio)
  428. {
  429. struct elevator_queue *e = q->elevator;
  430. if (e->type->ops.elevator_bio_merged_fn)
  431. e->type->ops.elevator_bio_merged_fn(q, rq, bio);
  432. }
  433. #ifdef CONFIG_PM_RUNTIME
  434. static void blk_pm_requeue_request(struct request *rq)
  435. {
  436. if (rq->q->dev && !(rq->cmd_flags & REQ_PM))
  437. rq->q->nr_pending--;
  438. }
  439. static void blk_pm_add_request(struct request_queue *q, struct request *rq)
  440. {
  441. if (q->dev && !(rq->cmd_flags & REQ_PM) && q->nr_pending++ == 0 &&
  442. (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING))
  443. pm_request_resume(q->dev);
  444. }
  445. #else
  446. static inline void blk_pm_requeue_request(struct request *rq) {}
  447. static inline void blk_pm_add_request(struct request_queue *q,
  448. struct request *rq)
  449. {
  450. }
  451. #endif
  452. void elv_requeue_request(struct request_queue *q, struct request *rq)
  453. {
  454. /*
  455. * it already went through dequeue, we need to decrement the
  456. * in_flight count again
  457. */
  458. if (blk_account_rq(rq)) {
  459. q->in_flight[rq_is_sync(rq)]--;
  460. if (rq->cmd_flags & REQ_SORTED)
  461. elv_deactivate_rq(q, rq);
  462. }
  463. rq->cmd_flags &= ~REQ_STARTED;
  464. blk_pm_requeue_request(rq);
  465. __elv_add_request(q, rq, ELEVATOR_INSERT_REQUEUE);
  466. }
  467. void elv_drain_elevator(struct request_queue *q)
  468. {
  469. static int printed;
  470. lockdep_assert_held(q->queue_lock);
  471. while (q->elevator->type->ops.elevator_dispatch_fn(q, 1))
  472. ;
  473. if (q->nr_sorted && printed++ < 10) {
  474. printk(KERN_ERR "%s: forced dispatching is broken "
  475. "(nr_sorted=%u), please report this\n",
  476. q->elevator->type->elevator_name, q->nr_sorted);
  477. }
  478. }
  479. void __elv_add_request(struct request_queue *q, struct request *rq, int where)
  480. {
  481. trace_block_rq_insert(q, rq);
  482. blk_pm_add_request(q, rq);
  483. rq->q = q;
  484. if (rq->cmd_flags & REQ_SOFTBARRIER) {
  485. /* barriers are scheduling boundary, update end_sector */
  486. if (rq->cmd_type == REQ_TYPE_FS) {
  487. q->end_sector = rq_end_sector(rq);
  488. q->boundary_rq = rq;
  489. }
  490. } else if (!(rq->cmd_flags & REQ_ELVPRIV) &&
  491. (where == ELEVATOR_INSERT_SORT ||
  492. where == ELEVATOR_INSERT_SORT_MERGE))
  493. where = ELEVATOR_INSERT_BACK;
  494. switch (where) {
  495. case ELEVATOR_INSERT_REQUEUE:
  496. case ELEVATOR_INSERT_FRONT:
  497. rq->cmd_flags |= REQ_SOFTBARRIER;
  498. list_add(&rq->queuelist, &q->queue_head);
  499. break;
  500. case ELEVATOR_INSERT_BACK:
  501. rq->cmd_flags |= REQ_SOFTBARRIER;
  502. elv_drain_elevator(q);
  503. list_add_tail(&rq->queuelist, &q->queue_head);
  504. /*
  505. * We kick the queue here for the following reasons.
  506. * - The elevator might have returned NULL previously
  507. * to delay requests and returned them now. As the
  508. * queue wasn't empty before this request, ll_rw_blk
  509. * won't run the queue on return, resulting in hang.
  510. * - Usually, back inserted requests won't be merged
  511. * with anything. There's no point in delaying queue
  512. * processing.
  513. */
  514. __blk_run_queue(q);
  515. break;
  516. case ELEVATOR_INSERT_SORT_MERGE:
  517. /*
  518. * If we succeed in merging this request with one in the
  519. * queue already, we are done - rq has now been freed,
  520. * so no need to do anything further.
  521. */
  522. if (elv_attempt_insert_merge(q, rq))
  523. break;
  524. case ELEVATOR_INSERT_SORT:
  525. BUG_ON(rq->cmd_type != REQ_TYPE_FS);
  526. rq->cmd_flags |= REQ_SORTED;
  527. q->nr_sorted++;
  528. if (rq_mergeable(rq)) {
  529. elv_rqhash_add(q, rq);
  530. if (!q->last_merge)
  531. q->last_merge = rq;
  532. }
  533. /*
  534. * Some ioscheds (cfq) run q->request_fn directly, so
  535. * rq cannot be accessed after calling
  536. * elevator_add_req_fn.
  537. */
  538. q->elevator->type->ops.elevator_add_req_fn(q, rq);
  539. break;
  540. case ELEVATOR_INSERT_FLUSH:
  541. rq->cmd_flags |= REQ_SOFTBARRIER;
  542. blk_insert_flush(rq);
  543. break;
  544. default:
  545. printk(KERN_ERR "%s: bad insertion point %d\n",
  546. __func__, where);
  547. BUG();
  548. }
  549. }
  550. EXPORT_SYMBOL(__elv_add_request);
  551. void elv_add_request(struct request_queue *q, struct request *rq, int where)
  552. {
  553. unsigned long flags;
  554. spin_lock_irqsave(q->queue_lock, flags);
  555. __elv_add_request(q, rq, where);
  556. spin_unlock_irqrestore(q->queue_lock, flags);
  557. }
  558. EXPORT_SYMBOL(elv_add_request);
  559. struct request *elv_latter_request(struct request_queue *q, struct request *rq)
  560. {
  561. struct elevator_queue *e = q->elevator;
  562. if (e->type->ops.elevator_latter_req_fn)
  563. return e->type->ops.elevator_latter_req_fn(q, rq);
  564. return NULL;
  565. }
  566. struct request *elv_former_request(struct request_queue *q, struct request *rq)
  567. {
  568. struct elevator_queue *e = q->elevator;
  569. if (e->type->ops.elevator_former_req_fn)
  570. return e->type->ops.elevator_former_req_fn(q, rq);
  571. return NULL;
  572. }
  573. int elv_set_request(struct request_queue *q, struct request *rq,
  574. struct bio *bio, gfp_t gfp_mask)
  575. {
  576. struct elevator_queue *e = q->elevator;
  577. if (e->type->ops.elevator_set_req_fn)
  578. return e->type->ops.elevator_set_req_fn(q, rq, bio, gfp_mask);
  579. return 0;
  580. }
  581. void elv_put_request(struct request_queue *q, struct request *rq)
  582. {
  583. struct elevator_queue *e = q->elevator;
  584. if (e->type->ops.elevator_put_req_fn)
  585. e->type->ops.elevator_put_req_fn(rq);
  586. }
  587. int elv_may_queue(struct request_queue *q, int rw)
  588. {
  589. struct elevator_queue *e = q->elevator;
  590. if (e->type->ops.elevator_may_queue_fn)
  591. return e->type->ops.elevator_may_queue_fn(q, rw);
  592. return ELV_MQUEUE_MAY;
  593. }
  594. void elv_abort_queue(struct request_queue *q)
  595. {
  596. struct request *rq;
  597. blk_abort_flushes(q);
  598. while (!list_empty(&q->queue_head)) {
  599. rq = list_entry_rq(q->queue_head.next);
  600. rq->cmd_flags |= REQ_QUIET;
  601. trace_block_rq_abort(q, rq);
  602. /*
  603. * Mark this request as started so we don't trigger
  604. * any debug logic in the end I/O path.
  605. */
  606. blk_start_request(rq);
  607. __blk_end_request_all(rq, -EIO);
  608. }
  609. }
  610. EXPORT_SYMBOL(elv_abort_queue);
  611. void elv_completed_request(struct request_queue *q, struct request *rq)
  612. {
  613. struct elevator_queue *e = q->elevator;
  614. /*
  615. * request is released from the driver, io must be done
  616. */
  617. if (blk_account_rq(rq)) {
  618. q->in_flight[rq_is_sync(rq)]--;
  619. if ((rq->cmd_flags & REQ_SORTED) &&
  620. e->type->ops.elevator_completed_req_fn)
  621. e->type->ops.elevator_completed_req_fn(q, rq);
  622. }
  623. }
  624. #define to_elv(atr) container_of((atr), struct elv_fs_entry, attr)
  625. static ssize_t
  626. elv_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
  627. {
  628. struct elv_fs_entry *entry = to_elv(attr);
  629. struct elevator_queue *e;
  630. ssize_t error;
  631. if (!entry->show)
  632. return -EIO;
  633. e = container_of(kobj, struct elevator_queue, kobj);
  634. mutex_lock(&e->sysfs_lock);
  635. error = e->type ? entry->show(e, page) : -ENOENT;
  636. mutex_unlock(&e->sysfs_lock);
  637. return error;
  638. }
  639. static ssize_t
  640. elv_attr_store(struct kobject *kobj, struct attribute *attr,
  641. const char *page, size_t length)
  642. {
  643. struct elv_fs_entry *entry = to_elv(attr);
  644. struct elevator_queue *e;
  645. ssize_t error;
  646. if (!entry->store)
  647. return -EIO;
  648. e = container_of(kobj, struct elevator_queue, kobj);
  649. mutex_lock(&e->sysfs_lock);
  650. error = e->type ? entry->store(e, page, length) : -ENOENT;
  651. mutex_unlock(&e->sysfs_lock);
  652. return error;
  653. }
  654. static const struct sysfs_ops elv_sysfs_ops = {
  655. .show = elv_attr_show,
  656. .store = elv_attr_store,
  657. };
  658. static struct kobj_type elv_ktype = {
  659. .sysfs_ops = &elv_sysfs_ops,
  660. .release = elevator_release,
  661. };
  662. int elv_register_queue(struct request_queue *q)
  663. {
  664. struct elevator_queue *e = q->elevator;
  665. int error;
  666. error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched");
  667. if (!error) {
  668. struct elv_fs_entry *attr = e->type->elevator_attrs;
  669. if (attr) {
  670. while (attr->attr.name) {
  671. if (sysfs_create_file(&e->kobj, &attr->attr))
  672. break;
  673. attr++;
  674. }
  675. }
  676. kobject_uevent(&e->kobj, KOBJ_ADD);
  677. e->registered = 1;
  678. }
  679. return error;
  680. }
  681. EXPORT_SYMBOL(elv_register_queue);
  682. void elv_unregister_queue(struct request_queue *q)
  683. {
  684. if (q) {
  685. struct elevator_queue *e = q->elevator;
  686. kobject_uevent(&e->kobj, KOBJ_REMOVE);
  687. kobject_del(&e->kobj);
  688. e->registered = 0;
  689. }
  690. }
  691. EXPORT_SYMBOL(elv_unregister_queue);
  692. int elv_register(struct elevator_type *e)
  693. {
  694. char *def = "";
  695. /* create icq_cache if requested */