Ordered mode rewrite for jbd2/ext4
Subsystems (5)
Jan Kara
maintainerHi,
So I've split and ported ordered mode rewrite for ext4+jbd2.
The core of the rewrite are two patches
jbd2-Implement-data-ordered-mode-handling-via-inode.patch ext4-Use-new-framework-for-data-ordered-mode-in-JBD.patch
They also need two trivial fixes:
vfs-export-filemap_fdatawrite_range.patch ext4-Use-new-framework-for-data-ordered-mode-in-JBD.patch
And finally there's a patch removing old ordered mode from jbd2:
jbd2-Remove-data-ordered-mode-support-using-jbd-buf.patch
I've created the patches to be added to the ext4 patch queue just after inversion of page lock and transaction start.
I have refreshed the following patches in the ext4 queue to apply cleanly and also fixed some typos in them and added one BUG_ON():
ext4-delalloc-sync-hang-with-journal-lock-inverse-fix.patch ext4-delalloc-inverse-jbd-and-page-lock-ordering.patch ext4-inverse-jbd-and-page-locking-order.patch
Finally, I've rewritten checks in writepage so ext4-Add-validation-to-jbd-lock-inversion-patch-and.patch should be replaced with ext4-add-checks-to-writepage
as we spoke about it with Aneesh.
All the patches are attached and I'll also post the new ones separately for more convenient review. The tests for 4k blocksize run fine for me. The kernel oopses for 1k blocksize because of a problem in ext4_page_mkwrite()
- I'll post that in a separate mail. If noone objects, patches can be added to ext4 patch queue.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
series +9 -2
@@ -42,9 +42,16 @@ ext4-mb-add-ext4_has_free_blocks-check.patch ext4-page-mkwrite.patch #page lock and transaction lock reverse series -ext4-inverse-jbd-and-page-locking-order.patch vfs-Move-mark_inode_dirty-from-under-page-lock-in.patch -ext4-Add-validation-to-jbd-lock-inversion-patch-and.patch +ext4-inverse-jbd-and-page-locking-order.patch +ext4-add-checks-to-writepage + +# Ordered mode rewrite +ext4-Set-journal-pointer-to-NULL-when-journal-is-re.patch +vfs-export-filemap_fdatawrite_range.patch +jbd2-Implement-data-ordered-mode-handling-via-inode.patch +ext4-Use-new-framework-for-data-ordered-mode-in-JBD.patch +jbd2-Remove-data-ordered-mode-support-using-jbd-buf.patch # New delayed allocation patch delalloc-vfs.patch
ext4: Add checks to writepage()
Add checks to writepage() calls to check that all pages are properly mapped and not delayed.
fs/ext4/inode.c +43 -1
72 lines not on this page · raw message
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 +76 -28
144 lines not on this page · raw message
ext4: Fix delalloc sync hang with journal lock inversion
From: Aneesh Kumar K.V <[email protected]>
---
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 +68 -32
158 lines not on this page · raw message
fs/mpage.c +7 -7
@@ -849,13 +849,12 @@ static void mpage_put_bnr_to_bhs(struct 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 mif (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 p 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_spapagevec_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 ;
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
From: Jan Kara <[email protected]>
Date: Wed, 21 May 2008 17:01:22 +0200
Subject: [PATCH] ext4: Set journal pointer to NULL when journal is released
Set sbi->s_journal to NULL after we call journal_destroy(). This will be later needed because after journal_destroy() is called, ext4_clear_inode() can still be called for some inodes (e.g. root inode) and we'll need to detect there that journal doesn't exists anymore.
--- fs/ext4/super.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/ext4/super.c +2 -0
@@ -506,6 +506,7 @@ static void ext4_put_super (struct superext4_ext_release (sb);ext4_xattr_put_super (sb);jbd2_journal_destroy (sbi->s_journal); + sbi->s_journal =NULL ;if (!(sb->s_flags &MS_RDONLY )) {EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); es->s_state =cpu_to_le16 (sbi->s_mount_state);
@@ -2398,6 +2399,7 @@ cantfind_ext4: failed_mount4:jbd2_journal_destroy (sbi->s_journal); + sbi->s_journal =NULL ; failed_mount3:percpu_counter_destroy (&sbi->s_freeblocks_counter);percpu_counter_destroy (&sbi->s_freeinodes_counter);
From: Jan Kara <[email protected]>
Date: Thu, 22 May 2008 00:51:17 +0200
Subject: [PATCH] ext4: Use new framework for data=ordered mode in JBD2
--- fs/ext4/ext4_i.h | 1 + fs/ext4/ext4_jbd2.h | 7 ++- fs/ext4/ialloc.c | 1 + fs/ext4/inode.c | 160 ++++++++++++++++++--------------------------------- fs/ext4/super.c | 4 +- 5 files changed, 67 insertions(+), 106 deletions(-)
fs/ext4/ext4_i.h +1 -0
@@ -150,6 +150,7 @@ struct ext4_inode_info {*/ struct rw_semaphore i_data_sem;struct inode vfs_inode; +struct jbd2_inode jinode;unsigned long i_ext_generation;struct ext4_ext_cache i_cached_extent;
fs/ext4/ext4_jbd2.h +5 -2
@@ -154,8 +154,6 @@ int __ext4_journal_dirty_metadata(const#define ext4_journal_forget (handle, bh) \ __ext4_journal_forget(__FUNCTION__, (handle), (bh)) -int ext4_journal_dirty_data (handle_t *handle,struct buffer_head *bh); -handle_t *ext4_journal_start_sb (struct super_block *sb,int nblocks);int __ext4_journal_stop (const char *where,handle_t *handle);
@@ -192,6 +190,11 @@ static inline int ext4_journal_force_comreturn jbd2_journal_force_commit (journal); } +static inline int ext4_jbd2_file_inode (handle_t *handle,struct inode *inode) +{ +return jbd2_journal_file_inode (handle, &EXT4_I (inode)->jinode); +} +/* super.c */ int ext4_force_commit (struct super_block *sb);
fs/ext4/ialloc.c +1 -0
@@ -820,6 +820,7 @@ got: ei->i_state =EXT4_STATE_NEW ; ei->i_extra_isize =EXT4_SB (sb)->s_want_extra_isize; +jbd2_journal_init_jbd_inode (&ei->jinode, inode); ret = inode;if (DQUOT_ALLOC_INODE (inode)) {
fs/ext4/inode.c +56 -114
268 lines not on this page · raw message
fs/ext4/super.c +3 -1
@@ -637,6 +637,8 @@ static void ext4_clear_inode(struct inodEXT4_I (inode)->i_block_alloc_info =NULL ;if (unlikely (rsv))kfree (rsv); +jbd2_journal_release_jbd_inode (EXT4_SB (inode->i_sb)->s_journal, + &EXT4_I (inode)->jinode); }static inline void ext4_show_quota_options (struct seq_file *seq,struct super_block *sb)
@@ -3353,7 +3355,7 @@ static ssize_t ext4_quota_write(struct s err =ext4_journal_dirty_metadata (handle, bh); else {/* Always do at least ordered writes for quotas */ - err =ext4_journal_dirty_data (handle, bh); + err =ext4_jbd2_file_inode (handle, inode);mark_buffer_dirty (bh); }brelse (bh);
fs/ext4/mballoc.c +2 -0
@@ -2255,6 +2255,8 @@ static int ext4_mb_init_backend(struct sprintk (KERN_ERR "EXT4-fs: can't get new inode\n" ); goto err_freesgi; } +jbd2_journal_init_jbd_inode (&EXT4_I (sbi->s_buddy_cache)->jinode, + sbi->s_buddy_cache);EXT4_I (sbi->s_buddy_cache)->i_disksize =0 ; metalen =sizeof (*meta_group_info) <<EXT4_DESC_PER_BLOCK_BITS (sb);
From: Jan Kara <[email protected]>
Date: Wed, 21 May 2008 17:48:42 +0200
Subject: [PATCH] jbd2: Implement data=ordered mode handling via inodes
This patch adds necessary framework into JBD2 to be able to track inodes with each transaction and write-out their dirty data during transaction commit time.
--- fs/jbd2/commit.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/jbd2/journal.c | 52 ++++++++++++++++++++++++++++ fs/jbd2/transaction.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/jbd2.h | 42 +++++++++++++++++++++++ 4 files changed, 270 insertions(+), 0 deletions(-)
fs/jbd2/commit.c +90 -0
114 lines not on this page · raw message
fs/jbd2/journal.c +52 -0
64 lines not on this page · raw message
fs/jbd2/transaction.c +86 -0
95 lines not on this page · raw message
include/linux/jbd2.h +42 -0
60 lines not on this page · raw message
Quoted 1 line
From
c0b315ae14dd43e6684edeb47912077bf480e59cMon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Thu, 22 May 2008 01:28:16 +0200
Subject: [PATCH] jbd2: Remove data=ordered mode support using jbd buffer heads
--- fs/jbd2/checkpoint.c | 1 - fs/jbd2/commit.c | 230 ++----------------------------------------------- fs/jbd2/journal.c | 1 - fs/jbd2/transaction.c | 217 ++--------------------------------------------- include/linux/jbd2.h | 29 ++----- 5 files changed, 21 insertions(+), 457 deletions(-)
fs/jbd2/checkpoint.c +0 -1
@@ -688,7 +688,6 @@ void __jbd2_journal_drop_transaction(jouJ_ASSERT (transaction->t_state ==T_FINISHED );J_ASSERT (transaction->t_buffers ==NULL ); -J_ASSERT (transaction->t_sync_datalist ==NULL );J_ASSERT (transaction->t_forget ==NULL );J_ASSERT (transaction->t_iobuf_list ==NULL );J_ASSERT (transaction->t_shadow_list ==NULL );
fs/jbd2/commit.c +8 -213
297 lines not on this page · raw message
fs/jbd2/journal.c +0 -1
@@ -50,7 +50,6 @@ EXPORT_SYMBOL(jbd2_journal_unlock_updateEXPORT_SYMBOL (jbd2_journal_get_write_access);EXPORT_SYMBOL (jbd2_journal_get_create_access);EXPORT_SYMBOL (jbd2_journal_get_undo_access); -EXPORT_SYMBOL (jbd2_journal_dirty_data);EXPORT_SYMBOL (jbd2_journal_dirty_metadata);EXPORT_SYMBOL (jbd2_journal_release_buffer);EXPORT_SYMBOL (jbd2_journal_forget);
fs/jbd2/transaction.c +6 -211
271 lines not on this page · raw message
include/linux/jbd2.h +7 -22
@@ -543,24 +543,12 @@ struct transaction_sstruct journal_head *t_reserved_list;/* -* Doubly-linked circular list of all buffers under writeout during -* commit [j_list_lock] -*/ -struct journal_head *t_locked_list; - -/* * Doubly-linked circular list of all metadata buffers owned by this * transaction [j_list_lock] */ struct journal_head *t_buffers;/* -* Doubly-linked circular list of all data buffers still to be -* flushed before this transaction can be committed [j_list_lock] -*/ -struct journal_head *t_sync_datalist; - -/* * Doubly-linked circular list of all forget buffers (superseded * buffers which we can un-checkpoint once this transaction commits) * [j_list_lock]
@@ -1041,7 +1029,6 @@ extern int jbd2_journal_extend (handle_extern int jbd2_journal_get_write_access (handle_t *,struct buffer_head *);extern int jbd2_journal_get_create_access (handle_t *,struct buffer_head *);extern int jbd2_journal_get_undo_access (handle_t *,struct buffer_head *); -extern int jbd2_journal_dirty_data (handle_t *,struct buffer_head *);extern int jbd2_journal_dirty_metadata (handle_t *,struct buffer_head *);extern void jbd2_journal_release_buffer (handle_t *,struct buffer_head *);extern int jbd2_journal_forget (handle_t *,struct buffer_head *);
@@ -1220,15 +1207,13 @@ static inline int jbd_space_needed(journ/* journaling buffer types */ #define BJ_None 0/* Not journaled */ -#define BJ_SyncData 1/* Normal data: flush before commit */ -#define BJ_Metadata 2/* Normal journaled metadata */ -#define BJ_Forget 3/* Buffer superseded by this transaction */ -#define BJ_IO 4/* Buffer is for temporary IO use */ -#define BJ_Shadow 5/* Buffer contents being shadowed to the log */ -#define BJ_LogCtl 6/* Buffer contains log descriptors */ -#define BJ_Reserved 7/* Buffer is reserved for access by journal */ -#define BJ_Locked 8/* Locked for I/O during commit */ -#define BJ_Types 9 +#define BJ_Metadata 1/* Normal journaled metadata */ +#define BJ_Forget 2/* Buffer superseded by this transaction */ +#define BJ_IO 3/* Buffer is for temporary IO use */ +#define BJ_Shadow 4/* Buffer contents being shadowed to the log */ +#define BJ_LogCtl 5/* Buffer contains log descriptors */ +#define BJ_Reserved 6/* Buffer is reserved for access by journal */ +#define BJ_Types 7extern int jbd_blocks_per_page (struct inode *inode);
From: Jan Kara <[email protected]>
Date: Wed, 21 May 2008 17:05:23 +0200
Subject: [PATCH] vfs: export filemap_fdatawrite_range()
Make filemap_fdatawrite_range() function public, so that it can later be used in ordered mode rewrite by JBD/JBD2.
--- include/linux/fs.h | 2 ++ mm/filemap.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletions(-)
include/linux/fs.h +2 -0
@@ -1741,6 +1741,8 @@ extern int wait_on_page_writeback_range( pgoff_t start, pgoff_t end);extern int __filemap_fdatawrite_range (struct address_space *mapping,loff_t start,loff_t end,int sync_mode); +extern int filemap_fdatawrite_range (struct address_space *mapping, +loff_t start,loff_t end);extern long do_fsync (struct file *file,int datasync);extern void sync_supers (void );
mm/filemap.c +2 -1
@@ -236,11 +236,12 @@ int filemap_fdatawrite(struct address_sp }EXPORT_SYMBOL (filemap_fdatawrite); -static int filemap_fdatawrite_range (struct address_space *mapping,loff_t start, +int filemap_fdatawrite_range (struct address_space *mapping,loff_t start,loff_t end) {return __filemap_fdatawrite_range (mapping, start, end,WB_SYNC_ALL ); } +EXPORT_SYMBOL (filemap_fdatawrite_range);/** * filemap_flush - mostly a non-blocking flush
Jan Kara
maintainerHello,
Sorry for replying to myself but I remembered one more thing :)
Quoted 10 lines
So I've split and ported ordered mode rewrite for ext4+jbd2.
The core of the rewrite are two patchesjbd2-Implement-data-ordered-mode-handling-via-inode.patch ext4-Use-new-framework-for-data-ordered-mode-in-JBD.patch
They also need two trivial fixes:
vfs-export-filemap_fdatawrite_range.patch ext4-Use-new-framework-for-data-ordered-mode-in-JBD.patch
Quoted 8 lines
And finally there's a patch removing old ordered mode from jbd2:
jbd2-Remove-data-ordered-mode-support-using-jbd-buf.patchI've created the patches to be added to the ext4 patch queue just after inversion of page lock and transaction start.
I have refreshed the following patches in the ext4 queue to apply cleanly and also fixed some typos in them and added one
BUG_ON():
I've fixed one more problem - during umount, we were callingext4_da_writepages() which starts a transaction and lockdep complains (because superblock lock ranks below transaction start). Because during this time, we can be actually called only for special inodes (like journal inode) from iput() we don't really need to start a transaction. So I've added check into ext4_da_writepages() to bail out if mapping has no pages (hmm, maybe adding there a check for mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) would be even better than what I've added).
Quoted 9 lines
ext4-delalloc-sync-hang-with-journal-lock-inverse-fix.patch ext4-delalloc-inverse-jbd-and-page-lock-ordering.patch ext4-inverse-jbd-and-page-locking-order.patch
Finally, I've rewritten checks in writepage so ext4-Add-validation-to-jbd-lock-inversion-patch-and.patch should be replaced with ext4-add-checks-to-writepage
Quoted 7 lines
as we spoke about it with Aneesh.
All the patches are attached and I'll also post the new ones separately for more convenient review. The tests for 4k blocksize run fine for me. The kernel oopses for 1k blocksize because of a problem in
ext4_page_mkwrite()
- I'll post that in a separate mail. If noone objects, patches can be added to ext4 patch queue.
Honza
Theodore Tso
maintainerQuoted 4 lines · Jan Kara
Hi,
So I've split and ported ordered mode rewrite for ext4+jbd2.
The core of the rewrite are two patches
I've integrated your patches into the unstable portion of the patch queue; I have not had a chance to review them yet, but this way they can start getting tested.
- Ted
Quoted 30 lines · Jan Kara
Hi,
So I've split and ported ordered mode rewrite for ext4+jbd2.
The core of the rewrite are two patchesjbd2-Implement-data-ordered-mode-handling-via-inode.patch ext4-Use-new-framework-for-data-ordered-mode-in-JBD.patch
They also need two trivial fixes:
vfs-export-filemap_fdatawrite_range.patch ext4-Use-new-framework-for-data-ordered-mode-in-JBD.patchAnd finally there's a patch removing old ordered mode from jbd2:
jbd2-Remove-data-ordered-mode-support-using-jbd-buf.patchI've created the patches to be added to the ext4 patch queue just after inversion of page lock and transaction start.
I have refreshed the following patches in the ext4 queue to apply cleanly and also fixed some typos in them and added one
BUG_ON():ext4-delalloc-sync-hang-with-journal-lock-inverse-fix.patch ext4-delalloc-inverse-jbd-and-page-lock-ordering.patch ext4-inverse-jbd-and-page-locking-order.patch
Finally, I've rewritten checks in writepage so ext4-Add-validation-to-jbd-lock-inversion-patch-and.patch should be replaced with ext4-add-checks-to-writepage
Quoted 8 lines
as we spoke about it with Aneesh.
All the patches are attached and I'll also post the new ones separately for more convenient review. The tests for 4k blocksize run fine for me. The kernel oopses for 1k blocksize because of a problem in
ext4_page_mkwrite()
- I'll post that in a separate mail. If noone objects, patches can be added to ext4 patch queue.
Thanks!
I have added the patches to the patch queue, will take a close look later.
Regards,
Mingming
Quoted 1 line
Honza