fs/fs-writeback.c
Source file repositories/reference/linux-study-clean/fs/fs-writeback.c
File Facts
- System
- Linux kernel
- Corpus path
fs/fs-writeback.c- Extension
.c- Size
- 90849 bytes
- Lines
- 3083
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- 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/sched/sysctl.hlinux/kernel.hlinux/export.hlinux/spinlock.hlinux/slab.hlinux/sched.hlinux/fs.hlinux/mm.hlinux/pagemap.hlinux/kthread.hlinux/writeback.hlinux/blkdev.hlinux/backing-dev.hlinux/tracepoint.hlinux/device.hlinux/memcontrol.hinternal.htrace/events/writeback.h
Detected Declarations
struct wb_writeback_workstruct inode_switch_wbs_contextfunction wb_io_lists_populatedfunction wb_io_lists_depopulatedfunction inode_io_list_move_lockedfunction wb_wakeupfunction wb_wakeup_delayedfunction finish_writeback_workfunction wb_queue_workfunction wb_wait_for_completion_cbfunction DEFINE_WB_COMPLETIONfunction __inode_attach_wbfunction inode_cgwb_move_to_attachedfunction locked_inode_to_wb_and_lock_listfunction locked_inode_to_wb_and_lock_listfunction bdi_down_write_wb_switch_rwsemfunction bdi_up_write_wb_switch_rwsemfunction inode_do_switch_wbsfunction cgroup_writeback_pinfunction cgroup_writeback_unpinfunction cgroup_writeback_drainfunction process_inode_switch_wbsfunction inode_switch_wbs_work_fnfunction inode_prepare_wbs_switchfunction inode_state_readfunction wb_queue_iswfunction inode_switch_wbsfunction isw_prepare_wbs_switchfunction list_for_each_entryfunction cleanup_offline_cgwbfunction wbc_attach_and_unlock_inodefunction filemap_writebackfunction wbc_attach_and_unlock_inodefunction wbc_detach_inodefunction wb_split_bdi_pagesfunction bdi_split_work_to_wbsfunction cgroup_writeback_by_idfunction cgroup_writeback_umountfunction cgroup_writeback_initfunction bdi_down_write_wb_switch_rwsemfunction locked_inode_to_wb_and_lock_listfunction wb_split_bdi_pagesfunction bdi_split_work_to_wbsfunction wbc_attach_and_unlock_inodefunction get_nr_dirty_pagesfunction wb_start_writebackfunction wb_start_background_writebackfunction inode_io_list_del
Annotated Snippet
struct wb_writeback_work {
long nr_pages;
struct super_block *sb;
enum writeback_sync_modes sync_mode;
unsigned int tagged_writepages:1;
unsigned int for_kupdate:1;
unsigned int range_cyclic:1;
unsigned int for_background:1;
unsigned int for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
unsigned int auto_free:1; /* free on completion */
enum wb_reason reason; /* why was writeback initiated? */
struct list_head list; /* pending work list */
struct wb_completion *done; /* set if the caller waits */
};
/*
* If an inode is constantly having its pages dirtied, but then the
* updates stop dirtytime_expire_interval seconds in the past, it's
* possible for the worst case time between when an inode has its
* timestamps updated and when they finally get written out to be two
* dirtytime_expire_intervals. We set the default to 12 hours (in
* seconds), which means most of the time inodes will have their
* timestamps written to disk after 12 hours, but in the worst case a
* few inodes might not their timestamps updated for 24 hours.
*/
static unsigned int dirtytime_expire_interval = 12 * 60 * 60;
static inline struct inode *wb_inode(struct list_head *head)
{
return list_entry(head, struct inode, i_io_list);
}
/*
* Include the creation of the trace points after defining the
* wb_writeback_work structure and inline functions so that the definition
* remains local to this file.
*/
#define CREATE_TRACE_POINTS
#include <trace/events/writeback.h>
EXPORT_TRACEPOINT_SYMBOL_GPL(wbc_writepage);
static bool wb_io_lists_populated(struct bdi_writeback *wb)
{
if (wb_has_dirty_io(wb)) {
return false;
} else {
set_bit(WB_has_dirty_io, &wb->state);
WARN_ON_ONCE(!wb->avg_write_bandwidth);
atomic_long_add(wb->avg_write_bandwidth,
&wb->bdi->tot_write_bandwidth);
return true;
}
}
static void wb_io_lists_depopulated(struct bdi_writeback *wb)
{
if (wb_has_dirty_io(wb) && list_empty(&wb->b_dirty) &&
list_empty(&wb->b_io) && list_empty(&wb->b_more_io)) {
clear_bit(WB_has_dirty_io, &wb->state);
WARN_ON_ONCE(atomic_long_sub_return(wb->avg_write_bandwidth,
&wb->bdi->tot_write_bandwidth) < 0);
}
}
/**
* inode_io_list_move_locked - move an inode onto a bdi_writeback IO list
* @inode: inode to be moved
* @wb: target bdi_writeback
* @head: one of @wb->b_{dirty|io|more_io|dirty_time}
*
* Move @inode->i_io_list to @list of @wb and set %WB_has_dirty_io.
* Returns %true if @inode is the first occupant of the !dirty_time IO
* lists; otherwise, %false.
*/
static bool inode_io_list_move_locked(struct inode *inode,
struct bdi_writeback *wb,
struct list_head *head)
{
assert_spin_locked(&wb->list_lock);
assert_spin_locked(&inode->i_lock);
WARN_ON_ONCE(inode_state_read(inode) & I_FREEING);
list_move(&inode->i_io_list, head);
/* dirty_time doesn't count as dirty_io until expiration */
if (head != &wb->b_dirty_time)
return wb_io_lists_populated(wb);
Annotation
- Immediate include surface: `linux/sched/sysctl.h`, `linux/kernel.h`, `linux/export.h`, `linux/spinlock.h`, `linux/slab.h`, `linux/sched.h`, `linux/fs.h`, `linux/mm.h`.
- Detected declarations: `struct wb_writeback_work`, `struct inode_switch_wbs_context`, `function wb_io_lists_populated`, `function wb_io_lists_depopulated`, `function inode_io_list_move_locked`, `function wb_wakeup`, `function wb_wakeup_delayed`, `function finish_writeback_work`, `function wb_queue_work`, `function wb_wait_for_completion_cb`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.