mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>,
	Linux Kernel Developers List <linux-kernel@vger.kernel.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
	Mingming Cao <cmm@us.ibm.com>, "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH 25/52] ext4: cleanup block allocator
Date: Sat,  5 Jul 2008 13:35:51 -0400	[thread overview]
Message-ID: <1215279378-30504-26-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1215279378-30504-25-git-send-email-tytso@mit.edu>

From: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

Move the code related to block allocation to a single function and add helper
funtions to differient allocation for data and meta data blocks

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 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(-)

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 816f1db..48787e8 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -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
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index b3e62b7..ed04642 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -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);
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index c729b35..555155d 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -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;
 
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 04059ba..884cf89 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -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)) {
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 8b67414..007b97b 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -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;
 	}
-- 
1.5.6.rc3.1.g36b7.dirty


  reply	other threads:[~2008-07-05 17:46 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-05 17:35 Ext4 patches for the next merge window Theodore Ts'o
2008-07-05 17:35 ` [PATCH 01/52] ext4: fix comments to say "ext4" Theodore Ts'o
2008-07-05 17:35   ` [PATCH 02/52] ext4: start searching for the right extent from the goal group Theodore Ts'o
2008-07-05 17:35     ` [PATCH 03/52] ext4: Use BUG_ON() instead of BUG() Theodore Ts'o
2008-07-05 17:35       ` [PATCH 04/52] ext4: switch to seq_files Theodore Ts'o
2008-07-05 17:35         ` [PATCH 05/52] ext4: improve some code in rb tree part of dir.c Theodore Ts'o
2008-07-05 17:35           ` [PATCH 06/52] ext4: Fix ext4_mb_init_cache return error Theodore Ts'o
2008-07-05 17:35             ` [PATCH 07/52] ext4: add error processing when calling ext4_mb_init_cache in mballoc Theodore Ts'o
2008-07-05 17:35               ` [PATCH 08/52] ext4: miscellaneous error checks and coding cleanups for mballoc Theodore Ts'o
2008-07-05 17:35                 ` [PATCH 09/52] ext4: remove double definitions of xattr macros Theodore Ts'o
2008-07-05 17:35                   ` [PATCH 10/52] ext4: Rename read_block_bitmap() to ext4_read_block_bitmap() Theodore Ts'o
2008-07-05 17:35                     ` [PATCH 11/52] ext4: Remove unused variable from ext4_show_options Theodore Ts'o
2008-07-05 17:35                       ` [PATCH 12/52] jbd2: Add commit time into the commit block Theodore Ts'o
2008-07-05 17:35                         ` [PATCH 13/52] ext4: New inode allocation for FLEX_BG meta-data groups Theodore Ts'o
2008-07-05 17:35                           ` [PATCH 14/52] jbd2: fix race between jbd2_journal_try_to_free_buffers() and jbd2 commit transaction Theodore Ts'o
2008-07-05 17:35                             ` [PATCH 15/52] ext4: remove redundant code in ext4_fill_super() Theodore Ts'o
2008-07-05 17:35                               ` [PATCH 16/52] ext4: remove quota allocation when ext4_mb_new_blocks fails Theodore Ts'o
2008-07-05 17:35                                 ` [PATCH 17/52] ext4: Update i_disksize properly when allocating from fallocate area Theodore Ts'o
2008-07-05 17:35                                   ` [PATCH 18/52] ext4: return error when calling ext4_ext_split failed Theodore Ts'o
2008-07-05 17:35                                     ` [PATCH 19/52] ext4: Make ext4_ext_find_extent fills ext_path completely Theodore Ts'o
2008-07-05 17:35                                       ` [PATCH 20/52] ext4: Fix ext4_ext_journal_restart() to reflect errors up to the caller Theodore Ts'o
2008-07-05 17:35                                         ` [PATCH 21/52] ext4: cleanup never-used magic numbers from htree code Theodore Ts'o
2008-07-05 17:35                                           ` [PATCH 22/52] ext4: Fix sparse warning Theodore Ts'o
2008-07-05 17:35                                             ` [PATCH 23/52] ext4: fix ext4_init_block_bitmap() for metablock block group Theodore Ts'o
2008-07-05 17:35                                               ` [PATCH 24/52] ext4: Use inode preallocation with -o noextents Theodore Ts'o
2008-07-05 17:35                                                 ` Theodore Ts'o [this message]
2008-07-05 17:35                                                   ` [PATCH 26/52] ext4: call blkdev_issue_flush on fsync Theodore Ts'o
2008-07-05 17:35                                                     ` [PATCH 27/52] ext4: mballoc avoid use root reserved blocks for non root allocation Theodore Ts'o
2008-07-05 17:35                                                       ` [PATCH 28/52] ext4: Set journal pointer to NULL when journal is released Theodore Ts'o
2008-07-05 17:35                                                         ` [PATCH 29/52] ext4: use atomic functions to set bh_state Theodore Ts'o
2008-07-05 17:35                                                           ` [PATCH 30/52] ext4: Add missing unlock to an error path in ext4_quota_write() Theodore Ts'o
2008-07-05 17:35                                                             ` [PATCH 31/52] ext4: fix online resize with mballoc Theodore Ts'o
2008-07-05 17:35                                                               ` [PATCH 32/52] ext4: Documentation updates Theodore Ts'o
2008-07-05 17:35                                                                 ` [PATCH 33/52] ext4: Use page_mkwrite vma_operations to get mmap write notification Theodore Ts'o
2008-07-05 17:36                                                                   ` [PATCH 34/52] vfs: Move mark_inode_dirty() from under page lock in generic_write_end() Theodore Ts'o
2008-07-05 17:36                                                                     ` [PATCH 35/52] ext4: Invert the locking order of page_lock and transaction start Theodore Ts'o
2008-07-05 17:36                                                                       ` [PATCH 36/52] ext4: Fix lock inversion in ext4_ext_truncate() Theodore Ts'o
2008-07-05 17:36                                                                         ` [PATCH 37/52] vfs: export filemap_fdatawrite_range() Theodore Ts'o
2008-07-05 17:36                                                                           ` [PATCH 38/52] jbd2: Implement data=ordered mode handling via inodes Theodore Ts'o
2008-07-05 17:36                                                                             ` [PATCH 39/52] ext4: Use new framework for data=ordered mode in JBD2 Theodore Ts'o
2008-07-05 17:36                                                                               ` [PATCH 40/52] jbd2: Remove data=ordered mode support using jbd buffer heads Theodore Ts'o
2008-07-05 17:36                                                                                 ` [PATCH 41/52] vfs: add basic delayed allocation support Theodore Ts'o
2008-07-05 17:36                                                                                   ` [PATCH 42/52] ext4: Add " Theodore Ts'o
2008-07-05 17:36                                                                                     ` [PATCH 43/52] percpu_counter: new function percpu_counter_sum_and_set Theodore Ts'o
2008-07-05 17:36                                                                                       ` [PATCH 44/52] ext4: delayed allocation ENOSPC handling Theodore Ts'o
2008-07-05 17:36                                                                                         ` [PATCH 45/52] mm: Add range_cont mode for writeback Theodore Ts'o
2008-07-05 17:36                                                                                           ` [PATCH 46/52] ext4: Invert lock ordering of page_lock and transaction start in delalloc Theodore Ts'o
2008-07-05 17:36                                                                                             ` [PATCH 47/52] ext4: Add ordered mode support for delalloc Theodore Ts'o
2008-07-05 17:36                                                                                               ` [PATCH 48/52] ext4: Handle page without buffers in ext4_*_writepage() Theodore Ts'o
2008-07-05 17:36                                                                                                 ` [PATCH 49/52] ext4: fix delalloc i_disksize early update issue Theodore Ts'o
2008-07-05 17:36                                                                                                   ` [PATCH 50/52] ext4: Enable delalloc by default Theodore Ts'o
2008-07-05 17:36                                                                                                     ` [PATCH 51/52] ext4: Don't allow nonextenst mount option for large filesystem Theodore Ts'o
2008-07-05 17:36                                                                                                       ` [PATCH 52/52] ext4: Documention update for new ordered mode and delayed allocation 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=1215279378-30504-26-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=cmm@us.ibm.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®