delalloc and journal locking order inversion fixes
Subsystems (4)
PATCH 1/1 delalloc and journal locking order inversion fixes
The below set of patches gets the delalloc work with journal locking order inversion patches.
The series file look like
+ ext4-new-defm-options
+ ext4-call-blkdev_issue_flush-on-fsync.patch 0001-ext4-Use-page_mkwrite-vma_operations-to-get-mmap-wr.patch
+ ext4_ialloc-flexbg.patch 0002-ext4-Inverse-locking-order-of-page_lock-and-transac.patch 0003-vfs-Move-mark_inode_dirty-from-under-page-lock-in.patch 0004-ext4-Add-validation-to-jbd-lock-inversion-patch-and.patch
+ delalloc-vfs.patch
+ ext4-fix-fs-corruption-with-delalloc.patch
+ delalloc-ext4.patch
+ delalloc-ext4-release-page-when-write_begin-failed.patch
+ delalloc-ext4-preallocation-handling.patch
...
...
.....
+ vfs-fiemap.patch
+ ext4-add-ext4_ext_walk_space.patch
+ ext4-fiemap.patch 0005-ext4-inverse-locking-ordering-of-page_lock-and-tra.patch 0006-ext4-Fix-delalloc-sync-hang-with-journal-lock-inver.patch
I have pushed the lock inversion patches and related changes to the top of the patch queue expecting it can be pushed upstream before delalloc changes.
-aneesh
PATCH 1/1 ext4: Use page_mkwrite vma_operations to get mmap write notification.
We would like to get notified when we are doing a write on mmap section. This is needed with respect to preallocated area. We split the preallocated area into initialzed extent and uninitialzed extent in the call back. This let us handle ENOSPC better. Otherwise we get ENOSPC in the writepage and that would result in data loss. The changes are also needed to handle ENOSPC when writing to an mmap section of files with holes.
--- fs/ext4/ext4.h | 1 + fs/ext4/file.c | 19 +++++++++++++- fs/ext4/inode.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -1053,6 +1053,7 @@ extern void ext4_set_aops(struct inode *inode);extern int ext4_writepage_trans_blocks (struct inode *);extern int ext4_block_truncate_page (handle_t *handle,struct page *page,struct address_space *mapping,loff_t from); +extern int ext4_page_mkwrite (struct vm_area_struct *vma,struct page *page);/* ioctl.c */ extern long ext4_ioctl (struct file *,unsigned int ,unsigned long );
fs/ext4/file.c +18 -1
@@ -123,6 +123,23 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,return ret; } +static struct vm_operations_struct ext4_file_vm_ops = { + .fault = filemap_fault, + .page_mkwrite = ext4_page_mkwrite, +}; + +static int ext4_file_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct address_space *mapping = file->f_mapping; + +if (!mapping->a_ops->readpage) +return -ENOEXEC ; +file_accessed (file); + vma->vm_ops = &ext4_file_vm_ops; + vma->vm_flags |=VM_CAN_NONLINEAR ; +return 0 ; +} +const struct file_operations ext4_file_operations = { .llseek = generic_file_llseek, .read = do_sync_read,
@@ -133,7 +150,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,#ifdef CONFIG_COMPAT .compat_ioctl = ext4_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ext4_file_mmap, .open = generic_file_open, .release = ext4_release_file, .fsync = ext4_sync_file,
fs/ext4/inode.c +76 -0
79 lines not on this page · raw message
Signature · 1 line
1.5.5.1.357.g1af8b.dirty
PATCH 1/1 ext4: Inverse locking order of page_lock and transaction start.
From: Jan Kara <[email protected]>
--- fs/ext4/ext4.h | 4 +- fs/ext4/extents.c | 15 +-- fs/ext4/inode.c | 274 ++++++++++++++++++++++++----------------------------- 3 files changed, 132 insertions(+), 161 deletions(-)
fs/ext4/ext4.h +2 -2
@@ -1063,7 +1063,7 @@ extern void ext4_set_inode_flags(struct inode *);extern void ext4_get_inode_flags (struct ext4_inode_info *);extern void ext4_set_aops (struct inode *inode);extern int ext4_writepage_trans_blocks (struct inode *); -extern int ext4_block_truncate_page (handle_t *handle,struct page *page, +extern int ext4_block_truncate_page (handle_t *handle,struct address_space *mapping,loff_t from);extern int ext4_page_mkwrite (struct vm_area_struct *vma,struct page *page);
@@ -1222,7 +1222,7 @@ extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,ext4_lblk_t iblock, unsigned long max_blocks, struct buffer_head *bh_result, int create, int extend_disksize); -extern void ext4_ext_truncate (struct inode *,struct page *); +extern void ext4_ext_truncate (struct inode *);extern void ext4_ext_init (struct super_block *);extern void ext4_ext_release (struct super_block *); extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset,
fs/ext4/extents.c +4 -11
@@ -2744,7 +2744,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,return err ? err : allocated; } -void ext4_ext_truncate (struct inode * inode,struct page *page) +void ext4_ext_truncate (struct inode *inode) {struct address_space *mapping = inode->i_mapping;struct super_block *sb = inode->i_sb;
@@ -2757,18 +2757,11 @@ void ext4_ext_truncate(struct inode * inode, struct page *page)*/ err =ext4_writepage_trans_blocks (inode) +3 ; handle =ext4_journal_start (inode, err); -if (IS_ERR (handle)) { -if (page) { -clear_highpage (page); -flush_dcache_page (page); -unlock_page (page); -page_cache_release (page); - } +if (IS_ERR (handle))return ; - } -if (page) -ext4_block_truncate_page (handle, page, mapping, inode->i_size); +if (inode->i_size & (sb->s_blocksize -1 )) +ext4_block_truncate_page (handle, mapping, inode->i_size);down_write (&EXT4_I (inode)->i_data_sem);ext4_ext_invalidate_cache (inode);
fs/ext4/inode.c +126 -148
474 lines not on this page · raw message
Signature · 1 line
1.5.5.1.357.g1af8b.dirty
PATCH 1/1 vfs: Move mark_inode_dirty() from under page lock in generic_write_end()
From: Jan Kara <[email protected]>
There's no need to call mark_inode_dirty() under page lock in generic_write_end(). It unnecessarily makes hold time of page lock longer and more importantly it forces locking order of page lock and transaction start for journaling filesystems.
--- fs/buffer.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
fs/buffer.c +11 -1
@@ -2061,6 +2061,7 @@ int generic_write_end(struct file *file, struct address_space *mapping, struct page *page, void *fsdata) { struct inode *inode = mapping->host; +int i_size_changed =0 ; copied =block_write_end (file, mapping, pos, len, copied, page, fsdata);
@@ -2073,12 +2074,21 @@ int generic_write_end(struct file *file, struct address_space *mapping,*/ if (pos+copied > inode->i_size) {i_size_write (inode, pos+copied); -mark_inode_dirty (inode); + i_size_changed =1 ; }unlock_page (page);page_cache_release (page); +/* +* We don't mark inode dirty under page lock. First, it unnecessarily +* makes the holding time of page lock longer. Second, it forces lock +* ordering of page lock and transaction start for journaling +* filesystems. +*/ +if (i_size_changed) +mark_inode_dirty (inode); +return copied; }EXPORT_SYMBOL (generic_write_end);
Signature · 1 line
1.5.5.1.357.g1af8b.dirty
PATCH 1/1 ext4: Add validation to jbd lock inversion patch and split and writepage
--- fs/ext4/inode.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 156 insertions(+), 25 deletions(-)
fs/ext4/inode.c +156 -25
@@ -1479,6 +1479,11 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)return 0 ; } +static int ext4_bh_unmapped_or_delay (handle_t *handle,struct buffer_head *bh) +{ +return (!buffer_mapped (bh) ||buffer_delay (bh)); +} +/* * Note that we don't need to start a transaction unless we're journaling * data because we should have holes filled from ext4_page_mkwrite(). If
@@ -1531,18 +1536,26 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)static int __ext4_ordered_writepage (struct page *page,struct writeback_control *wbc) { -struct inode *inode = page->mapping->host; -struct buffer_head *page_bufs; +int ret =0 , err; +unsigned long len;handle_t *handle =NULL ; -int ret =0 ; -int err; +struct buffer_head *page_bufs; +struct inode *inode = page->mapping->host; +loff_t size =i_size_read (inode); -if (!page_has_buffers (page)) { -create_empty_buffers (page, inode->i_sb->s_blocksize, - (1 << BH_Dirty)|(1 << BH_Uptodate)); - } page_bufs =page_buffers (page); -walk_page_buffers (handle, page_bufs,0 , +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; + +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + } +walk_page_buffers (NULL , page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , bget_one); ret =block_write_full_page (page, ext4_get_block, wbc);
@@ -1574,8 +1587,8 @@ static int __ext4_ordered_writepage(struct page *page, ret = err; } out_put: -walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , - bput_one); +walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , bput_one);return ret; }
@@ -1583,7 +1596,7 @@ static int ext4_ordered_writepage(struct page *page, struct writeback_control *wbc) {J_ASSERT (PageLocked (page)); - +BUG_ON (!page_has_buffers (page));/* * We give up here if we're reentered, because it might be for a * different filesystem.
@@ -1599,18 +1612,34 @@ static int ext4_ordered_writepage(struct page *page,static int __ext4_writeback_writepage (struct page *page,struct writeback_control *wbc) { +unsigned long len; +struct buffer_head *page_bufs;struct inode *inode = page->mapping->host; +loff_t size =i_size_read (inode); + + page_bufs =page_buffers (page); +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + }if (test_opt (inode->i_sb,NOBH ))return nobh_writepage (page, ext4_get_block, wbc);else return block_write_full_page (page, ext4_get_block, wbc); } -static int ext4_writeback_writepage (struct page *page,struct writeback_control *wbc) { +BUG_ON (!page_has_buffers (page)); +if (!ext4_journal_current_handle ())return __ext4_writeback_writepage (page, wbc);
@@ -1622,18 +1651,31 @@ static int ext4_writeback_writepage(struct page *page,static int __ext4_journalled_writepage (struct page *page,struct writeback_control *wbc) { +int ret =0 , err; +unsigned long len; +handle_t *handle =NULL ;struct address_space *mapping = page->mapping;struct inode *inode = mapping->host;struct buffer_head *page_bufs; -handle_t *handle =NULL ; -int ret =0 ; -int err; +loff_t size =i_size_read (inode); + + page_bufs =page_buffers (page); +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + } +/* FIXME!! do we need to call prepare_write for a mapped buffer */ ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block);if (ret !=0 ) goto out_unlock; - page_bufs =page_buffers (page);walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , bget_one);/* As soon as we unlock the page, it can go away, but we have
@@ -1671,14 +1713,13 @@ static int __ext4_journalled_writepage(struct page *page,static int ext4_journalled_writepage (struct page *page,struct writeback_control *wbc) { +BUG_ON (!page_has_buffers (page)); +if (ext4_journal_current_handle ()) goto no_write; -if (!page_has_buffers (page) ||PageChecked (page)) { -/* -* It's mmapped pagecache. Add buffers and journal it. There -* doesn't seem much point in redirtying the page here. -*/ +if (PageChecked (page)) { +/* dirty pages in data=journal mode */ ClearPageChecked (page);return __ext4_journalled_writepage (page, wbc); }else {
@@ -3520,6 +3561,96 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)return err; } +static int __ext4_journalled_allocpage (struct page *page, +struct writeback_control *wbc) +{ +int ret =0 , err; +handle_t *handle =NULL ; +struct address_space *mapping = page->mapping; +struct inode *inode = mapping->host; +struct buffer_head *page_bufs; + +/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); + + ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block); +if (ret !=0 ) + goto out_unlock; + +/* FIXME!! should we do a bget_one */ + page_bufs =page_buffers (page); + ret =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , do_journal_get_write_access); + + err =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , write_end_fn); +if (ret ==0 ) + ret = err; +EXT4_I (inode)->i_state |=EXT4_STATE_JDATA ; + +out_unlock: +unlock_page (page); +return ret; +} + +static int __ext4_ordered_allocpage (struct page *page, +struct writeback_control *wbc) +{ +int ret =0 ; +handle_t *handle =NULL ; +struct buffer_head *page_bufs; +struct inode *inode = page->mapping->host; + +/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); +if (!page_has_buffers (page)) { +create_empty_buffers (page, inode->i_sb->s_blocksize, + (1 << BH_Dirty)|(1 << BH_Uptodate)); + } + page_bufs =page_buffers (page); +walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , bget_one); + + ret =block_write_full_page (page, ext4_get_block, wbc); + +/* +* The page can become unlocked at any point now, and +* truncate can then come in and change things. So we +* can't touch *page from now on. But *page_bufs is +* safe due to elevated refcount. +*/ + +/* +* And attach them to the current transaction. But only if +* block_write_full_page() succeeded. Otherwise they are unmapped, +* and generally junk. +*/ +if (ret ==0 ) { + ret =walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE , +NULL , jbd2_journal_dirty_data_fn); + } +walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , bput_one); +return ret; +} + +static int __ext4_writeback_allocpage (struct page *page, +struct writeback_control *wbc) +{ +handle_t *handle =NULL ; +struct inode *inode = page->mapping->host; +/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); + +if (test_opt (inode->i_sb,NOBH )) +return nobh_writepage (page, ext4_get_block, wbc); +else +return block_write_full_page (page, ext4_get_block, wbc); +} +static int ext4_bh_prepare_fill (handle_t *handle,struct buffer_head *bh) {if (!buffer_mapped (bh)) {
@@ -3596,11 +3727,11 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page) wbc.range_start =page_offset (page); wbc.range_end =page_offset (page) + len;if (ext4_should_writeback_data (inode)) - ret =__ext4_writeback_writepage (page, &wbc); + ret =__ext4_writeback_allocpage (page, &wbc);else if (ext4_should_order_data (inode)) - ret =__ext4_ordered_writepage (page, &wbc); + ret =__ext4_ordered_allocpage (page, &wbc);else - ret =__ext4_journalled_writepage (page, &wbc); + ret =__ext4_journalled_allocpage (page, &wbc);/* Page got unlocked in writepage */ err =ext4_journal_stop (handle);if (!ret)
Signature · 1 line
1.5.5.1.357.g1af8b.dirty
PATCH 1/1 ext4: inverse locking ordering of page_lock and transaction start in delalloc
From: Mingming Cao <[email protected]>
Inverse locking ordering of page_lock and transaction start in delalloc
--- fs/ext4/inode.c | 96 +++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 68 insertions(+), 28 deletions(-)
fs/ext4/inode.c +68 -28
@@ -1448,18 +1448,14 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,static int ext4_da_get_block_write (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create) { -int ret, needed_blocks =ext4_writepage_trans_blocks (inode); +int ret;unsigned max_blocks = bh_result->b_size >> inode->i_blkbits;loff_t disksize =EXT4_I (inode)->i_disksize;handle_t *handle =NULL ; -if (create) { - handle =ext4_journal_start (inode, needed_blocks); -if (IS_ERR (handle)) { - ret =PTR_ERR (handle); - goto out; - } - } + handle =ext4_journal_current_handle (); +BUG_ON (handle ==0 ); +BUG_ON (create ==0 ); ret =ext4_get_blocks_wrap (handle, inode, iblock, max_blocks, bh_result, create,0 );
@@ -1494,29 +1490,17 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock, ret =0 ; } -out: -if (handle && !IS_ERR (handle)) -ext4_journal_stop (handle); -return ret; }/* FIXME!! only support data=writeback mode */ -static int ext4_da_writepage (struct page *page, +static int __ext4_da_writepage (struct page *page,struct writeback_control *wbc) {struct inode *inode = page->mapping->host;handle_t *handle =NULL ;int ret =0 ; -int err; - -if (ext4_journal_current_handle ()) - goto out_fail; - handle =ext4_journal_start (inode,ext4_writepage_trans_blocks (inode)); -if (IS_ERR (handle)) { - ret =PTR_ERR (handle); - goto out_fail; - } + handle =ext4_journal_current_handle ();if (test_opt (inode->i_sb,NOBH ) &&ext4_should_writeback_data (inode)) ret =nobh_writepage (page, ext4_get_block, wbc);
@@ -1528,21 +1512,77 @@ static int ext4_da_writepage(struct page *page,ext4_mark_inode_dirty (handle, inode); } - err =ext4_journal_stop (handle); -if (!ret) - ret = err;return ret; +} +static int ext4_da_writepage (struct page *page, +struct writeback_control *wbc) +{ +if (!ext4_journal_current_handle ()) +return __ext4_da_writepage (page, wbc); -out_fail:redirty_page_for_writepage (wbc, page);unlock_page (page); -return ret; +return 0 ; } +/* +* For now just follow the DIO way to estimate the max credits +* needed to write out EXT4_MAX_WRITEBACK_PAGES. +* todo: need to calculate the max credits need for +* extent based files, currently the DIO credits is based on +* indirect-blocks mapping way. +* +* Probably should have a generic way to calculate credits +* for DIO, writepages, and truncate +*/ +#define EXT4_MAX_WRITEBACK_PAGES DIO_MAX_BLOCKS +#define EXT4_MAX_WRITEBACK_CREDITS DIO_CREDITS +static int ext4_da_writepages (struct address_space *mapping,struct writeback_control *wbc) { -return mpage_da_writepages (mapping, wbc, ext4_da_get_block_write); +struct inode *inode = mapping->host; +handle_t *handle =NULL ; +int needed_blocks; +int ret =0 ; +unsigned range_cyclic; +long to_write; + +/* +* Estimate the worse case needed credits to write out +* EXT4_MAX_BUF_BLOCKS pages +*/ + needed_blocks =EXT4_MAX_WRITEBACK_CREDITS ; + + to_write = wbc->nr_to_write; + range_cyclic = wbc->range_cyclic; + wbc->range_cyclic =1 ; + +while (!ret && to_write) { +/* start a new transaction*/ + handle =ext4_journal_start (inode, needed_blocks); +if (IS_ERR (handle)) { + ret =PTR_ERR (handle); + goto out_writepages; + } +/* +* set the max dirty pages could be write at a time +* to fit into the reserved transaction credits +*/ +if (wbc->nr_to_write >EXT4_MAX_WRITEBACK_PAGES ) + wbc->nr_to_write =EXT4_MAX_WRITEBACK_PAGES ; + to_write -= wbc->nr_to_write; + + ret =mpage_da_writepages (mapping, wbc, + ext4_da_get_block_write); +ext4_journal_stop (handle); + to_write += wbc->nr_to_write; + } + +out_writepages: + wbc->nr_to_write = to_write; + wbc->range_cyclic = range_cyclic; +return ret; } static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
Signature · 1 line
1.5.5.1.357.g1af8b.dirty
PATCH 1/1 ext4: Fix delalloc sync hang with journal lock inversion
--- fs/ext4/inode.c | 99 ++++++++++++++++++++++++++++++++++---------------- fs/mpage.c | 14 ++++---- mm/page-writeback.c | 7 +++- 3 files changed, 80 insertions(+), 40 deletions(-)
fs/ext4/inode.c +67 -32
@@ -1480,50 +1480,73 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,up_write (&EXT4_I (inode)->i_data_sem);if (EXT4_I (inode)->i_disksize == disksize) { -if (handle ==NULL ) - handle =ext4_journal_start (inode,1 ); -if (!IS_ERR (handle)) -ext4_mark_inode_dirty (handle, inode); + ret =ext4_mark_inode_dirty (handle, inode); +return ret; } } - ret =0 ; } -return ret; } + +static int ext4_bh_unmapped_or_delay (handle_t *handle,struct buffer_head *bh) +{ +return (!buffer_mapped (bh) ||buffer_delay (bh)); +} +/* FIXME!! only support data=writeback mode */ -static int __ext4_da_writepage (struct page *page, +/* +* get called vi ext4_da_writepages after taking page lock +* We may end up doing block allocation here in case +* mpage_da_map_blocks failed to allocate blocks. +*/ +static int ext4_da_writepage (struct page *page,struct writeback_control *wbc) { -struct inode *inode = page->mapping->host; -handle_t *handle =NULL ;int ret =0 ; +loff_t size; +unsigned long len; +handle_t *handle =NULL ; +struct buffer_head *page_bufs; +struct inode *inode = page->mapping->host; handle =ext4_journal_current_handle (); +if (!handle) { +/* +* This can happen when we aren't called via +* ext4_da_writepages() but directly (shrink_page_lis). +* We cannot easily start a transaction here so we just skip +* writing the page in case we would have to do so. +*/ + size =i_size_read (inode); -if (test_opt (inode->i_sb,NOBH ) &&ext4_should_writeback_data (inode)) - ret =nobh_writepage (page, ext4_get_block, wbc); -else - ret =block_write_full_page (page, ext4_get_block, wbc); + page_bufs =page_buffers (page); +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; -if (!ret && inode->i_size >EXT4_I (inode)->i_disksize) { -EXT4_I (inode)->i_disksize = inode->i_size; -ext4_mark_inode_dirty (handle, inode); +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +/* +* We can't do block allocation under +* page lock without a handle . So redirty +* the page and return +*/ +redirty_page_for_writepage (wbc, page); +unlock_page (page); +return 0 ; + } } +if (test_opt (inode->i_sb,NOBH ) &&ext4_should_writeback_data (inode)) + ret =nobh_writepage (page, ext4_da_get_block_write, wbc); +else + ret =block_write_full_page (page, ext4_da_get_block_write, wbc); +return ret; } -static int ext4_da_writepage (struct page *page, -struct writeback_control *wbc) -{ -if (!ext4_journal_current_handle ()) -return __ext4_da_writepage (page, wbc); -redirty_page_for_writepage (wbc, page); -unlock_page (page); -return 0 ; -}/* * For now just follow the DIO way to estimate the max credits
@@ -1547,6 +1570,7 @@ static int ext4_da_writepages(struct address_space *mapping,int ret =0 ;unsigned range_cyclic;long to_write; +pgoff_t index;/* * Estimate the worse case needed credits to write out
@@ -1557,6 +1581,15 @@ static int ext4_da_writepages(struct address_space *mapping, to_write = wbc->nr_to_write; range_cyclic = wbc->range_cyclic; wbc->range_cyclic =1 ; + index = mapping->writeback_index; +if (!range_cyclic) { +/* +* We force cyclic write out of pages. If the +* caller didn't request for range_cyclic update +* set the writeback_index to what the caller requested. +*/ + mapping->writeback_index = wbc->range_start >>PAGE_CACHE_SHIFT ; + }while (!ret && to_write) {/* start a new transaction*/
@@ -1571,17 +1604,24 @@ static int ext4_da_writepages(struct address_space *mapping,*/ if (wbc->nr_to_write >EXT4_MAX_WRITEBACK_PAGES ) wbc->nr_to_write =EXT4_MAX_WRITEBACK_PAGES ; - to_write -= wbc->nr_to_write; + to_write -= wbc->nr_to_write; ret =mpage_da_writepages (mapping, wbc, ext4_da_get_block_write);ext4_journal_stop (handle); - to_write += wbc->nr_to_write; +if (wbc->nr_to_write) { +/* There is no more writeout needed */ + to_write += wbc->nr_to_write; +break ; + } + wbc->nr_to_write = to_write; } out_writepages: wbc->nr_to_write = to_write; wbc->range_cyclic = range_cyclic; +if (!range_cyclic) + mapping->writeback_index = index;return ret; }
@@ -1719,11 +1759,6 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)return 0 ; } -static int ext4_bh_unmapped_or_delay (handle_t *handle,struct buffer_head *bh) -{ -return (!buffer_mapped (bh) ||buffer_delay (bh)); -} -/* * Note that we don't need to start a transaction unless we're journaling * data because we should have holes filled from ext4_page_mkwrite(). If
fs/mpage.c +7 -7
@@ -849,13 +849,12 @@ static void mpage_put_bnr_to_bhs(struct mpage_da_data *mpd, sector_t logical, do { if (cur_logical >= logical + blocks) break; - if (buffer_delay(bh)) { bh->b_blocknr = pblock; clear_buffer_delay(bh); - } else if (buffer_mapped(bh)) { + set_buffer_mapped(bh); + } else if (buffer_mapped(bh)) BUG_ON(bh->b_blocknr != pblock); - } cur_logical++; pblock++;
@@ -930,10 +929,10 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)if (buffer_delay (lbh))mpage_put_bnr_to_bhs (mpd, next, &new); -/* go for the remaining blocks */ - next += new.b_size >> mpd->inode->i_blkbits; - remain -= new.b_size; - } +/* go for the remaining blocks */ + next += new.b_size >> mpd->inode->i_blkbits; + remain -= new.b_size; + } }#define BH_FLAGS ((1 << BH_Uptodate) | (1 << BH_Mapped) | (1 << BH_Delay))
@@ -1052,6 +1051,7 @@ static int __mpage_da_writepage(struct page *page, head =page_buffers (page); bh = head; do { + BUG_ON(buffer_locked(bh)); if (buffer_dirty(bh)) mpage_add_bh_to_extent(mpd, logical, bh);
mm/page-writeback.c +6 -1
@@ -881,7 +881,12 @@ int write_cache_pages(struct address_space *mapping,pagevec_init (&pvec,0 );if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ - end =-1 ; +/* +* write only till the specified range_end even in cyclic mode +*/ + end = wbc->range_end >>PAGE_CACHE_SHIFT ; +if (!end) + end =-1 ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;
Signature · 1 line
1.5.5.1.357.g1af8b.dirty
Quoted 26 lines · Aneesh Kumar K.V
The below set of patches gets the delalloc work with journal locking order inversion patches.
The series file look like
+ ext4-new-defm-options
+ ext4-call-blkdev_issue_flush-on-fsync.patch 0001-ext4-Use-page_mkwrite-vma_operations-to-get-mmap-wr.patch
+ ext4_ialloc-flexbg.patch 0002-ext4-Inverse-locking-order-of-page_lock-and-transac.patch 0003-vfs-Move-mark_inode_dirty-from-under-page-lock-in.patch 0004-ext4-Add-validation-to-jbd-lock-inversion-patch-and.patch
+ delalloc-vfs.patch
+ ext4-fix-fs-corruption-with-delalloc.patch
+ delalloc-ext4.patch
+ delalloc-ext4-release-page-when-write_begin-failed.patch
+ delalloc-ext4-preallocation-handling.patch
...
...
.....
+ vfs-fiemap.patch
+ ext4-add-ext4_ext_walk_space.patch
+ ext4-fiemap.patch 0005-ext4-inverse-locking-ordering-of-page_lock-and-tra.patch 0006-ext4-Fix-delalloc-sync-hang-with-journal-lock-inver.patch
Quoted 5 lines
I have pushed the lock inversion patches and related changes to the top of the patch queue expecting it can be pushed upstream before delalloc changes.
Thanks for fixing this up.
Added the series to patch queue.
Mingming
Quoted 3 lines
-aneesh
PATCH 1/1 ext4: Need clear buffer_delay after page writeout for delayed allocation
In reply to Aneesh Kumar K.Vext4: Need clear buffer_delay after page writeout for delayed allocation
From: Mingming Cao <[email protected]>
Need clear buffer_delay in ext4_da_writepage() after page has been writeout
--- fs/ext4/inode.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
fs/ext4/inode.c +14 -9
@@ -1495,6 +1495,13 @@ static int ext4_bh_unmapped_or_delay(hanreturn (!buffer_mapped (bh) ||buffer_delay (bh)); } +static int ext4_bh_clear_delay (handle_t *handle,struct buffer_head *bh) +{ +clear_buffer_delay (bh); +return 1 ; +} + +/* FIXME!! only support data=writeback mode */ /* * get called vi ext4_da_writepages after taking page lock
@@ -1508,10 +1515,16 @@ static int ext4_da_writepage(struct pageloff_t size;unsigned long len;handle_t *handle =NULL ; -struct buffer_head *page_bufs; +struct buffer_head *page_bufs =page_buffers (page);struct inode *inode = page->mapping->host; + size =i_size_read (inode); +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; handle =ext4_journal_current_handle (); +if (!handle) {/* * This can happen when we aren't called via
@@ -1519,14 +1532,6 @@ static int ext4_da_writepage(struct page* We cannot easily start a transaction here so we just skip * writing the page in case we would have to do so. */ - size =i_size_read (inode); - - page_bufs =page_buffers (page); -if (page->index == size >>PAGE_CACHE_SHIFT ) - len = size & ~PAGE_CACHE_MASK ; -else - len =PAGE_CACHE_SIZE ; -if (walk_page_buffers (NULL , page_bufs,0 , len,NULL , ext4_bh_unmapped_or_delay)) {/*
@@ -1544,7 +1549,9 @@ static int ext4_da_writepage(struct page ret =nobh_writepage (page, ext4_da_get_block_write, wbc); else ret =block_write_full_page (page, ext4_da_get_block_write, wbc);
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 9 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>---
We do that in mpage_put_bnr_to_bhs.
-aneesh
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 5 lines · Aneesh Kumar K.V
Quoted 4 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Quoted 8 lines
Quoted 5 lines
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>---
We do that in
mpage_put_bnr_to_bhs.
Normally delayed buffer could be cleared in that case, but if allocation failed in __mapge_da_writepages(), it will keep buffer_delay marked and deferring to later ext4_da_writepage() to do block allocation. This patch handles clear bh delay bit in this case.
Mingming
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 10 lines · Mingming Cao
Quoted 9 lines · Aneesh Kumar K.V
Quoted 8 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
---
We do that in
mpage_put_bnr_to_bhs.Normally delayed buffer could be cleared in that case, but if allocation failed in
__mapge_da_writepages(), it will keepbuffer_delaymarked and deferring to laterext4_da_writepage()to do block allocation. This patch handles clear bh delay bit in this case.
Why not do it in ext4_da_get_block_write then. The reason being block_write_full_page can return an error even though we have some of the blocks allocated. With 1K block size we could allocate 3 blocks and fail for the last block in that case with the above patch we don't clear the delay bit of the buffer head of all the blocks allocated.
-aneesh
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 15 lines · Aneesh Kumar K.V
Quoted 14 lines · Mingming Cao
Quoted 13 lines · Aneesh Kumar K.V
Quoted 9 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>---
We do that in
mpage_put_bnr_to_bhs.
Quoted 7 lines
Quoted 5 lines
Normally delayed buffer could be cleared in that case, but if allocation failed in
__mapge_da_writepages(), it will keepbuffer_delaymarked and deferring to laterext4_da_writepage()to do block allocation. This patch handles clear bh delay bit in this case.Why not do it in
ext4_da_get_block_writethen.
The buffer head passed to ext4_da_get_block_write() calling from mpage_da_map_blocks is a dummy one, to store the allocated extent, not the bh that need map.
Quoted 6 lines
The reason being
block_write_full_pagecan return an error even though we have some of the blocks allocated. With 1K block size we could allocate 3 blocks and fail for the last block in that case with the above patch we don't clear the delay bit of the buffer head of all the blocks allocated.
It only clear the delayed bits if block_write_full_page() returns successfully. But that reminds me to do some block reservation handling for the error case.
Quoted 5 lines
-aneesh
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 22 lines · Mingming Cao
Quoted 21 lines · Aneesh Kumar K.V
Quoted 19 lines · Mingming Cao
Quoted 5 lines · Aneesh Kumar K.V
Quoted 4 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Quoted 8 lines
Quoted 5 lines
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>---
We do that in
mpage_put_bnr_to_bhs.Normally delayed buffer could be cleared in that case, but if allocation failed in
__mapge_da_writepages(), it will keepbuffer_delaymarked and deferring to laterext4_da_writepage()to do block allocation. This patch handles clear bh delay bit in this case.
Quoted 5 lines
Quoted 1 line
Why not do it in
ext4_da_get_block_writethen.The buffer head passed to
ext4_da_get_block_write()calling frommpage_da_map_blocksis a dummy one, to store the allocated extent, not the bh that need map.
ie true when ext4_da_get_block_write is called via writepages. In that case mpage_put_bnr_to_bhs clears the delay bit properly. How about the changes below.
fs/ext4/extents.c +1 -0
@@ -2873,6 +2873,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, allocated = max_blocks;ext4_ext_show_leaf (inode, path);__set_bit (BH_Mapped, &bh_result->b_state); +__clear_bit (BH_Delay, &bh_result->b_state); bh_result->b_bdev = inode->i_sb->s_bdev; bh_result->b_blocknr = newblock; out2:
fs/ext4/inode.c +1 -0
@@ -917,6 +917,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, goto cleanup;set_buffer_new (bh_result); +clear_buffer_delay (bh_result); got_it:map_bh (bh_result, inode->i_sb,le32_to_cpu (chain[depth-1 ].key));if (count > blocks_to_boundary)
fs/mpage.c +9 -1
@@ -897,6 +897,14 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)int err =0 , remain = lbh->b_size;sector_t next = lbh->b_blocknr;struct buffer_head new; +int delay_buf =0 ; + +/* +* We clear the delay bit in get_block so remember +* whether we are doing a delay allocation +*/ +if (buffer_delay (lbh)) + delay_buf =1 ;/* * We consider only non-mapped and non-allocated blocks
@@ -926,7 +934,7 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)* If blocks are delayed marked, we need to * put actual blocknr and drop delayed bit */ -if (buffer_delay (lbh)) +if (delay_buf)mpage_put_bnr_to_bhs (mpd, next, &new);/* go for the remaining blocks */
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 25 lines · Aneesh Kumar K.V
Quoted 24 lines · Mingming Cao
Quoted 22 lines · Aneesh Kumar K.V
Quoted 10 lines · Mingming Cao
Quoted 9 lines · Aneesh Kumar K.V
Quoted 8 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>Quoted 9 lines
Quoted 4 lines
Quoted 1 line
---
We do that in
mpage_put_bnr_to_bhs.Normally delayed buffer could be cleared in that case, but if allocation failed in
__mapge_da_writepages(), it will keepbuffer_delaymarked and deferring to laterext4_da_writepage()to do block allocation. This patch handles clear bh delay bit in this case.Why not do it in
ext4_da_get_block_writethen.
Quoted 9 lines
Quoted 3 lines
The buffer head passed to
ext4_da_get_block_write()calling frommpage_da_map_blocksis a dummy one, to store the allocated extent, not the bh that need map.ie true when
ext4_da_get_block_writeis called via writepages. In that casempage_put_bnr_to_bhsclears the delay bit properly. How about the changes below.
I see your patch below is trying to address how to detect and assign blocks with your suggestion(i.e clear delayed bit in get_block). But I don;t think it's needed.
My last email I mean the buffer head new in mpage_da_map_blocks() is a dummy bh, the real buffer head lbh is not passed to get_block. We could clear the delayed bit on successful return of get_block, mpage_put_bnr_to_bhs() ignore that dummy bh anyway. But that seems twisted, unccessary.
I still think clear the bit in the ext4_da_write_page() is more clean way. the original patch clears the delayed bit on success case.
For the error case I think we could handle properly by only clear the delayed bit if buffer is mapped.
Mingming
Quoted 54 lines
fs/ext4/extents.c +1
-0@@ -2873,6 +2873,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, allocated = max_blocks;ext4_ext_show_leaf (inode, path);__set_bit (BH_Mapped, &bh_result->b_state); +__clear_bit (BH_Delay, &bh_result->b_state); bh_result->b_bdev = inode->i_sb->s_bdev; bh_result->b_blocknr = newblock; out2:fs/ext4/inode.c +1
-0@@ -917,6 +917,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, goto cleanup;set_buffer_new (bh_result); +clear_buffer_delay (bh_result); got_it:map_bh (bh_result, inode->i_sb,le32_to_cpu (chain[depth-1 ].key));if (count > blocks_to_boundary)fs/mpage.c +9
-1@@ -897,6 +897,14 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)int err =0 , remain = lbh->b_size;sector_t next = lbh->b_blocknr;struct buffer_head new; +int delay_buf =0 ; + +/* +* We clear the delay bit in get_block so remember +* whether we are doing a delay allocation +*/ +if (buffer_delay (lbh)) + delay_buf =1 ;/* * We consider only non-mapped and non-allocated blocks @@ -926,7 +934,7 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)* If blocks are delayed marked, we need to * put actual blocknr and drop delayed bit */ -if (buffer_delay (lbh)) +if (delay_buf)mpage_put_bnr_to_bhs (mpd, next, &new);/* go for the remaining blocks */
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 45 lines · Mingming Cao
Quoted 25 lines · Aneesh Kumar K.V
Quoted 24 lines · Mingming Cao
Quoted 22 lines · Aneesh Kumar K.V
Quoted 10 lines · Mingming Cao
Quoted 9 lines · Aneesh Kumar K.V
Quoted 8 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>Quoted 9 lines
Quoted 4 lines
Quoted 1 line
---
We do that in
mpage_put_bnr_to_bhs.Normally delayed buffer could be cleared in that case, but if allocation failed in
__mapge_da_writepages(), it will keepbuffer_delaymarked and deferring to laterext4_da_writepage()to do block allocation. This patch handles clear bh delay bit in this case.Why not do it in
ext4_da_get_block_writethen.Quoted 9 lines
Quoted 3 lines
The buffer head passed to
ext4_da_get_block_write()calling frommpage_da_map_blocksis a dummy one, to store the allocated extent, not the bh that need map.ie true when
ext4_da_get_block_writeis called via writepages. In that casempage_put_bnr_to_bhsclears the delay bit properly. How about the changes below.I see your patch below is trying to address how to detect and assign blocks with your
suggestion(i.e clear delayed bit in get_block). But I don;t think it's needed.My last email I mean the buffer head new in
mpage_da_map_blocks()is a dummy bh, the real buffer head lbh is not passed toget_block. We could clear the delayed bit on successful return ofget_block,mpage_put_bnr_to_bhs()ignore that dummy bh anyway. But that seems twisted, unccessary.
Quoted 5 lines
I still think clear the bit in the
ext4_da_write_page()is more clean way. the original patch clears the delayed bit on success case.For the error case I think we could handle properly by only clear the delayed bit if buffer is mapped.
Buffer marked as delay is also mappedfs/ext4/inode.c
1437 map_bh(bh_result, inode->i_sb, 0); 1438 set_buffer_new(bh_result); 1439 set_buffer_delay(bh_result);
Quoted 22 lines
Mingming
Quoted 20 lines
fs/ext4/extents.c +1
-0@@ -2873,6 +2873,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, allocated = max_blocks;ext4_ext_show_leaf (inode, path);__set_bit (BH_Mapped, &bh_result->b_state); +__clear_bit (BH_Delay, &bh_result->b_state); bh_result->b_bdev = inode->i_sb->s_bdev; bh_result->b_blocknr = newblock; out2:fs/ext4/inode.c +0
-0@@ -917,6 +917,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, goto cleanup;
Quoted 5 lines
fs/ext4/inode.c int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, · line 923
Quoted 5 lines
fs/ext4/inode.c +1
-0set_buffer_new (bh_result); +clear_buffer_delay (bh_result); got_it:map_bh (bh_result, inode->i_sb,le32_to_cpu (chain[depth-1 ].key));if (count > blocks_to_boundary)
I think we need only the above chage. since we are using buffer_head new for block request in writepages. The below change can be dropped. It handles all the error case.
Quoted 27 lines
Quoted 27 lines
fs/mpage.c +9
-1@@ -897,6 +897,14 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)int err =0 , remain = lbh->b_size;sector_t next = lbh->b_blocknr;struct buffer_head new; +int delay_buf =0 ; + +/* +* We clear the delay bit in get_block so remember +* whether we are doing a delay allocation +*/ +if (buffer_delay (lbh)) + delay_buf =1 ;/* * We consider only non-mapped and non-allocated blocks @@ -926,7 +934,7 @@ static void mpage_da_map_blocks(struct mpage_da_data *mpd)* If blocks are delayed marked, we need to * put actual blocknr and drop delayed bit */ -if (buffer_delay (lbh)) +if (delay_buf)mpage_put_bnr_to_bhs (mpd, next, &new);
Quoted 3 lines
fs/mpage.c static void mpage_da_map_blocks(struct mpage_da_data *mpd) · line 940
Quoted 2 lines
fs/mpage.c +0
-0/* go for the remaining blocks */
-aneesh
Jan Kara
maintainerRe: [PATCH] ext4: Add validation to jbd lock inversion patch and split and writepage
In reply to Aneesh Kumar K.VHi Aneesh,
Thanks for the patch but I though we decided to do this a bit differently -
see below.
Quoted 30 lines · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>--- fs/ext4/inode.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 156 insertions(+), 25 deletions(-)fs/ext4/inode.c +7
-2@@ -1479,6 +1479,11 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)return 0 ; } +static int ext4_bh_unmapped_or_delay (handle_t *handle,struct buffer_head *bh) +{ +return (!buffer_mapped (bh) ||buffer_delay (bh)); +} +/* * Note that we don't need to start a transaction unless we're journaling * data because we should have holes filled from ext4_page_mkwrite(). If @@ -1531,18 +1536,26 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)static int __ext4_ordered_writepage (struct page *page,struct writeback_control *wbc) { -struct inode *inode = page->mapping->host; -struct buffer_head *page_bufs; +int ret =0 , err; +unsigned long len;handle_t *handle =NULL ;
fs/ext4/inode.c static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh) · line 1543
Quoted 10 lines
fs/ext4/inode.c +3
-6-int ret =0 ; -int err; +struct buffer_head *page_bufs; +struct inode *inode = page->mapping->host; +loff_t size =i_size_read (inode); -if (!page_has_buffers (page)) { -create_empty_buffers (page, inode->i_sb->s_blocksize, - (1 << BH_Dirty)|(1 << BH_Uptodate)); - }
This is OK.
fs/ext4/inode.c static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh) · line 1557
Quoted 13 lines
fs/ext4/inode.c +11
-1page_bufs =page_buffers (page); - walk_page_buffers(handle, page_bufs, 0, +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; + +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + }
But I'd move this check to ext4_ordered_writepage().
Quoted 35 lines
fs/ext4/inode.c +10
-3+walk_page_buffers (NULL , page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , bget_one); ret =block_write_full_page (page, ext4_get_block, wbc);@@ -1574,8 +1587,8 @@ static int __ext4_ordered_writepage(struct page *page, ret = err; } out_put: -walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , - bput_one); +walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , bput_one);return ret; }@@ -1583,7 +1596,7 @@ static int ext4_ordered_writepage(struct page *page, struct writeback_control *wbc) {J_ASSERT (PageLocked (page)); - +BUG_ON (!page_has_buffers (page));/* * We give up here if we're reentered, because it might be for a * different filesystem. @@ -1599,18 +1612,34 @@ static int ext4_ordered_writepage(struct page *page,static int __ext4_writeback_writepage (struct page *page,struct writeback_control *wbc) { +unsigned long len; +struct buffer_head *page_bufs;struct inode *inode = page->mapping->host; +loff_t size =i_size_read (inode); + + page_bufs =page_buffers (page); +if (page->index == size >>PAGE_CACHE_SHIFT )
fs/ext4/inode.c static int ext4_ordered_writepage(struct page *page, · line 1631
Quoted 10 lines
fs/ext4/inode.c +9
-0+ len = size & ~PAGE_CACHE_MASK ; + else + len =PAGE_CACHE_SIZE ; +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + }
And similarly move this check to ext4_writeback_writepage().
Quoted 33 lines
fs/ext4/inode.c +10
-4if (test_opt (inode->i_sb,NOBH ))return nobh_writepage (page, ext4_get_block, wbc);else return block_write_full_page (page, ext4_get_block, wbc); } -static int ext4_writeback_writepage (struct page *page,struct writeback_control *wbc) { +BUG_ON (!page_has_buffers (page)); +if (!ext4_journal_current_handle ())return __ext4_writeback_writepage (page, wbc);@@ -1622,18 +1651,31 @@ static int ext4_writeback_writepage(struct page *page,static int __ext4_journalled_writepage (struct page *page,struct writeback_control *wbc) { +int ret =0 , err; +unsigned long len; +handle_t *handle =NULL ;struct address_space *mapping = page->mapping;struct inode *inode = mapping->host;struct buffer_head *page_bufs; -handle_t *handle =NULL ; -int ret =0 ; -int err; +loff_t size =i_size_read (inode); + + page_bufs =page_buffers (page); +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ;
fs/ext4/inode.c static int ext4_writeback_writepage(struct page *page, · line 1674
Quoted 10 lines
fs/ext4/inode.c +9
-0+else + len =PAGE_CACHE_SIZE ; +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + } +/* FIXME!! do we need to call prepare_write for a mapped buffer */
This can go to ext4_journalled_writepage(). What is actually this FIXME
about? I'm not sure I get it...
Quoted 111 lines
fs/ext4/inode.c +84
-6ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block);if (ret !=0 ) goto out_unlock; - page_bufs =page_buffers (page);walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , bget_one);/* As soon as we unlock the page, it can go away, but we have @@ -1671,14 +1713,13 @@ static int __ext4_journalled_writepage(struct page *page,static int ext4_journalled_writepage (struct page *page,struct writeback_control *wbc) { +BUG_ON (!page_has_buffers (page)); +if (ext4_journal_current_handle ()) goto no_write; -if (!page_has_buffers (page) ||PageChecked (page)) { -/* -* It's mmapped pagecache. Add buffers and journal it. There -* doesn't seem much point in redirtying the page here. -*/ +if (PageChecked (page)) { +/* dirty pages in data=journal mode */ ClearPageChecked (page);return __ext4_journalled_writepage (page, wbc); }else {@@ -3520,6 +3561,96 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)return err; } +static int __ext4_journalled_allocpage (struct page *page, +struct writeback_control *wbc) +{ +int ret =0 , err; +handle_t *handle =NULL ; +struct address_space *mapping = page->mapping; +struct inode *inode = mapping->host; +struct buffer_head *page_bufs; + +/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); + + ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block); +if (ret !=0 ) + goto out_unlock; + +/* FIXME!! should we do a bget_one */ + page_bufs =page_buffers (page); + ret =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , do_journal_get_write_access); + + err =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , write_end_fn); +if (ret ==0 ) + ret = err; +EXT4_I (inode)->i_state |=EXT4_STATE_JDATA ; + +out_unlock: +unlock_page (page); +return ret; +} + +static int __ext4_ordered_allocpage (struct page *page, +struct writeback_control *wbc) +{ +int ret =0 ; +handle_t *handle =NULL ; +struct buffer_head *page_bufs; +struct inode *inode = page->mapping->host; + +/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); +if (!page_has_buffers (page)) { +create_empty_buffers (page, inode->i_sb->s_blocksize, + (1 << BH_Dirty)|(1 << BH_Uptodate)); + } + page_bufs =page_buffers (page); +walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , bget_one); + + ret =block_write_full_page (page, ext4_get_block, wbc); + +/* +* The page can become unlocked at any point now, and +* truncate can then come in and change things. So we +* can't touch *page from now on. But *page_bufs is +* safe due to elevated refcount. +*/ + +/* +* And attach them to the current transaction. But only if +* block_write_full_page() succeeded. Otherwise they are unmapped, +* and generally junk. +*/ +if (ret ==0 ) { + ret =walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE , +NULL , jbd2_journal_dirty_data_fn); + } +walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , bput_one); +return ret; +} + +static int __ext4_writeback_allocpage (struct page *page, +struct writeback_control *wbc) +{ +handle_t *handle =NULL ; +struct inode *inode = page->mapping->host;
fs/ext4/inode.c int ext4_change_inode_journal_flag(struct inode *inode, int val) · line 3653
Quoted 10 lines
fs/ext4/inode.c +10
-0+/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); + +if (test_opt (inode->i_sb,NOBH )) +return nobh_writepage (page, ext4_get_block, wbc); +else +return block_write_full_page (page, ext4_get_block, wbc); +} +
And then you don't need these __ext4_..._allocpage() calls because that
is what's left in __ext4_..._writepage(), isn't it? It seems also logically more consistent - you do checks in ext4_..._writepage() and then you do the real work in __ext4_..._writepage().
For data=journaled mode, it may be better to really haveext4_journaled_allocpage() because we don't have to do nasty locking tricks. But for writeback and ordered mode I really see no need for these special functions. So at least for these two, I'd change the code as I suggest.
Quoted 20 lines
fs/ext4/inode.c +3
-3static int ext4_bh_prepare_fill (handle_t *handle,struct buffer_head *bh) {if (!buffer_mapped (bh)) {@@ -3596,11 +3727,11 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page) wbc.range_start =page_offset (page); wbc.range_end =page_offset (page) + len;if (ext4_should_writeback_data (inode)) - ret =__ext4_writeback_writepage (page, &wbc); + ret =__ext4_writeback_allocpage (page, &wbc);else if (ext4_should_order_data (inode)) - ret =__ext4_ordered_writepage (page, &wbc); + ret =__ext4_ordered_allocpage (page, &wbc);else - ret =__ext4_journalled_writepage (page, &wbc); + ret =__ext4_journalled_allocpage (page, &wbc);/* Page got unlocked in writepage */ err =ext4_journal_stop (handle);if (!ret)Signature · 1 line
1.5.5.1.357.g1af8b.dirty
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
maintainerRe: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
In reply to Aneesh Kumar K.Vfs/mpage.c static int __mpage_da_writepage(struct page *page, · line 1054
Quoted 5 lines
fs/mpage.c +1
-0@@ -1052,6 +1051,7 @@ static int __mpage_da_writepage(struct page *page, head =page_buffers (page); bh = head; do { +
I guess this line is a typo.
Quoted 11 lines
fs/mpage.c +0
-0BUG_ON (buffer_locked (bh));if (buffer_dirty (bh))mpage_add_bh_to_extent (mpd, logical, bh);mm/page-writeback.c +0
-0@@ -881,7 +881,12 @@ int write_cache_pages(struct address_space *mapping,pagevec_init (&pvec,0 );if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 892
Quoted 10 lines
mm/page-writeback.c +6
-1- end =-1 ; +/* +* write only till the specified range_end even in cyclic mode +*/ + end = wbc->range_end >>PAGE_CACHE_SHIFT ; +if (!end) + end =-1 ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;
Are you sure you won't break other users of range_cyclic with this
change?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH] ext4: Add validation to jbd lock inversion patch and split and writepage
In reply to Jan KaraHi Jan,
Quoted 4 lines · Jan Kara
Hi Aneesh,
Thanks for the patch but I though we decided to do this a bit differently -
see below.
Please feel free to merge the changes back to the lock inversion patches. I sent it as a separate the patches to make it easier for review.
Quoted 44 lines · Aneesh Kumar K.V
Quoted 30 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- fs/ext4/inode.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 156 insertions(+), 25 deletions(-)fs/ext4/inode.c +7
-2@@ -1479,6 +1479,11 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)return 0 ; } +static int ext4_bh_unmapped_or_delay (handle_t *handle,struct buffer_head *bh) +{ +return (!buffer_mapped (bh) ||buffer_delay (bh)); +} +/* * Note that we don't need to start a transaction unless we're journaling * data because we should have holes filled from ext4_page_mkwrite(). If @@ -1531,18 +1536,26 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)static int __ext4_ordered_writepage (struct page *page,struct writeback_control *wbc) { -struct inode *inode = page->mapping->host; -struct buffer_head *page_bufs; +int ret =0 , err; +unsigned long len;handle_t *handle =NULL ;fs/ext4/inode.c static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh) · line 1543
Quoted 10 lines
fs/ext4/inode.c +3
-6-int ret =0 ; -int err; +struct buffer_head *page_bufs; +struct inode *inode = page->mapping->host; +loff_t size =i_size_read (inode); -if (!page_has_buffers (page)) { -create_empty_buffers (page, inode->i_sb->s_blocksize, - (1 << BH_Dirty)|(1 << BH_Uptodate)); - }This is OK.
Quoted 15 lines
fs/ext4/inode.c static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh) · line 1557
Quoted 13 lines
fs/ext4/inode.c +11
-1page_bufs =page_buffers (page); - walk_page_buffers(handle, page_bufs, 0, +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; + +if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + }But I'd move this check to
ext4_ordered_writepage().
Please feel free to do so. The only reason for me to do it as a separate function is to clarify that with the changes writepage doesn't do any block allocation at all. And calling writepage via page_mkwrite goes against that. So i renamed the page_mkwrite call out to *_allocpage and made sure writepage doesn't do any block allocation.
Quoted 3 lines
Quoted 3 lines
fs/ext4/inode.c +1
-0+walk_page_buffers (NULL , page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , bget_one);
[.... snip ..... ]
Quoted 11 lines
fs/ext4/inode.c static int ext4_writeback_writepage(struct page *page, · line 1674
Quoted 8 lines
fs/ext4/inode.c +7
-0+if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + } +/* FIXME!! do we need to call prepare_write for a mapped buffer */ This can go to
ext4_journalled_writepage(). What is actually this FIXME
about? I'm not sure I get it...
I was wondering whether we need to call prepare_write in writepage ?. We are not allocating any new blocks in writepage with these changes.
Quoted 45 lines
Quoted 45 lines
fs/ext4/inode.c +18
-6ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block);if (ret !=0 ) goto out_unlock; - page_bufs =page_buffers (page);walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , bget_one);/* As soon as we unlock the page, it can go away, but we have @@ -1671,14 +1713,13 @@ static int __ext4_journalled_writepage(struct page *page,static int ext4_journalled_writepage (struct page *page,struct writeback_control *wbc) { +BUG_ON (!page_has_buffers (page)); +if (ext4_journal_current_handle ()) goto no_write; -if (!page_has_buffers (page) ||PageChecked (page)) { -/* -* It's mmapped pagecache. Add buffers and journal it. There -* doesn't seem much point in redirtying the page here. -*/ +if (PageChecked (page)) { +/* dirty pages in data=journal mode */ ClearPageChecked (page);return __ext4_journalled_writepage (page, wbc); }else {@@ -3520,6 +3561,96 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)return err; } +static int __ext4_journalled_allocpage (struct page *page, +struct writeback_control *wbc) +{ +int ret =0 , err; +handle_t *handle =NULL ; +struct address_space *mapping = page->mapping; +struct inode *inode = mapping->host; +struct buffer_head *page_bufs; + +/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); + + ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block);
Quoted 8 lines
fs/ext4/inode.c int ext4_change_inode_journal_flag(struct inode *inode, int val) · line 3585
Quoted 8 lines
fs/ext4/inode.c +8
-0+if (ret !=0 ) + goto out_unlock; + +/* FIXME!! should we do a bget_one */ + page_bufs =page_buffers (page); + ret =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , do_journal_get_write_access); +
I also have a FIXME here. I am not sure whether unlocking the page have some effect. Can you verify this ?
Quoted 11 lines
fs/ext4/inode.c int ext4_change_inode_journal_flag(struct inode *inode, int val) · line 3596
Quoted 11 lines
fs/ext4/inode.c +11
-0+ err =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , write_end_fn); +if (ret ==0 ) + ret = err; +EXT4_I (inode)->i_state |=EXT4_STATE_JDATA ; + +out_unlock: +unlock_page (page); +return ret; +} +
-aneesh
Re: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
In reply to Jan KaraQuoted 7 lines · Jan Kara
fs/mpage.c static int __mpage_da_writepage(struct page *page, · line 1054
Quoted 5 lines
fs/mpage.c +1
-0@@ -1052,6 +1051,7 @@ static int __mpage_da_writepage(struct page *page, head =page_buffers (page); bh = head; do { +I guess this line is a typo.
Yes, Mostly some debug lines I removed, but missed the newline added.
Quoted 15 lines
Quoted 15 lines
fs/mpage.c +0
-0BUG_ON (buffer_locked (bh));if (buffer_dirty (bh))mpage_add_bh_to_extent (mpd, logical, bh);mm/page-writeback.c +3
-1@@ -881,7 +881,12 @@ int write_cache_pages(struct address_space *mapping,pagevec_init (&pvec,0 );if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ - end =-1 ; +/* +* write only till the specified range_end even in cyclic mode +*/
Quoted 9 lines
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 892
Quoted 6 lines
mm/page-writeback.c +3
-0+ end = wbc->range_end >>PAGE_CACHE_SHIFT ; +if (!end) + end =-1 ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;Are you sure you won't break other users of
range_cyclicwith this
change?
I haven't run any specific test to verify that. The concern was that if we force cyclic mode for writeout in delalloc we may be starting the writeout from a different offset than specified and would be writing more. So the changes was to use the offset specified. A quick look at the kernel suggested most of them had range_end as 0 with cyclic_mode. I haven't audited the full kernel. I will do that. Meanwhile if you think it is risky to make this changes i guess we should drop this part. But i guess we can keep the below change
+ index = mapping->writeback_index;
+ if (!range_cyclic) {
+ /*
+ * We force cyclic write out of pages. If the + * caller didn't request for range_cyclic update + * set the writeback_index to what the caller requested. + */
+ mapping->writeback_index = wbc->range_start >> PAGE_CACHE_SHIFT;
+ }
-aneesh
Jan Kara
maintainerRe: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
Quoted 25 lines · Aneesh Kumar K.V
Quoted 15 lines · Jan Kara
Quoted 15 lines
fs/mpage.c +0
-0BUG_ON (buffer_locked (bh));if (buffer_dirty (bh))mpage_add_bh_to_extent (mpd, logical, bh);mm/page-writeback.c +3
-1@@ -881,7 +881,12 @@ int write_cache_pages(struct address_space *mapping,pagevec_init (&pvec,0 );if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ - end =-1 ; +/* +* write only till the specified range_end even in cyclic mode +*/ Quoted 9 lines
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 892
Quoted 6 lines
mm/page-writeback.c +3
-0+ end = wbc->range_end >>PAGE_CACHE_SHIFT ; +if (!end) + end =-1 ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;Are you sure you won't break other users of
range_cyclicwith this
change?
Quoted 8 lines
I haven't run any specific test to verify that. The concern was that if we force cyclic mode for writeout in delalloc we may be starting the writeout from a different offset than specified and would be writing more. So the changes was to use the offset specified. A quick look at the kernel suggested most of them had
range_endas 0 withcyclic_mode. I haven't audited the full kernel. I will do that. Meanwhile if you think it is risky to make this changes i guess we should drop this part. But i guess we can keep the below change
Hmm, I've just got an idea that it may be better to introduce a new flag
for wbc like range_cont and it would mean that we start scan at writeback_index (we use range_start if writeback_index is not set) and end with range_end. That way we don't have to be afraid of interference with other range_cyclic users and in principle, range_cyclic is originally meant for other uses...
fs/ext4/inode.c static int ext4_da_writepages(struct address_space *mapping, · line 1592
Quoted 9 lines
fs/ext4/inode.c +9
-0+ index = mapping->writeback_index; +if (!range_cyclic) { +/* +* We force cyclic write out of pages. If the +* caller didn't request for range_cyclic update +* set the writeback_index to what the caller requested. +*/ + mapping->writeback_index = wbc->range_start >>PAGE_CACHE_SHIFT ; + }
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
maintainerRe: [PATCH] ext4: Add validation to jbd lock inversion patch and split and writepage
In reply to Aneesh Kumar K.VQuoted 11 lines · Aneesh Kumar K.V
Hi Jan,
Quoted 4 lines · Jan Kara
Hi Aneesh,
Thanks for the patch but I though we decided to do this a bit differently -
see below.Please feel free to merge the changes back to the lock inversion patches. I sent it as a separate the patches to make it easier for review.
OK, thanks. I'll look into this.
Quoted 11 lines
Quoted 11 lines
fs/ext4/inode.c static int ext4_writeback_writepage(struct page *page, · line 1674
Quoted 8 lines
fs/ext4/inode.c +7
-0+if (walk_page_buffers (NULL , page_bufs,0 , + len,NULL , ext4_bh_unmapped_or_delay)) { +printk (KERN_CRIT "%s called with unmapped or delay buffer\n" , + __func__); +BUG (); + } +/* FIXME!! do we need to call prepare_write for a mapped buffer */ This can go to
ext4_journalled_writepage(). What is actually this FIXME
about? I'm not sure I get it...
Quoted 2 lines
I was wondering whether we need to call
prepare_writein writepage ?. We are not allocating any new blocks in writepage with these changes.
Ah, I see. I'm only not sure whether we can rely on all buffers in the
page being uptodate... Otherwise I think block_prepare_write() is not needed.
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
fs/ext4/inode.c +20
-6ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block);if (ret !=0 ) goto out_unlock; - page_bufs =page_buffers (page);walk_page_buffers (handle, page_bufs,0 ,PAGE_CACHE_SIZE ,NULL , bget_one);/* As soon as we unlock the page, it can go away, but we have @@ -1671,14 +1713,13 @@ static int __ext4_journalled_writepage(struct page *page,static int ext4_journalled_writepage (struct page *page,struct writeback_control *wbc) { +BUG_ON (!page_has_buffers (page)); +if (ext4_journal_current_handle ()) goto no_write; -if (!page_has_buffers (page) ||PageChecked (page)) { -/* -* It's mmapped pagecache. Add buffers and journal it. There -* doesn't seem much point in redirtying the page here. -*/ +if (PageChecked (page)) { +/* dirty pages in data=journal mode */ ClearPageChecked (page);return __ext4_journalled_writepage (page, wbc); }else {@@ -3520,6 +3561,96 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)return err; } +static int __ext4_journalled_allocpage (struct page *page, +struct writeback_control *wbc) +{ +int ret =0 , err; +handle_t *handle =NULL ; +struct address_space *mapping = page->mapping; +struct inode *inode = mapping->host; +struct buffer_head *page_bufs; + +/* if alloc we are called after statring a journal */ + handle =ext4_journal_current_handle (); +BUG_ON (!handle); + + ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block); +if (ret !=0 ) + goto out_unlock;
Quoted 8 lines
Quoted 6 lines
fs/ext4/inode.c int ext4_change_inode_journal_flag(struct inode *inode, int val) · line 3585
Quoted 6 lines
fs/ext4/inode.c +6
-0+ +/* FIXME!! should we do a bget_one */ + page_bufs =page_buffers (page); + ret =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , do_journal_get_write_access); +I also have a FIXME here. I am not sure whether unlocking the page have some effect. Can you verify this ?
Well, you unlock the page only after you're completely done with it as
far as I read the code. So that is correct. You only need to get references to buffers when you need to access them after you unlock the page.
Quoted 11 lines
Quoted 11 lines
fs/ext4/inode.c int ext4_change_inode_journal_flag(struct inode *inode, int val) · line 3596
Quoted 11 lines
fs/ext4/inode.c +11
-0+ err =walk_page_buffers (handle, page_bufs,0 , +PAGE_CACHE_SIZE ,NULL , write_end_fn); +if (ret ==0 ) + ret = err; +EXT4_I (inode)->i_state |=EXT4_STATE_JDATA ; + +out_unlock: +unlock_page (page); +return ret; +} +
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
In reply to Aneesh Kumar K.VQuoted 53 lines · Aneesh Kumar K.V
Quoted 45 lines · Mingming Cao
Quoted 25 lines · Aneesh Kumar K.V
Quoted 24 lines · Mingming Cao
Quoted 22 lines · Aneesh Kumar K.V
Quoted 10 lines · Mingming Cao
Quoted 9 lines · Aneesh Kumar K.V
Quoted 8 lines · Mingming Cao
ext4: Need clear
buffer_delayafter page writeout for delayed allocationFrom: Mingming Cao <[email protected]>
Need clear
buffer_delayinext4_da_writepage()after page has been writeoutSigned-off-by Mingming Cao <[email protected]>Quoted 9 lines
Quoted 4 lines
Quoted 1 line
---
We do that in
mpage_put_bnr_to_bhs.Normally delayed buffer could be cleared in that case, but if allocation failed in
__mapge_da_writepages(), it will keepbuffer_delaymarked and deferring to laterext4_da_writepage()to do block allocation. This patch handles clear bh delay bit in this case.Why not do it in
ext4_da_get_block_writethen.Quoted 9 lines
Quoted 3 lines
The buffer head passed to
ext4_da_get_block_write()calling frommpage_da_map_blocksis a dummy one, to store the allocated extent, not the bh that need map.ie true when
ext4_da_get_block_writeis called via writepages. In that casempage_put_bnr_to_bhsclears the delay bit properly. How about the changes below.I see your patch below is trying to address how to detect and assign blocks with your
suggestion(i.e clear delayed bit in get_block). But I don;t think it's needed.My last email I mean the buffer head new in
mpage_da_map_blocks()is a dummy bh, the real buffer head lbh is not passed toget_block. We could clear the delayed bit on successful return ofget_block,mpage_put_bnr_to_bhs()ignore that dummy bh anyway. But that seems twisted, unccessary.Quoted 5 lines
I still think clear the bit in the
ext4_da_write_page()is more clean way. the original patch clears the delayed bit on success case.For the error case I think we could handle properly by only clear the delayed bit if buffer is mapped.
Quoted 8 lines
Buffer marked as delay is also mapped
fs/ext4/inode.c1437 map_bh(bh_result, inode->i_sb, 0); 1438 set_buffer_new(bh_result); 1439 set_buffer_delay(bh_result);
I find a better place to handle this, it make sense to clear this bit in block_write_full_page() after get_block() returns successfully. This handles partial error case smoothly. Updated patch below (to replace the original patch)
ext4: Need clear buffer_delay in block_write_full_page() after allocation
From: Mingming Cao <[email protected]>
Normally delayed buffer could be cleared in mpage_da_map_blocks(), after blocks are successfully allocated. But if allocation failed, it will keep buffer_delay marked and deferring to later ext4_da_writepage()(via block_write_full_page()) to do block allocation. This patch handles clear bh delay bit in this case. Clear buffer_delay in block_write_full_page() after the block is allocated.
This patch also fixed a bug in block_write_full_page() error case, we need to check the delayed flag before flush bh to disk when trying to recover from error.
--- fs/buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/buffer.c +3 -1
@@ -1697,6 +1697,7 @@ static int __block_write_full_page(struc err =get_block (inode, block, bh,1 );if (err) goto recover; +clear_buffer_delay (bh);if (buffer_new (bh)) {/* blockdev mappings never come here */ clear_buffer_new (bh);
@@ -1775,7 +1776,8 @@ recover: bh = head;/* Recovery: lock and submit the mapped buffers */ do { - if (buffer_mapped(bh) && buffer_dirty(bh)) { + if (buffer_mapped(bh) && buffer_dirty(bh) + && !buffer_delay(bh)) { lock_buffer(bh); mark_buffer_async_write(bh); } else {
Re: [PATCH] ext4: Need clear buffer_delay after page writeout for delayed allocation
Quoted 40 lines · Mingming Cao
Quoted 9 lines
Buffer marked as delay is also mapped
fs/ext4/inode.c1437 map_bh(bh_result, inode->i_sb, 0); 1438 set_buffer_new(bh_result); 1439 set_buffer_delay(bh_result);I find a better place to handle this, it make sense to clear this bit in
block_write_full_page()afterget_block()returns successfully. This handles partial error case smoothly. Updated patch below (to replace the original patch)ext4: Need clear
buffer_delayinblock_write_full_page()after allocationFrom: Mingming Cao <[email protected]>
Normally delayed buffer could be cleared in
mpage_da_map_blocks(), after blocks are successfully allocated. But if allocation failed, it will keepbuffer_delaymarked and deferring to later ext4_da_writepage()(viablock_write_full_page()) to do block allocation. This patch handles clear bh delay bit in this case. Clearbuffer_delayinblock_write_full_page()after the block is allocated.This patch also fixed a bug in
block_write_full_page()error case, we need to check the delayed flag before flush bh to disk when trying to recover from error.Signed-off-by Mingming Cao <[email protected]>--- fs/buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Index:
linux-2.6.26-rc4/fs/buffer.c
===================================================================
fs/buffer.c static int __block_write_full_page(struc · line 1700
Quoted 4 lines
fs/buffer.c +1
-0@@ -1697,6 +1697,7 @@ static int __block_write_full_page(struc err =get_block (inode, block, bh,1 );if (err) goto recover; +clear_buffer_delay (bh);
I still think we should clear the buffer_head delay bit in the get_block rather than the callers. That way all the callers will be returned the buffer_head with delay bit cleared. We do that for mapped and new bit already.
Quoted 6 lines
fs/buffer.c +0
-0if (buffer_new (bh)) {/* blockdev mappings never come here */ clear_buffer_new (bh);
fs/buffer.c recover: · line 1783
Quoted 9 lines
fs/buffer.c +2
-1@@ -1775,7 +1776,8 @@ recover: bh = head;/* Recovery: lock and submit the mapped buffers */ do { - if (buffer_mapped(bh) && buffer_dirty(bh)) { + if (buffer_mapped(bh) && buffer_dirty(bh) + && !buffer_delay(bh)) { lock_buffer(bh); mark_buffer_async_write(bh); } else {
This should be a separate bug fix patch. If we fail the allocation of a block marked delay we should not write it.
-aneesh
Re: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
In reply to Jan KaraQuoted 34 lines · Jan Kara
Quoted 25 lines · Aneesh Kumar K.V
Quoted 15 lines · Jan Kara
Quoted 15 lines
(quoted diff) +0
-0BUG_ON(buffer_locked(bh)); if (buffer_dirty(bh)) mpage_add_bh_to_extent(mpd, logical, bh);mm/page-writeback.c +3
-1@@ -881,7 +881,12 @@ int write_cache_pages(struct address_space *mapping,pagevec_init (&pvec,0 );if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ - end =-1 ; +/* +* write only till the specified range_end even in cyclic mode +*/ Quoted 9 lines
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 892
Quoted 6 lines
mm/page-writeback.c +3
-0+ end = wbc->range_end >>PAGE_CACHE_SHIFT ; +if (!end) + end =-1 ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;Are you sure you won't break other users of
range_cyclicwith this
change?Quoted 8 lines
I haven't run any specific test to verify that. The concern was that if we force cyclic mode for writeout in delalloc we may be starting the writeout from a different offset than specified and would be writing more. So the changes was to use the offset specified. A quick look at the kernel suggested most of them had
range_endas 0 withcyclic_mode. I haven't audited the full kernel. I will do that. Meanwhile if you think it is risky to make this changes i guess we should drop this part. But i guess we can keep the below change
Quoted 7 lines
Hmm, I've just got an idea that it may be better to introduce a new flag
for wbc likerange_contand it would mean that we start scan atwriteback_index(we userange_startifwriteback_indexis not set) and end withrange_end. That way we don't have to be afraid of interference with otherrange_cyclicusers and in principle,range_cyclicis originally meant for other uses...
something like below ?. With this ext4_da_writepages have
pgoff_t writeback_index = 0;
.....
if (!wbc->range_cyclic) {
/*
* If range_cyclic is not set force range_cont
* and save the old writeback_index
*/
wbc->range_cont = 1;
writeback_index = mapping->writeback_index;
mapping->writeback_index = 0;
}...mpage_da_writepages(..)
..
if (writeback_index)
mapping->writeback_index = writeback_index;
return ret;
mm: Add range_cont mode for writeback.
From: Aneesh Kumar K.V <[email protected]>
Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call write_cache_pages multiple times with wbc->nr_to_write set to the maximum possible value limitted by the max journal credits available.
Add a new mode to writeback that enables us to handle this behaviour. If mapping->writeback_index is not set we use wbc->range_start to find the start index and then at the end of write_cache_pages we store the index in writeback_index. Next call to write_cache_pages will start writeout from writeback_index. Also we limit writing to the specified wbc->range_end.
---
include/linux/writeback.h | 1 + mm/page-writeback.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletions(-)
include/linux/writeback.h +1 -0
@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };/*
mm/page-writeback.c +9 -1
@@ -882,6 +882,12 @@ int write_cache_pages(struct address_space *mapping,if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ end =-1 ; + }else if (wbc->range_cont) { +if (!mapping->writeback_index) + index = wbc->range_start >>PAGE_CACHE_SHIFT ; +else + index = mapping->writeback_index; + end = wbc->range_end >>PAGE_CACHE_SHIFT ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;
@@ -954,7 +960,9 @@ int write_cache_pages(struct address_space *mapping, index =0 ; goto retry; } -if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) +if (wbc->range_cyclic || + (range_whole && wbc->nr_to_write >0 ) || + wbc->range_cont) mapping->writeback_index = index;return ret; }
Jan Kara
maintainerRe: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
Quoted 49 lines · Aneesh Kumar K.V
Quoted 7 lines
Hmm, I've just got an idea that it may be better to introduce a new flag
for wbc likerange_contand it would mean that we start scan atwriteback_index(we userange_startifwriteback_indexis not set) and end withrange_end. That way we don't have to be afraid of interference with otherrange_cyclicusers and in principle,range_cyclicis originally meant for other uses...something like below ?. With this
ext4_da_writepageshave
pgoff_twriteback_index= 0;
.....if (!wbc->range_cyclic) { /* * If range_cyclic is not set force range_cont * and save the old writeback_index */ wbc->range_cont = 1; writeback_index = mapping->writeback_index; mapping->writeback_index = 0; }...
mpage_da_writepages(..)
..
if (writeback_index)mapping->writeback_index = writeback_index;return ret;
mm: Add
range_contmode for writeback.From: Aneesh Kumar K.V <[email protected]>
Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call
write_cache_pagesmultiple times withwbc->nr_to_writeset to the maximum possible value limitted by the max journal credits available.Add a new mode to writeback that enables us to handle this behaviour. If
mapping->writeback_indexis not set we usewbc->range_startto find the start index and then at the end ofwrite_cache_pageswe store the index inwriteback_index. Next call towrite_cache_pageswill start writeout fromwriteback_index. Also we limit writing to the specifiedwbc->range_end.
Quoted 6 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>---
include/linux/writeback.h | 1 + mm/page-writeback.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletions(-)
I like it. I'm only not sure whether there cannot be two users ofwrite_cache_pages() operating on the same mapping at the same time. Because then they could alter writeback_index under each other and that would probably result in unpleasant behavior. I think there can be two parallel calls for example from sync_single_inode() and sync_page_range().
In that case we'd need something like writeback_index inside wbc (or
maybe just alter range_start automatically when range_cont is set?) so that parallel callers do no influence each other.
Honza
Quoted 40 lines
include/linux/writeback.h +1
-0@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };/* mm/page-writeback.c +9
-1@@ -882,6 +882,12 @@ int write_cache_pages(struct address_space *mapping,if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ end =-1 ; + }else if (wbc->range_cont) { +if (!mapping->writeback_index) + index = wbc->range_start >>PAGE_CACHE_SHIFT ; +else + index = mapping->writeback_index; + end = wbc->range_end >>PAGE_CACHE_SHIFT ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;@@ -954,7 +960,9 @@ int write_cache_pages(struct address_space *mapping, index =0 ; goto retry; } -if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) +if (wbc->range_cyclic || + (range_whole && wbc->nr_to_write >0 ) || + wbc->range_cont) mapping->writeback_index = index;return ret; }
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
Quoted 9 lines · Jan Kara
I like it. I'm only not sure whether there cannot be two users of
write_cache_pages()operating on the same mapping at the same time. Because then they could alterwriteback_indexunder each other and that would probably result in unpleasant behavior. I think there can be two parallel calls for example fromsync_single_inode()andsync_page_range().
In that case we'd need something likewriteback_indexinside wbc (or
maybe just alterrange_startautomatically whenrange_contis set?) so that parallel callers do no influence each other.
commit e56edfdeea0d336e496962782f08e1224a101cf2
Author: Aneesh Kumar K.V <[email protected]> Date: Fri Jun 6 00:47:35 2008 +0530
mm: Add range_cont mode for writeback.
Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call write_cache_pages multiple times with wbc->nr_to_write set to the maximum possible value limitted by the max journal credits available.
Add a new mode to writeback that enables us to handle this behaviour. If mapping->writeback_index is not set we use wbc->range_start to find the start index and then at the end of write_cache_pages we store the index in writeback_index. Next call to write_cache_pages will start writeout from writeback_index. Also we limit writing to the specified wbc->range_end.
include/linux/writeback.h +1 -0
@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };/*
mm/page-writeback.c +6 -0
@@ -882,6 +882,9 @@ int write_cache_pages(struct address_space *mapping,if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ end =-1 ; + }else if (wbc->range_cont) { + index = wbc->range_start >>PAGE_CACHE_SHIFT ; + end = wbc->range_end >>PAGE_CACHE_SHIFT ; }else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;
@@ -956,6 +959,9 @@ int write_cache_pages(struct address_space *mapping, }if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) mapping->writeback_index = index; + +if (wbc->range_cont) + wbc->range_start = index <<PAGE_CACHE_SHIFT ;return ret; }EXPORT_SYMBOL (write_cache_pages);
Jan Kara
maintainerRe: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
Quoted 24 lines · Aneesh Kumar K.V
Quoted 9 lines · Jan Kara
I like it. I'm only not sure whether there cannot be two users of
write_cache_pages()operating on the same mapping at the same time. Because then they could alterwriteback_indexunder each other and that would probably result in unpleasant behavior. I think there can be two parallel calls for example fromsync_single_inode()andsync_page_range().
In that case we'd need something likewriteback_indexinside wbc (or
maybe just alterrange_startautomatically whenrange_contis set?) so that parallel callers do no influence each other.commit
e56edfdeea0d336e496962782f08e1224a101cf2Author: Aneesh Kumar K.V <[email protected]> Date: Fri Jun 6 00:47:35 2008 +0530mm: Add
range_contmode for writeback.Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call
write_cache_pagesmultiple times withwbc->nr_to_writeset to the maximum possible value limitted by the max journal credits available.
Quoted 6 lines
Add a new mode to writeback that enables us to handle this behaviour. If
mapping->writeback_indexis not set we usewbc->range_startto find the start index and then at the end ofwrite_cache_pageswe store the index inwriteback_index. Next call towrite_cache_pageswill start writeout fromwriteback_index. Also we limit writing to the specifiedwbc->range_end.
I think this changelog is out of date...
Quoted 19 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>include/linux/writeback.h +1
-0@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };/* mm/page-writeback.c +0
-0
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 887
Quoted 6 lines
mm/page-writeback.c +3
-0@@ -882,6 +882,9 @@ int write_cache_pages(struct address_space *mapping,if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ end =-1 ; + }else if (wbc->range_cont) { + index = wbc->range_start >>PAGE_CACHE_SHIFT ; + end = wbc->range_end >>PAGE_CACHE_SHIFT ;
Hmm, why isn't this in the next else?
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 967
Quoted 13 lines
mm/page-writeback.c +3
-0}else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;@@ -956,6 +959,9 @@ int write_cache_pages(struct address_space *mapping, }if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) mapping->writeback_index = index; + +if (wbc->range_cont) + wbc->range_start = index <<PAGE_CACHE_SHIFT ;return ret; }EXPORT_SYMBOL (write_cache_pages);
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
Quoted 25 lines · Jan Kara
Quoted 24 lines · Aneesh Kumar K.V
Quoted 9 lines · Jan Kara
I like it. I'm only not sure whether there cannot be two users of
write_cache_pages()operating on the same mapping at the same time. Because then they could alterwriteback_indexunder each other and that would probably result in unpleasant behavior. I think there can be two parallel calls for example fromsync_single_inode()andsync_page_range().
In that case we'd need something likewriteback_indexinside wbc (or
maybe just alterrange_startautomatically whenrange_contis set?) so that parallel callers do no influence each other.commit
e56edfdeea0d336e496962782f08e1224a101cf2Author: Aneesh Kumar K.V <[email protected]> Date: Fri Jun 6 00:47:35 2008 +0530mm: Add
range_contmode for writeback.Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call
write_cache_pagesmultiple times withwbc->nr_to_writeset to the maximum possible value limitted by the max journal credits available.
Quoted 7 lines
Quoted 6 lines
Add a new mode to writeback that enables us to handle this behaviour. If
mapping->writeback_indexis not set we usewbc->range_startto find the start index and then at the end ofwrite_cache_pageswe store the index inwriteback_index. Next call towrite_cache_pageswill start writeout fromwriteback_index. Also we limit writing to the specifiedwbc->range_end.I think this changelog is out of date...
The patch in the patchqueue have an updated changelog.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>include/linux/writeback.h +1
-0@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };
Quoted 13 lines
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 887
Quoted 12 lines
include/linux/writeback.h +0
-0/* mm/page-writeback.c +3
-0@@ -882,6 +882,9 @@ int write_cache_pages(struct address_space *mapping,if (wbc->range_cyclic) { index = mapping->writeback_index;/* Start from prev offset */ end =-1 ; + }else if (wbc->range_cont) { + index = wbc->range_start >>PAGE_CACHE_SHIFT ; + end = wbc->range_end >>PAGE_CACHE_SHIFT ;Hmm, why isn't this in the next else?
The patch in the patchqueue have
+ } else if (wbc->range_cont) {
+ index = wbc->range_start >> PAGE_CACHE_SHIFT; + end = wbc->range_end >> PAGE_CACHE_SHIFT; + /* + * we want to set the writeback_index when congested + * and we are requesting for nonblocking mode, + * because we won't force the range_cont mode then + */
+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
+ range_whole = 1;
I was not clear about setting scanned = 1; Now that I read it again I guess it makes sense to set scanned = 1. We don't need to start the writeout from index=0 when range_cont is set.
Quoted 16 lines
Quoted 5 lines
mm/page-writeback.c +0
-0}else { index = wbc->range_start >>PAGE_CACHE_SHIFT ; end = wbc->range_end >>PAGE_CACHE_SHIFT ;mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 967
Quoted 9 lines
mm/page-writeback.c +3
-0@@ -956,6 +959,9 @@ int write_cache_pages(struct address_space *mapping, }if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) mapping->writeback_index = index; + +if (wbc->range_cont) + wbc->range_start = index <<PAGE_CACHE_SHIFT ;return ret; }EXPORT_SYMBOL (write_cache_pages);Honza
Attaching the updated patch.
Mingming,
Can you update the patchqueu with the below attached patch ?
-aneesh
mm: Add range_cont mode for writeback.
From: Aneesh Kumar K.V <[email protected]>
Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call write_cache_pages multiple times with wbc->nr_to_write set to the maximum possible value limitted by the max journal credits available.
Add a new mode to writeback that enables us to handle this behaviour. In the new mode we update the wbc->range_start to point to the new offset to be written. Next call to call to write_cache_pages will start writeout from specified range_start offset. In the new mode we also limit writing to the specified wbc->range_end.
---
include/linux/writeback.h | 1 + mm/page-writeback.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-)
include/linux/writeback.h +1 -0
@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };/*
mm/page-writeback.c +3 -0
@@ -956,6 +956,9 @@ int write_cache_pages(struct address_space *mapping, }if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) mapping->writeback_index = index; + +if (wbc->range_cont) + wbc->range_start = index <<PAGE_CACHE_SHIFT ;return ret; }EXPORT_SYMBOL (write_cache_pages);
Re: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
Quoted 27 lines
Attaching the updated patch.
Mingming,
Can you update the patchqueu with the below attached patch ?
-aneesh
mm: Add
range_contmode for writeback.From: Aneesh Kumar K.V <[email protected]>
Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call
write_cache_pagesmultiple times withwbc->nr_to_writeset to the maximum possible value limitted by the max journal credits available.Add a new mode to writeback that enables us to handle this behaviour. In the new mode we update the
wbc->range_startto point to the new offset to be written. Next call to call towrite_cache_pageswill start writeout from specifiedrange_startoffset. In the new mode we also limit writing to the specifiedwbc->range_end.
Quoted 1 line
Signed-off-by Aneesh Kumar K.V <[email protected]>
Honza
Quoted 33 lines
---
include/linux/writeback.h | 1 + mm/page-writeback.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-)include/linux/writeback.h +1
-0@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };/* mm/page-writeback.c +3
-0@@ -956,6 +956,9 @@ int write_cache_pages(struct address_space *mapping, }if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) mapping->writeback_index = index; + +if (wbc->range_cont) + wbc->range_start = index <<PAGE_CACHE_SHIFT ;return ret; }EXPORT_SYMBOL (write_cache_pages);
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH] ext4: Fix delalloc sync hang with journal lock inversion
In reply to Aneesh Kumar K.VQuoted 6 lines · Aneesh Kumar K.V
Attaching the updated patch.
Mingming,
Can you update the patchqueu with the below attached patch ?
Sure, just did.
Mingming
Quoted 59 lines
-aneesh
mm: Add
range_contmode for writeback.From: Aneesh Kumar K.V <[email protected]>
Filesystems like ext4 needs to start a new transaction in the writepages for block allocation. This happens with delayed allocation and there is limit to how many credits we can request from the journal layer. So we call
write_cache_pagesmultiple times withwbc->nr_to_writeset to the maximum possible value limitted by the max journal credits available.Add a new mode to writeback that enables us to handle this behaviour. In the new mode we update the
wbc->range_startto point to the new offset to be written. Next call to call towrite_cache_pageswill start writeout from specifiedrange_startoffset. In the new mode we also limit writing to the specifiedwbc->range_end.Signed-off-by Aneesh Kumar K.V <[email protected]>---
include/linux/writeback.h | 1 + mm/page-writeback.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-)include/linux/writeback.h +1
-0@@ -63,6 +63,7 @@ struct writeback_control { unsigned for_writepages:1; /* This is a writepages() call */ unsigned range_cyclic:1; /* range_start is cyclic */ unsigned more_io:1; /* more io to be dispatched */ + unsigned range_cont:1; };/* mm/page-writeback.c +3
-1@@ -956,6 +956,9 @@ int write_cache_pages(struct address_space *mapping, }if (wbc->range_cyclic || (range_whole && wbc->nr_to_write >0 )) mapping->writeback_index = index; + +if (wbc->range_cont) + wbc->range_start = index <<PAGE_CACHE_SHIFT ;return ret; }EXPORT_SYMBOL (write_cache_pages); --To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html