From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 07/12] libext2fs: add ext2fs_block_alloc_stats_range()
Date: Thu, 13 Feb 2014 13:50:29 -0800 [thread overview]
Message-ID: <20140213215029.GG9176@birch.djwong.org> (raw)
In-Reply-To: <1390197254-14583-8-git-send-email-tytso@mit.edu>
On Mon, Jan 20, 2014 at 12:54:09AM -0500, Theodore Ts'o wrote:
> This function is more efficient than using ext2fs_block_alloc_stats2()
> for each block in a range. The efficiencies come from being able to
> set a block range in the block bitmap at once, and from being update
> the block group descriptors once per block group. Especially now that
> we are checksuming the block group descriptors, and we are using red
> black trees for the allocation bitmaps, these changes can make a huge
> difference in the CPU time used by mke2fs when creating very large
> file systems.
>
> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> ---
> lib/ext2fs/alloc_stats.c | 41 +++++++++++++++++++++++++++++++++++++++++
> lib/ext2fs/ext2fs.h | 2 ++
> 2 files changed, 43 insertions(+)
>
> diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c
> index adec363..7919c09 100644
> --- a/lib/ext2fs/alloc_stats.c
> +++ b/lib/ext2fs/alloc_stats.c
> @@ -106,3 +106,44 @@ void ext2fs_set_block_alloc_stats_callback(ext2_filsys fs,
>
> fs->block_alloc_stats = func;
> }
> +
> +void ext2fs_block_alloc_stats_range(ext2_filsys fs, blk64_t blk,
> + blk_t num, int inuse)
> +{
> +#ifndef OMIT_COM_ERR
> + if (blk + num >= ext2fs_blocks_count(fs->super)) {
> + com_err("ext2fs_block_alloc_stats_range", 0,
> + "Illegal block range: %llu (%u) ",
> + (unsigned long long) blk, num);
> + return;
> + }
> +#endif
> + if (inuse == 0)
> + return;
> + if (inuse > 0) {
> + ext2fs_mark_block_bitmap_range2(fs->block_map, blk, num);
> + inuse = 1;
> + } else {
> + ext2fs_unmark_block_bitmap_range2(fs->block_map, blk, num);
> + inuse = -1;
> + }
> + while (num) {
> + int group = ext2fs_group_of_blk2(fs, blk);
> + blk64_t last_blk = ext2fs_group_last_block2(fs, group);
> + blk_t n = num;
> +
> + if (blk + num > last_blk)
> + n = last_blk - blk + 1;
> +
> + ext2fs_bg_free_blocks_count_set(fs, group,
> + ext2fs_bg_free_blocks_count(fs, group) -
> + inuse*n/EXT2FS_CLUSTER_RATIO(fs));
> + ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
> + ext2fs_group_desc_csum_set(fs, group);
> + ext2fs_free_blocks_count_add(fs->super, -inuse * n);
When I use this function, e2fsck complains:
"Free blocks count wrong (124554823344, counted=771760)."
It looks like "-inuse * n" is an 32bit quantity that isn't correctly
sign-extended to the blk64_t that ext2fs_free_blocks_count_add() requires.
A trivial fix is to change n to blk64_t to force a conversion.
Will send a patch soon.
(gcc 4.6.3, Ubuntu 12.04)
--D
> + blk += n;
> + num -= n;
> + }
> + ext2fs_mark_super_dirty(fs);
> + ext2fs_mark_bb_dirty(fs);
> +}
> diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
> index 1e07f88..47340dd 100644
> --- a/lib/ext2fs/ext2fs.h
> +++ b/lib/ext2fs/ext2fs.h
> @@ -683,6 +683,8 @@ void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
> int inuse, int isdir);
> void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
> void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse);
> +void ext2fs_block_alloc_stats_range(ext2_filsys fs, blk64_t blk,
> + blk_t num, int inuse);
>
> /* alloc_tables.c */
> extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
> --
> 1.8.5.rc3.362.gdf10213
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-02-13 21:50 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-20 5:54 [PATCH 00/12] e2fsprogs mke2fs optimizations and new features Theodore Ts'o
2014-01-20 5:54 ` [PATCH 01/12] libext2fs: fix off-by-one bug in ext2fs_extent_insert() Theodore Ts'o
2014-01-20 5:54 ` [PATCH 02/12] libext2fs: clean up generic handling of ext2fs_find_first_{set,zero}_*() Theodore Ts'o
2014-01-20 5:54 ` [PATCH 03/12] libext2fs: build tst_bitmaps with rep invariants checking enabled Theodore Ts'o
2014-01-20 5:54 ` [PATCH 04/12] libext: optimize find_first_set() for bitarray-based bitmaps Theodore Ts'o
2014-01-20 5:54 ` [PATCH 05/12] libext2fs: optimize find_first_{zero,set}() for red-black tree based bitmaps Theodore Ts'o
2014-01-20 5:54 ` [PATCH 06/12] libext2fs: further clean up and rename check_block_uninit Theodore Ts'o
2014-01-20 20:17 ` Darrick J. Wong
2014-01-20 5:54 ` [PATCH 07/12] libext2fs: add ext2fs_block_alloc_stats_range() Theodore Ts'o
2014-02-13 21:50 ` Darrick J. Wong [this message]
2014-01-20 5:54 ` [PATCH 08/12] libext2fs: optimize ext2fs_allocate_group_table() Theodore Ts'o
2014-01-20 5:54 ` [PATCH 09/12] libext2: optimize ext2fs_new_block2() Theodore Ts'o
2014-01-20 21:52 ` Andreas Dilger
2014-01-21 15:54 ` Theodore Ts'o
2014-01-20 5:54 ` [PATCH 10/12] mke2fs: optimize fix_cluster_bg_counts() Theodore Ts'o
2014-01-20 5:54 ` [PATCH 11/12] Add support for new compat feature "sparse_super2" Theodore Ts'o
2014-01-20 21:49 ` Andreas Dilger
[not found] ` <alpine.DEB.2.10.1402051559390.16807@tglase.lan.tarent.de>
2014-02-05 16:17 ` Theodore Ts'o
2014-01-20 5:54 ` [PATCH 12/12] mke2fs: allow metadata blocks to be at the beginning of the file system Theodore Ts'o
2014-01-20 16:30 ` Theodore Ts'o
2014-01-20 23:25 ` Andreas Dilger
2014-01-21 6:23 ` Theodore Ts'o
2014-01-23 21:28 ` Andreas Dilger
2014-01-20 16:30 ` [PATCH 00/12] e2fsprogs mke2fs optimizations and new features Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140213215029.GG9176@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).