mm/backing-dev.c
Source file repositories/reference/linux-study-clean/mm/backing-dev.c
File Facts
- System
- Linux kernel
- Corpus path
mm/backing-dev.c- Extension
.c- Size
- 30321 bytes
- Lines
- 1224
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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/blkdev.hlinux/wait.hlinux/rbtree.hlinux/kthread.hlinux/backing-dev.hlinux/blk-cgroup.hlinux/freezer.hlinux/fs.hlinux/pagemap.hlinux/mm.hlinux/sched/mm.hlinux/sched.hlinux/module.hlinux/writeback.hlinux/device.htrace/events/writeback.hinternal.hlinux/debugfs.hlinux/seq_file.hlinux/memcontrol.h
Detected Declarations
struct wb_statsfunction bdi_debug_initfunction collect_wb_statsfunction bdi_collect_statsfunction bdi_collect_statsfunction bdi_debug_stats_showfunction wb_stats_showfunction cgwb_debug_stats_showfunction bdi_debug_registerfunction bdi_debug_unregisterfunction bdi_debug_initfunction min_ratio_storefunction min_ratio_fine_storefunction max_ratio_storefunction max_ratio_fine_storefunction min_bytes_showfunction min_bytes_storefunction max_bytes_showfunction max_bytes_storefunction stable_pages_required_showfunction strict_limit_storefunction strict_limit_showfunction bdi_class_initfunction default_bdi_initfunction wb_update_bandwidth_workfnfunction wb_initfunction wb_shutdownfunction wb_exitfunction cgwb_free_rcufunction cgwb_release_workfnfunction cgwb_releasefunction cgwb_killfunction cgwb_remove_from_bdi_listfunction cgwb_createfunction css_getfunction cgwb_bdi_initfunction cgwb_bdi_unregisterfunction cleanup_offline_cgwbs_workfnfunction wb_memcg_offlinefunction wb_blkcg_offlinefunction cgwb_bdi_registerfunction cgwb_initfunction cgwb_bdi_initfunction cgwb_bdi_unregisterfunction cgwb_remove_from_bdi_listfunction bdi_initfunction bdi_register_vafunction bdi_register
Annotated Snippet
subsys_initcall(default_bdi_init);
static void wb_update_bandwidth_workfn(struct work_struct *work)
{
struct bdi_writeback *wb = container_of(to_delayed_work(work),
struct bdi_writeback, bw_dwork);
wb_update_bandwidth(wb);
}
/*
* Initial write bandwidth: 100 MB/s
*/
#define INIT_BW MB_TO_PAGES(100)
static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,
gfp_t gfp)
{
int err;
memset(wb, 0, sizeof(*wb));
wb->bdi = bdi;
wb->last_old_flush = jiffies;
INIT_LIST_HEAD(&wb->b_dirty);
INIT_LIST_HEAD(&wb->b_io);
INIT_LIST_HEAD(&wb->b_more_io);
INIT_LIST_HEAD(&wb->b_dirty_time);
spin_lock_init(&wb->list_lock);
atomic_set(&wb->writeback_inodes, 0);
wb->bw_time_stamp = jiffies;
wb->balanced_dirty_ratelimit = INIT_BW;
wb->dirty_ratelimit = INIT_BW;
wb->write_bandwidth = INIT_BW;
wb->avg_write_bandwidth = INIT_BW;
spin_lock_init(&wb->work_lock);
INIT_LIST_HEAD(&wb->work_list);
INIT_DELAYED_WORK(&wb->dwork, wb_workfn);
INIT_DELAYED_WORK(&wb->bw_dwork, wb_update_bandwidth_workfn);
err = fprop_local_init_percpu(&wb->completions, gfp);
if (err)
return err;
err = percpu_counter_init_many(wb->stat, 0, gfp, NR_WB_STAT_ITEMS);
if (err)
fprop_local_destroy_percpu(&wb->completions);
return err;
}
static void cgwb_remove_from_bdi_list(struct bdi_writeback *wb);
/*
* Remove bdi from the global list and shutdown any threads we have running
*/
static void wb_shutdown(struct bdi_writeback *wb)
{
/* Make sure nobody queues further work */
spin_lock_irq(&wb->work_lock);
if (!test_and_clear_bit(WB_registered, &wb->state)) {
spin_unlock_irq(&wb->work_lock);
return;
}
spin_unlock_irq(&wb->work_lock);
cgwb_remove_from_bdi_list(wb);
/*
* Drain work list and shutdown the delayed_work. !WB_registered
* tells wb_workfn() that @wb is dying and its work_list needs to
* be drained no matter what.
*/
mod_delayed_work(bdi_wq, &wb->dwork, 0);
flush_delayed_work(&wb->dwork);
WARN_ON(!list_empty(&wb->work_list));
flush_delayed_work(&wb->bw_dwork);
}
static void wb_exit(struct bdi_writeback *wb)
{
WARN_ON(delayed_work_pending(&wb->dwork));
percpu_counter_destroy_many(wb->stat, NR_WB_STAT_ITEMS);
fprop_local_destroy_percpu(&wb->completions);
}
#ifdef CONFIG_CGROUP_WRITEBACK
#include <linux/memcontrol.h>
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/wait.h`, `linux/rbtree.h`, `linux/kthread.h`, `linux/backing-dev.h`, `linux/blk-cgroup.h`, `linux/freezer.h`, `linux/fs.h`.
- Detected declarations: `struct wb_stats`, `function bdi_debug_init`, `function collect_wb_stats`, `function bdi_collect_stats`, `function bdi_collect_stats`, `function bdi_debug_stats_show`, `function wb_stats_show`, `function cgwb_debug_stats_show`, `function bdi_debug_register`, `function bdi_debug_unregister`.
- Atlas domain: Core OS / Memory Management.
- 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.