public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] concurrent block allocation for ext3
@ 2003-03-10 15:41 Alex Tomas
  2003-03-10 16:25 ` Andreas Dilger
  2003-03-14 21:22 ` Martin J. Bligh
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Tomas @ 2003-03-10 15:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Alex Tomas


Hi!

Here is the small patch which implements concurrent block allocation
for ext3. It removes lock_super() in ext3_new_block() and ext3_free_blocks().
Modifications of counters in superblock and group descriptors are protected
by spinlock. Tested on SMP for several hours.


--- linux/fs/ext3/balloc.c	Thu Feb 20 16:19:06 2003
+++ balloc.c	Mon Mar 10 16:00:49 2003
@@ -118,7 +118,6 @@
 		printk ("ext3_free_blocks: nonexistent device");
 		return;
 	}
-	lock_super (sb);
 	es = EXT3_SB(sb)->s_es;
 	if (block < le32_to_cpu(es->s_first_data_block) ||
 	    block + count < block ||
@@ -214,11 +213,13 @@
 				      block + i);
 			BUFFER_TRACE(bitmap_bh, "bit already cleared");
 		} else {
+			spin_lock(&EXT3_SB(sb)->s_alloc_lock);
 			dquot_freed_blocks++;
 			gdp->bg_free_blocks_count =
 			  cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)+1);
 			es->s_free_blocks_count =
 			  cpu_to_le32(le32_to_cpu(es->s_free_blocks_count)+1);
+			spin_unlock(&EXT3_SB(sb)->s_alloc_lock);
 		}
 		/* @@@ This prevents newly-allocated data from being
 		 * freed and then reallocated within the same
@@ -267,7 +268,6 @@
 error_return:
 	brelse(bitmap_bh);
 	ext3_std_error(sb, err);
-	unlock_super(sb);
 	if (dquot_freed_blocks)
 		DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
 	return;
@@ -408,7 +408,6 @@
 		return 0;
 	}
 
-	lock_super(sb);
 	es = EXT3_SB(sb)->s_es;
 	if (le32_to_cpu(es->s_free_blocks_count) <=
 			le32_to_cpu(es->s_r_blocks_count) &&
@@ -461,6 +460,7 @@
 
 	ext3_debug("Bit not found in block group %d.\n", group_no);
 
+repeat:
 	/*
 	 * Now search the rest of the groups.  We assume that 
 	 * i and gdp correctly point to the last group visited.
@@ -538,9 +538,9 @@
 
 	/* The superblock lock should guard against anybody else beating
 	 * us to this point! */
-	J_ASSERT_BH(bitmap_bh, !ext3_test_bit(ret_block, bitmap_bh->b_data));
 	BUFFER_TRACE(bitmap_bh, "setting bitmap bit");
-	ext3_set_bit(ret_block, bitmap_bh->b_data);
+	if (ext3_set_bit(ret_block, bitmap_bh->b_data)) 
+		goto repeat;
 	performed_allocation = 1;
 
 #ifdef CONFIG_JBD_DEBUG
@@ -586,11 +586,13 @@
 	ext3_debug("allocating block %d. Goal hits %d of %d.\n",
 			ret_block, goal_hits, goal_attempts);
 
+	spin_lock(&EXT3_SB(sb)->s_alloc_lock);
 	gdp->bg_free_blocks_count =
 			cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) - 1);
 	es->s_free_blocks_count =
 			cpu_to_le32(le32_to_cpu(es->s_free_blocks_count) - 1);
-
+	spin_unlock(&EXT3_SB(sb)->s_alloc_lock);
+	
 	BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
 	err = ext3_journal_dirty_metadata(handle, gdp_bh);
 	if (!fatal)
@@ -606,7 +608,6 @@
 	if (fatal)
 		goto out;
 
-	unlock_super(sb);
 	*errp = 0;
 	brelse(bitmap_bh);
 	return ret_block;
@@ -618,7 +619,6 @@
 		*errp = fatal;
 		ext3_std_error(sb, fatal);
 	}
-	unlock_super(sb);
 	/*
 	 * Undo the block allocation
 	 */


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-03-15  5:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-10 15:41 [PATCH] concurrent block allocation for ext3 Alex Tomas
2003-03-10 16:25 ` Andreas Dilger
2003-03-10 16:33   ` Alex Tomas
2003-03-10 16:43   ` Daniel Phillips
2003-03-14 21:22 ` Martin J. Bligh
2003-03-15  2:56   ` Martin J. Bligh
2003-03-15  6:08     ` Martin J. Bligh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox