linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: amir73il@users.sourceforge.net
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org, Amir Goldstein <amir73il@users.sf.net>
Subject: [PATCH v2 2/5] ext4: implement ext4_add_groupblocks() by freeing blocks
Date: Thu, 24 Mar 2011 18:58:10 +0200	[thread overview]
Message-ID: <1300985893-4371-3-git-send-email-amir73il@users.sourceforge.net> (raw)
In-Reply-To: <1300985893-4371-1-git-send-email-amir73il@users.sourceforge.net>

From: Amir Goldstein <amir73il@users.sf.net>

The old imlementation used to take grp->alloc_sem and set the
GROUP_NEED_INIT flag, so that the buddy cache would be reloaded.

The new implementation updates the buddy cache by freeing the added
blocks and making them available for use, so there is no need to
reload the buddy cache and there is no need to take grp->alloc_sem.

Signed-off-by: Amir Goldstein <amir73il@users.sf.net>
---
 fs/ext4/mballoc.c |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 1e3c826..da52bd9 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4710,9 +4710,7 @@ error_return:
  * @block:			start physcial block to add to the block group
  * @count:			number of blocks to free
  *
- * This marks the blocks as free in the bitmap. We ask the
- * mballoc to reload the buddy after this by setting group
- * EXT4_GROUP_INFO_NEED_INIT_BIT flag
+ * This marks the blocks as free in the bitmap and buddy.
  */
 void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
 			 ext4_fsblk_t block, unsigned long count)
@@ -4724,6 +4722,7 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
 	unsigned int i;
 	struct ext4_group_desc *desc;
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
+	struct ext4_buddy e4b;
 	int err = 0, ret, blk_free_count;
 	ext4_grpblk_t blocks_freed;
 	struct ext4_group_info *grp;
@@ -4771,15 +4770,10 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
 	err = ext4_journal_get_write_access(handle, gd_bh);
 	if (err)
 		goto error_return;
-	/*
-	 * make sure we don't allow a parallel init on other groups in the
-	 * same buddy cache
-	 */
-	down_write(&grp->alloc_sem);
+
 	for (i = 0, blocks_freed = 0; i < count; i++) {
 		BUFFER_TRACE(bitmap_bh, "clear bit");
-		if (!ext4_clear_bit_atomic(ext4_group_lock_ptr(sb, block_group),
-						bit + i, bitmap_bh->b_data)) {
+		if (!mb_test_bit(bit + i, bitmap_bh->b_data)) {
 			ext4_error(sb, "bit already cleared for block %llu",
 				   (ext4_fsblk_t)(block + i));
 			BUFFER_TRACE(bitmap_bh, "bit already cleared");
@@ -4787,7 +4781,19 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
 			blocks_freed++;
 		}
 	}
+
+	err = ext4_mb_load_buddy(sb, block_group, &e4b);
+	if (err)
+		goto error_return;
+
+	/*
+	 * need to update group_info->bb_free and bitmap
+	 * with group lock held. generate_buddy look at
+	 * them with group lock_held
+	 */
 	ext4_lock_group(sb, block_group);
+	mb_clear_bits(bitmap_bh->b_data, bit, count);
+	mb_free_blocks(NULL, &e4b, bit, count);
 	blk_free_count = blocks_freed + ext4_free_blks_count(sb, desc);
 	ext4_free_blks_set(sb, desc, blk_free_count);
 	desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc);
@@ -4799,13 +4805,8 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
 		atomic_add(blocks_freed,
 			   &sbi->s_flex_groups[flex_group].free_blocks);
 	}
-	/*
-	 * request to reload the buddy with the
-	 * new bitmap information
-	 */
-	set_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state));
-	grp->bb_free += blocks_freed;
-	up_write(&grp->alloc_sem);
+
+	ext4_mb_unload_buddy(&e4b);
 
 	/* We dirtied the bitmap block */
 	BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
-- 
1.7.0.4


  parent reply	other threads:[~2011-03-24 16:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24 16:58 [PATCHSET v2] ext4: removal of alloc_sem locks from block allocation paths amir73il
2011-03-24 16:58 ` [PATCH v2 1/5] ext4: move ext4_add_groupblocks() to mballoc.c amir73il
2011-05-09 14:54   ` Ted Ts'o
2011-05-09 14:59     ` [PATCH 1/2] " Theodore Ts'o
2011-05-09 14:59     ` [PATCH 2/2] ext4: remove unneeded ext4_journal_get_undo_access Theodore Ts'o
2011-05-09 16:01     ` [PATCH v2 1/5] ext4: move ext4_add_groupblocks() to mballoc.c Amir G.
2011-05-09 16:28       ` Yongqiang Yang
2011-03-24 16:58 ` amir73il [this message]
2011-03-24 16:58 ` [PATCH v2 3/5] ext4: synchronize ext4_mb_init_group() with buddy page lock amir73il
2011-03-24 16:58 ` [PATCH v2 4/5] ext4: teach ext4_mb_init_cache() to skip uptodate buddy caches amir73il
2011-03-24 16:58 ` [PATCH v2 5/5] ext4: remove alloc_semp amir73il
2011-05-10 13:29   ` Ted Ts'o
2011-05-10 18:20     ` Amir G.
2011-05-03 15:47 ` [PATCHSET v2] ext4: removal of alloc_sem locks from block allocation paths Amir G.
2011-05-10 13:48 ` Lukas Czerner
2011-05-10 18:30   ` Amir G.
2011-05-10 18:43     ` Lukas Czerner
2011-05-10 18:58       ` Amir G.

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=1300985893-4371-3-git-send-email-amir73il@users.sourceforge.net \
    --to=amir73il@users.sourceforge.net \
    --cc=amir73il@users.sf.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;
as well as URLs for NNTP newsgroup(s).