Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Frédéric Bohé" <frederic.bohe@bull.net>
To: Theodore Ts'o <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH 2/4] Create the journal in the middle of the filesystem
Date: Thu, 28 Aug 2008 11:55:21 +0200	[thread overview]
Message-ID: <1219917321.3591.79.camel@frecb007923.frec.bull.fr> (raw)
In-Reply-To: <1219871676-18456-2-git-send-email-tytso@mit.edu>

Le mercredi 27 août 2008 à 17:14 -0400, Theodore Ts'o a écrit :
> This speeds up access to the journal by eliminating worst-case seeks
> from one end of the disk to another, which can be quite common in very
> fsync-intensive workloads if the file is located near the end of the
> disk, and the journal is located the beginning of the disk.
> 
> In addition, this can help eliminate journal fragmentation when
> flex_bg is enabled, since the first block group has a large amount of
> metadata.
> 
> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
> ---
>  lib/ext2fs/mkjournal.c |   28 +++++++++++++++++++++++-----
>  1 files changed, 23 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c
> index 3cae874..cd3df07 100644
> --- a/lib/ext2fs/mkjournal.c
> +++ b/lib/ext2fs/mkjournal.c
> @@ -198,6 +198,7 @@ errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
>  struct mkjournal_struct {
>  	int		num_blocks;
>  	int		newblocks;
> +	blk_t		goal;
>  	blk_t		blk_to_zero;
>  	int		zero_count;
>  	char		*buf;
> @@ -213,14 +214,13 @@ static int mkjournal_proc(ext2_filsys	fs,
>  {
>  	struct mkjournal_struct *es = (struct mkjournal_struct *) priv_data;
>  	blk_t	new_blk;
> -	static blk_t	last_blk = 0;
>  	errcode_t	retval;
>  	
>  	if (*blocknr) {
> -		last_blk = *blocknr;
> +		es->goal = *blocknr;
>  		return 0;
>  	}
> -	retval = ext2fs_new_block(fs, last_blk, 0, &new_blk);
> +	retval = ext2fs_new_block(fs, es->goal, 0, &new_blk);
>  	if (retval) {
>  		es->err = retval;
>  		return BLOCK_ABORT;
> @@ -258,8 +258,7 @@ static int mkjournal_proc(ext2_filsys	fs,
>  		es->err = retval;
>  		return BLOCK_ABORT;
>  	}
> -	*blocknr = new_blk;
> -	last_blk = new_blk;
> +	*blocknr = es->goal = new_blk;
>  	ext2fs_block_alloc_stats(fs, new_blk, +1);
>  
>  	if (es->num_blocks == 0)
> @@ -276,6 +275,7 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
>  				     blk_t size, int flags)
>  {
>  	char			*buf;
> +	dgrp_t			group, start, end, i;
>  	errcode_t		retval;
>  	struct ext2_inode	inode;
>  	struct mkjournal_struct	es;
> @@ -298,6 +298,24 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
>  	es.err = 0;
>  	es.zero_count = 0;
>  
> +	/*
> +	 * Set the initial goal block to be roughly at the middle of
> +	 * the filesystem.  Pick a group that has the largest number
> +	 * of free blocks.
> +	 */
> +	group = ext2fs_group_of_blk(fs, (fs->super->s_blocks_count - 
> +					 fs->super->s_first_data_block) / 2);
> +	start = (group > 0) ? group-1 : group;
> +	end = ((group+1) < fs->group_desc_count) ? group+1 : group;

With 512 groups by flex group, meta-datas for a single flex-group are 8
groups long ! If we have no luck and there are a bunch of groups
occupied by meta-datas at the middle of the filesystem, we should
slightly increase the number of groups scanned to find a completely free
group.

> +	group = start;
> +	for (i=start+1; i <= end; i++)
> +		if (fs->group_desc[i].bg_free_blocks_count >
> +		    fs->group_desc[group].bg_free_blocks_count)
> +			group = i;

This is ok if the journal file has the default size, but not optimal if
it's bigger than one group.

> +
> +	es.goal = (fs->super->s_blocks_per_group * group) +
> +		fs->super->s_first_data_block;
> +
>  	retval = ext2fs_block_iterate2(fs, journal_ino, BLOCK_FLAG_APPEND,
>  				       0, mkjournal_proc, &es);
>  	if (es.err) {

--
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

  parent reply	other threads:[~2008-08-28  7:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-27 17:36 Journal file fragmentation Frédéric Bohé
2008-08-27 20:12 ` Jose R. Santos
2008-08-27 21:06 ` Theodore Tso
2008-08-27 21:14   ` [PATCH 1/4] ext2fs_mkjournal(): Don't allocate an extra block to the journal Theodore Ts'o
2008-08-27 21:14     ` [PATCH 2/4] Create the journal in the middle of the filesystem Theodore Ts'o
2008-08-27 21:14       ` [PATCH 3/4] ext2fs_block_iterate2: Add BLOCK_FLAG_APPEND support for extent-based files Theodore Ts'o
2008-08-27 21:14         ` [PATCH 4/4] If the filesystem supports extents create an extent-based journal inode Theodore Ts'o
2008-08-28  9:55       ` Frédéric Bohé [this message]
2008-08-28 13:34         ` [PATCH 2/4] Create the journal in the middle of the filesystem Theodore Tso
2008-08-28 13:40           ` Ric Wheeler
2008-08-28 14:36             ` Theodore Tso
2008-08-28 14:38               ` Ric Wheeler
2008-09-03 14:08                 ` Ric Wheeler
2008-08-28 16:16           ` Frédéric Bohé

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=1219917321.3591.79.camel@frecb007923.frec.bull.fr \
    --to=frederic.bohe@bull.net \
    --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