btrfs: remove cow fixup related code
Subsystems (2)
RFC PATCH 1/1 btrfs: remove cow fixup related code
From the initial merge of btrfs, there is always the mystery cow fixup.
According to its comment and code, the functionality is to detect MM code which dirtied the page when it has been unlocked and under writeback.
But there are several problems:
- The fixup timing can be in next transaction
That means, even if such case really happens, the "corrupted" data will be written to disk, and fixup can be queued for next transaction.
Thus it doesn't really solve anything, but masking the "problem"
- No cow fixup really get executed
At least I didn't find it in my test environment. I know this doesn't mean anything, but see my next comment.
- All page dirty path have already waited writeback
For existing btrfs page dirty path, we always wait page writeback before populating the page.
I don't see why MM/VFS layer can't do it.
- munmap is not dirtying related page
A quick glance into mmap code doesn't show anywhere we dirty the pages.
Since I'm not familiar with ancient btrfs code, nor the MM layer, this patch is mostly RFC and hopes the community can either give a sold answer on why cow fixup is still needed, or can use this patch as the first step to remove cow fixup.
--- fs/btrfs/compression.c | 7 -- fs/btrfs/ctree.h | 8 -- fs/btrfs/disk-io.c | 7 +- fs/btrfs/extent_io.c | 12 --- fs/btrfs/extent_io.h | 5 +- fs/btrfs/file.c | 8 -- fs/btrfs/free-space-cache.c | 1 - fs/btrfs/inode.c | 192 +----------------------------------- fs/btrfs/ioctl.c | 1 - fs/btrfs/reflink.c | 1 - 10 files changed, 4 insertions(+), 238 deletions(-)
fs/btrfs/compression.c +0 -7
@@ -246,14 +246,7 @@ static void end_compressed_bio_read(struct bio *bio)struct bio_vec *bvec;struct bvec_iter_all iter_all; -/* -* we have verified the checksum already, set page -* checked so the end_io handlers know about it -*/ ASSERT (!bio_flagged (bio,BIO_CLONED )); -bio_for_each_segment_all (bvec, cb->orig_bio, iter_all) -SetPageChecked (bvec->bv_page); -bio_endio (cb->orig_bio); }
fs/btrfs/ctree.h +0 -8
@@ -772,13 +772,6 @@ struct btrfs_fs_info {struct btrfs_workqueue *endio_freespace_worker;struct btrfs_workqueue *caching_workers;struct btrfs_workqueue *readahead_workers; - -/* -* fixup workers take dirty pages that didn't properly go through -* the cow mechanism and make them safe to write. It happens -* for the sys_munmap function call path -*/ -struct btrfs_workqueue *fixup_workers;struct btrfs_workqueue *delayed_workers;struct task_struct *transaction_kthread;
@@ -3136,7 +3129,6 @@ int btrfs_prealloc_file_range_trans(struct inode *inode,int btrfs_run_delalloc_range (struct btrfs_inode *inode,struct page *locked_page,u64 start,u64 end,int *page_started,unsigned long *nr_written,struct writeback_control *wbc); -int btrfs_writepage_cow_fixup (struct page *page,u64 start,u64 end);void btrfs_writepage_endio_finish_ordered (struct page *page,u64 start,u64 end,int uptodate);extern const struct dentry_operations btrfs_dentry_operations;
fs/btrfs/disk-io.c +1 -6
@@ -1958,7 +1958,6 @@ static int read_backup_root(struct btrfs_fs_info *fs_info, u8 priority)/* helper to cleanup workers */ static void btrfs_stop_all_workers (struct btrfs_fs_info *fs_info) { -btrfs_destroy_workqueue (fs_info->fixup_workers);btrfs_destroy_workqueue (fs_info->delalloc_workers);btrfs_destroy_workqueue (fs_info->workers);btrfs_destroy_workqueue (fs_info->endio_workers);
@@ -2144,9 +2143,6 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, fs_info->caching_workers =btrfs_alloc_workqueue (fs_info,"cache" , flags, max_active,0 ); - fs_info->fixup_workers = -btrfs_alloc_workqueue (fs_info,"fixup" , flags,1 ,0 ); -/* * endios are largely parallel and should have a very * low idle thresh
@@ -2188,8 +2184,7 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info, fs_info->endio_write_workers && fs_info->endio_raid56_workers && fs_info->endio_freespace_worker && fs_info->rmw_workers && fs_info->caching_workers && fs_info->readahead_workers && - fs_info->fixup_workers && fs_info->delayed_workers && - fs_info->qgroup_rescan_workers && + fs_info->delayed_workers && fs_info->qgroup_rescan_workers && fs_info->discard_ctl.discard_workers)) { return -ENOMEM; }
fs/btrfs/extent_io.c +0 -12
@@ -1969,9 +1969,6 @@ static int __process_pages_contig(struct address_space *mapping, }for (i =0 ; i < ret; i++) { -if (page_ops &PAGE_SET_PRIVATE2 ) -SetPagePrivate2 (pages[i]); -if (locked_page && pages[i] == locked_page) {put_page (pages[i]); pages_processed++;
@@ -3523,15 +3520,6 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,const unsigned int write_flags =wbc_to_write_flags (wbc);bool compressed; - ret =btrfs_writepage_cow_fixup (page, start, page_end); -if (ret) { -/* Fixup worker will requeue */ -redirty_page_for_writepage (wbc, page); -update_nr_written (wbc, nr_written); -unlock_page (page); -return 1 ; - } -/* * we don't want to touch the inode after unlocking the page, * so we update the mapping writeback index now
fs/btrfs/extent_io.h +2 -3
@@ -37,9 +37,8 @@ enum {#define PAGE_CLEAR_DIRTY (1 << 1)#define PAGE_SET_WRITEBACK (1 << 2)#define PAGE_END_WRITEBACK (1 << 3) -#define PAGE_SET_PRIVATE2 (1 << 4) -#define PAGE_SET_ERROR (1 << 5) -#define PAGE_LOCK (1 << 6) +#define PAGE_SET_ERROR (1 << 4) +#define PAGE_LOCK (1 << 5)/* * page->private values. Every page that is controlled by the extent
fs/btrfs/file.c +0 -8
@@ -440,13 +440,6 @@ static void btrfs_drop_pages(struct page **pages, size_t num_pages) {size_t i;for (i =0 ; i < num_pages; i++) { -/* page checked is some magic around finding pages that -* have been modified without going through btrfs_set_page_dirty -* clear it here. There should be no need to mark the pages -* accessed as prepare_pages should have marked them accessed -* in prepare_pages via find_or_create_page() -*/ -ClearPageChecked (pages[i]);unlock_page (pages[i]);put_page (pages[i]); }
@@ -502,7 +495,6 @@ int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,for (i =0 ; i < num_pages; i++) {struct page *p = pages[i];SetPageUptodate (p); -ClearPageChecked (p);set_page_dirty (p); }
fs/btrfs/free-space-cache.c +0 -1
@@ -424,7 +424,6 @@ static void io_ctl_drop_pages(struct btrfs_io_ctl *io_ctl)for (i =0 ; i < io_ctl->num_pages; i++) {if (io_ctl->pages[i]) { -ClearPageChecked (io_ctl->pages[i]);unlock_page (io_ctl->pages[i]);put_page (io_ctl->pages[i]); }
fs/btrfs/inode.c +1 -191
234 lines not on this page · raw message
fs/btrfs/ioctl.c +0 -1
@@ -1439,7 +1439,6 @@ static int cluster_pages_for_defrag(struct inode *inode,for (i =0 ; i < i_done; i++) {clear_page_dirty_for_io (pages[i]); -ClearPageChecked (pages[i]);set_page_extent_mapped (pages[i]);set_page_dirty (pages[i]);unlock_page (pages[i]);
fs/btrfs/reflink.c +0 -1
@@ -126,7 +126,6 @@ static int copy_inline_to_page(struct btrfs_inode *inode, }SetPageUptodate (page); -ClearPageChecked (page);set_page_dirty (page); out_unlock:if (page) {
Signature · 1 line
2.29.2
Quoted 1 line · Qu Wenruo
Quoted 1 line
From the initial merge of btrfs, there is always the mystery cow fixup.
For the record, the code needs to stay for because it's still needed. Though finding the exact point where it happens on intel architectures is not easy, it's required on s390 because of the separate page bits tracking at least. How exactly it works and why the code exists is left as an exercise to the reader.