block/blk-wbt.c
Source file repositories/reference/linux-study-clean/block/blk-wbt.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-wbt.c- Extension
.c- Size
- 23944 bytes
- Lines
- 1027
- 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/blk_types.hlinux/slab.hlinux/backing-dev.hlinux/swap.hblk-stat.hblk-wbt.hblk-rq-qos.helevator.hblk.htrace/events/wbt.h
Detected Declarations
struct rq_wbstruct wbt_wait_dataenum wbt_flagsfunction wbt_clear_statefunction wbt_flagsfunction wbt_is_trackedfunction wbt_is_readfunction rwb_enabledfunction wb_timestampfunction balance_dirty_pagesfunction rwb_wake_allfunction wbt_rqw_donefunction __wbt_donefunction wbt_donefunction stat_sample_validfunction rwb_sync_issue_latfunction wbt_inflightfunction latency_exceededfunction rwb_trace_stepfunction calc_wb_limitsfunction scale_upfunction scale_downfunction rwb_arm_timerfunction wb_timer_fnfunction wbt_update_limitsfunction wbt_disabledfunction wbt_get_min_latfunction wbt_set_min_latfunction close_iofunction get_limitfunction wbt_inflight_cbfunction wbt_cleanup_cbfunction __wbt_waitfunction wbt_should_throttlefunction bio_to_wbt_flagsfunction wbt_cleanupfunction wbt_waitfunction wbt_trackfunction wbt_issuefunction wbt_requeuefunction wbt_data_dirfunction wbt_freefunction __wbt_enable_defaultfunction wbt_enable_defaultfunction wbt_init_enable_defaultfunction wbt_default_latency_nsecfunction wbt_queue_depth_changedfunction wbt_exit
Annotated Snippet
struct rq_wb {
/*
* Settings that govern how we throttle
*/
unsigned int wb_background; /* background writeback */
unsigned int wb_normal; /* normal writeback */
short enable_state; /* WBT_STATE_* */
/*
* Number of consecutive periods where we don't have enough
* information to make a firm scale up/down decision.
*/
unsigned int unknown_cnt;
u64 win_nsec; /* default window size */
u64 cur_win_nsec; /* current window size */
struct blk_stat_callback *cb;
u64 sync_issue;
void *sync_cookie;
unsigned long last_issue; /* issue time of last read rq */
unsigned long last_comp; /* completion time of last read rq */
unsigned long min_lat_nsec;
struct rq_qos rqos;
struct rq_wait rq_wait[WBT_NUM_RWQ];
struct rq_depth rq_depth;
};
static int wbt_init(struct gendisk *disk, struct rq_wb *rwb);
static inline struct rq_wb *RQWB(struct rq_qos *rqos)
{
return container_of(rqos, struct rq_wb, rqos);
}
static inline void wbt_clear_state(struct request *rq)
{
rq->wbt_flags = 0;
}
static inline enum wbt_flags wbt_flags(struct request *rq)
{
return rq->wbt_flags;
}
static inline bool wbt_is_tracked(struct request *rq)
{
return rq->wbt_flags & WBT_TRACKED;
}
static inline bool wbt_is_read(struct request *rq)
{
return rq->wbt_flags & WBT_READ;
}
enum {
/*
* Default setting, we'll scale up (to 75% of QD max) or down (min 1)
* from here depending on device stats
*/
RWB_DEF_DEPTH = 16,
/*
* 100msec window
*/
RWB_WINDOW_NSEC = 100 * 1000 * 1000ULL,
/*
* Disregard stats, if we don't meet this minimum
*/
RWB_MIN_WRITE_SAMPLES = 3,
/*
* If we have this number of consecutive windows without enough
* information to scale up or down, slowly return to center state
* (step == 0).
*/
RWB_UNKNOWN_BUMP = 5,
};
static inline bool rwb_enabled(struct rq_wb *rwb)
{
return rwb && rwb->enable_state != WBT_STATE_OFF_DEFAULT &&
rwb->enable_state != WBT_STATE_OFF_MANUAL;
}
static void wb_timestamp(struct rq_wb *rwb, unsigned long *var)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/blk_types.h`, `linux/slab.h`, `linux/backing-dev.h`, `linux/swap.h`, `blk-stat.h`, `blk-wbt.h`, `blk-rq-qos.h`.
- Detected declarations: `struct rq_wb`, `struct wbt_wait_data`, `enum wbt_flags`, `function wbt_clear_state`, `function wbt_flags`, `function wbt_is_tracked`, `function wbt_is_read`, `function rwb_enabled`, `function wb_timestamp`, `function balance_dirty_pages`.
- 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.