block/blk-cgroup.c
Source file repositories/reference/linux-study-clean/block/blk-cgroup.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-cgroup.c- Extension
.c- Size
- 59490 bytes
- Lines
- 2217
- 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/ioprio.hlinux/kdev_t.hlinux/module.hlinux/sched/signal.hlinux/err.hlinux/blkdev.hlinux/backing-dev.hlinux/slab.hlinux/delay.hlinux/wait_bit.hlinux/atomic.hlinux/ctype.hlinux/resume_user_mode.hlinux/psi.hlinux/part_stat.hblk.hblk-cgroup.hblk-ioprio.hblk-throttle.h
Detected Declarations
function blkcg_gqfunction blkg_free_workfnfunction blkg_freefunction __blkg_releasefunction blkg_releasefunction blkg_async_bio_workfnfunction blkcg_punt_bio_submitfunction blkcg_punt_bio_initfunction blkg_createfunction blkg_createfunction blkg_destroyfunction blkg_destroy_allfunction blkg_iostat_setfunction __blkg_clear_statfunction blkg_clear_statfunction for_each_possible_cpufunction blkcg_reset_statsfunction blkcg_print_blkgsfunction __blkg_prfill_u64function blkg_conf_prepfunction blkg_conf_open_bdevfunction blkg_conf_open_bdevfunction msleepfunction blkg_conf_unprepfunction blkg_conf_close_bdevfunction blkg_iostat_addfunction blkg_iostat_subfunction blkcg_iostat_updatefunction __blkcg_rstat_flushfunction blkcg_rstat_flushfunction blkcg_fill_root_iostatsfunction for_each_possible_cpufunction blkcg_print_one_statfunction blkcg_print_statfunction blkcg_css_freefunction blkcg_pin_onlinefunction blkcg_destroy_blkgsfunction blkcg_css_offlinefunction blkcg_css_freefunction blkcg_css_allocfunction blkcg_css_onlinefunction blkg_init_queuefunction blkcg_init_diskfunction blkcg_exit_diskfunction blkcg_exitfunction blkcg_policy_enabledfunction blkcg_activate_policyfunction list_for_each_entry
Annotated Snippet
subsys_initcall(blkcg_punt_bio_init);
#endif /* CONFIG_BLK_CGROUP_PUNT_BIO */
/**
* bio_blkcg_css - return the blkcg CSS associated with a bio
* @bio: target bio
*
* This returns the CSS for the blkcg associated with a bio, or %NULL if not
* associated. Callers are expected to either handle %NULL or know association
* has been done prior to calling this.
*/
struct cgroup_subsys_state *bio_blkcg_css(struct bio *bio)
{
if (!bio || !bio->bi_blkg)
return NULL;
return &bio->bi_blkg->blkcg->css;
}
EXPORT_SYMBOL_GPL(bio_blkcg_css);
/**
* blkcg_parent - get the parent of a blkcg
* @blkcg: blkcg of interest
*
* Return the parent blkcg of @blkcg. Can be called anytime.
*/
static inline struct blkcg *blkcg_parent(struct blkcg *blkcg)
{
return css_to_blkcg(blkcg->css.parent);
}
/**
* blkg_alloc - allocate a blkg
* @blkcg: block cgroup the new blkg is associated with
* @disk: gendisk the new blkg is associated with
* @gfp_mask: allocation mask to use
*
* Allocate a new blkg associating @blkcg and @disk.
*/
static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk,
gfp_t gfp_mask)
{
struct blkcg_gq *blkg;
int i, cpu;
/* alloc and init base part */
blkg = kzalloc_node(sizeof(*blkg), gfp_mask, disk->queue->node);
if (!blkg)
return NULL;
if (percpu_ref_init(&blkg->refcnt, blkg_release, 0, gfp_mask))
goto out_free_blkg;
blkg->iostat_cpu = alloc_percpu_gfp(struct blkg_iostat_set, gfp_mask);
if (!blkg->iostat_cpu)
goto out_exit_refcnt;
if (!blk_get_queue(disk->queue))
goto out_free_iostat;
blkg->q = disk->queue;
INIT_LIST_HEAD(&blkg->q_node);
blkg->blkcg = blkcg;
blkg->iostat.blkg = blkg;
#ifdef CONFIG_BLK_CGROUP_PUNT_BIO
spin_lock_init(&blkg->async_bio_lock);
bio_list_init(&blkg->async_bios);
INIT_WORK(&blkg->async_bio_work, blkg_async_bio_workfn);
#endif
u64_stats_init(&blkg->iostat.sync);
for_each_possible_cpu(cpu) {
u64_stats_init(&per_cpu_ptr(blkg->iostat_cpu, cpu)->sync);
per_cpu_ptr(blkg->iostat_cpu, cpu)->blkg = blkg;
}
for (i = 0; i < BLKCG_MAX_POLS; i++) {
struct blkcg_policy *pol = blkcg_policy[i];
struct blkg_policy_data *pd;
if (!blkcg_policy_enabled(disk->queue, pol))
continue;
/* alloc per-policy data and attach it to blkg */
pd = pol->pd_alloc_fn(disk, blkcg, gfp_mask);
if (!pd)
goto out_free_pds;
blkg->pd[i] = pd;
pd->blkg = blkg;
pd->plid = i;
pd->online = false;
}
return blkg;
Annotation
- Immediate include surface: `linux/ioprio.h`, `linux/kdev_t.h`, `linux/module.h`, `linux/sched/signal.h`, `linux/err.h`, `linux/blkdev.h`, `linux/backing-dev.h`, `linux/slab.h`.
- Detected declarations: `function blkcg_gq`, `function blkg_free_workfn`, `function blkg_free`, `function __blkg_release`, `function blkg_release`, `function blkg_async_bio_workfn`, `function blkcg_punt_bio_submit`, `function blkcg_punt_bio_init`, `function blkg_create`, `function blkg_create`.
- 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.