block/elevator.c
Source file repositories/reference/linux-study-clean/block/elevator.c
File Facts
- System
- Linux kernel
- Corpus path
block/elevator.c- Extension
.c- Size
- 21140 bytes
- Lines
- 896
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/fs.hlinux/blkdev.hlinux/bio.hlinux/module.hlinux/slab.hlinux/init.hlinux/compiler.hlinux/blktrace_api.hlinux/hash.hlinux/uaccess.hlinux/pm_runtime.htrace/events/block.helevator.hblk.hblk-mq-sched.hblk-pm.hblk-wbt.hblk-cgroup.h
Detected Declarations
function elv_iosched_allow_bio_mergefunction elv_bio_merge_okfunction elevator_matchfunction elevator_releasefunction elevator_exitfunction __elv_rqhash_delfunction elv_rqhash_delfunction elv_rqhash_addfunction elv_rqhash_repositionfunction hash_for_each_possible_safefunction elv_rb_addfunction elv_rb_delfunction elv_mergefunction elv_attempt_insert_mergefunction elv_merged_requestfunction elv_merge_requestsfunction elv_attr_showfunction elv_attr_storefunction elv_register_queuefunction elv_unregister_queuefunction elv_registerfunction elv_unregisterfunction elevator_switchfunction elv_exit_and_releasefunction elevator_change_donefunction elevator_changefunction elv_update_nr_hw_queuesfunction elevator_set_defaultfunction elevator_set_nonefunction elv_iosched_load_modulefunction elv_iosched_storefunction elv_iosched_showfunction elevator_setupexport elv_bio_merge_okexport elv_rqhash_delexport elv_rqhash_addexport elv_rb_addexport elv_rb_delexport elv_rb_findexport elv_registerexport elv_unregisterexport elv_rb_former_requestexport elv_rb_latter_request
Annotated Snippet
if (unlikely(!rq_mergeable(rq))) {
__elv_rqhash_del(rq);
continue;
}
if (rq_hash_key(rq) == offset)
return rq;
}
return NULL;
}
/*
* 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);
}
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);
}
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;
}
EXPORT_SYMBOL(elv_rb_find);
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;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/fs.h`, `linux/blkdev.h`, `linux/bio.h`, `linux/module.h`, `linux/slab.h`, `linux/init.h`, `linux/compiler.h`.
- Detected declarations: `function elv_iosched_allow_bio_merge`, `function elv_bio_merge_ok`, `function elevator_match`, `function elevator_release`, `function elevator_exit`, `function __elv_rqhash_del`, `function elv_rqhash_del`, `function elv_rqhash_add`, `function elv_rqhash_reposition`, `function hash_for_each_possible_safe`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.