网站设计怎么做/seo关键词优化怎么做
将数据写到page cache
写文件的时候其实是通过文件系统写到page cache中,然后再由相应的线程在适当的时机将page cache中的数据写到磁盘中。
//fs/fat/file.c
const struct file_operations fat_file_operations = {
....aio_write = generic_file_aio_write,
...
};//mm/filemap.c
generic_file_aio_write__generic_file_aio_writegeneric_file_buffered_writegeneric_perform_writea_ops->write_beginiov_iter_copy_from_user_atomic(page, i, offset, bytes)a_ops->write_end
回写page cache到磁盘
通过sync系统调用将page cache写到磁盘中
//fs/fat/file.c
const struct file_operations fat_file_operations = {
....fsync = fat_file_fsync,
...
};fat_file_fsync generic_file_fsyncsync_inode_metadatasync_inodewriteback_single_inode__writeback_single_inodedo_writepagesmapping->a_ops->writepageswrite_inode
通过回写工作队列bdi_writeback将page cache写到磁盘中
//mm/backing_dev.c
bdi_initbdi_wb_initINIT_DELAYED_WORK(&wb->dwork, bdi_writeback_workfn);//fs/fs-writeback.c
bdi_writeback_workfnwb_do_writebackwb_writebackwriteback_sb_inodes__writeback_single_inodedo_writepagesmapping->a_ops->writepageswrite_inode
在这里初始化的时候安装了回写wb->dwork,并且wb->dwork的回调函数和前面系统sync系统调用一样最终都会调用__writeback_single_inode来回写page cache。
blk_init_queueblk_init_queue_nodeblk_alloc_queue_nodebdi_init(&q->backing_dev_info);setup_timer(&q->backing_dev_info.laptop_mode_wb_timer, laptop_mode_timer_fn, ...//mm/page-writeback.c
laptop_mode_timer_fnbdi_start_writeback //fs/fs-writeback.c__bdi_start_writebackbdi_queue_workmod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
在blk_init_queue时会初始化一个timer,并且timer的回调函数是laptop_mode_timer_fn,他里面会通过bdi_queue_work来调度回写wb->dwork。这样这个回写wb->dwork就会不断的被这个timer定时的调度执行了。