cregit-Linux how code gets into the kernel

Release 4.14 block/elevator.c

Directory: block
/*
 *  Block device elevator/IO-scheduler.
 *
 *  Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
 *
 * 30042000 Jens Axboe <axboe@kernel.dk> :
 *
 * Split the elevator a bit so that it is possible to choose a different
 * one or even write a new "plug in". There are three pieces:
 * - elevator_fn, inserts a new request in the queue list
 * - elevator_merge_fn, decides whether a new buffer can be merged with
 *   an existing request
 * - elevator_dequeue_fn, called when a request is taken off the active list
 *
 * 20082000 Dave Jones <davej@suse.de> :
 * Removed tests for max-bomb-segments, which was breaking elvtune
 *  when run without -bN
 *
 * Jens:
 * - Rework again to work with bio instead of buffer_heads
 * - loose bi_dev comparisons, partition handling is right now
 * - completely modularize elevator setup and teardown
 *
 */
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/blkdev.h>
#include <linux/elevator.h>
#include <linux/bio.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/compiler.h>
#include <linux/blktrace_api.h>
#include <linux/hash.h>
#include <linux/uaccess.h>
#include <linux/pm_runtime.h>
#include <linux/blk-cgroup.h>

#include <trace/events/block.h>

#include "blk.h"
#include "blk-mq-sched.h"
#include "blk-wbt.h"

static DEFINE_SPINLOCK(elv_list_lock);
static LIST_HEAD(elv_list);

/*
 * Merge hash stuff.
 */

#define rq_hash_key(rq)		(blk_rq_pos(rq) + blk_rq_sectors(rq))

/*
 * Query io scheduler to see if the current process issuing bio may be
 * merged with rq.
 */

static int elv_iosched_allow_bio_merge(struct request *rq, struct bio *bio) { struct request_queue *q = rq->q; struct elevator_queue *e = q->elevator; if (e->uses_mq && e->type->ops.mq.allow_merge) return e->type->ops.mq.allow_merge(q, rq, bio); else if (!e->uses_mq && e->type->ops.sq.elevator_allow_bio_merge_fn) return e->type->ops.sq.elevator_allow_bio_merge_fn(q, rq, bio); return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe9891.59%571.43%
Tejun Heo65.61%114.29%
Tahsin Erdogan32.80%114.29%
Total107100.00%7100.00%

/* * can we safely merge with this request? */
bool elv_bio_merge_ok(struct request *rq, struct bio *bio) { if (!blk_rq_merge_ok(rq, bio)) return false; if (!elv_iosched_allow_bio_merge(rq, bio)) return false; return true; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds2045.45%342.86%
Jens Axboe1125.00%114.29%
Tahsin Erdogan511.36%114.29%
Martin K. Petersen511.36%114.29%
Tejun Heo36.82%114.29%
Total44100.00%7100.00%

EXPORT_SYMBOL(elv_bio_merge_ok);
static struct elevator_type *elevator_find(const char *name) { struct elevator_type *e; list_for_each_entry(e, &elv_list, list) { if (!strcmp(e->elevator_name, name)) return e; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe3780.43%125.00%
Vasily Tarasov48.70%125.00%
Matthias Kaehlcke48.70%125.00%
Adrian Bunk12.17%125.00%
Total46100.00%4100.00%


static void elevator_put(struct elevator_type *e) { module_put(e->elevator_owner); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe18100.00%1100.00%
Total18100.00%1100.00%


static struct elevator_type *elevator_get(const char *name, bool try_loading) { struct elevator_type *e; spin_lock(&elv_list_lock); e = elevator_find(name); if (!e && try_loading) { spin_unlock(&elv_list_lock); request_module("%s-iosched", name); spin_lock(&elv_list_lock); e = elevator_find(name); } if (e && !try_module_get(e->elevator_owner)) e = NULL; spin_unlock(&elv_list_lock); return e; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe6973.40%342.86%
Tejun Heo2324.47%228.57%
wzt wzt11.06%114.29%
Kees Cook11.06%114.29%
Total94100.00%7100.00%

static char chosen_elevator[ELV_NAME_MAX];
static int __init elevator_setup(char *str) { /* * Be backwards-compatible with previous kernels, so users * won't get the wrong elevator. */ strncpy(chosen_elevator, str, sizeof(chosen_elevator) - 1); return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe1758.62%228.57%
Nate Diller620.69%114.29%
Linus Torvalds (pre-git)26.90%114.29%
Linus Torvalds26.90%114.29%
Chuck Ebbert13.45%114.29%
Hirofumi Ogawa13.45%114.29%
Total29100.00%7100.00%

__setup("elevator=", elevator_setup); /* called during boot to load the elevator chosen by the elevator param */
void __init load_default_elevator_module(void) { struct elevator_type *e; if (!chosen_elevator[0]) return; spin_lock(&elv_list_lock); e = elevator_find(chosen_elevator); spin_unlock(&elv_list_lock); if (!e) request_module("%s-iosched", chosen_elevator); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo53100.00%1100.00%
Total53100.00%1100.00%

static struct kobj_type elv_ktype;
struct elevator_queue *elevator_alloc(struct request_queue *q, struct elevator_type *e) { struct elevator_queue *eq; eq = kzalloc_node(sizeof(*eq), GFP_KERNEL, q->node); if (unlikely(!eq)) return NULL; eq->type = e; kobject_init(&eq->kobj, &elv_ktype); mutex_init(&eq->sysfs_lock); hash_init(eq->hash); eq->uses_mq = e->uses_mq; return eq; }

Contributors

PersonTokensPropCommitsCommitProp
Al Viro4447.31%17.69%
Jens Axboe4043.01%538.46%
Chao Yu33.23%17.69%
Greg Kroah-Hartman33.23%323.08%
Tejun Heo11.08%17.69%
Joe Perches11.08%17.69%
Sasha Levin11.08%17.69%
Total93100.00%13100.00%

EXPORT_SYMBOL(elevator_alloc);
static void elevator_release(struct kobject *kobj) { struct elevator_queue *e; e = container_of(kobj, struct elevator_queue, kobj); elevator_put(e->type); kfree(e); }

Contributors

PersonTokensPropCommitsCommitProp
Al Viro3177.50%133.33%
Jens Axboe820.00%133.33%
Tejun Heo12.50%133.33%
Total40100.00%3100.00%


int elevator_init(struct request_queue *q, char *name) { struct elevator_type *e = NULL; int err; /* * q->sysfs_lock must be held to provide mutual exclusion between * elevator_switch() and here. */ lockdep_assert_held(&q->sysfs_lock); if (unlikely(q->elevator)) return 0; INIT_LIST_HEAD(&q->queue_head); q->last_merge = NULL; q->end_sector = 0; q->boundary_rq = NULL; if (name) { e = elevator_get(name, true); if (!e) return -EINVAL; } /* * Use the default elevator specified by config boot param for * non-mq devices, or by config option. Don't try to load modules * as we could be running off async and request_module() isn't * allowed from async. */ if (!e && !q->mq_ops && *chosen_elevator) { e = elevator_get(chosen_elevator, false); if (!e) printk(KERN_ERR "I/O scheduler %s not found\n", chosen_elevator); } if (!e) { /* * For blk-mq devices, we default to using mq-deadline, * if available, for single queue devices. If deadline * isn't available OR we have multiple queues, default * to "none". */ if (q->mq_ops) { if (q->nr_hw_queues == 1) e = elevator_get("mq-deadline", false); if (!e) return 0; } else e = elevator_get(CONFIG_DEFAULT_IOSCHED, false); if (!e) { printk(KERN_ERR "Default I/O scheduler not found. " \ "Using noop.\n"); e = elevator_get("noop", false); } } if (e->uses_mq) err = blk_mq_init_sched(q, e); else err = e->ops.sq.elevator_init_fn(q, e); if (err) elevator_put(e); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe11947.41%1045.45%
Nate Diller4517.93%29.09%
Tejun Heo4216.73%418.18%
Mike Snitzer124.78%14.55%
Linus Torvalds114.38%14.55%
Sudip Mukherjee103.98%14.55%
Tomoki Sekiyama93.59%14.55%
Jianpeng Ma (马建朋)20.80%14.55%
Omar Sandoval10.40%14.55%
Total251100.00%22100.00%

EXPORT_SYMBOL(elevator_init);
void elevator_exit(struct request_queue *q, struct elevator_queue *e) { mutex_lock(&e->sysfs_lock); if (e->uses_mq && e->type->ops.mq.exit_sched) blk_mq_exit_sched(q, e); else if (!e->uses_mq && e->type->ops.sq.elevator_exit_fn) e->type->ops.sq.elevator_exit_fn(e); mutex_unlock(&e->sysfs_lock); kobject_put(&e->kobj); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe6266.67%457.14%
Al Viro1718.28%114.29%
Omar Sandoval88.60%114.29%
Tejun Heo66.45%114.29%
Total93100.00%7100.00%

EXPORT_SYMBOL(elevator_exit);
static inline void __elv_rqhash_del(struct request *rq) { hash_del(&rq->hash); rq->rq_flags &= ~RQF_HASHED; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe2488.89%250.00%
Christoph Hellwig27.41%125.00%
Sasha Levin13.70%125.00%
Total27100.00%4100.00%


void elv_rqhash_del(struct request_queue *q, struct request *rq) { if (ELV_ON_HASH(rq)) __elv_rqhash_del(rq); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe27100.00%2100.00%
Total27100.00%2100.00%

EXPORT_SYMBOL_GPL(elv_rqhash_del);
void elv_rqhash_add(struct request_queue *q, struct request *rq) { struct elevator_queue *e = q->elevator; BUG_ON(ELV_ON_HASH(rq)); hash_add(e->hash, &rq->hash, rq_hash_key(rq)); rq->rq_flags |= RQF_HASHED; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe4989.09%466.67%
Sasha Levin47.27%116.67%
Christoph Hellwig23.64%116.67%
Total55100.00%6100.00%

EXPORT_SYMBOL_GPL(elv_rqhash_add);
void elv_rqhash_reposition(struct request_queue *q, struct request *rq) { __elv_rqhash_del(rq); elv_rqhash_add(q, rq); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe27100.00%2100.00%
Total27100.00%2100.00%


struct request *elv_rqhash_find(struct request_queue *q, sector_t offset) { struct elevator_queue *e = q->elevator; struct hlist_node *next; struct request *rq; hash_for_each_possible_safe(e->hash, rq, next, hash, offset) { BUG_ON(!ELV_ON_HASH(rq)); if (unlikely(!rq_mergeable(rq))) { __elv_rqhash_del(rq); continue; } if (rq_hash_key(rq) == offset) return rq; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe8694.51%375.00%
Sasha Levin55.49%125.00%
Total91100.00%4100.00%

/* * RB-tree support functions for inserting/lookup/removal of requests * in a sorted RB tree. */
void elv_rb_add(struct rb_root *root, struct request *rq) { struct rb_node **p = &root->rb_node; struct rb_node *parent = NULL; struct request *__rq; while (*p) { parent = *p; __rq = rb_entry(parent, struct request, rb_node); if (blk_rq_pos(rq) < blk_rq_pos(__rq)) p = &(*p)->rb_left; else if (blk_rq_pos(rq) >= blk_rq_pos(__rq)) p = &(*p)->rb_right; } rb_link_node(&rq->rb_node, parent, p); rb_insert_color(&rq->rb_node, root); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe11589.15%133.33%
Tejun Heo129.30%133.33%
Jeff Moyer21.55%133.33%
Total129100.00%3100.00%

EXPORT_SYMBOL(elv_rb_add);
void elv_rb_del(struct rb_root *root, struct request *rq) { BUG_ON(RB_EMPTY_NODE(&rq->rb_node)); rb_erase(&rq->rb_node, root); RB_CLEAR_NODE(&rq->rb_node); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe44100.00%1100.00%
Total44100.00%1100.00%

EXPORT_SYMBOL(elv_rb_del);
struct request *elv_rb_find(struct rb_root *root, sector_t sector) { struct rb_node *n = root->rb_node; struct request *rq; while (n) { rq = rb_entry(n, struct request, rb_node); if (sector < blk_rq_pos(rq)) n = n->rb_left; else if (sector > blk_rq_pos(rq)) n = n->rb_right; else return rq; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe7992.94%150.00%
Tejun Heo67.06%150.00%
Total85100.00%2100.00%

EXPORT_SYMBOL(elv_rb_find); /* * Insert rq into dispatch queue of q. Queue lock must be held on * entry. rq is sort instead into the dispatch queue. To be used by * specific elevators. */
void elv_dispatch_sort(struct request_queue *q, struct request *rq) { sector_t boundary; struct list_head *entry; if (q->last_merge == rq) q->last_merge = NULL; elv_rqhash_del(q, rq); q->nr_sorted--; boundary = q->end_sector; list_for_each_prev(entry, &q->queue_head) { struct request *pos = list_entry_rq(entry); if (req_op(rq) != req_op(pos)) break; if (rq_data_dir(rq) != rq_data_dir(pos)) break; if (pos->rq_flags & (RQF_STARTED | RQF_SOFTBARRIER)) break; if (blk_rq_pos(rq) >= boundary) { if (blk_rq_pos(pos) < boundary) continue; } else { if (blk_rq_pos(pos) >= boundary) break; } if (blk_rq_pos(rq) >= blk_rq_pos(pos)) break; } list_add(&rq->queuelist, entry); }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo12674.56%436.36%
Jens Axboe2414.20%436.36%
David Woodhouse74.14%19.09%
Michael Christie63.55%19.09%
Christoph Hellwig63.55%19.09%
Total169100.00%11100.00%

EXPORT_SYMBOL(elv_dispatch_sort); /* * Insert rq into dispatch queue of q. Queue lock must be held on * entry. rq is added to the back of the dispatch queue. To be used by * specific elevators. */
void elv_dispatch_add_tail(struct request_queue *q, struct request *rq) { if (q->last_merge == rq) q->last_merge = NULL; elv_rqhash_del(q, rq); q->nr_sorted--; q->end_sector = rq_end_sector(rq); q->boundary_rq = rq; list_add_tail(&rq->queuelist, &q->queue_head); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe69100.00%1100.00%
Total69100.00%1100.00%

EXPORT_SYMBOL(elv_dispatch_add_tail);
enum elv_merge elv_merge(struct request_queue *q, struct request **req, struct bio *bio) { struct elevator_queue *e = q->elevator; struct request *__rq; /* * Levels of merges: * nomerges: No merges at all attempted * noxmerges: Only simple one-hit cache try * merges: All merge tries attempted */ if (blk_queue_nomerges(q) || !bio_mergeable(bio)) return ELEVATOR_NO_MERGE; /* * First try one-hit cache. */ if (q->last_merge && elv_bio_merge_ok(q->last_merge, bio)) { enum elv_merge ret = blk_try_merge(q->last_merge, bio); if (ret != ELEVATOR_NO_MERGE) { *req = q->last_merge; return ret; } } if (blk_queue_noxmerges(q)) return ELEVATOR_NO_MERGE; /* * See if our hash lookup can find a potential backmerge. */ __rq = elv_rqhash_find(q, bio->bi_iter.bi_sector); if (__rq && elv_bio_merge_ok(__rq, bio)) { *req = __rq; return ELEVATOR_BACK_MERGE; } if (e->uses_mq && e->type->ops.mq.request_merge) return e->type->ops.mq.request_merge(q, req, bio); else if (!e->uses_mq && e->type->ops.sq.elevator_merge_fn) return e->type->ops.sq.elevator_merge_fn(q, req, bio); return ELEVATOR_NO_MERGE; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe11150.45%741.18%
Tejun Heo4922.27%317.65%
Linus Torvalds2310.45%15.88%
Alan D. Brunelle219.55%211.76%
Christoph Hellwig62.73%15.88%
Ming Lei62.73%15.88%
Kent Overstreet20.91%15.88%
Tahsin Erdogan20.91%15.88%
Total220100.00%17100.00%

/* * Attempt to do an insertion back merge. Only check for the case where * we can append 'rq' to an existing request, so we can throw 'rq' away * afterwards. * * Returns true if we merged, false otherwise */
bool elv_attempt_insert_merge(struct request_queue *q, struct request *rq) { struct request *__rq; bool ret; if (blk_queue_nomerges(q)) return false; /* * First try one-hit cache. */ if (q->last_merge && blk_attempt_req_merge(q, q->last_merge, rq)) return true; if (blk_queue_noxmerges(q)) return false; ret = false; /* * See if our hash lookup can find a potential backmerge. */ while (1) { __rq = elv_rqhash_find(q, blk_rq_pos(rq)); if (!__rq || !blk_attempt_req_merge(q, __rq, rq)) break; /* The merged request could be merged with others, try again */ ret = true; rq = __rq; } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe8977.39%150.00%
Shaohua Li2622.61%150.00%
Total115100.00%2100.00%


void elv_merged_request(struct request_queue *q, struct request *rq, enum elv_merge type) { struct elevator_queue *e = q->elevator; if (e->uses_mq && e->type->ops.mq.request_merged) e->type->ops.mq.request_merged(q, rq, type); else if (!e->uses_mq && e->type->ops.sq.elevator_merged_fn) e->type->ops.sq.elevator_merged_fn(q, rq, type); if (type == ELEVATOR_BACK_MERGE) elv_rqhash_reposition(q, rq); q->last_merge = rq; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe10187.83%872.73%
Tejun Heo1210.43%218.18%
Christoph Hellwig21.74%19.09%
Total115100.00%11100.00%


void elv_merge_requests(struct request_queue *q, struct request *rq, struct request *next) { struct elevator_queue *e = q->elevator; bool next_sorted = false; if (e->uses_mq && e->type->ops.mq.requests_merged) e->type->ops.mq.requests_merged(q, rq, next); else if (e->type->ops.sq.elevator_merge_req_fn) { next_sorted = (__force bool)(next->rq_flags & RQF_SORTED); if (next_sorted) e->type->ops.sq.elevator_merge_req_fn(q, rq, next); } elv_rqhash_reposition(q, rq); if (next_sorted) { elv_rqhash_del(q, next); q->nr_sorted--; } q->last_merge = rq; }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe8758.78%861.54%
Linus Torvalds3825.68%17.69%
Tejun Heo1711.49%323.08%
Bart Van Assche64.05%17.69%
Total148100.00%13100.00%


void elv_bio_merged(struct request_queue *q, struct request *rq, struct bio *bio) { struct elevator_queue *e = q->elevator; if (WARN_ON_ONCE(e->uses_mq)) return; if (e->type->ops.sq.elevator_bio_merged_fn) e->type->ops.sq.elevator_bio_merged_fn(q, rq, bio); }

Contributors

PersonTokensPropCommitsCommitProp
Divyesh Shah4870.59%125.00%
Jens Axboe1420.59%250.00%
Tejun Heo68.82%125.00%
Total68100.00%4100.00%

#ifdef CONFIG_PM
static void blk_pm_requeue_request(struct request *rq) { if (rq->q->dev && !(rq->rq_flags & RQF_PM)) rq->q->nr_pending--; }

Contributors

PersonTokensPropCommitsCommitProp
Lin Ming3394.29%150.00%
Christoph Hellwig25.71%150.00%
Total35100.00%2100.00%


static void blk_pm_add_request(struct request_queue *q, struct request *rq) { if (q->dev && !(rq->rq_flags & RQF_PM) && q->nr_pending++ == 0 && (q->rpm_status == RPM_SUSPENDED || q->rpm_status == RPM_SUSPENDING)) pm_request_resume(q->dev); }

Contributors

PersonTokensPropCommitsCommitProp
Lin Ming5796.61%150.00%
Christoph Hellwig23.39%150.00%
Total59100.00%2100.00%

#else
static inline void blk_pm_requeue_request(struct request *rq) {}

Contributors

PersonTokensPropCommitsCommitProp
Lin Ming11100.00%1100.00%
Total11100.00%1100.00%


static inline void blk_pm_add_request(struct request_queue *q, struct request *rq) { }

Contributors

PersonTokensPropCommitsCommitProp
Lin Ming16100.00%1100.00%
Total16100.00%1100.00%

#endif
void elv_requeue_request(struct request_queue *q, struct request *rq) { /* * it already went through dequeue, we need to decrement the * in_flight count again */ if (blk_account_rq(rq)) { q->in_flight[rq_is_sync(rq)]--; if (rq->rq_flags & RQF_SORTED) elv_deactivate_rq(q, rq); } rq->rq_flags &= ~RQF_STARTED; blk_pm_requeue_request(rq); __elv_add_request(q, rq, ELEVATOR_INSERT_REQUEUE); }

Contributors

PersonTokensPropCommitsCommitProp
Jens Axboe4156.94%650.00%
Andrew Morton1318.06%18.33%
Tejun Heo79.72%216.67%
Christoph Hellwig68.33%216.67%
Lin Ming56.94%18.33%
Total72100.00%12100.00%


void elv_drain_elevator(struct request_queue *q) { struct elevator_queue *e = q->elevator; static int printed; if (WARN_ON_ONCE(e->uses_mq)) return; lockdep_assert_held(q->queue_lock); while (e->type->ops.sq.elevator_dispatch_fn(q, 1)) ; if (q->nr_sorted && printed++ < 10) { printk(KERN_ERR "%s: forced dispatching is broken " "(nr_sorted=%u), please report this\n", q->elevator->type->elevator_name, q->nr_sorted); } }

Contributors

PersonTokensPropCommitsCommitProp
Tejun Heo6673.33%350.00%
Jens Axboe2426.67%350.00%
Total90100.00%6100.00%


void __elv_add_request(struct request_queue *q, struct request *rq, int where) { trace_block_rq_insert(q, rq); blk_pm_add_request(q, rq); rq->q = q; if (rq->rq_flags & RQF_SOFTBARRIER) { /* barriers are scheduling boundary, update end_sector */ if (!blk_rq_is_passthrough(rq)) { q->end_sector = rq_end_sector(rq); q->boundary_rq = rq; } } else if (!(rq->rq_flags & RQF_ELVPRIV) && (where == ELEVATOR_INSERT_SORT || where == ELEVATOR_INSERT_SORT_MERGE)) where = ELEVATOR_INSERT_BACK; switch (where) { case ELEVATOR_INSERT_REQUEUE: case ELEVATOR_INSERT_FRONT: rq->rq_flags |= RQF_SOFTBARRIER; list_add(&rq->queuelist, &q->queue_head); break; case ELEVATOR_INSERT_BACK: rq->rq_flags |= RQF_SOFTBARRIER; elv_drain_elevator(q); list_add_tail(&rq->queuelist, &q->queue_head); /* * We kick the queue here for the following reasons. * - The elevator might have returned NULL previously * to delay requests and returned them now. As the * queue wasn't empty before this request, ll_rw_blk * won't run the queue on return, resulting in hang. * - Usually, back inserted requests won't be merged * with anything. There's no point in delaying queue * processing. */ __blk_run_queue(q); break; case ELEVATOR_INSERT_SORT_MERGE: /* * If we succeed in merging this request with one in the * queue already, we are done - rq has now been freed, * so no need to do anything further. */ if (elv_attempt_insert_merge(q, rq)) break; /* fall through */ case ELEVATOR_INSERT_SORT: BUG_ON(blk_rq_is_passthrough(rq)); rq->rq_flags |= RQF_SORTED; q->nr_sorted++; if (rq_mergeable(rq)) { elv_rqhash_add(q, rq); if (!q->last_merge) q->last_merge = rq; }