Ext4 patches for the next merge window
Subsystems (8)
Theodore Ts'o
maintainerPATCH 3/52 ext4: Use BUG_ON() instead of BUG()
In reply to Theodore Ts'oFrom: Julia Lawall <[email protected]>
if (...) BUG(); should be replaced with BUG_ON(...) when the test has no side-effects to allow a definition of BUG_ON that drops the code completely.
The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@ disable unlikely @ expression E,f; @@
(
if (<... f(...) ...>) { BUG(); }
|
- if (unlikely(E)) { BUG(); }
+ BUG_ON(E);
)
@@ expression E,f; @@
(
if (<... f(...) ...>) { BUG(); }
|
- if (E) { BUG(); }
+ BUG_ON(E);
)
// </smpl>
--- fs/ext4/balloc.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
fs/ext4/balloc.c +1 -2
@@ -409,8 +409,7 @@ restart: prev = rsv; }printk ("Window map complete.\n" ); -if (bad) -BUG (); +BUG_ON (bad); }#define rsv_window_dump (root, verbose) \ __rsv_window_dump((root), (verbose), __func__)
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerThe following set of patches are being prepared for pushing to Linus during the next patch window. Aside from a large number of cleanups the big new feature in this patchset is delayed allocation support.
I've been running this patch series on my laptop for the past couple of days in production, and it's been working quite well for me.
- Ted
Theodore Ts'o
maintainerPATCH 10/52 ext4: Rename read_block_bitmap() to ext4_read_block_bitmap()
In reply to Theodore Ts'oSince this a non-static function, make it be ext4 specific to avoid conflicts with potentially other filesystems.
--- fs/ext4/balloc.c | 12 ++++++------ fs/ext4/group.h | 2 +- fs/ext4/ialloc.c | 2 +- fs/ext4/mballoc.c | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-)
fs/ext4/balloc.c +6 -6
@@ -295,7 +295,7 @@ err_out:return 0 ; }/** -* read_block_bitmap() +* ext4_read_block_bitmap() * @sb: super block * @block_group: given block group *
@@ -305,7 +305,7 @@ err_out:* Return buffer_head on success or NULL in case of failure. */ struct buffer_head * -read_block_bitmap (struct super_block *sb,ext4_group_t block_group) +ext4_read_block_bitmap (struct super_block *sb,ext4_group_t block_group) {struct ext4_group_desc * desc;struct buffer_head * bh =NULL ;
@@ -693,7 +693,7 @@ do_more: count -= overflow; }brelse (bitmap_bh); - bitmap_bh =read_block_bitmap (sb, block_group); + bitmap_bh =ext4_read_block_bitmap (sb, block_group);if (!bitmap_bh) goto error_return; desc =ext4_get_group_desc (sb, block_group, &gd_bh);
@@ -1733,7 +1733,7 @@ retry_alloc: my_rsv =NULL ;if (free_blocks >0 ) { - bitmap_bh =read_block_bitmap (sb, group_no); + bitmap_bh =ext4_read_block_bitmap (sb, group_no);if (!bitmap_bh) goto io_error; grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
@@ -1769,7 +1769,7 @@ retry_alloc:continue ;brelse (bitmap_bh); - bitmap_bh =read_block_bitmap (sb, group_no); + bitmap_bh =ext4_read_block_bitmap (sb, group_no);if (!bitmap_bh) goto io_error;/*
@@ -1985,7 +1985,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)continue ; desc_count +=le16_to_cpu (gdp->bg_free_blocks_count);brelse (bitmap_bh); - bitmap_bh =read_block_bitmap (sb, i); + bitmap_bh =ext4_read_block_bitmap (sb, i);if (bitmap_bh ==NULL )continue ;
fs/ext4/group.h +1 -1
@@ -13,7 +13,7 @@ extern __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 group, struct ext4_group_desc *gdp);extern int ext4_group_desc_csum_verify (struct ext4_sb_info *sbi,__u32 group,struct ext4_group_desc *gdp); -struct buffer_head *read_block_bitmap (struct super_block *sb, +struct buffer_head *ext4_read_block_bitmap (struct super_block *sb,ext4_group_t block_group); extern unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
fs/ext4/ialloc.c +1 -1
@@ -600,7 +600,7 @@ got:/* We may have to initialize the block bitmap if it isn't already */ if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_GDT_CSUM ) && gdp->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) { -struct buffer_head *block_bh =read_block_bitmap (sb, group); +struct buffer_head *block_bh =ext4_read_block_bitmap (sb, group);BUFFER_TRACE (block_bh,"get block bitmap access" ); err =ext4_journal_get_write_access (handle, block_bh);
fs/ext4/mballoc.c +5 -5
@@ -2320,7 +2320,7 @@ static int ext4_mb_init_backend(struct super_block *sb) meta_group_info[j]->bb_bitmap =kmalloc (sb->s_blocksize,GFP_KERNEL );BUG_ON (meta_group_info[j]->bb_bitmap ==NULL ); - bh =read_block_bitmap (sb, i); + bh =ext4_read_block_bitmap (sb, i);BUG_ON (bh ==NULL );memcpy (meta_group_info[j]->bb_bitmap, bh->b_data, sb->s_blocksize);
@@ -2763,7 +2763,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, err = -EIO ; - bitmap_bh =read_block_bitmap (sb, ac->ac_b_ex.fe_group); + bitmap_bh =ext4_read_block_bitmap (sb, ac->ac_b_ex.fe_group);if (!bitmap_bh) goto out_err;
@@ -3585,7 +3585,7 @@ ext4_mb_discard_group_preallocations(struct super_block *sb,if (list_empty (&grp->bb_prealloc_list))return 0 ; - bitmap_bh =read_block_bitmap (sb, group); + bitmap_bh =ext4_read_block_bitmap (sb, group);if (bitmap_bh ==NULL ) {/* error handling here */ ext4_mb_release_desc (&e4b);
@@ -3759,7 +3759,7 @@ repeat: err =ext4_mb_load_buddy (sb, group, &e4b);BUG_ON (err !=0 );/* error handling here */ - bitmap_bh =read_block_bitmap (sb, group); + bitmap_bh =ext4_read_block_bitmap (sb, group);if (bitmap_bh ==NULL ) {/* error handling here */ ext4_mb_release_desc (&e4b);
@@ -4258,7 +4258,7 @@ do_more: overflow = bit + count -EXT4_BLOCKS_PER_GROUP (sb); count -= overflow; } - bitmap_bh =read_block_bitmap (sb, block_group); + bitmap_bh =ext4_read_block_bitmap (sb, block_group);if (!bitmap_bh) goto error_return; gdp =ext4_get_group_desc (sb, block_group, &gd_bh);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 12/52 jbd2: Add commit time into the commit block
In reply to Theodore Ts'oCarlo Wood has demonstrated that it's possible to recover deleted files from the journal. Something that will make this easier is if we can put the time of the commit into commit block.
--- fs/jbd2/commit.c | 3 +++ include/linux/jbd2.h | 2 ++ 2 files changed, 5 insertions(+), 0 deletions(-)
fs/jbd2/commit.c +3 -0
@@ -112,6 +112,7 @@ static int journal_submit_commit_record(journal_t *journal,struct buffer_head *bh;int ret;int barrier_done =0 ; +struct timespec now =current_kernel_time ();if (is_journal_aborted (journal))return 0 ;
@@ -126,6 +127,8 @@ static int journal_submit_commit_record(journal_t *journal, tmp->h_magic =cpu_to_be32 (JBD2_MAGIC_NUMBER ); tmp->h_blocktype =cpu_to_be32 (JBD2_COMMIT_BLOCK ); tmp->h_sequence =cpu_to_be32 (commit_transaction->t_tid); + tmp->h_commit_sec =cpu_to_be64 (now.tv_sec); + tmp->h_commit_nsec =cpu_to_be32 (now.tv_nsec);if (JBD2_HAS_COMPAT_FEATURE (journal,JBD2_FEATURE_COMPAT_CHECKSUM )) {
include/linux/jbd2.h +2 -0
@@ -168,6 +168,8 @@ struct commit_header {unsigned char h_chksum_size;unsigned char h_padding[2 ];__be32 h_chksum[JBD2_CHECKSUM_BYTES ]; +__be64 h_commit_sec; +__be32 h_commit_nsec; };/*
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 6/52 ext4: Fix ext4_mb_init_cache return error
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
ext4_mb_init_cache() incorrectly always return EIO on success. This causes the caller of ext4_mb_init_cache() fail when it checks the return value.
--- fs/ext4/mballoc.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/ext4/mballoc.c +1 -0
@@ -803,6 +803,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore)if (!buffer_uptodate (bh[i])) goto out; + err =0 ; first_block = page->index * blocks_per_page;for (i =0 ; i < blocks_per_page; i++) {int group;
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 32/52 ext4: Documentation updates.
In reply to Theodore Ts'oFrom: Jose R. Santos <[email protected]>
Some of the information in Documentation/filesystems/ext4.txt is out of date and in need of an update.
--- Documentation/filesystems/ext4.txt | 102 ++++++++++++++++++++--------------- 1 files changed, 58 insertions(+), 44 deletions(-)
Documentation/filesystems/ext4.txt +58 -44
@@ -13,72 +13,85 @@ Mailing list: [email protected] 1. Quick usage instructions: =========================== - - Grab updated e2fsprogs from + - Compile and install the latest version of e2fsprogs (at least + 1.41-WIP-0617) from: + ftp://ftp.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs-interim/ - This is a patchset on top of e2fsprogs-1.39, which can be found at - ftp://ftp.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/ - - It's still mke2fs -j /dev/hda1 + or grab the latest git repository from: + + git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git + + - Create a new filesystem using the ext4dev filesystem type: + + # mke2fs -t ext4dev /dev/hda1 + + Or configure an existing ext3 filesystem to support extents and set + the test_fs flag to indicate that it's ok for an in-development + filesystem to touch this filesystem: - - mount /dev/hda1 /wherever -t ext4dev + # tune2fs -O extents -E test_fs /dev/hda1 - - To enable extents, + If the filesystem was created with 128 byte inodes, it can be + converted to use 256 byte for greater efficiency via: - mount /dev/hda1 /wherever -t ext4dev -o extents + # tune2fs -I 256 /dev/hda1 - - The filesystem is compatible with the ext3 driver until you add a file - which has extents (ie: `mount -o extents', then create a file). + (Note: we currently do not have tools to convert an ext4dev + filesystem back to ext3; so please do not do try this on production + filesystems.) - NOTE: The "extents" mount flag is temporary. It will soon go away and - extents will be enabled by the "-o extents" flag to mke2fs or tune2fs + - Mounting: + + # mount -t ext4dev /dev/hda1 /wherever - When comparing performance with other filesystems, remember that - ext3/4 by default offers higher data integrity guarantees than most. So - when comparing with a metadata-only journalling filesystem, use `mount -o - data=writeback'. And you might as well use `mount -o nobh' too along - with it. Making the journal larger than the mke2fs default often helps - performance with metadata-intensive workloads. + ext3/4 by default offers higher data integrity guarantees than most. + So when comparing with a metadata-only journalling filesystem, such + as ext3, use `mount -o data=writeback'. And you might as well use + `mount -o nobh' too along with it. Making the journal larger than + the mke2fs default often helps performance with metadata-intensive + workloads. 2. Features =========== 2.1 Currently available -* ability to use filesystems > 16TB +* ability to use filesystems > 16TB (e2fsprogs support not available yet) * extent format reduces metadata overhead (RAM, IO for access, transactions) * extent format more robust in face of on-disk corruption due to magics, * internal redunancy in tree - -2.1 Previously available, soon to be enabled by default by "mkefs.ext4": - -* dir_index and resize inode will be on by default -* large inodes will be used by default for fast EAs, nsec timestamps, etc +* improved file allocation (multi-block alloc, delayed alloc) +* fix 32000 subdirectory limit +* nsec timestamps for mtime, atime, ctime, create time +* inode version field on disk (NFSv4, Lustre) +* reduced e2fsck time via uninit_bg feature +* journal checksumming for robustness, performance +* persistent file preallocation (e.g for streaming media, databases) +* ability to pack bitmaps and inode tables into larger virtual groups via the + flex_bg feature +* large file support +* Inode allocation using large virtual block groups via flex_bg 2.2 Candidate features for future inclusion -There are several under discussion, whether they all make it in is -partly a function of how much time everyone has to work on them: +* Online defrag (patches available but not well tested) +* reduced mke2fs time via lazy itable initialization in conjuction with + the uninit_bg feature (capability to do this is available in e2fsprogs + but a kernel thread to do lazy zeroing of unused inode table blocks + after filesystem is first mounted is required for safety) -* improved file allocation (multi-block alloc, delayed alloc; basically done) -* fix 32000 subdirectory limit (patch exists, needs some e2fsck work) -* nsec timestamps for mtime, atime, ctime, create time (patch exists, - needs some e2fsck work) -* inode version field on disk (NFSv4, Lustre; prototype exists) -* reduced mke2fs/e2fsck time via uninitialized groups (prototype exists) -* journal checksumming for robustness, performance (prototype exists) -* persistent file preallocation (e.g for streaming media, databases) +There are several others under discussion, whether they all make it in is +partly a function of how much time everyone has to work on them. Features like +metadata checksumming have been discussed and planned for a bit but no patches +exist yet so I'm not sure they're in the near-term roadmap. -Features like metadata checksumming have been discussed and planned for -a bit but no patches exist yet so I'm not sure they're in the near-term -roadmap. +The big performance win will come with mballoc, delalloc and flex_bg +grouping of bitmaps and inode tables. Some test results available here: -The big performance win will come with mballoc and delalloc. CFS has -been using mballoc for a few years already with Lustre, and IBM + Bull -did a lot of benchmarking on it. The reason it isn't in the first set of -patches is partly a manageability issue, and partly because it doesn't -directly affect the on-disk format (outside of much better allocation) -so it isn't critical to get into the first round of changes. I believe -Alex is working on a new set of patches right now. + - http://www.bullopensource.org/ext4/20080530/ffsb-write-2.6.26-rc2.html + - http://www.bullopensource.org/ext4/20080530/ffsb-readwrite-2.6.26-rc2.html 3. Options ==========
@@ -224,7 +237,7 @@ stripe=n Number of filesystem blocks that mballoc will try disks * RAID chunk size in file system blocks. Data Mode ---------- +========= There are 3 different data modes: * writeback mode
@@ -256,7 +269,8 @@ kernel source: <file:fs/ext4/> <file:fs/jbd2/> programs: http://e2fsprogs.sourceforge.net/ - http://ext2resize.sourceforge.net useful links: http://fedoraproject.org/wiki/ext3-devel http://www.bullopensource.org/ext4/ + http://ext4.wiki.kernel.org/index.php/Main_Page + http://fedoraproject.org/wiki/Features/Ext4
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 37/52 vfs: export filemap_fdatawrite_range()
In reply to Theodore Ts'oFrom: Jan Kara <[email protected]>
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(struct address_space *mapping, 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_space *mapping) }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
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 38/52 jbd2: Implement data=ordered mode handling via inodes
From: Jan Kara <[email protected]>
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.
This new ordered mode brings all sorts of advantages such as possibility to get rid of journal heads and buffer heads for data buffers in ordered mode, better ordering of writes on transaction commit, simplification of
some JBD code, no more anonymous pages when truncate of data being
committed happens. Also with this new ordered mode, delayed allocation on ordered mode is much simpler.
--- 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
@@ -355,6 +355,81 @@ write_out_data:journal_do_submit_data (wbuf, bufs); } +/* +* Submit all the data buffers of inode associated with the transaction to +* disk. +* +* We are in a committing transaction. Therefore no new inode can be added to +* our inode list. We use JI_COMMIT_RUNNING flag to protect inode we currently +* operate on from being released while we write out pages. +*/ +static int journal_submit_inode_data_buffers (journal_t *journal, +transaction_t *commit_transaction) +{ +struct jbd2_inode *jinode; +int err, ret =0 ; +struct address_space *mapping; + +spin_lock (&journal->j_list_lock); +list_for_each_entry (jinode, &commit_transaction->t_inode_list, i_list) { + mapping = jinode->i_vfs_inode->i_mapping; + jinode->i_flags |=JI_COMMIT_RUNNING ; +spin_unlock (&journal->j_list_lock); + err =filemap_fdatawrite_range (mapping,0 , +i_size_read (jinode->i_vfs_inode)); +if (!ret) + ret = err; +spin_lock (&journal->j_list_lock); +J_ASSERT (jinode->i_transaction == commit_transaction); + jinode->i_flags &= ~JI_COMMIT_RUNNING ; +wake_up_bit (&jinode->i_flags, __JI_COMMIT_RUNNING); + } +spin_unlock (&journal->j_list_lock); +return ret; +} + +/* +* Wait for data submitted for writeout, refile inodes to proper +* transaction if needed. +* +*/ +static int journal_finish_inode_data_buffers (journal_t *journal, +transaction_t *commit_transaction) +{ +struct jbd2_inode *jinode, *next_i; +int err, ret =0 ; + +/* For locking, see the comment in journal_submit_inode_data_buffers() */ +spin_lock (&journal->j_list_lock); +list_for_each_entry (jinode, &commit_transaction->t_inode_list, i_list) { + jinode->i_flags |=JI_COMMIT_RUNNING ; +spin_unlock (&journal->j_list_lock); + err =filemap_fdatawait (jinode->i_vfs_inode->i_mapping); +if (!ret) + ret = err; +spin_lock (&journal->j_list_lock); + jinode->i_flags &= ~JI_COMMIT_RUNNING ; +wake_up_bit (&jinode->i_flags, __JI_COMMIT_RUNNING); + } + +/* Now refile inode to proper lists */ +list_for_each_entry_safe (jinode, next_i, + &commit_transaction->t_inode_list, i_list) { +list_del (&jinode->i_list); +if (jinode->i_next_transaction) { + jinode->i_transaction = jinode->i_next_transaction; + jinode->i_next_transaction =NULL ; +list_add (&jinode->i_list, + &jinode->i_transaction->t_inode_list); + }else { + jinode->i_transaction =NULL ; + } + } +spin_unlock (&journal->j_list_lock); + +return ret; +} +static __u32 jbd2_checksum_data (__u32 crc32_sum,struct buffer_head *bh) {struct page *page = bh->b_page;
@@ -529,6 +604,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)*/ err =0 ;journal_submit_data_buffers (journal, commit_transaction); + err =journal_submit_inode_data_buffers (journal, commit_transaction); +if (err) +jbd2_journal_abort (journal, err);/* * Wait for all previously submitted IO to complete if commit
@@ -760,6 +838,17 @@ start_journal_io:__jbd2_journal_abort_hard (journal); } +/* +* This is the right place to wait for data buffers both for ASYNC +* and !ASYNC commit. If commit is ASYNC, we need to wait only after +* the commit block went to disk (which happens above). If commit is +* SYNC, we need to wait for data buffers before we start writing +* commit block, which happens below in such setting. +*/ + err =journal_finish_inode_data_buffers (journal, commit_transaction); +if (err) +jbd2_journal_abort (journal, err); +/* Lo and behold: we have just managed to send a transaction to the log. Before we can commit it, wait for the IO so far to complete. Control buffers being written are on the
@@ -880,6 +969,7 @@ wait_for_iobuf:jbd_debug (3 ,"JBD: commit phase 7\n" );J_ASSERT (commit_transaction->t_sync_datalist ==NULL ); +J_ASSERT (list_empty (&commit_transaction->t_inode_list));J_ASSERT (commit_transaction->t_buffers ==NULL );J_ASSERT (commit_transaction->t_checkpoint_list ==NULL );J_ASSERT (commit_transaction->t_iobuf_list ==NULL );
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
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 2/52 ext4: start searching for the right extent from the goal group.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
With mballoc we search for the best extent using different criteria. We should always use the goal group when we are starting with a new criteria.
--- fs/ext4/mballoc.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
fs/ext4/mballoc.c +0 -3
@@ -1730,10 +1730,6 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) ac->ac_g_ex.fe_start = sbi->s_mb_last_start;spin_unlock (&sbi->s_md_lock); } - -/* searching for the right group start from the goal value specified */ - group = ac->ac_g_ex.fe_group;
Theodore Ts'o
maintainerPATCH 4/52 ext4: switch to seq_files
In reply to Theodore Ts'oFrom: Alexey Dobriyan <[email protected]>
--- fs/ext4/mballoc.c | 68 ++++++++++++++++++++++++++-------------------------- 1 files changed, 34 insertions(+), 34 deletions(-)
fs/ext4/mballoc.c +34 -34
@@ -2577,25 +2577,24 @@ ext4_mb_free_committed_blocks(struct super_block *sb) -#define MB_PROC_VALUE_READ (name) \ -static int ext4_mb_read_##name(char *page, char **start, \ - off_t off, int count, int *eof, void *data) \ +#define MB_PROC_FOPS (name) \ +static int ext4_mb_##name##_proc_show(struct seq_file *m, void *v) \ { \ - struct ext4_sb_info *sbi = data; \ - int len; \ - *eof = 1; \ - if (off != 0) \ - return 0; \ - len = sprintf(page, "%ld\n", sbi->s_mb_##name); \ - *start = page; \ - return len; \ -} - -#define MB_PROC_VALUE_WRITE (name) \ -static int ext4_mb_write_##name(struct file *file, \ - const char __user *buf, unsigned long cnt, void *data) \ + struct ext4_sb_info *sbi = m->private; \ + \ + seq_printf(m, "%ld\n", sbi->s_mb_##name); \ + return 0; \ +} \ + \ +static int ext4_mb_##name##_proc_open(struct inode *inode, struct file *file)\ +{ \ + return single_open(file, ext4_mb_##name##_proc_show, PDE(inode)->data);\ +} \ + \ +static ssize_t ext4_mb_##name##_proc_write(struct file *file, \ + const char __user *buf, size_t cnt, loff_t *ppos) \ { \ - struct ext4_sb_info *sbi = data; \ + struct ext4_sb_info *sbi = PDE(file->f_path.dentry->d_inode)->data;\ char str[32]; \ long value; \ if (cnt >= sizeof(str)) \
@@ -2607,31 +2606,32 @@ static int ext4_mb_write_##name(struct file *file, \return -ERANGE ; \ sbi->s_mb_##name = value; \ return cnt; \ -} +} \ + \ +static const struct file_operations ext4_mb_##name##_proc_fops = { \ + .owner = THIS_MODULE, \ + .open = ext4_mb_##name##_proc_open, \ + .read = seq_read, \ + .llseek = seq_lseek, \ + .release = single_release, \ + .write = ext4_mb_##name##_proc_write, \ +}; -MB_PROC_VALUE_READ (stats); -MB_PROC_VALUE_WRITE (stats); -MB_PROC_VALUE_READ (max_to_scan); -MB_PROC_VALUE_WRITE (max_to_scan); -MB_PROC_VALUE_READ (min_to_scan); -MB_PROC_VALUE_WRITE (min_to_scan); -MB_PROC_VALUE_READ (order2_reqs); -MB_PROC_VALUE_WRITE (order2_reqs); -MB_PROC_VALUE_READ (stream_request); -MB_PROC_VALUE_WRITE (stream_request); -MB_PROC_VALUE_READ (group_prealloc); -MB_PROC_VALUE_WRITE (group_prealloc); +MB_PROC_FOPS (stats); +MB_PROC_FOPS (max_to_scan); +MB_PROC_FOPS (min_to_scan); +MB_PROC_FOPS (order2_reqs); +MB_PROC_FOPS (stream_request); +MB_PROC_FOPS (group_prealloc);#define MB_PROC_HANDLER (name, var) \ do { \ - proc = create_proc_entry(name, mode, sbi->s_mb_proc); \ + proc = proc_create_data(name, mode, sbi->s_mb_proc, \ + &ext4_mb_##var##_proc_fops, sbi); \ if (proc == NULL) { \ printk(KERN_ERR "EXT4-fs: can't to create %s\n", name); \ goto err_out; \ } \ - proc->data = sbi; \ - proc->read_proc = ext4_mb_read_##var ; \ - proc->write_proc = ext4_mb_write_##var; \ } while (0)static int ext4_mb_init_per_dev_proc (struct super_block *sb)
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 33/52 ext4: Use page_mkwrite vma_operations to get mmap write notification.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
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 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -1067,6 +1067,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 @@ force_commit: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 @@ const struct file_operations ext4_file_operations = {#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 +61 -0
64 lines not on this page · raw message
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 36/52 ext4: Fix lock inversion in ext4_ext_truncate()
In reply to Theodore Ts'oWe cannot call ext4_orphan_add() from under i_data_sem because that causes lock inversion between i_data_sem and superblock lock:
-> #1 (&type->s_lock_key#7){--..}:
[<ffffffff8024dbcf>] __lock_acquire+0xc3c/0xe20
[<ffffffff8024e052>] lock_acquire+0x53/0x6d
[<ffffffff80503ae2>] mutex_lock_nested+0xd6/0x27d
[<ffffffff8028a856>] lock_super+0x22/0x24
[<ffffffff803105e1>] ext4_orphan_add+0x29/0x17d
[<ffffffff8031a538>] ext4_ext_truncate+0x91/0x19c
[<ffffffff8030c984>] ext4_truncate+0xbb/0x568
[<ffffffff8026f07e>] vmtruncate+0xc2/0xe0
[<ffffffff8029d586>] inode_setattr+0x28/0x123
[<ffffffff8030ad2f>] ext4_setattr+0x226/0x284
[<ffffffff8029d7ea>] notify_change+0x169/0x27b
[<ffffffff80287886>] do_truncate+0x60/0x7e
[<ffffffff80287a16>] sys_truncate+0x172/0x1a8
[<ffffffff80222721>] sys32_truncate64+0x16/0x18-> #0 (&ei->i_data_sem){----}:
[<ffffffff8024dab7>] __lock_acquire+0xb24/0xe20
[<ffffffff8024e052>] lock_acquire+0x53/0x6d
[<ffffffff805045f7>] down_read+0x25/0x31
[<ffffffff8030be45>] ext4_get_blocks_wrap+0x36/0x15c
[<ffffffff8030c4cc>] ext4_get_block+0xb5/0xf3
[<ffffffff802ab7ee>] generic_block_bmap+0x3a/0x40
[<ffffffff803093bb>] ext4_bmap+0x70/0x79
[<ffffffff8029c9aa>] bmap+0x1f/0x27
[<ffffffff80335c8d>] jbd2_journal_bmap+0x2c/0x8a
[<ffffffff80335fe5>] jbd2_journal_next_log_block+0x76/0x7e
[<ffffffff803362cd>] jbd2_journal_get_descriptor_buffer+0x17/0x80
[<ffffffff80331b15>] jbd2_journal_commit_transaction+0x56e/0x1045
[<ffffffff803356c4>] jbd2_journal_destroy+0xfc/0x250
[<ffffffff80312acf>] ext4_put_super+0x3e/0x213
[<ffffffff8028a96a>] generic_shutdown_super+0x63/0xf8
[<ffffffff8028b6d6>] kill_block_super+0x12/0x27
[<ffffffff8028a81f>] deactivate_super+0x4c/0x61
[<ffffffff8029f28b>] mntput_no_expire+0xed/0x120
[<ffffffff802a0d30>] sys_umount+0x312/0x327--- fs/ext4/extents.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
fs/ext4/extents.c +3 -2
@@ -2768,6 +2768,9 @@ void ext4_ext_truncate(struct inode *inode)if (inode->i_size & (sb->s_blocksize -1 ))ext4_block_truncate_page (handle, mapping, inode->i_size); +if (ext4_orphan_add (handle, inode)) + goto out_stop; +down_write (&EXT4_I (inode)->i_data_sem);ext4_ext_invalidate_cache (inode);
@@ -2778,8 +2781,6 @@ void ext4_ext_truncate(struct inode *inode)* Probably we need not scan at all, * because page truncation is enough. */ -if (ext4_orphan_add (handle, inode)) - goto out_stop;/* we have to know where to truncate from in crash case */ EXT4_I (inode)->i_disksize = inode->i_size;
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 40/52 jbd2: Remove data=ordered mode support using jbd buffer heads
In reply to Theodore Ts'oFrom: Jan Kara <[email protected]>
--- fs/jbd2/checkpoint.c | 1 - fs/jbd2/commit.c | 221 ++----------------------------------------------- fs/jbd2/journal.c | 1 - fs/jbd2/transaction.c | 217 ++---------------------------------------------- include/linux/jbd2.h | 29 ++----- 5 files changed, 21 insertions(+), 448 deletions(-)
fs/jbd2/checkpoint.c +0 -1
@@ -688,7 +688,6 @@ void __jbd2_journal_drop_transaction(journal_t *journal, transaction_t *transactJ_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_updates);EXPORT_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]
@@ -1044,7 +1032,6 @@ extern int jbd2_journal_extend (handle_t *, int nblocks);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 *);
@@ -1223,15 +1210,13 @@ static inline int jbd_space_needed(journal_t *journal)/* 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);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 43/52 percpu_counter: new function percpu_counter_sum_and_set
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
Delayed allocation need to check free blocks at every write time. percpu_counter_read_positive() is not quit accurate. delayed allocation need a more accurate accounting, but using percpu_counter_sum_positive() is frequently is quite expensive.
This patch added a new function to update center counter when sum per-cpu counter, to increase the accurate rate for next percpu_counter_read() and require less calling expensive percpu_counter_sum().
--- fs/ext4/balloc.c | 2 +- include/linux/percpu_counter.h | 12 +++++++++--- lib/percpu_counter.c | 7 ++++++- 3 files changed, 16 insertions(+), 5 deletions(-)
fs/ext4/balloc.c +1 -1
@@ -1621,7 +1621,7 @@ ext4_fsblk_t ext4_has_free_blocks(struct ext4_sb_info *sbi,#ifdef CONFIG_SMP if (free_blocks - root_blocks <FBC_BATCH ) free_blocks = -percpu_counter_sum_positive (&sbi->s_freeblocks_counter); +percpu_counter_sum_and_set (&sbi->s_freeblocks_counter);#endif if (free_blocks - root_blocks < nblocks)return free_blocks - root_blocks;
include/linux/percpu_counter.h +9 -3
@@ -35,7 +35,7 @@ int percpu_counter_init_irq(struct percpu_counter *fbc, s64 amount);void percpu_counter_destroy (struct percpu_counter *fbc);void percpu_counter_set (struct percpu_counter *fbc,s64 amount);void __percpu_counter_add (struct percpu_counter *fbc,s64 amount,s32 batch); -s64 __percpu_counter_sum (struct percpu_counter *fbc); +s64 __percpu_counter_sum (struct percpu_counter *fbc,int set);static inline void percpu_counter_add (struct percpu_counter *fbc,s64 amount) {
@@ -44,13 +44,19 @@ static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount)static inline s64 percpu_counter_sum_positive (struct percpu_counter *fbc) { -s64 ret =__percpu_counter_sum (fbc); +s64 ret =__percpu_counter_sum (fbc,0 );return ret <0 ?0 : ret; } +static inline s64 percpu_counter_sum_and_set (struct percpu_counter *fbc) +{ +return __percpu_counter_sum (fbc,1 ); +} + +static inline s64 percpu_counter_sum (struct percpu_counter *fbc) { -return __percpu_counter_sum (fbc); +return __percpu_counter_sum (fbc,0 ); }static inline s64 percpu_counter_read (struct percpu_counter *fbc)
lib/percpu_counter.c +6 -1
@@ -52,7 +52,7 @@ EXPORT_SYMBOL(__percpu_counter_add);* Add up all the per-cpu counts, return the result. This is a more accurate * but much slower version of percpu_counter_read_positive() */ -s64 __percpu_counter_sum (struct percpu_counter *fbc) +s64 __percpu_counter_sum (struct percpu_counter *fbc,int set) {s64 ret;int cpu;
@@ -62,7 +62,12 @@ s64 __percpu_counter_sum(struct percpu_counter *fbc)for_each_online_cpu (cpu) {s32 *pcount =per_cpu_ptr (fbc->counters, cpu); ret += *pcount; +if (set) + *pcount =0 ; } +if (set) + fbc->count = ret; +spin_unlock (&fbc->lock);return ret; }
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 49/52 ext4: fix delalloc i_disksize early update issue
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
Ext4_da_write_end() used walk_page_buffers() with a callback function of ext4_bh_unmapped_or_delay() to check if it extended the file size without allocating any blocks (since in this case i_disksize needs to be updated). However, this is didn't work proprely because the buffer head has not been marked dirty yet --- this is done later in block_commit_write() --- which caused ext4_bh_unmapped_or_delay() to always return false.
In addition, walk_page_buffers() checks all of the buffer heads covering the page, and the only buffer_head that should be checked is the one covering the end of the write. Otherwise, given a 1k blocksize filesystem and a 4k page size, the buffer head covering the first 1k stripe of the file could be unmapped (because it was a sparse file), and the second or third buffer_head covering that page could be mapped, and using walk_page_buffers() would fail in this case since it would stop at the first unmapped buffer_head and return true.
The core problem is that walk_page_buffers() was intended to do work in a callback function, and a non-zero return value indicated a failure, which termined the walk of the buffer heads covering the page. It was not intended to be used with a boolean function, such as ext4_bh_unmapped_or_delay().
Add addtional fix from Aneesh to protect i_disksize update rave with truncate.
--- fs/ext4/inode.c | 63 +++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 47 insertions(+), 16 deletions(-)
fs/ext4/inode.c +47 -15
@@ -1891,6 +1891,29 @@ out:return ret; } +/* +* Check if we should update i_disksize +* when write to the end of file but not require block allocation +*/ +static int ext4_da_should_update_i_disksize (struct page *page, +unsigned long offset) +{ +struct buffer_head *bh; +struct inode *inode = page->mapping->host; +unsigned int idx; +int i; + + bh =page_buffers (page); + idx = offset >> inode->i_blkbits; + +for (i=0 ; i < idx; i++) + bh = bh->b_this_page; + +if (!buffer_mapped (bh) || (buffer_delay (bh))) +return 0 ; +return 1 ; +} + static int ext4_da_write_end(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned copied,
@@ -1900,6 +1923,10 @@ static int ext4_da_write_end(struct file *file,int ret =0 , ret2;handle_t *handle =ext4_journal_current_handle ();loff_t new_i_size; +unsigned long start, end; + + start = pos & (PAGE_CACHE_SIZE -1 ); + end = start + copied -1 ;/* * generic_write_end() will run mark_inode_dirty() if i_size
@@ -1908,18 +1935,23 @@ static int ext4_da_write_end(struct file *file,*/ new_i_size = pos + copied; -if (new_i_size >EXT4_I (inode)->i_disksize) -if (!walk_page_buffers (NULL ,page_buffers (page), -0 , len,NULL , ext4_bh_unmapped_or_delay)){ -/* -* Updating i_disksize when extending file without -* needing block allocation -*/ -if (ext4_should_order_data (inode)) - ret =ext4_jbd2_file_inode (handle, inode); +if (new_i_size >EXT4_I (inode)->i_disksize) { +if (ext4_da_should_update_i_disksize (page, end)) { +down_write (&EXT4_I (inode)->i_data_sem); +if (new_i_size >EXT4_I (inode)->i_disksize) { +/* +* Updating i_disksize when extending file +* without needing block allocation +*/ +if (ext4_should_order_data (inode)) + ret =ext4_jbd2_file_inode (handle, + inode); -EXT4_I (inode)->i_disksize = new_i_size; +EXT4_I (inode)->i_disksize = new_i_size; + } +up_write (&EXT4_I (inode)->i_data_sem); } + } ret2 =generic_write_end (file, mapping, pos, len, copied, page, fsdata); copied = ret2;
@@ -2965,6 +2997,11 @@ void ext4_truncate(struct inode *inode) goto out_stop;/* +* From here we block out all ext4_get_block() callers who want to +* modify the block allocation tree. +*/ +down_write (&ei->i_data_sem); +/* * The orphan list entry will now protect us from any crash which * occurs before the truncate completes, so it is now safe to propagate * the new, shorter inode size (held for now in i_size) into the
@@ -2973,12 +3010,6 @@ void ext4_truncate(struct inode *inode)*/ ei->i_disksize = inode->i_size; -/* -* From here we block out all ext4_get_block() callers who want to -* modify the block allocation tree. -*/ -down_write (&ei->i_data_sem);
Theodore Ts'o
maintainerPATCH 52/52 ext4: Documention update for new ordered mode and delayed allocation
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
Adding some documentations for delayed allocation and new ordered mode.
--- Documentation/filesystems/ext4.txt | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-)
Documentation/filesystems/ext4.txt +14 -7
@@ -62,7 +62,7 @@ Mailing list: [email protected] * extent format reduces metadata overhead (RAM, IO for access, transactions) * extent format more robust in face of on-disk corruption due to magics, * internal redunancy in tree -* improved file allocation (multi-block alloc, delayed alloc) +* improved file allocation (multi-block alloc) * fix 32000 subdirectory limit * nsec timestamps for mtime, atime, ctime, create time * inode version field on disk (NFSv4, Lustre)
@@ -73,6 +73,10 @@ Mailing list: [email protected] flex_bg feature * large file support * Inode allocation using large virtual block groups via flex_bg +* delayed allocation +* large block (up to pagesize) support +* efficent new ordered mode in JBD2 and ext4(avoid using buffer head to force + the ordering) 2.2 Candidate features for future inclusion
@@ -235,7 +239,9 @@ stripe=n Number of filesystem blocks that mballoc will try to use for allocation size and alignment. For RAID5/6 systems this should be the number of data disks * RAID chunk size in file system blocks. - +delalloc (*) Deferring block allocation until write-out time. +nodelalloc Disable delayed allocation. Blocks are allocation + when data is copied from user to page cache. Data Mode ========= There are 3 different data modes:
@@ -249,10 +255,10 @@ typically provide the best ext4 performance. * ordered mode In data=ordered mode, ext4 only officially journals metadata, but it logically -groups metadata and data blocks into a single unit called a transaction. When -it's time to write the new metadata out to disk, the associated data blocks -are written first. In general, this mode performs slightly slower than -writeback but significantly faster than journal mode. +groups metadata information related to data changes with the data blocks into a +single unit called a transaction. When it's time to write the new metadata +out to disk, the associated data blocks are written first. In general, +this mode performs slightly slower than writeback but significantly faster than journal mode. * journal mode data=journal mode provides full data and metadata journaling. All new data is
@@ -260,7 +266,8 @@ written to the journal first, and then to its final location. In the event of a crash, the journal can be replayed, bringing both data and metadata into a consistent state. This mode is the slowest except when data needs to be read from and written to disk at the same time where it -outperforms all others modes. +outperforms all others modes. Curently ext4 does not have delayed +allocation support if this data journalling mode is selected. References ==========
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 31/52 ext4: fix online resize with mballoc
In reply to Theodore Ts'oFrom: Frederic Bohe <[email protected]>
Update group infos when updating a group's descriptor.
Add group infos when adding a group's descriptor.
Refresh cache pages used by mb_alloc when changes occur.
This will probably need modifications when META_BG resizing will be allowed.
--- fs/ext4/ext4.h | 4 + fs/ext4/mballoc.c | 234 ++++++++++++++++++++++++++++++++++++++++------------- fs/ext4/resize.c | 52 ++++++++++++- 3 files changed, 234 insertions(+), 56 deletions(-)
fs/ext4/ext4.h +4 -0
@@ -1033,6 +1033,10 @@ extern int __init init_ext4_mballoc(void);extern void exit_ext4_mballoc (void );extern void ext4_mb_free_blocks (handle_t *,struct inode *,unsigned long ,unsigned long ,int ,unsigned long *); +extern int ext4_mb_add_more_groupinfo (struct super_block *sb, +ext4_group_t i,struct ext4_group_desc *desc); +extern void ext4_mb_update_group_info (struct ext4_group_info *grp, +ext4_grpblk_t add);/* inode.c */
fs/ext4/mballoc.c +179 -55
262 lines not on this page · raw message
fs/ext4/resize.c +51 -1
76 lines not on this page · raw message
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 45/52 mm: Add range_cont mode for writeback
In reply to Theodore Ts'oFrom: 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 @@ retry: }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 · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 47/52 ext4: Add ordered mode support for delalloc
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
This provides a new ordered mode implementation which gets rid of using buffer heads to enforce the ordering between metadata change with the related data chage. Instead, in the new ordering mode, it keeps track of all of the inodes touched by each transaction on a list, and when that transaction is committed, it flushes all of the dirty pages for those inodes. In addition, the new ordered mode reverses the lock ordering of the page lock and transaction lock, which provides easier support for delayed allocation.
--- fs/ext4/inode.c | 30 +++++++++++++++++++++++++----- fs/jbd2/commit.c | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 10 deletions(-)
fs/ext4/inode.c +25 -5
@@ -1636,11 +1636,12 @@ 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 */ /* * 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. +* +* We also get called via journal_submit_inode_data_buffers */ static int ext4_da_writepage (struct page *page,struct writeback_control *wbc)
@@ -1659,6 +1660,7 @@ static int ext4_da_writepage(struct page *page,* ext4_da_writepages() but directly (shrink_page_list). * We cannot easily start a transaction here so we just skip * writing the page in case we would have to do so. +* We reach here also via journal_submit_inode_data_buffers */ size =i_size_read (inode);
@@ -1674,8 +1676,11 @@ static int ext4_da_writepage(struct page *page,* We can't do block allocation under * page lock without a handle . So redirty * the page and return +* We may reach here when we do a journal commit +* via journal_submit_inode_data_buffers. +* If we don't have mapping block we just ignore +* them */ -BUG_ON (wbc->sync_mode !=WB_SYNC_NONE );redirty_page_for_writepage (wbc, page);unlock_page (page);return 0 ;
@@ -1690,7 +1695,6 @@ static int ext4_da_writepage(struct page *page,return ret; } -/* * For now just follow the DIO way to estimate the max credits * needed to write out EXT4_MAX_WRITEBACK_PAGES.
@@ -1723,7 +1727,7 @@ static int ext4_da_writepages(struct address_space *mapping,return 0 ;/* -* Estimate the worse case needed credits to write out +* Estimate the worse case needed credits to write out * EXT4_MAX_BUF_BLOCKS pages */ needed_blocks =EXT4_MAX_WRITEBACK_CREDITS ;
@@ -1745,6 +1749,19 @@ static int ext4_da_writepages(struct address_space *mapping, ret =PTR_ERR (handle); goto out_writepages; } +if (ext4_should_order_data (inode)) { +/* +* With ordered mode we need to add +* the inode to the journal handle +* when we do block allocation. +*/ + ret =ext4_jbd2_file_inode (handle, inode); +if (ret) { +ext4_journal_stop (handle); + goto out_writepages; + } + + }/* * set the max dirty pages could be write at a time * to fit into the reserved transaction credits
@@ -2328,7 +2345,10 @@ static const struct address_space_operations ext4_da_aops = {void ext4_set_aops (struct inode *inode) { -if (ext4_should_order_data (inode)) +if (ext4_should_order_data (inode) && +test_opt (inode->i_sb,DELALLOC )) + inode->i_mapping->a_ops = &ext4_da_aops; +else if (ext4_should_order_data (inode)) inode->i_mapping->a_ops = &ext4_ordered_aops;else if (ext4_should_writeback_data (inode) &&test_opt (inode->i_sb,DELALLOC ))
fs/jbd2/commit.c +33 -5
@@ -22,6 +22,8 @@#include <linux/pagemap.h> #include <linux/jiffies.h> #include <linux/crc32.h> +#include <linux/writeback.h> +#include <linux/backing-dev.h> /* * Default IO end handler for temporary BJ_IO buffer_heads.
@@ -185,6 +187,27 @@ static int journal_wait_on_commit_record(struct buffer_head *bh) }/* +* write the filemap data using writepage() address_space_operations. +* We don't do block allocation here even for delalloc. We don't +* use writepages() because with dealyed allocation we may be doing +* block allocation in writepages(). +*/ +static int journal_submit_inode_data_buffers (struct address_space *mapping) +{ +int ret; +struct writeback_control wbc = { + .sync_mode =WB_SYNC_ALL , + .nr_to_write = mapping->nrpages *2 , + .range_start =0 , + .range_end =i_size_read (mapping->host), + .for_writepages =1 , + }; + + ret =generic_writepages (mapping, &wbc); +return ret; +} + +/* * Submit all the data buffers of inode associated with the transaction to * disk. *
@@ -192,7 +215,7 @@ static int journal_wait_on_commit_record(struct buffer_head *bh)* our inode list. We use JI_COMMIT_RUNNING flag to protect inode we currently * operate on from being released while we write out pages. */ -static int journal_submit_inode_data_buffers (journal_t *journal, +static int journal_submit_data_buffers (journal_t *journal,transaction_t *commit_transaction) {struct jbd2_inode *jinode;
@@ -204,8 +227,13 @@ static int journal_submit_inode_data_buffers(journal_t *journal, mapping = jinode->i_vfs_inode->i_mapping; jinode->i_flags |=JI_COMMIT_RUNNING ;spin_unlock (&journal->j_list_lock); - err =filemap_fdatawrite_range (mapping,0 , -i_size_read (jinode->i_vfs_inode)); +/* +* submit the inode data buffers. We use writepage +* instead of writepages. Because writepages can do +* block allocation with delalloc. We need to write +* only allocated blocks here. +*/ + err =journal_submit_inode_data_buffers (mapping);if (!ret) ret = err;spin_lock (&journal->j_list_lock);
@@ -228,7 +256,7 @@ static int journal_finish_inode_data_buffers(journal_t *journal,struct jbd2_inode *jinode, *next_i;int err, ret =0 ; -/* For locking, see the comment in journal_submit_inode_data_buffers() */ +/* For locking, see the comment in journal_submit_data_buffers() */ spin_lock (&journal->j_list_lock);list_for_each_entry (jinode, &commit_transaction->t_inode_list, i_list) { jinode->i_flags |=JI_COMMIT_RUNNING ;
@@ -431,7 +459,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)* Now start flushing things to disk, in the order they appear * on the transaction lists. Data blocks go first. */ - err =journal_submit_inode_data_buffers (journal, commit_transaction); + err =journal_submit_data_buffers (journal, commit_transaction);if (err)jbd2_journal_abort (journal, err);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 48/52 ext4: Handle page without buffers in ext4_*_writepage()
From: Aneesh Kumar <[email protected]>
It can happen that buffers are removed from the page before it gets marked dirty and then is passed to writepage(). In writepage() we just initialize the buffers and check whether they are mapped and non delay. If they are mapped and non delay we write the page. Otherwise we mark them dirty. With this change we don't do block allocation at all in ext4_*_write_page.
writepage() can get called under many condition and with a locking order of journal_start -> lock_page, we should not try to allocate blocks in writepage() which get called after taking page lock. writepage() can get called via shrink_page_list even with a journal handle which was created for doing inode update. For example when doing ext4_da_write_begin we create a journal handle with credit 1 expecting a i_disksize update for the inode. But ext4_da_write_begin can cause shrink_page_list via _grab_page_cache. So having a valid handle via ext4_journal_current_handle is not a guarantee that we can use the handle for block allocation in writepage, since we shouldn't be using credits that had been reserved for other updates. That it could result in we running out of credits when we update inodes.
--- fs/ext4/inode.c | 169 ++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 124 insertions(+), 45 deletions(-)
fs/ext4/inode.c +124 -45
@@ -1592,11 +1592,15 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,handle_t *handle =NULL ; handle =ext4_journal_current_handle (); -BUG_ON (handle ==NULL ); -BUG_ON (create ==0 ); - - ret =ext4_get_blocks_wrap (handle, inode, iblock, max_blocks, +if (!handle) { + ret =ext4_get_blocks_wrap (handle, inode, iblock, max_blocks, + bh_result,0 ,0 ,0 ); +BUG_ON (!ret); + }else { + ret =ext4_get_blocks_wrap (handle, inode, iblock, max_blocks, bh_result, create,0 ,EXT4_DELALLOC_RSVED ); + } +if (ret >0 ) { bh_result->b_size = (ret << inode->i_blkbits);
@@ -1633,15 +1637,37 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,static int ext4_bh_unmapped_or_delay (handle_t *handle,struct buffer_head *bh) { -return !buffer_mapped (bh) ||buffer_delay (bh); +/* +* unmapped buffer is possible for holes. +* delay buffer is possible with delayed allocation +*/ +return ((!buffer_mapped (bh) ||buffer_delay (bh)) &&buffer_dirty (bh)); +} + +static int ext4_normal_get_block_write (struct inode *inode,sector_t iblock, +struct buffer_head *bh_result,int create) +{ +int ret =0 ; +unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; + +/* +* we don't want to do block allocation in writepage +* so call get_block_wrap with create = 0 +*/ + ret =ext4_get_blocks_wrap (NULL , inode, iblock, max_blocks, + bh_result,0 ,0 ,0 ); +if (ret >0 ) { + bh_result->b_size = (ret << inode->i_blkbits); + ret =0 ; + } +return ret; }/* -* 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. -* -* We also get called via journal_submit_inode_data_buffers +* get called vi ext4_da_writepages after taking page lock (have journal handle) +* get called via journal_submit_inode_data_buffers (no journal handle) +* get called via shrink_page_list via pdflush (no journal handle) +* or grab_page_cache when doing write_begin (have journal handle) */ static int ext4_da_writepage (struct page *page,struct writeback_control *wbc)
@@ -1649,37 +1675,61 @@ static int ext4_da_writepage(struct page *page,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_list). -* We cannot easily start a transaction here so we just skip -* writing the page in case we would have to do so. -* We reach here also via journal_submit_inode_data_buffers -*/ - size =i_size_read (inode); + size =i_size_read (inode); +if (page->index == size >>PAGE_CACHE_SHIFT ) + len = size & ~PAGE_CACHE_MASK ; +else + len =PAGE_CACHE_SIZE ; +if (page_has_buffers (page)) { 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)) { +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 +* We don't want to do block allocation +* So redirty the page and return * We may reach here when we do a journal commit * via journal_submit_inode_data_buffers. * If we don't have mapping block we just ignore -* them +* them. We can also reach here via shrink_page_list +*/ +redirty_page_for_writepage (wbc, page); +unlock_page (page); +return 0 ; + } + }else { +/* +* The test for page_has_buffers() is subtle: +* We know the page is dirty but it lost buffers. That means +* that at some moment in time after write_begin()/write_end() +* has been called all buffers have been clean and thus they +* must have been written at least once. So they are all +* mapped and we can happily proceed with mapping them +* and writing the page. +* +* Try to initialize the buffer_heads and check whether +* all are mapped and non delay. We don't want to +* do block allocation here. +*/ + ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , + ext4_normal_get_block_write); +if (!ret) { + page_bufs =page_buffers (page); +/* check whether all are mapped and non delay */ +if (walk_page_buffers (NULL , page_bufs,0 , len,NULL , + ext4_bh_unmapped_or_delay)) { +redirty_page_for_writepage (wbc, page); +unlock_page (page); +return 0 ; + } + }else { +/* +* We can't do block allocation here +* so just redity the page and unlock +* and return */ redirty_page_for_writepage (wbc, page);unlock_page (page);
@@ -1688,9 +1738,11 @@ static int ext4_da_writepage(struct page *page, }if (test_opt (inode->i_sb,NOBH ) &&ext4_should_writeback_data (inode)) - ret =nobh_writepage (page, ext4_da_get_block_write, wbc); + ret =nobh_writepage (page, ext4_normal_get_block_write, wbc);else - ret =block_write_full_page (page, ext4_da_get_block_write, wbc); + ret =block_write_full_page (page, + ext4_normal_get_block_write, + wbc);return ret; }
@@ -2031,12 +2083,14 @@ static int __ext4_normal_writepage(struct page *page,struct inode *inode = page->mapping->host;if (test_opt (inode->i_sb,NOBH )) -return nobh_writepage (page, ext4_get_block, wbc); +return nobh_writepage (page, + ext4_normal_get_block_write, wbc);else -return block_write_full_page (page, ext4_get_block, wbc); +return block_write_full_page (page, + ext4_normal_get_block_write, + wbc); } -static int ext4_normal_writepage (struct page *page,struct writeback_control *wbc) {
@@ -2045,13 +2099,24 @@ static int ext4_normal_writepage(struct page *page,loff_t len;J_ASSERT (PageLocked (page)); -J_ASSERT (page_has_buffers (page));if (page->index == size >>PAGE_CACHE_SHIFT ) len = size & ~PAGE_CACHE_MASK ;else len =PAGE_CACHE_SIZE ; -BUG_ON (walk_page_buffers (NULL ,page_buffers (page),0 , len,NULL , - ext4_bh_unmapped_or_delay)); + +if (page_has_buffers (page)) { +/* if page has buffers it should all be mapped +* and allocated. If there are not buffers attached +* to the page we know the page is dirty but it lost +* buffers. That means that at some moment in time +* after write_begin() / write_end() has been called +* all buffers have been clean and thus they must have been +* written at least once. So they are all mapped and we can +* happily proceed with mapping them and writing the page. +*/ +BUG_ON (walk_page_buffers (NULL ,page_buffers (page),0 , len,NULL , + ext4_bh_unmapped_or_delay)); + }if (!ext4_journal_current_handle ())return __ext4_normal_writepage (page, wbc);
@@ -2071,7 +2136,8 @@ static int __ext4_journalled_writepage(struct page *page,int ret =0 ;int err; - ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , ext4_get_block); + ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , + ext4_normal_get_block_write);if (ret !=0 ) goto out_unlock;
@@ -2118,13 +2184,24 @@ static int ext4_journalled_writepage(struct page *page,loff_t len;J_ASSERT (PageLocked (page)); -J_ASSERT (page_has_buffers (page));if (page->index == size >>PAGE_CACHE_SHIFT ) len = size & ~PAGE_CACHE_MASK ;else len =PAGE_CACHE_SIZE ; -BUG_ON (walk_page_buffers (NULL ,page_buffers (page),0 , len,NULL , - ext4_bh_unmapped_or_delay)); + +if (page_has_buffers (page)) { +/* if page has buffers it should all be mapped +* and allocated. If there are not buffers attached +* to the page we know the page is dirty but it lost +* buffers. That means that at some moment in time +* after write_begin() / write_end() has been called +* all buffers have been clean and thus they must have been +* written at least once. So they are all mapped and we can +* happily proceed with mapping them and writing the page. +*/ +BUG_ON (walk_page_buffers (NULL ,page_buffers (page),0 , len,NULL , + ext4_bh_unmapped_or_delay)); + }if (ext4_journal_current_handle ()) goto no_write;
@@ -2142,7 +2219,9 @@ static int ext4_journalled_writepage(struct page *page,* really know unless we go poke around in the buffer_heads. * But block_write_full_page will do the right thing. */ -return block_write_full_page (page, ext4_get_block, wbc); +return block_write_full_page (page, + ext4_normal_get_block_write, + wbc); } no_write:redirty_page_for_writepage (wbc, page);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 50/52 ext4: Enable delalloc by default.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
Enable delalloc by default to ensure it gets sufficient testing and because it makes the filesystem much more efficient. Add a nodealalloc option to disable delayed allocation, and update ext4_show_options to show delayed allocation off if it is disabled.
If the data=journal mount option is used, disable delayed allocation since the delalloc code doesn't support data=journal yet.
--- fs/ext4/super.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
fs/ext4/super.c +22 -1
@@ -756,6 +756,9 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_puts (seq,",nomballoc" );if (test_opt (sb,I_VERSION ))seq_puts (seq,",i_version" ); +if (!test_opt (sb,DELALLOC )) +seq_puts (seq,",nodelalloc" ); +if (sbi->s_stripe)seq_printf (seq,",stripe=%lu" , sbi->s_stripe);
@@ -903,7 +906,7 @@ enum { Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota, Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version, - Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, + Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, Opt_nodelalloc, }; static match_table_t tokens = {
@@ -963,6 +966,7 @@ static match_table_t tokens = { {Opt_stripe, "stripe=%u"}, {Opt_resize, "resize"}, {Opt_delalloc, "delalloc"}, + {Opt_nodelalloc, "nodelalloc"}, {Opt_err, NULL}, };
@@ -1328,6 +1332,9 @@ set_qf_format:set_opt (sbi->s_mount_opt,I_VERSION ); sb->s_flags |=MS_I_VERSION ;break ; +case Opt_nodelalloc: +clear_opt (sbi->s_mount_opt,DELALLOC ); +break ;case Opt_mballoc:set_opt (sbi->s_mount_opt,MBALLOC );break ;
@@ -1984,6 +1991,13 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)*/ set_opt (sbi->s_mount_opt,MBALLOC ); +/* +* enable delayed allocation by default +* Use -o nodelalloc to turn it off +*/ +set_opt (sbi->s_mount_opt,DELALLOC ); + +if (!parse_options ((char *) data, sb, &journal_inum, &journal_devnum,NULL ,0 )) goto failed_mount;
@@ -2422,6 +2436,13 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_ORDERED_DATA ?"ordered" : "writeback"); +if (test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_JOURNAL_DATA ) { +printk (KERN_WARNING "EXT4-fs: Ignoring delalloc option - " +"requested data journaling mode\n" ); +clear_opt (sbi->s_mount_opt,DELALLOC ); + }else if (test_opt (sb,DELALLOC )) +printk (KERN_INFO "EXT4-fs: delayed allocation enabled\n" ); +ext4_ext_init (sb);ext4_mb_init (sb, needs_recovery);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 13/52 ext4: New inode allocation for FLEX_BG meta-data groups.
In reply to Theodore Ts'oFrom: Jose R. Santos <[email protected]>
This patch mostly controls the way inode are allocated in order to make ialloc aware of flex_bg block group grouping. It achieves this by bypassing the Orlov allocator when block group meta-data are packed toghether through mke2fs. Since the impact on the block allocator is minimal, this patch should have little or no effect on other block allocation algorithms. By controlling the inode allocation, it can basically control where the initial search for new block begins and thus indirectly manipulate the block allocator.
This allocator favors data and meta-data locality so the disk will gradually be filled from block group zero upward. This helps improve performance by reducing seek time. Since the group of inode tables within one flex_bg are treated as one giant inode table, uninitialized block groups would not need to partially initialize as many inode table as with Orlov which would help fsck time as the filesystem usage goes up.
--- fs/ext4/balloc.c | 14 ++++++++ fs/ext4/ext4.h | 25 +++++++++++++- fs/ext4/ext4_sb.h | 3 ++ fs/ext4/ialloc.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/mballoc.c | 15 ++++++++ fs/ext4/super.c | 57 +++++++++++++++++++++++++++++++ 6 files changed, 209 insertions(+), 1 deletions(-)
fs/ext4/balloc.c +14 -0
@@ -809,6 +809,13 @@ do_more:spin_unlock (sb_bgl_lock (sbi, block_group));percpu_counter_add (&sbi->s_freeblocks_counter, count); +if (sbi->s_log_groups_per_flex) { +ext4_group_t flex_group =ext4_flex_group (sbi, block_group); +spin_lock (sb_bgl_lock (sbi, flex_group)); + sbi->s_flex_groups[flex_group].free_blocks += count; +spin_unlock (sb_bgl_lock (sbi, flex_group)); + } +/* We dirtied the bitmap block */ BUFFER_TRACE (bitmap_bh,"dirtied bitmap block" ); err =ext4_journal_dirty_metadata (handle, bitmap_bh);
@@ -1883,6 +1890,13 @@ allocated:spin_unlock (sb_bgl_lock (sbi, group_no));percpu_counter_sub (&sbi->s_freeblocks_counter, num); +if (sbi->s_log_groups_per_flex) { +ext4_group_t flex_group =ext4_flex_group (sbi, group_no); +spin_lock (sb_bgl_lock (sbi, flex_group)); + sbi->s_flex_groups[flex_group].free_blocks -= num; +spin_unlock (sb_bgl_lock (sbi, flex_group)); + } +BUFFER_TRACE (gdp_bh,"journal_dirty_metadata for group descriptor" ); err =ext4_journal_dirty_metadata (handle, gdp_bh);if (!fatal)
fs/ext4/ext4.h +24 -1
@@ -170,6 +170,15 @@ struct ext4_group_desc__u32 bg_reserved2[3 ]; }; +/* +* Structure of a flex block group info +*/ + +struct flex_groups { +__u32 free_inodes; +__u32 free_blocks; +}; +#define EXT4_BG_INODE_UNINIT 0x0001/* Inode table/bitmap not in use */ #define EXT4_BG_BLOCK_UNINIT 0x0002/* Block bitmap not in use */ #define EXT4_BG_INODE_ZEROED 0x0004/* On-disk itable initialized to zero */
@@ -647,7 +656,10 @@ struct ext4_super_block {__le16 s_mmp_interval;/* # seconds to wait in MMP checking */ __le64 s_mmp_block;/* Block for multi-mount protection */ __le32 s_raid_stripe_width;/* blocks on all data disks (N*stride)*/ -__u32 s_reserved[163 ];/* Padding to the end of the block */ +__u8 s_log_groups_per_flex;/* FLEX_BG group size */ +__u8 s_reserved_char_pad2; +__le16 s_reserved_pad; +__u32 s_reserved[162 ];/* Padding to the end of the block */ };#ifdef __KERNEL__
@@ -1159,6 +1171,17 @@ struct ext4_group_info *ext4_get_group_info(struct super_block *sb, } +static inline ext4_group_t ext4_flex_group (struct ext4_sb_info *sbi, +ext4_group_t block_group) +{ +return block_group >> sbi->s_log_groups_per_flex; +} + +static inline unsigned int ext4_flex_bg_size (struct ext4_sb_info *sbi) +{ +return 1 << sbi->s_log_groups_per_flex; +} +#define ext4_std_error (sb, errno) \ do { \ if ((errno)) \
fs/ext4/ext4_sb.h +3 -0
@@ -143,6 +143,9 @@ struct ext4_sb_info {/* locality groups */ struct ext4_locality_group *s_locality_groups; + +unsigned int s_log_groups_per_flex; + struct flex_groups *s_flex_groups; };#endif /* _EXT4_SB */
fs/ext4/ialloc.c +96 -0
138 lines not on this page · raw message
fs/ext4/mballoc.c +15 -0
@@ -2834,6 +2834,14 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,spin_unlock (sb_bgl_lock (sbi, ac->ac_b_ex.fe_group));percpu_counter_sub (&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len); +if (sbi->s_log_groups_per_flex) { +ext4_group_t flex_group =ext4_flex_group (sbi, + ac->ac_b_ex.fe_group); +spin_lock (sb_bgl_lock (sbi, flex_group)); + sbi->s_flex_groups[flex_group].free_blocks -= ac->ac_b_ex.fe_len; +spin_unlock (sb_bgl_lock (sbi, flex_group)); + } + err =ext4_journal_dirty_metadata (handle, bitmap_bh);if (err) goto out_err;
@@ -4337,6 +4345,13 @@ do_more:spin_unlock (sb_bgl_lock (sbi, block_group));percpu_counter_add (&sbi->s_freeblocks_counter, count); +if (sbi->s_log_groups_per_flex) { +ext4_group_t flex_group =ext4_flex_group (sbi, block_group); +spin_lock (sb_bgl_lock (sbi, flex_group)); + sbi->s_flex_groups[flex_group].free_blocks += count; +spin_unlock (sb_bgl_lock (sbi, flex_group)); + } +ext4_mb_release_desc (&e4b); *freed += count;
fs/ext4/super.c +57 -0
75 lines not on this page · raw message
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 24/52 ext4: Use inode preallocation with -o noextents
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
When mballoc is enabled, block allocation for old block-based files are allocated using mballoc allocator instead of old block-based allocator. The old ext3 block reservation is turned off when mballoc is turned on.
However, the in-core preallocation is not enabled for block-based/ non-extent based file block allocation. This result in performance regression, as now we don't have "reservation" ore in-core preallocation to prevent interleaved fragmentation in multiple writes workload.
This patch fix this by enable per inode in-core preallocation for non extent files when mballoc is used.
--- fs/ext4/balloc.c | 36 +++++++++++++++++++++++++- fs/ext4/ext4.h | 7 +++- fs/ext4/extents.c | 2 +- fs/ext4/inode.c | 72 +++++++++++++++++++++++++++++++++++++++------------- fs/ext4/xattr.c | 2 +- 5 files changed, 95 insertions(+), 24 deletions(-)
fs/ext4/balloc.c +34 -2
@@ -1923,7 +1923,7 @@ out:return 0 ; } -ext4_fsblk_t ext4_new_block (handle_t *handle,struct inode *inode, +ext4_fsblk_t ext4_new_meta_block (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,int *errp) {struct ext4_allocation_request ar;
@@ -1942,9 +1942,29 @@ ext4_fsblk_t ext4_new_block(handle_t *handle, struct inode *inode, ret =ext4_mb_new_blocks (handle, &ar, errp);return ret; } +ext4_fsblk_t ext4_new_meta_blocks (handle_t *handle,struct inode *inode, +ext4_fsblk_t goal,unsigned long *count,int *errp) +{ +struct ext4_allocation_request ar; +ext4_fsblk_t ret; + +if (!test_opt (inode->i_sb,MBALLOC )) { + ret =ext4_new_blocks_old (handle, inode, goal, count, errp); +return ret; + } + +memset (&ar,0 ,sizeof (ar)); + ar.inode = inode; + ar.goal = goal; + ar.len = *count; + ret =ext4_mb_new_blocks (handle, &ar, errp); + *count = ar.len; +return ret; +}ext4_fsblk_t ext4_new_blocks (handle_t *handle,struct inode *inode, -ext4_fsblk_t goal,unsigned long *count,int *errp) +ext4_lblk_t iblock,ext4_fsblk_t goal, +unsigned long *count,int *errp) {struct ext4_allocation_request ar;ext4_fsblk_t ret;
@@ -1955,9 +1975,21 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, }memset (&ar,0 ,sizeof (ar)); +/* Fill with neighbour allocated blocks */ + ar.lleft =0 ; + ar.pleft =0 ; + ar.lright =0 ; + ar.pright =0 ; + ar.inode = inode; ar.goal = goal; ar.len = *count; + ar.logical = iblock; +if (S_ISREG (inode->i_mode)) + ar.flags =EXT4_MB_HINT_DATA ; +else +/* disable in-core preallocation for non-regular files */ + ar.flags =0 ; ret =ext4_mb_new_blocks (handle, &ar, errp); *count = ar.len;return ret;
fs/ext4/ext4.h +5 -2
@@ -970,10 +970,13 @@ extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,extern int ext4_bg_has_super (struct super_block *sb,ext4_group_t group);extern unsigned long ext4_bg_num_gdb (struct super_block *sb,ext4_group_t group); -extern ext4_fsblk_t ext4_new_block (handle_t *handle,struct inode *inode, +extern ext4_fsblk_t ext4_new_meta_block (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,int *errp); -extern ext4_fsblk_t ext4_new_blocks (handle_t *handle,struct inode *inode, +extern ext4_fsblk_t ext4_new_meta_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,unsigned long *count,int *errp); +extern ext4_fsblk_t ext4_new_blocks (handle_t *handle,struct inode *inode, +ext4_lblk_t iblock,ext4_fsblk_t goal, +unsigned long *count,int *errp);extern ext4_fsblk_t ext4_new_blocks_old (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,unsigned long *count,int *errp); extern void ext4_free_blocks (handle_t *handle, struct inode *inode,
fs/ext4/extents.c +1 -1
@@ -187,7 +187,7 @@ ext4_ext_new_block(handle_t *handle, struct inode *inode,ext4_fsblk_t goal, newblock; goal =ext4_ext_find_goal (inode, path,le32_to_cpu (ex->ee_block)); - newblock =ext4_new_block (handle, inode, goal, err); + newblock =ext4_new_meta_block (handle, inode, goal, err);return newblock; }
fs/ext4/inode.c +54 -18
116 lines not on this page · raw message
fs/ext4/xattr.c +1 -1
@@ -810,7 +810,7 @@ inserted:/* We need to allocate a new block */ ext4_fsblk_t goal =ext4_group_first_block_no (sb,EXT4_I (inode)->i_block_group); -ext4_fsblk_t block =ext4_new_block (handle, inode, +ext4_fsblk_t block =ext4_new_meta_block (handle, inode, goal, &error);if (error) goto cleanup;
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 25/52 ext4: cleanup block allocator
From: Aneesh Kumar K.V <[email protected]>
Move the code related to block allocation to a single function and add helper funtions to differient allocation for data and meta data blocks
--- fs/ext4/balloc.c | 127 +++++++++++++++++++++++++++++++---------------------- fs/ext4/ext4.h | 2 +- fs/ext4/extents.c | 10 +++- fs/ext4/inode.c | 2 +- fs/ext4/mballoc.c | 2 +- 5 files changed, 84 insertions(+), 59 deletions(-)
fs/ext4/balloc.c +74 -53
@@ -1640,20 +1640,24 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries) }/** -* ext4_new_blocks_old() -- core block(s) allocation function +* ext4_old_new_blocks() -- core block bitmap based block allocation function +* * @handle: handle to this transaction * @inode: file inode * @goal: given target block(filesystem wide) * @count: target number of blocks to allocate * @errp: error code * -* ext4_new_blocks uses a goal block to assist allocation. It tries to -* allocate block(s) from the block group contains the goal block first. If that -* fails, it will try to allocate block(s) from other block groups without -* any specific goal block. +* ext4_old_new_blocks uses a goal block to assist allocation and look up +* the block bitmap directly to do block allocation. It tries to +* allocate block(s) from the block group contains the goal block first. If +* that fails, it will try to allocate block(s) from other block groups +* without any specific goal block. +* +* This function is called when -o nomballoc mount option is enabled * */ -ext4_fsblk_t ext4_new_blocks_old (handle_t *handle,struct inode *inode, +ext4_fsblk_t ext4_old_new_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,unsigned long *count,int *errp) {struct buffer_head *bitmap_bh =NULL ;
@@ -1923,78 +1927,95 @@ out:return 0 ; } -ext4_fsblk_t ext4_new_meta_block (handle_t *handle,struct inode *inode, -ext4_fsblk_t goal,int *errp) -{ -struct ext4_allocation_request ar; -ext4_fsblk_t ret; - -if (!test_opt (inode->i_sb,MBALLOC )) { -unsigned long count =1 ; - ret =ext4_new_blocks_old (handle, inode, goal, &count, errp); -return ret; - } +#define EXT4_META_BLOCK 0x1 -memset (&ar,0 ,sizeof (ar)); - ar.inode = inode; - ar.goal = goal; - ar.len =1 ; - ret =ext4_mb_new_blocks (handle, &ar, errp); -return ret; -} -ext4_fsblk_t ext4_new_meta_blocks (handle_t *handle,struct inode *inode, -ext4_fsblk_t goal,unsigned long *count,int *errp) -{ -struct ext4_allocation_request ar; -ext4_fsblk_t ret; - -if (!test_opt (inode->i_sb,MBALLOC )) { - ret =ext4_new_blocks_old (handle, inode, goal, count, errp); -return ret; - } - -memset (&ar,0 ,sizeof (ar)); - ar.inode = inode; - ar.goal = goal; - ar.len = *count; - ret =ext4_mb_new_blocks (handle, &ar, errp); - *count = ar.len; -return ret; -} - -ext4_fsblk_t ext4_new_blocks (handle_t *handle,struct inode *inode, +static ext4_fsblk_t do_blk_alloc (handle_t *handle,struct inode *inode,ext4_lblk_t iblock,ext4_fsblk_t goal, -unsigned long *count,int *errp) +unsigned long *count,int *errp,int flags) {struct ext4_allocation_request ar;ext4_fsblk_t ret;if (!test_opt (inode->i_sb,MBALLOC )) { - ret =ext4_new_blocks_old (handle, inode, goal, count, errp); -return ret; +return ext4_old_new_blocks (handle, inode, goal, count, errp); }memset (&ar,0 ,sizeof (ar));/* Fill with neighbour allocated blocks */ - ar.lleft =0 ; - ar.pleft =0 ; - ar.lright =0 ; - ar.pright =0 ; ar.inode = inode; ar.goal = goal; ar.len = *count; ar.logical = iblock; -if (S_ISREG (inode->i_mode)) + +if (S_ISREG (inode->i_mode) && !(flags &EXT4_META_BLOCK )) +/* enable in-core preallocation for data block allocation */ ar.flags =EXT4_MB_HINT_DATA ;else /* disable in-core preallocation for non-regular files */ ar.flags =0 ; + ret =ext4_mb_new_blocks (handle, &ar, errp); *count = ar.len;return ret; } +/* +* ext4_new_meta_block() -- allocate block for meta data (indexing) blocks +* +* @handle: handle to this transaction +* @inode: file inode +* @goal: given target block(filesystem wide) +* @errp: error code +* +* Return allocated block number on success +*/ +ext4_fsblk_t ext4_new_meta_block (handle_t *handle,struct inode *inode, +ext4_fsblk_t goal,int *errp) +{ +unsigned long count =1 ; +return do_blk_alloc (handle, inode,0 , goal, + &count, errp,EXT4_META_BLOCK ); +} + +/* +* ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks +* +* @handle: handle to this transaction +* @inode: file inode +* @goal: given target block(filesystem wide) +* @count: total number of blocks need +* @errp: error code +* +* Return 1st allocated block numberon success, *count stores total account +* error stores in errp pointer +*/ +ext4_fsblk_t ext4_new_meta_blocks (handle_t *handle,struct inode *inode, +ext4_fsblk_t goal,unsigned long *count,int *errp) +{ +return do_blk_alloc (handle, inode,0 , goal, + count, errp,EXT4_META_BLOCK ); +} + +/* +* ext4_new_blocks() -- allocate data blocks +* +* @handle: handle to this transaction +* @inode: file inode +* @goal: given target block(filesystem wide) +* @count: total number of blocks need +* @errp: error code +* +* Return 1st allocated block numberon success, *count stores total account +* error stores in errp pointer +*/ + +ext4_fsblk_t ext4_new_blocks (handle_t *handle,struct inode *inode, +ext4_lblk_t iblock,ext4_fsblk_t goal, +unsigned long *count,int *errp) +{ +return do_blk_alloc (handle, inode, iblock, goal, count, errp,0 ); +}/** * ext4_count_free_blocks() -- count filesystem free blocks
fs/ext4/ext4.h +1 -1
@@ -977,7 +977,7 @@ extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,extern ext4_fsblk_t ext4_new_blocks (handle_t *handle,struct inode *inode,ext4_lblk_t iblock,ext4_fsblk_t goal,unsigned long *count,int *errp); -extern ext4_fsblk_t ext4_new_blocks_old (handle_t *handle,struct inode *inode, +extern ext4_fsblk_t ext4_old_new_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,unsigned long *count,int *errp);extern void ext4_free_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t block,unsigned long count,int metadata);
fs/ext4/extents.c +7 -3
@@ -179,8 +179,11 @@ static ext4_fsblk_t ext4_ext_find_goal(struct inode *inode,return bg_start + colour + block; } +/* +* Allocation for a meta data block +*/ static ext4_fsblk_t -ext4_ext_new_block (handle_t *handle,struct inode *inode, +ext4_ext_new_meta_block (handle_t *handle,struct inode *inode,struct ext4_ext_path *path,struct ext4_extent *ex,int *err) {
@@ -690,7 +693,8 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,/* allocate all needed blocks */ ext_debug ("allocate %d blocks for indexes/leaf\n" , depth - at);for (a =0 ; a < depth - at; a++) { - newblock =ext4_ext_new_block (handle, inode, path, newext, &err); + newblock =ext4_ext_new_meta_block (handle, inode, path, + newext, &err);if (newblock ==0 ) goto cleanup; ablocks[a] = newblock;
@@ -886,7 +890,7 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,ext4_fsblk_t newblock;int err =0 ; - newblock =ext4_ext_new_block (handle, inode, path, newext, &err); + newblock =ext4_ext_new_meta_block (handle, inode, path, newext, &err);if (newblock ==0 )return err;
fs/ext4/inode.c +1 -1
@@ -561,7 +561,7 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, goto allocated;/* Now allocate data blocks */ count = target; -/* allocating blocks for indirect blocks and direct blocks */ +/* allocating blocks for data blocks */ current_block =ext4_new_blocks (handle, inode, iblock, goal, &count, err);if (*err && (target == blks)) {
fs/ext4/mballoc.c +1 -1
@@ -4035,7 +4035,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, sbi =EXT4_SB (sb);if (!test_opt (sb,MBALLOC )) { - block =ext4_new_blocks_old (handle, ar->inode, ar->goal, + block =ext4_old_new_blocks (handle, ar->inode, ar->goal, &(ar->len), errp);return block; }
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 27/52 ext4: mballoc avoid use root reserved blocks for non root allocation
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
mballoc allocation missed check for blocks reserved for root users. Add ext4_has_free_blocks() check before allocation. Also modified ext4_has_free_blocks() to support multiple block allocation request.
--- fs/ext4/balloc.c | 51 +++++++++++++++++++++++++++++++++------------------ fs/ext4/ext4.h | 2 ++ fs/ext4/mballoc.c | 7 ++++++- 3 files changed, 41 insertions(+), 19 deletions(-)
fs/ext4/balloc.c +33 -18
@@ -1599,23 +1599,35 @@ out:/** * ext4_has_free_blocks() -* @sbi: in-core super block structure. +* @sbi: in-core super block structure. +* @nblocks: number of neeed blocks * -* Check if filesystem has at least 1 free block available for allocation. +* Check if filesystem has free blocks available for allocation. +* Return the number of blocks avaible for allocation for this request +* On success, return nblocks */ -static int ext4_has_free_blocks (struct ext4_sb_info *sbi) +ext4_fsblk_t ext4_has_free_blocks (struct ext4_sb_info *sbi, +ext4_fsblk_t nblocks) { -ext4_fsblk_t free_blocks, root_blocks; +ext4_fsblk_t free_blocks; +ext4_fsblk_t root_blocks =0 ; free_blocks =percpu_counter_read_positive (&sbi->s_freeblocks_counter); - root_blocks =ext4_r_blocks_count (sbi->s_es); -if (free_blocks < root_blocks +1 && !capable (CAP_SYS_RESOURCE ) && + +if (!capable (CAP_SYS_RESOURCE ) && sbi->s_resuid != current->fsuid && - (sbi->s_resgid ==0 || !in_group_p (sbi->s_resgid))) { -return 0 ; - } -return 1 ; -} + (sbi->s_resgid ==0 || !in_group_p (sbi->s_resgid))) + root_blocks =ext4_r_blocks_count (sbi->s_es); +#ifdef CONFIG_SMP +if (free_blocks - root_blocks <FBC_BATCH ) + free_blocks = +percpu_counter_sum_positive (&sbi->s_freeblocks_counter); +#endif +if (free_blocks - root_blocks < nblocks) +return free_blocks - root_blocks; +return nblocks; + } +/** * ext4_should_retry_alloc()
@@ -1631,7 +1643,7 @@ static int ext4_has_free_blocks(struct ext4_sb_info *sbi)*/ int ext4_should_retry_alloc (struct super_block *sb,int *retries) { -if (!ext4_has_free_blocks (EXT4_SB (sb)) || (*retries)++ >3 ) +if (!ext4_has_free_blocks (EXT4_SB (sb),1 ) || (*retries)++ >3 )return 0 ;jbd_debug (1 ,"%s: retrying operation after ENOSPC\n" , sb->s_id);
@@ -1681,13 +1693,21 @@ ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,ext4_group_t ngroups;unsigned long num = *count; - *errp = -ENOSPC ; sb = inode->i_sb;if (!sb) { + *errp = -ENODEV ;printk ("ext4_new_block: nonexistent device" );return 0 ; } + sbi =EXT4_SB (sb); + *count =ext4_has_free_blocks (sbi, *count); +if (*count ==0 ) { + *errp = -ENOSPC ; +return 0 ;/*return with ENOSPC error */ + } + num = *count; +/* * Check quota for allocation of this block. */
@@ -1711,11 +1731,6 @@ ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode,if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) >0 )) my_rsv = &block_i->rsv_window_node; -if (!ext4_has_free_blocks (sbi)) { - *errp = -ENOSPC ; - goto out; - } -/* * First, test whether the goal block is free. */
fs/ext4/ext4.h +2 -0
@@ -979,6 +979,8 @@ extern ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, unsigned long *count, int *errp);extern ext4_fsblk_t ext4_old_new_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,unsigned long *count,int *errp); +extern ext4_fsblk_t ext4_has_free_blocks (struct ext4_sb_info *sbi, +ext4_fsblk_t nblocks);extern void ext4_free_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t block,unsigned long count,int metadata); extern void ext4_free_blocks_sb (handle_t *handle, struct super_block *sb,
fs/ext4/mballoc.c +6 -0
@@ -4039,6 +4039,12 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, &(ar->len), errp);return block; } + ar->len =ext4_has_free_blocks (sbi, ar->len); + +if (ar->len ==0 ) { + *errp = -ENOSPC ; +return 0 ; + }while (ar->len &&DQUOT_ALLOC_BLOCK (ar->inode, ar->len)) { ar->flags |=EXT4_MB_HINT_NOPREALLOC ;
@@ -4067,7 +4073,6 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, ac->ac_op =EXT4_MB_HISTORY_PREALLOC ;if (!ext4_mb_use_preallocated (ac)) {
Theodore Ts'o
maintainerPATCH 28/52 ext4: Set journal pointer to NULL when journal is released
From: Jan Kara <[email protected]>
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 super_block * sb)ext4_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);
@@ -2423,6 +2424,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);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 30/52 ext4: Add missing unlock to an error path in ext4_quota_write()
In reply to Theodore Ts'oFrom: Jan Kara <[email protected]>
Add missing unlock of i_mutex in the error path of ext4_quota_write().
--- fs/ext4/super.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
fs/ext4/super.c +3 -1
@@ -3390,8 +3390,10 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, blk++; } out: -if (len == towrite) +if (len == towrite) { +mutex_unlock (&inode->i_mutex);return err; + }if (inode->i_size < off+len-towrite) {i_size_write (inode, off+len-towrite);EXT4_I (inode)->i_disksize = inode->i_size;
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 34/52 vfs: Move mark_inode_dirty() from under page lock in generic_write_end()
In reply to Theodore Ts'oFrom: 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); +/* +* Don't mark the 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.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 39/52 ext4: Use new framework for data=ordered mode in JBD2
In reply to Theodore Ts'oFrom: Jan Kara <[email protected]>
This patch makes ext4 use inode-based implementation of data=ordered mode in JBD2. It allows us to unify some data=ordered and data=writeback paths (especially writepage since we don't have to start a transaction anymore) and remove some buffer walking.
Updated fix from Aneesh Kumar K.V <[email protected]> to fix file system hang due to corrupt jinode values.
--- fs/ext4/ext4_i.h | 1 + fs/ext4/ext4_jbd2.h | 7 ++- fs/ext4/inode.c | 158 ++++++++++++++++----------------------------------- fs/ext4/super.c | 5 +- 4 files changed, 59 insertions(+), 112 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 char *where,#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_commit(journal_t *journal)return 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/inode.c +49 -109
243 lines not on this page · raw message
fs/ext4/super.c +4 -1
@@ -573,6 +573,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)memset (&ei->i_cached_extent,0 ,sizeof (struct ext4_ext_cache ));INIT_LIST_HEAD (&ei->i_prealloc_list);spin_lock_init (&ei->i_prealloc_lock); +jbd2_journal_init_jbd_inode (&ei->jinode, &ei->vfs_inode);return &ei->vfs_inode; }
@@ -637,6 +638,8 @@ static void ext4_clear_inode(struct inode *inode)EXT4_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)
@@ -3378,7 +3381,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, 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);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 51/52 ext4: Don't allow nonextenst mount option for large filesystem
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
The block mapped inode format can address only blocks within 2**32. This causes a number of issues, the biggest of which is that the block allocator needs to be taught that certain inodes can not utilize block numbers > 2**32. So until this is fixed, it is simplest to fail mounting of file systems with more than 2**32 blocks if the -o noextents option is given.
--- fs/ext4/super.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
fs/ext4/super.c +15 -0
@@ -1004,6 +1004,7 @@ static int parse_options (char *options, struct super_block *sb,int qtype, qfmt;char *qname;#endif +ext4_fsblk_t last_block;if (!options)return 1 ;
@@ -1326,6 +1327,20 @@ set_qf_format:set_opt (sbi->s_mount_opt,EXTENTS );break ;case Opt_noextents: +/* +* When e2fsprogs support resizing an already existing +* ext3 file system to greater than 2**32 we need to +* add support to block allocator to handle growing +* already existing block mapped inode so that blocks +* allocated for them fall within 2**32 +*/ + last_block =ext4_blocks_count (sbi->s_es) -1 ; +if (last_block >0xffffffffULL ) { +printk (KERN_ERR "EXT4-fs: Filesystem too " +"large to mount with " +"-o noextents options\n" ); +return 0 ; + }clear_opt (sbi->s_mount_opt,EXTENTS );break ;case Opt_i_version:
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 11/52 ext4: Remove unused variable from ext4_show_options
In reply to Theodore Ts'o--- fs/ext4/super.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
fs/ext4/super.c +0 -1
@@ -671,7 +671,6 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)unsigned long def_mount_opts;struct super_block *sb = vfs->mnt_sb;struct ext4_sb_info *sbi =EXT4_SB (sb); -journal_t *journal = sbi->s_journal;struct ext4_super_block *es = sbi->s_es; def_mount_opts =le32_to_cpu (es->s_default_mount_opts);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 14/52 jbd2: fix race between jbd2_journal_try_to_free_buffers() and jbd2 commit transaction
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
journal_try_to_free_buffers() could race with jbd commit transaction when the later is holding the buffer reference while waiting for the data buffer to flush to disk. If the caller of journal_try_to_free_buffers() request tries hard to release the buffers, it will treat the failure as error and return back to the caller. We have seen the directo IO failed due to this race. Some of the caller of releasepage() also expecting the buffer to be dropped when passed with GFP_KERNEL mask to the releasepage()->journal_try_to_free_buffers().
With this patch, if the caller is passing the GFP_KERNEL to indicating this call could wait, in case of try_to_free_buffers() failed, let's waiting for journal_commit_transaction() to finish commit the current committing transaction , then try to free those buffers again with journal locked.
--- fs/jbd2/transaction.c | 62 +++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 58 insertions(+), 4 deletions(-)
fs/jbd2/transaction.c +58 -4
@@ -41,7 +41,6 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh);* new transaction and we can't block without protecting against other * processes trying to touch the journal while it is in transition. * -* Called under j_state_lock */ static transaction_t *
@@ -1656,12 +1655,43 @@ out:return ; } +/* +* jbd2_journal_try_to_free_buffers() could race with +* jbd2_journal_commit_transaction(). The later might still hold the +* reference count to the buffers when inspecting them on +* t_syncdata_list or t_locked_list. +* +* jbd2_journal_try_to_free_buffers() will call this function to +* wait for the current transaction to finish syncing data buffers, before +* try to free that buffer. +* +* Called with journal->j_state_lock hold. +*/ +static void jbd2_journal_wait_for_transaction_sync_data (journal_t *journal) +{ +transaction_t *transaction =NULL ; +tid_t tid; + +spin_lock (&journal->j_state_lock); + transaction = journal->j_committing_transaction; + +if (!transaction) { +spin_unlock (&journal->j_state_lock); +return ; + } + + tid = transaction->t_tid; +spin_unlock (&journal->j_state_lock); +jbd2_log_wait_commit (journal, tid); +}/** * int jbd2_journal_try_to_free_buffers() - try to free page buffers. * @journal: journal for operation * @page: to try and free -* @unused_gfp_mask: unused +* @gfp_mask: we use the mask to detect how hard should we try to release +* buffers. If __GFP_WAIT and __GFP_FS is set, we wait for commit code to +* release the buffers. * * * For all the buffers on this page,
@@ -1690,9 +1720,11 @@ out:* journal_try_to_free_buffer() is changing its state. But that * cannot happen because we never reallocate freed data as metadata * while the data is part of a transaction. Yes? +* +* Return 0 on failure, 1 on success */ int jbd2_journal_try_to_free_buffers (journal_t *journal, -struct page *page,gfp_t unused_gfp_mask) +struct page *page,gfp_t gfp_mask) {struct buffer_head *head;struct buffer_head *bh;
@@ -1708,7 +1740,8 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal,/* * We take our own ref against the journal_head here to avoid * having to add tons of locking around each instance of -* jbd2_journal_remove_journal_head() and jbd2_journal_put_journal_head(). +* jbd2_journal_remove_journal_head() and +* jbd2_journal_put_journal_head(). */ jh =jbd2_journal_grab_journal_head (bh);if (!jh)
@@ -1721,7 +1754,28 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal,if (buffer_jbd (bh)) goto busy; }while ((bh = bh->b_this_page) != head); + ret =try_to_free_buffers (page); + +/* +* There are a number of places where jbd2_journal_try_to_free_buffers() +* could race with jbd2_journal_commit_transaction(), the later still +* holds the reference to the buffers to free while processing them. +* try_to_free_buffers() failed to free those buffers. Some of the +* caller of releasepage() request page buffers to be dropped, otherwise +* treat the fail-to-free as errors (such as generic_file_direct_IO()) +* +* So, if the caller of try_to_release_page() wants the synchronous +* behaviour(i.e make sure buffers are dropped upon return), +* let's wait for the current transaction to finish flush of +* dirty data buffers, then try to free those buffers again, +* with the journal locked. +*/ +if (ret ==0 && (gfp_mask & __GFP_WAIT) && (gfp_mask & __GFP_FS)) { +jbd2_journal_wait_for_transaction_sync_data (journal); + ret =try_to_free_buffers (page); + } + busy:return ret; }
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 16/52 ext4: remove quota allocation when ext4_mb_new_blocks fails
In reply to Theodore Ts'oFrom: Shen Feng <[email protected]>
Quota allocation is not removed when ext4_mb_new_blocks calls kmem_cache_alloc failed. Also make sure the allocation context is freed on the error path.
--- fs/ext4/mballoc.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
fs/ext4/mballoc.c +6 -4
@@ -4052,8 +4052,9 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, ac =kmem_cache_alloc (ext4_ac_cachep,GFP_NOFS );if (!ac) { + ar->len =0 ; *errp = -ENOMEM ; -return 0 ; + goto out1; }ext4_mb_poll_new_transaction (sb, handle);
@@ -4061,7 +4062,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, *errp =ext4_mb_initialize_context (ac, ar);if (*errp) { ar->len =0 ; - goto out; + goto out2; } ac->ac_op =EXT4_MB_HISTORY_PREALLOC ;
@@ -4109,11 +4110,12 @@ repeat:ext4_mb_release_context (ac); -out: +out2: +kmem_cache_free (ext4_ac_cachep, ac); +out1:if (ar->len < inquota)DQUOT_FREE_BLOCK (ar->inode, inquota - ar->len); -kmem_cache_free (ext4_ac_cachep, ac);return block; } static void ext4_mb_poll_new_transaction(struct super_block *sb,
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 17/52 ext4: Update i_disksize properly when allocating from fallocate area.
From: Aneesh Kumar K.V <[email protected]>
When allocating unitialized space at the end of file which had been preallocated with the FALLOC_FL_KEEP_SIZE option, the file size is not updated at that time. But the later we are not updating the file size when writing to that preallocated space.
These changes are for code correctness. This patch allows us to update the i_disksize at the write_end() callback of filesystem properly.
--- fs/ext4/extents.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
fs/ext4/extents.c +0 -2
@@ -2716,13 +2716,13 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, goto out2; } -if (extend_disksize && inode->i_size >EXT4_I (inode)->i_disksize) -EXT4_I (inode)->i_disksize = inode->i_size;
Theodore Ts'o
maintainerPATCH 18/52 ext4: return error when calling ext4_ext_split failed
From: Shen Feng <[email protected]>
ext4_ext_create_new_leaf must return error when its calling to ext4_ext_split failed.
--- fs/ext4/extents.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/ext4/extents.c +2 -0
@@ -981,6 +981,8 @@ repeat:/* if we found index with free entry, then use that * entry: create all needed subtree and add new leaf */ err =ext4_ext_split (handle, inode, path, newext, i); +if (err) + goto out;/* refill path */ ext4_ext_drop_refs (path);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 21/52 ext4: cleanup never-used magic numbers from htree code
In reply to Theodore Ts'oFrom: Li Zefan <[email protected]>
dx_root_limit() will had some dead code which forced it to always return 20, and dx_node_limit to always return 22 for debugging purposes. Remove it.
--- fs/ext4/namei.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/ext4/namei.c +2 -2
@@ -231,13 +231,13 @@ static inline unsigned dx_root_limit (struct inode *dir, unsigned infosize) {unsigned entry_space = dir->i_sb->s_blocksize -EXT4_DIR_REC_LEN (1 ) -EXT4_DIR_REC_LEN (2 ) - infosize; -return 0 ?20 : entry_space /sizeof (struct dx_entry ); +return entry_space /sizeof (struct dx_entry ); }static inline unsigned dx_node_limit (struct inode *dir) {unsigned entry_space = dir->i_sb->s_blocksize -EXT4_DIR_REC_LEN (0 ); -return 0 ?22 : entry_space /sizeof (struct dx_entry ); +return entry_space /sizeof (struct dx_entry ); }/*
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 22/52 ext4: Fix sparse warning
From: Aneesh Kumar K.V <[email protected]>
--- fs/ext4/balloc.c | 2 +- fs/ext4/super.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/ext4/balloc.c +1 -1
@@ -47,7 +47,7 @@ static int ext4_block_in_group(struct super_block *sb, ext4_fsblk_t block, ext4_group_t block_group) {ext4_group_t actual_group; -ext4_get_group_no_and_offset (sb, block, &actual_group,0 ); +ext4_get_group_no_and_offset (sb, block, &actual_group,NULL );if (actual_group == block_group)return 1 ;return 0 ;
fs/ext4/super.c +2 -2
@@ -1858,8 +1858,8 @@ static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi) }static int ext4_fill_super (struct super_block *sb,void *data,int silent) -__releases (kernel_sem) -__acquires (kernel_sem) +__releases (kernel_lock) +__acquires (kernel_lock) {struct buffer_head * bh;
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 35/52 ext4: Invert the locking order of page_lock and transaction start
In reply to Theodore Ts'oFrom: Jan Kara <[email protected]>
This changes are needed to support data=ordered mode handling via inodes. This enables us to get rid of the journal heads and buffer heads for data buffers in the ordered mode. With the changes, during tranasaction commit we writeout the inode pages using the writepages()/writepage(). That implies we take page lock during transaction commit. This can cause a deadlock with the locking order page_lock -> jbd2_journal_start, since the jbd2_journal_start can wait for the journal_commit to happen and the journal_commit now needs to take the page lock. To avoid this dead lock reverse the locking order.
--- fs/ext4/ext4.h | 4 +- fs/ext4/extents.c | 15 +-- fs/ext4/inode.c | 292 +++++++++++++++++++++++++++-------------------------- 3 files changed, 155 insertions(+), 156 deletions(-)
fs/ext4/ext4.h +2 -2
@@ -1065,7 +1065,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);
@@ -1224,7 +1224,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
@@ -2749,7 +2749,7 @@ out2: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;
@@ -2762,18 +2762,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 +149 -143
479 lines not on this page · raw message
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 44/52 ext4: delayed allocation ENOSPC handling
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
This patch does block reservation for delayed allocation, to avoid ENOSPC later at page flush time.
Blocks(data and metadata) are reserved at da_write_begin() time, the freeblocks counter is updated by then, and the number of reserved blocks is store in per inode counter.
At the writepage time, the unused reserved meta blocks are returned back. At unlink/truncate time, reserved blocks are properly released.
Updated fix from Aneesh Kumar K.V <[email protected]> to fix the oldallocator block reservation accounting with delalloc, added lock to guard the counters and also fix the reservation for meta blocks.
--- fs/ext4/balloc.c | 49 +++++++++----- fs/ext4/dir.c | 3 +- fs/ext4/ext4.h | 6 ++- fs/ext4/ext4_extents.h | 1 + fs/ext4/ext4_i.h | 7 ++ fs/ext4/extents.c | 32 ++++++++- fs/ext4/inode.c | 178 ++++++++++++++++++++++++++++++++++++++++-------- fs/ext4/mballoc.c | 20 +++++- fs/ext4/super.c | 5 ++ 9 files changed, 251 insertions(+), 50 deletions(-)
fs/ext4/balloc.c +32 -17
@@ -1701,7 +1701,12 @@ ext4_fsblk_t ext4_old_new_blocks(handle_t *handle, struct inode *inode, } sbi =EXT4_SB (sb); - *count =ext4_has_free_blocks (sbi, *count); +if (!EXT4_I (inode)->i_delalloc_reserved_flag) { +/* +* With delalloc we already reserved the blocks +*/ + *count =ext4_has_free_blocks (sbi, *count); + }if (*count ==0 ) { *errp = -ENOSPC ;return 0 ;/*return with ENOSPC error */
@@ -1902,7 +1907,8 @@ allocated:le16_add_cpu (&gdp->bg_free_blocks_count, -num); gdp->bg_checksum =ext4_group_desc_csum (sbi, group_no, gdp);spin_unlock (sb_bgl_lock (sbi, group_no)); -percpu_counter_sub (&sbi->s_freeblocks_counter, num); +if (!EXT4_I (inode)->i_delalloc_reserved_flag) +percpu_counter_sub (&sbi->s_freeblocks_counter, num);if (sbi->s_log_groups_per_flex) {ext4_group_t flex_group =ext4_flex_group (sbi, group_no);
@@ -1976,40 +1982,49 @@ static ext4_fsblk_t do_blk_alloc(handle_t *handle, struct inode *inode, }/* -* ext4_new_meta_block() -- allocate block for meta data (indexing) blocks +* ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks * * @handle: handle to this transaction * @inode: file inode * @goal: given target block(filesystem wide) +* @count: total number of blocks need * @errp: error code * -* Return allocated block number on success +* Return 1st allocated block numberon success, *count stores total account +* error stores in errp pointer */ -ext4_fsblk_t ext4_new_meta_block (handle_t *handle,struct inode *inode, -ext4_fsblk_t goal,int *errp) +ext4_fsblk_t ext4_new_meta_blocks (handle_t *handle,struct inode *inode, +ext4_fsblk_t goal,unsigned long *count,int *errp) { -unsigned long count =1 ; -return do_blk_alloc (handle, inode,0 , goal, - &count, errp,EXT4_META_BLOCK ); +ext4_fsblk_t ret; + ret =do_blk_alloc (handle, inode,0 , goal, + count, errp,EXT4_META_BLOCK ); +/* +* Account for the allocated meta blocks +*/ +if (!(*errp)) { +spin_lock (&EXT4_I (inode)->i_block_reservation_lock); +EXT4_I (inode)->i_allocated_meta_blocks += *count; +spin_unlock (&EXT4_I (inode)->i_block_reservation_lock); + } +return ret; }/* -* ext4_new_meta_blocks() -- allocate block for meta data (indexing) blocks +* ext4_new_meta_block() -- allocate block for meta data (indexing) blocks * * @handle: handle to this transaction * @inode: file inode * @goal: given target block(filesystem wide) -* @count: total number of blocks need * @errp: error code * -* Return 1st allocated block numberon success, *count stores total account -* error stores in errp pointer +* Return allocated block number on success */ -ext4_fsblk_t ext4_new_meta_blocks (handle_t *handle,struct inode *inode, -ext4_fsblk_t goal,unsigned long *count,int *errp) +ext4_fsblk_t ext4_new_meta_block (handle_t *handle,struct inode *inode, +ext4_fsblk_t goal,int *errp) { -return do_blk_alloc (handle, inode,0 , goal, - count, errp,EXT4_META_BLOCK ); +unsigned long count =1 ; +return ext4_new_meta_blocks (handle, inode, goal, &count, errp); }/*
fs/ext4/dir.c +2 -1
@@ -129,7 +129,8 @@ static int ext4_readdir(struct file * filp,struct buffer_head *bh =NULL ; map_bh.b_state =0 ; - err =ext4_get_blocks_wrap (NULL , inode, blk,1 , &map_bh,0 ,0 ); + err =ext4_get_blocks_wrap (NULL , inode, blk,1 , &map_bh, +0 ,0 ,0 );if (err >0 ) {pgoff_t index = map_bh.b_blocknr >> (PAGE_CACHE_SHIFT - inode->i_blkbits);
fs/ext4/ext4.h +5 -1
@@ -74,6 +74,9 @@#define EXT4_MB_HINT_GOAL_ONLY 256/* goal is meaningful */ #define EXT4_MB_HINT_TRY_GOAL 512 +/* blocks already pre-reserved by delayed allocation */ +#define EXT4_MB_DELALLOC_RESERVED 1024 +struct ext4_allocation_request {/* target inode for block we're allocating */
@@ -1041,6 +1044,7 @@ extern void ext4_mb_update_group_info(struct ext4_group_info *grp,/* inode.c */ +void ext4_da_release_space (struct inode *inode,int used,int to_free);int ext4_forget (handle_t *handle,int is_metadata,struct inode *inode,struct buffer_head *bh,ext4_fsblk_t blocknr); struct buffer_head *ext4_getblk(handle_t *, struct inode *,
@@ -1233,7 +1237,7 @@ extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset,extern int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode,sector_t block,unsigned long max_blocks,struct buffer_head *bh,int create, -int extend_disksize); +int extend_disksize,int flag);#endif /* __KERNEL__ */ #endif /* _EXT4_H */
fs/ext4/ext4_extents.h +1 -0
@@ -212,6 +212,7 @@ static inline int ext4_ext_get_actual_len(struct ext4_extent *ext) (le16_to_cpu(ext->ee_len) - EXT_INIT_MAX_LEN)); } +extern int ext4_ext_calc_metadata_amount (struct inode *inode,int blocks);extern ext4_fsblk_t idx_pblock (struct ext4_extent_idx *);extern void ext4_ext_store_pblock (struct ext4_extent *,ext4_fsblk_t );extern int ext4_extent_tree_init (handle_t *,struct inode *);
fs/ext4/ext4_i.h +7 -0
@@ -163,6 +163,13 @@ struct ext4_inode_info {/* mballoc */ struct list_head i_prealloc_list;spinlock_t i_prealloc_lock; + +/* allocation reservation info for delalloc */ +unsigned long i_reserved_data_blocks; +unsigned long i_reserved_meta_blocks; +unsigned long i_allocated_meta_blocks; +unsigned short i_delalloc_reserved_flag; + spinlock_t i_block_reservation_lock; };#endif /* _EXT4_I */
fs/ext4/extents.c +31 -1
@@ -248,6 +248,36 @@ static int ext4_ext_space_root_idx(struct inode *inode)return size; } +/* +* Calculate the number of metadata blocks needed +* to allocate @blocks +* Worse case is one block per extent +*/ +int ext4_ext_calc_metadata_amount (struct inode *inode,int blocks) +{ +int lcap, icap, rcap, leafs, idxs, num; +int newextents = blocks; + + rcap =ext4_ext_space_root_idx (inode); + lcap =ext4_ext_space_block (inode); + icap =ext4_ext_space_block_idx (inode); + +/* number of new leaf blocks needed */ + num = leafs = (newextents + lcap -1 ) / lcap; + +/* +* Worse case, we need separate index block(s) +* to link all new leaf blocks +*/ + idxs = (leafs + icap -1 ) / icap; +do { + num += idxs; + idxs = (idxs + icap -1 ) / icap; + }while (idxs > rcap); + +return num; +} +static int ext4_ext_max_entries (struct inode *inode,int depth) {
@@ -2910,7 +2940,7 @@ retry: } ret =ext4_get_blocks_wrap (handle, inode, block, max_blocks, &map_bh, -EXT4_CREATE_UNINITIALIZED_EXT ,0 ); +EXT4_CREATE_UNINITIALIZED_EXT ,0 ,0 );if (ret <=0 ) {#ifdef EXT4FS_DEBUG WARN_ON (ret <=0 );
fs/ext4/inode.c +150 -28
275 lines not on this page · raw message
fs/ext4/mballoc.c +18 -2
@@ -2956,7 +2956,15 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,le16_add_cpu (&gdp->bg_free_blocks_count, -ac->ac_b_ex.fe_len); gdp->bg_checksum =ext4_group_desc_csum (sbi, ac->ac_b_ex.fe_group, gdp);spin_unlock (sb_bgl_lock (sbi, ac->ac_b_ex.fe_group)); -percpu_counter_sub (&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len); + +/* +* free blocks account has already be reduced/reserved +* at write_begin() time for delayed allocation +* do not double accounting +*/ +if (!(ac->ac_flags &EXT4_MB_DELALLOC_RESERVED )) +percpu_counter_sub (&sbi->s_freeblocks_counter, + ac->ac_b_ex.fe_len);if (sbi->s_log_groups_per_flex) { ext4_group_t flex_group = ext4_flex_group(sbi,
@@ -4163,7 +4171,12 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, &(ar->len), errp);return block; } - ar->len =ext4_has_free_blocks (sbi, ar->len); +if (!EXT4_I (ar->inode)->i_delalloc_reserved_flag) { +/* +* With delalloc we already reserved the blocks +*/ + ar->len =ext4_has_free_blocks (sbi, ar->len); + }if (ar->len ==0 ) { *errp = -ENOSPC ;
@@ -4180,6 +4193,9 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, } inquota = ar->len; +if (EXT4_I (ar->inode)->i_delalloc_reserved_flag) + ar->flags |=EXT4_MB_DELALLOC_RESERVED ; + ac =kmem_cache_alloc (ext4_ac_cachep,GFP_NOFS );if (!ac) { ar->len =0 ;
fs/ext4/super.c +5 -0
@@ -574,6 +574,11 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)INIT_LIST_HEAD (&ei->i_prealloc_list);spin_lock_init (&ei->i_prealloc_lock);jbd2_journal_init_jbd_inode (&ei->jinode, &ei->vfs_inode); + ei->i_reserved_data_blocks =0 ; + ei->i_reserved_meta_blocks =0 ; + ei->i_allocated_meta_blocks =0 ; + ei->i_delalloc_reserved_flag =0 ; +spin_lock_init (&(ei->i_block_reservation_lock));return &ei->vfs_inode; }
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 46/52 ext4: Invert lock ordering of page_lock and transaction start in delalloc
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
With the reverse locking, we need to start a transation before taking the page lock, so in ext4_da_writepages() we need to break the write-out into chunks, and restart the journal for each chunck to ensure the write-out fits in a single transaction.
Updated patch from Aneesh Kumar K.V <[email protected]> which fixes delalloc sync hang with journal lock inversion, and address the performance regression issue.
--- fs/ext4/extents.c | 10 ++- fs/ext4/inode.c | 189 +++++++++++++++++++++++++++++++++++++++-------------- fs/mpage.c | 12 ++-- 3 files changed, 152 insertions(+), 59 deletions(-)
fs/ext4/extents.c +8 -2
@@ -2565,6 +2565,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,int err =0 , depth, ret;unsigned long allocated =0 ;struct ext4_allocation_request ar; +loff_t disksize;__clear_bit (BH_New, &bh_result->b_state); ext_debug("blocks %u/%lu requested for inode %u\n",
@@ -2755,8 +2756,13 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, newblock =ext_pblock (&newex); allocated =ext4_ext_get_actual_len (&newex); outnew: -if (extend_disksize && inode->i_size >EXT4_I (inode)->i_disksize) -EXT4_I (inode)->i_disksize = inode->i_size; +if (extend_disksize) { + disksize = ((loff_t ) iblock + ar.len) << inode->i_blkbits; +if (disksize >i_size_read (inode)) + disksize =i_size_read (inode); +if (disksize >EXT4_I (inode)->i_disksize) +EXT4_I (inode)->i_disksize = disksize; + }set_buffer_new (bh_result);
fs/ext4/inode.c +139 -50
247 lines not on this page · raw message
fs/mpage.c +5 -7
@@ -849,13 +849,11 @@ 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)) { + } else if (buffer_mapped(bh)) BUG_ON(bh->b_blocknr != pblock); - } cur_logical++; pblock++;
@@ -930,10 +928,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))
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 1/52 ext4: fix comments to say "ext4"
In reply to Theodore Ts'oFrom: Shen Feng <[email protected]>
Change second/third to fourth.
--- fs/ext4/ext4.h | 2 +- fs/ext4/ext4_i.h | 2 +- fs/ext4/ext4_sb.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/ext4/ext4.h +1 -1
@@ -22,7 +22,7 @@#include "ext4_i.h" /* -* The second extended filesystem constants/structures +* The fourth extended filesystem constants/structures */ /*
fs/ext4/ext4_i.h +1 -1
@@ -79,7 +79,7 @@ struct ext4_ext_cache { };/* -* third extended file system inode data in memory +* fourth extended file system inode data in memory */ struct ext4_inode_info {__le32 i_data[15 ];/* unconverted */
fs/ext4/ext4_sb.h +1 -1
@@ -25,7 +25,7 @@#include <linux/rbtree.h> /* -* third extended-fs super-block data in memory +* fourth extended-fs super-block data in memory */ struct ext4_sb_info {unsigned long s_desc_size;/* Size of a group descriptor in bytes */
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 15/52 ext4: remove redundant code in ext4_fill_super()
In reply to Theodore Ts'oFrom: Li Zefan <[email protected]>
The previous sb_min_blocksize() has already set the block size.
--- fs/ext4/super.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
fs/ext4/super.c +0 -4
@@ -1899,11 +1899,6 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) goto out_fail; } -if (!sb_set_blocksize (sb, blocksize)) { -printk (KERN_ERR "EXT4-fs: bad blocksize %d.\n" , blocksize); - goto out_fail; - }
Theodore Ts'o
maintainerPATCH 20/52 ext4: Fix ext4_ext_journal_restart() to reflect errors up to the caller
In reply to Theodore Ts'oFrom: Shen Feng <[email protected]>
Fix ext4_ext_journal_restart() so it returns any errors reported by ext4_journal_extend() and ext4_journal_restart().
--- fs/ext4/extents.c | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-)
fs/ext4/extents.c +8 -11
@@ -92,17 +92,16 @@ static void ext4_idx_store_pblock(struct ext4_extent_idx *ix, ext4_fsblk_t pb) ix->ei_leaf_hi =cpu_to_le16 ((unsigned long ) ((pb >>31 ) >>1 ) &0xffff ); } -static handle_t *ext4_ext_journal_restart (handle_t *handle,int needed) +static int ext4_ext_journal_restart (handle_t *handle,int needed) {int err;if (handle->h_buffer_credits > needed) -return handle; -if (!ext4_journal_extend (handle, needed)) -return handle; - err =ext4_journal_restart (handle, needed); - -return handle; +return 0 ; + err =ext4_journal_extend (handle, needed); +if (err) +return err; +return ext4_journal_restart (handle, needed); }/*
@@ -1888,11 +1887,9 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, credits +=2 *EXT4_QUOTA_TRANS_BLOCKS (inode->i_sb);#endif - handle =ext4_ext_journal_restart (handle, credits); -if (IS_ERR (handle)) { - err =PTR_ERR (handle); + err =ext4_ext_journal_restart (handle, credits); +if (err) goto out; - } err =ext4_ext_get_access (handle, inode, path + depth);if (err)
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 5/52 ext4: improve some code in rb tree part of dir.c
In reply to Theodore Ts'oFrom: Shen Feng <[email protected]>
* remove unnecessary code in free_rb_tree_fname
* rename free_rb_tree_fname to ext4_htree_create_dir_info since it and ext4_htree_free_dir_info are a pair
* replace kmalloc with kzalloc in ext4_htree_free_dir_info
All these make the code more readable and simple.
PS: this patch is also suitable for ext3.
--- fs/ext4/dir.c | 14 ++++---------- 1 files changed, 4 insertions(+), 10 deletions(-)
fs/ext4/dir.c +4 -10
@@ -272,7 +272,7 @@ static void free_rb_tree_fname(struct rb_root *root)while (n) {/* Do the node's children first */ -if ((n)->rb_left) { +if (n->rb_left) { n = n->rb_left;continue ; }
@@ -301,24 +301,18 @@ static void free_rb_tree_fname(struct rb_root *root) parent->rb_right =NULL ; n = parent; } - root->rb_node =NULL ; } -static struct dir_private_info *create_dir_info (loff_t pos) +static struct dir_private_info *ext4_htree_create_dir_info (loff_t pos) {struct dir_private_info *p; - p =kmalloc (sizeof (struct dir_private_info ),GFP_KERNEL ); + p =kzalloc (sizeof (struct dir_private_info ),GFP_KERNEL );if (!p)return NULL ; - p->root.rb_node =NULL ; - p->curr_node =NULL ; - p->extra_fname =NULL ; - p->last_pos =0 ; p->curr_hash =pos2maj_hash (pos); p->curr_minor_hash =pos2min_hash (pos); - p->next_hash =0 ;return p; }
@@ -433,7 +427,7 @@ static int ext4_dx_readdir(struct file * filp,int ret;if (!info) { - info =create_dir_info (filp->f_pos); + info =ext4_htree_create_dir_info (filp->f_pos);if (!info)return -ENOMEM ; filp->private_data = info;
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 7/52 ext4: add error processing when calling ext4_mb_init_cache in mballoc
In reply to Theodore Ts'oFrom: Shen Feng <[email protected]>
Add error processing for ext4_mb_load_buddy when it calls ext4_mb_init_cache.
--- fs/ext4/mballoc.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-)
fs/ext4/mballoc.c +20 -7
@@ -884,6 +884,7 @@ ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group,int pnum;int poff;struct page *page; +int ret;mb_debug ("load group %lu\n" , group);
@@ -915,15 +916,21 @@ ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group,if (page) {BUG_ON (page->mapping != inode->i_mapping);if (!PageUptodate (page)) { -ext4_mb_init_cache (page,NULL ); + ret =ext4_mb_init_cache (page,NULL ); +if (ret) { +unlock_page (page); + goto err; + }mb_cmp_bitmaps (e4b,page_address (page) + (poff * sb->s_blocksize)); }unlock_page (page); } } -if (page ==NULL || !PageUptodate (page)) +if (page ==NULL || !PageUptodate (page)) { + ret = -EIO ; goto err; + } e4b->bd_bitmap_page = page; e4b->bd_bitmap =page_address (page) + (poff * sb->s_blocksize);mark_page_accessed (page);
@@ -939,14 +946,20 @@ ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group, page =find_or_create_page (inode->i_mapping, pnum,GFP_NOFS );if (page) {BUG_ON (page->mapping != inode->i_mapping); -if (!PageUptodate (page)) -ext4_mb_init_cache (page, e4b->bd_bitmap); - +if (!PageUptodate (page)) { + ret =ext4_mb_init_cache (page, e4b->bd_bitmap); +if (ret) { +unlock_page (page); + goto err; + } + }unlock_page (page); } } -if (page ==NULL || !PageUptodate (page)) +if (page ==NULL || !PageUptodate (page)) { + ret = -EIO ; goto err; + } e4b->bd_buddy_page = page; e4b->bd_buddy =page_address (page) + (poff * sb->s_blocksize);mark_page_accessed (page);
@@ -963,7 +976,7 @@ err:page_cache_release (e4b->bd_buddy_page); e4b->bd_buddy =NULL ; e4b->bd_bitmap =NULL ; -return -EIO ; +return ret; }static void ext4_mb_release_desc (struct ext4_buddy *e4b)
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 8/52 ext4: miscellaneous error checks and coding cleanups for mballoc
From: Shen Feng <[email protected]>
ext4_mb_seq_history_open(): check if sbi->s_mb_history is NULL
ext4_mb_history_init(): replace kmalloc and memset with kzalloc
ext4_mb_init_backend(): remove memset since kzalloc is used
ext4_mb_init(): the return value of ext4_mb_init_backend is int,
but i is unsigned, replace it with a new int variable.
--- fs/ext4/mballoc.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
fs/ext4/mballoc.c +7 -7
@@ -1979,6 +1979,8 @@ static int ext4_mb_seq_history_open(struct inode *inode, struct file *file)int rc;int size; +if (unlikely (sbi->s_mb_history ==NULL )) +return -ENOMEM ; s =kmalloc (sizeof (*s),GFP_KERNEL );if (s ==NULL )return -ENOMEM ;
@@ -2181,9 +2183,7 @@ static void ext4_mb_history_init(struct super_block *sb) sbi->s_mb_history_cur =0 ;spin_lock_init (&sbi->s_mb_history_lock); i = sbi->s_mb_history_max *sizeof (struct ext4_mb_history ); - sbi->s_mb_history =kmalloc (i,GFP_KERNEL ); -if (likely (sbi->s_mb_history !=NULL )) -memset (sbi->s_mb_history,0 , i); + sbi->s_mb_history =kzalloc (i,GFP_KERNEL );/* if we can't allocate history, then we simple won't use it */ }
@@ -2297,7 +2297,6 @@ static int ext4_mb_init_backend(struct super_block *sb) i++; goto err_freebuddy; } -memset (meta_group_info[j],0 , len);set_bit (EXT4_GROUP_INFO_NEED_INIT_BIT , &(meta_group_info[j]->bb_state));
@@ -2352,6 +2351,7 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)unsigned i;unsigned offset;unsigned max; +int ret;if (!test_opt (sb,MBALLOC ))return 0 ;
@@ -2386,12 +2386,12 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery) }while (i <= sb->s_blocksize_bits +1 );/* init file for buddy data */ - i =ext4_mb_init_backend (sb); -if (i) { + ret =ext4_mb_init_backend (sb); +if (ret !=0 ) {clear_opt (sbi->s_mount_opt,MBALLOC );kfree (sbi->s_mb_offsets);kfree (sbi->s_mb_maxs); -return i; +return ret; }spin_lock_init (&sbi->s_md_lock);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 9/52 ext4: remove double definitions of xattr macros
From: Shen Feng <[email protected]>
remove the definitions of macros XATTR_TRUSTED_PREFIX and XATTR_USER_PREFIX since they are defined in linux/xattr.h
--- fs/ext4/xattr_trusted.c | 4 +--- fs/ext4/xattr_user.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-)
fs/ext4/xattr_trusted.c +1 -3
@@ -13,13 +13,11 @@#include "ext4.h" #include "xattr.h" -#define XATTR_TRUSTED_PREFIX "trusted." -static size_t ext4_xattr_trusted_list (struct inode *inode,char *list,size_t list_size,const char *name,size_t name_len) { -const size_t prefix_len =sizeof (XATTR_TRUSTED_PREFIX )-1 ; +const size_t prefix_len =XATTR_TRUSTED_PREFIX_LEN ;const size_t total_len = prefix_len + name_len +1 ;if (!capable (CAP_SYS_ADMIN ))
fs/ext4/xattr_user.c +0 -1
@@ -12,13 +12,11 @@#include "ext4.h" #include "xattr.h" -#define XATTR_USER_PREFIX "user."
Theodore Ts'o
maintainerPATCH 19/52 ext4: Make ext4_ext_find_extent fills ext_path completely
In reply to Theodore Ts'oFrom: Shen Feng <[email protected]>
When pos=0 or depth, the fields of ext4_ext_path is are not completely filled. This patch also removes some unnecessary code.
--- fs/ext4/extents.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
fs/ext4/extents.c +4 -1
@@ -524,6 +524,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, alloc =1 ; } path[0 ].p_hdr = eh; + path[0 ].p_bh =NULL ; i = depth;/* walk through the tree */
@@ -552,12 +553,14 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block, } path[ppos].p_depth = i; - path[ppos].p_hdr = eh; path[ppos].p_ext =NULL ; path[ppos].p_idx =NULL ;/* find extent */ ext4_ext_binsearch (inode, path + ppos, block); +/* if not an empty leaf */ +if (path[ppos].p_ext) + path[ppos].p_block =ext_pblock (path[ppos].p_ext);ext4_ext_show_path (inode, path);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 23/52 ext4: fix ext4_init_block_bitmap() for metablock block group
In reply to Theodore Ts'oFrom: Akinobu Mita <[email protected]>
When meta_bg feature is enabled and s_first_meta_bg != 0, ext4_init_block_bitmap() miscalculates the number of block used by the group descriptor table (0 or 1 for metablock block group)
This patch fixes this by using ext4_bg_num_gdb()
--- fs/ext4/balloc.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
fs/ext4/balloc.c +1 -6
@@ -121,12 +121,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,le16_to_cpu (sbi->s_es->s_reserved_gdt_blocks); } }else {/* For META_BG_BLOCK_GROUPS */ -int group_rel = (block_group - -le32_to_cpu (sbi->s_es->s_first_meta_bg)) % -EXT4_DESC_PER_BLOCK (sb); -if (group_rel ==0 || group_rel ==1 || - (group_rel ==EXT4_DESC_PER_BLOCK (sb) -1 )) - bit_max +=1 ; + bit_max +=ext4_bg_num_gdb (sb, block_group); }if (block_group == sbi->s_groups_count -1 ) {
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 26/52 ext4: call blkdev_issue_flush on fsync
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
To ensure that bits are truly on-disk after an fsync, we should call blkdev_issue_flush if barriers are supported.
Inspired by an old thread on barriers, by reiserfs & xfs which do the same, and by a patch SuSE ships with their kernel
--- fs/ext4/fsync.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
fs/ext4/fsync.c +4 -0
@@ -27,6 +27,7 @@#include <linux/sched.h> #include <linux/writeback.h> #include <linux/jbd2.h> +#include <linux/blkdev.h> #include "ext4.h" #include "ext4_jbd2.h"
@@ -45,6 +46,7 @@int ext4_sync_file (struct file * file,struct dentry *dentry,int datasync) {struct inode *inode = dentry->d_inode; +journal_t *journal =EXT4_SB (inode->i_sb)->s_journal;int ret =0 ;J_ASSERT (ext4_journal_current_handle () ==NULL );
@@ -85,6 +87,8 @@ int ext4_sync_file(struct file * file, struct dentry *dentry, int datasync) .nr_to_write = 0, /* sys_fsync did this */ }; ret =sync_inode (inode, &wbc); +if (journal && (journal->j_flags &JBD2_BARRIER )) +blkdev_issue_flush (inode->i_sb->s_bdev,NULL ); } out:return ret;
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 29/52 ext4: use atomic functions to set bh_state
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
Use the BUFFER_FNS functions (set_buffer_foo) to set buffer head state atomically instead of nonatomic __set_bit().
--- fs/ext4/extents.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
fs/ext4/extents.c +3 -4
@@ -2622,8 +2622,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,*/ if (allocated > max_blocks) allocated = max_blocks; -/* mark the buffer unwritten */ -__set_bit (BH_Unwritten, &bh_result->b_state); +set_buffer_unwritten (bh_result); goto out2; }
@@ -2729,7 +2728,7 @@ outnew:if (extend_disksize && inode->i_size >EXT4_I (inode)->i_disksize)EXT4_I (inode)->i_disksize = inode->i_size; -__set_bit (BH_New, &bh_result->b_state); +set_buffer_new (bh_result);/* Cache only when it is _not_ an uninitialized extent */ if (create !=EXT4_CREATE_UNINITIALIZED_EXT )
@@ -2739,7 +2738,7 @@ out:if (allocated > max_blocks) allocated = max_blocks;ext4_ext_show_leaf (inode, path); -__set_bit (BH_Mapped, &bh_result->b_state); +set_buffer_mapped (bh_result); bh_result->b_bdev = inode->i_sb->s_bdev; bh_result->b_blocknr = newblock; out2:
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 41/52 vfs: add basic delayed allocation support
In reply to Theodore Ts'oFrom: Alex Tomas <[email protected]>
* block_prepare_write() can be passed a special ->get_block() which doesn't allocate blocks, but reserve them and mark bh delayed
* a filesystem can use mpage_da_writepages() with other ->get_block() which doesn't defer allocation. mpage_da_writepages() finds all non-allocated blocks and try to allocate them with minimal calls to ->get_block(), then submit IO using __mpage_writepage()
Updated fix from Valerie Clement <[email protected]> fixes a filesystem corruption issue when the filesystem is mounted with the delalloc option and blocksize < pagesize.
Updated fix from Mingming Cao <[email protected]> to clear buffer_delay in block_write_full_page() after allocation to those delayed buffer.
--- fs/buffer.c | 7 +- fs/mpage.c | 405 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mpage.h | 2 + 3 files changed, 412 insertions(+), 2 deletions(-)
fs/buffer.c +5 -2
@@ -1691,11 +1691,13 @@ static int __block_write_full_page(struct inode *inode, struct page *page,*/ clear_buffer_dirty (bh);set_buffer_uptodate (bh); - }else if (!buffer_mapped (bh) &&buffer_dirty (bh)) { + }else if ((!buffer_mapped (bh) ||buffer_delay (bh)) + &&buffer_dirty (bh)) {WARN_ON (bh->b_size != blocksize); 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);
@@ -1774,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 {
fs/mpage.c +405 -0
414 lines not on this page · raw message
include/linux/mpage.h +2 -0
@@ -18,6 +18,8 @@ int mpage_readpages(struct address_space *mapping, struct list_head *pages,int mpage_readpage (struct page *page,get_block_t get_block);int mpage_writepages (struct address_space *mapping,struct writeback_control *wbc,get_block_t get_block); +int mpage_da_writepages (struct address_space *mapping, +struct writeback_control *wbc,get_block_t get_block);int mpage_writepage (struct page *page,get_block_t *get_block,struct writeback_control *wbc);
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty
Theodore Ts'o
maintainerPATCH 42/52 ext4: Add basic delayed allocation support
From: Alex Tomas <[email protected]>
Two special ->get_block() methods are introduced:
* ext4_da_get_block_prep()
to be used with ->write_begin(), defers allocation till flush
* ext4_da_get_block_write()
to be used with mpage_da_writepages(), allocate blocks and correct on-disk size
This patch supports data=writeback mode, to enable delalloc, need to mount filesystem with delalloc,data=writeback options.
Updated fixes from Mingming cao <[email protected]> to unlock and release the page from page cache if the delalloc write_begin failed, and properly handle preallocated blocks.
Updated fixes from Aneesh Kumar K.V <[email protected]> to update i_disksize properly with delayed allocation,
and add bmap support for delalloc.
--- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- fs/ext4/super.c | 6 +- 3 files changed, 297 insertions(+), 6 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -536,6 +536,7 @@ do { \#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000/* Journal Async Commit */ #define EXT4_MOUNT_I_VERSION 0x2000000/* i_version support */ #define EXT4_MOUNT_MBALLOC 0x4000000/* Buddy allocation support */ +#define EXT4_MOUNT_DELALLOC 0x8000000/* Delalloc support */ /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ #ifndef _LINUX_EXT2_FS_H#define clear_opt (o, opt) o &= ~EXT4_MOUNT_##opt
fs/ext4/inode.c +291 -5
330 lines not on this page · raw message
fs/ext4/super.c +5 -1
@@ -898,7 +898,7 @@ enum { Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota, Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version, - Opt_mballoc, Opt_nomballoc, Opt_stripe, + Opt_mballoc, Opt_nomballoc, Opt_stripe, Opt_delalloc, }; static match_table_t tokens = {
@@ -957,6 +957,7 @@ static match_table_t tokens = { {Opt_nomballoc, "nomballoc"}, {Opt_stripe, "stripe=%u"}, {Opt_resize, "resize"}, + {Opt_delalloc, "delalloc"}, {Opt_err, NULL}, };
@@ -1335,6 +1336,9 @@ set_qf_format:return 0 ; sbi->s_stripe = option;break ; +case Opt_delalloc: +set_opt (sbi->s_mount_opt,DELALLOC ); +break ;default :printk (KERN_ERR "EXT4-fs: Unrecognized mount option \"%s\" "
Signature · 1 line
1.5.6.rc3.1.g36b7.dirty