Skip to contentSkip to conversation

ext4: Use inode preallocation with -o noextents

PATCH New Aneesh Kumar K.V 2 participants 7 messages May 15, 2008 – May 19, 2008 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Use inode preallocation with -o noextents

When mouting ext4 with -o noextents, request for
file data blocks from inode prealloc space.

---
 fs/ext4/balloc.c |    9 ++++++++-
 fs/ext4/ext4.h   |    5 +++--
 fs/ext4/inode.c  |   20 ++++++++++++--------
 3 files changed, 23 insertions(+), 11 deletions(-)
fs/ext4/balloc.c +8 -1
index da99437..769b2b3 100644
@@ -1878,7 +1878,8 @@ ext4_fsblk_t ext4_new_block(handle_t *handle, struct inode *inode,
 }
 
 ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
-		ext4_fsblk_t goal, unsigned long *count, int *errp)
+				ext4_lblk_t iblock, ext4_fsblk_t goal,
+				unsigned long *count, int *errp)
 {
 	struct ext4_allocation_request ar;
 	ext4_fsblk_t ret;
@@ -1892,6 +1893,12 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
 	ar.inode = inode;
 	ar.goal = goal;
 	ar.len = *count;
+	ar.logical = iblock;
+	if (S_ISREG(inode->i_mode))
+		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;
fs/ext4/ext4.h +3 -2
index 8158083..1bd8e28 100644
@@ -960,8 +960,9 @@ extern unsigned long ext4_bg_num_gdb(struct super_block *sb,
 			ext4_group_t group);
 extern ext4_fsblk_t ext4_new_block (handle_t *handle, struct inode *inode,
 			ext4_fsblk_t goal, int *errp);
-extern ext4_fsblk_t ext4_new_blocks (handle_t *handle, struct inode *inode,
-			ext4_fsblk_t goal, unsigned long *count, int *errp);
+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,
 			ext4_fsblk_t goal, unsigned long *count, int *errp);
 extern void ext4_free_blocks (handle_t *handle, struct inode *inode,
fs/ext4/inode.c +12 -8
index 8d97077..0d1923e 100644
@@ -508,8 +508,9 @@ static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned long blks,
  *		direct blocks
  */
 static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,
-			ext4_fsblk_t goal, int indirect_blks, int blks,
-			ext4_fsblk_t new_blocks[4], int *err)
+				ext4_lblk_t iblock, ext4_fsblk_t goal,
+				int indirect_blks, int blks,
+				ext4_fsblk_t new_blocks[4], int *err)
 {
 	int target, i;
 	unsigned long count = 0;
@@ -530,7 +531,8 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,
 	while (1) {
 		count = target;
 		/* allocating blocks for indirect blocks and direct blocks */
-		current_block = ext4_new_blocks(handle,inode,goal,&count,err);
+		current_block = ext4_new_blocks(handle, inode, iblock,
+							goal, &count, err);
 		if (*err)
 			goto failed_out;
 
@@ -584,8 +586,9 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,
  *	as described above and return 0.
  */
 static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
-			int indirect_blks, int *blks, ext4_fsblk_t goal,
-			ext4_lblk_t *offsets, Indirect *branch)
+				ext4_lblk_t iblock, int indirect_blks,
+				int *blks, ext4_fsblk_t goal,
+				ext4_lblk_t *offsets, Indirect *branch)
 {
 	int blocksize = inode->i_sb->s_blocksize;
 	int i, n = 0;
@@ -595,7 +598,7 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode,
 	ext4_fsblk_t new_blocks[4];
 	ext4_fsblk_t current_block;
 
-	num = ext4_alloc_blocks(handle, inode, goal, indirect_blks,
+	num = ext4_alloc_blocks(handle, inode, iblock, goal, indirect_blks,
 				*blks, new_blocks, &err);
 	if (err)
 		return err;
@@ -855,8 +858,9 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
 	/*
 	 * Block out ext4_truncate while we alter the tree
 	 */
-	err = ext4_alloc_branch(handle, inode, indirect_blks, &count, goal,
-				offsets + (partial - chain), partial);
+	err = ext4_alloc_branch(handle, inode, iblock, indirect_blks,
+					&count, goal,
+					offsets + (partial - chain), partial);
 
 	/*
 	 * The ext4_splice_branch call will free and forget any buffers
Signature · 1 line
1.5.5.1.211.g65ea3.dirty
#1 lore raw

PATCH 1/1 ext4: Group meta-data blocks together.

This adds a per inode meta-block prealloc space from which meta-data block requests are served. This help in making sure meta-data block are closer. This is needed to speedup unlink of the file. Any new prealloc space is allocated near the goal block specified. The goal block is the last block allocated for the file. So we don't keep the data-block and meta-data block far apart.

---
 fs/ext4/balloc.c  |   27 +++++-
 fs/ext4/ext4.h    |   26 +++--
 fs/ext4/ext4_i.h  |    1 +
 fs/ext4/extents.c |    6 +-
 fs/ext4/inode.c   |   54 +++++++++--
 fs/ext4/mballoc.c |  266 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 fs/ext4/mballoc.h |    7 +-
 fs/ext4/super.c   |    1 +
 fs/ext4/xattr.c   |    2 +-
 9 files changed, 335 insertions(+), 55 deletions(-)
fs/ext4/balloc.c +24 -3
index 769b2b3..5c80eb5 100644
@@ -1857,7 +1857,7 @@ ext4_fsblk_t ext4_new_blocks_old(handle_t *handle, struct inode *inode,
 	return 0;
 }
 
-ext4_fsblk_t ext4_new_block(handle_t *handle, struct inode *inode,
+ext4_fsblk_t ext4_new_meta_block(handle_t *handle, struct inode *inode,
 		ext4_fsblk_t goal, int *errp)
 {
 	struct ext4_allocation_request ar;
@@ -1873,9 +1873,30 @@ ext4_fsblk_t ext4_new_block(handle_t *handle, struct inode *inode,
 	ar.inode = inode;
 	ar.goal = goal;
 	ar.len = 1;
+	ar.flags = EXT4_MB_HINT_META_DATA;
 	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;
+	ar.flags = EXT4_MB_HINT_META_DATA;
+	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,
 				ext4_lblk_t iblock, ext4_fsblk_t goal,
@@ -1895,10 +1916,10 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,
 	ar.len = *count;
 	ar.logical = iblock;
 	if (S_ISREG(inode->i_mode))
-		ar.flags = EXT4_MB_HINT_DATA;
+		ar.flags = EXT4_MB_HINT_FILE_DATA;
 	else
 		/* disable in-core preallocation for non-regular files */
-		ar.flags = 0;
+		ar.flags = EXT4_MB_HINT_DIR_DATA;
 	ret = ext4_mb_new_blocks(handle, &ar, errp);
 	*count = ar.len;
 	return ret;
fs/ext4/ext4.h +15 -11
index 1bd8e28..b4bd67f 100644
@@ -55,25 +55,27 @@
 #define EXT4_MULTIBLOCK_ALLOCATOR	1
 
 /* prefer goal again. length */
-#define EXT4_MB_HINT_MERGE		1
+#define EXT4_MB_HINT_MERGE		0x001
 /* blocks already reserved */
-#define EXT4_MB_HINT_RESERVED		2
+#define EXT4_MB_HINT_RESERVED		0x002
 /* metadata is being allocated */
-#define EXT4_MB_HINT_METADATA		4
+#define EXT4_MB_HINT_METADATA		0x004
 /* first blocks in the file */
-#define EXT4_MB_HINT_FIRST		8
+#define EXT4_MB_HINT_FIRST		0x008
 /* search for the best chunk */
-#define EXT4_MB_HINT_BEST		16
+#define EXT4_MB_HINT_BEST		0x010
 /* data is being allocated */
-#define EXT4_MB_HINT_DATA		32
+#define EXT4_MB_HINT_FILE_DATA		0x020
+#define EXT4_MB_HINT_DIR_DATA		0x040
+#define EXT4_MB_HINT_META_DATA		0x080
 /* don't preallocate (for tails) */
-#define EXT4_MB_HINT_NOPREALLOC		64
+#define EXT4_MB_HINT_NOPREALLOC		0x100
 /* allocate for locality group */
-#define EXT4_MB_HINT_GROUP_ALLOC	128
+#define EXT4_MB_HINT_GROUP_ALLOC	0x200
 /* allocate goal blocks or none */
-#define EXT4_MB_HINT_GOAL_ONLY		256
+#define EXT4_MB_HINT_GOAL_ONLY		0x400
 /* goal is meaningful */
-#define EXT4_MB_HINT_TRY_GOAL		512
+#define EXT4_MB_HINT_TRY_GOAL		0x800
 
 struct ext4_allocation_request {
 	/* target inode for block we're allocating */
@@ -958,8 +960,10 @@ extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,
 extern int ext4_bg_has_super(struct super_block *sb, ext4_group_t group);
 extern unsigned long ext4_bg_num_gdb(struct super_block *sb,
 			ext4_group_t group);
-extern ext4_fsblk_t ext4_new_block (handle_t *handle, struct inode *inode,
+extern ext4_fsblk_t ext4_new_meta_block(handle_t *handle, struct inode *inode,
 			ext4_fsblk_t goal, int *errp);
+extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
+			ext4_fsblk_t goal, unsigned long *count, int *errp);
 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);
fs/ext4/ext4_i.h +1 -0
index 26a4ae2..4f11ec4 100644
@@ -161,6 +161,7 @@ struct ext4_inode_info {
 
 	/* mballoc */
 	struct list_head i_prealloc_list;
+	struct list_head i_metaprealloc_list;
 	spinlock_t i_prealloc_lock;
 };
 
fs/ext4/extents.c +3 -3
index 47929c4..c58ebd8 100644
@@ -188,7 +188,7 @@ ext4_ext_new_block(handle_t *handle, struct inode *inode,
 	ext4_fsblk_t goal, newblock;
 
 	goal = ext4_ext_find_goal(inode, path, le32_to_cpu(ex->ee_block));
-	newblock = ext4_new_block(handle, inode, goal, err);
+	newblock = ext4_new_meta_block(handle, inode, goal, err);
 	return newblock;
 }
 
@@ -2690,10 +2690,10 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
 	ar.logical = iblock;
 	ar.len = allocated;
 	if (S_ISREG(inode->i_mode))
-		ar.flags = EXT4_MB_HINT_DATA;
+		ar.flags = EXT4_MB_HINT_FILE_DATA;
 	else
 		/* disable in-core preallocation for non-regular files */
-		ar.flags = 0;
+		ar.flags =  EXT4_MB_HINT_DIR_DATA;
 	newblock = ext4_mb_new_blocks(handle, &ar, &err);
 	if (!newblock)
 		goto out2;
fs/ext4/inode.c +43 -11

78 lines not on this page · raw message

fs/ext4/mballoc.c +242 -24

390 lines not on this page · raw message

fs/ext4/mballoc.h +5 -2
index bfe6add..2cc8440 100644
@@ -131,6 +131,10 @@ struct ext4_group_info {
 #define EXT4_MB_GRP_NEED_INIT(grp)	\
 	(test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
 
+#define PA_INODE_PA 0
+#define PA_GROUP_PA 1
+#define PA_META_PA 2
+
 
 struct ext4_prealloc_space {
 	struct list_head	pa_inode_list;
@@ -146,8 +150,7 @@ struct ext4_prealloc_space {
 	ext4_lblk_t		pa_lstart;	/* log. block */
 	unsigned short		pa_len;		/* len of preallocated chunk */
 	unsigned short		pa_free;	/* how many blocks are free */
-	unsigned short		pa_linear;	/* consumed in one direction
-						 * strictly, for grp prealloc */
+	unsigned short		pa_type;	/* Trype of prealloc space */
 	spinlock_t		*pa_obj_lock;
 	struct inode		*pa_inode;	/* hack, for history only */
 };
fs/ext4/super.c +1 -0
index d70165a..cd7cac0 100644
@@ -570,6 +570,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
 	ei->vfs_inode.i_version = 1;
 	memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
 	INIT_LIST_HEAD(&ei->i_prealloc_list);
+	INIT_LIST_HEAD(&ei->i_metaprealloc_list);
 	spin_lock_init(&ei->i_prealloc_lock);
 	return &ei->vfs_inode;
 }
fs/ext4/xattr.c +1 -1
index 3fbc2c6..4c8c742 100644
@@ -810,7 +810,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
 			/* We need to allocate a new block */
 			ext4_fsblk_t goal = ext4_group_first_block_no(sb,
 						EXT4_I(inode)->i_block_group);
-			ext4_fsblk_t block = ext4_new_block(handle, inode,
+			ext4_fsblk_t block = ext4_new_meta_block(handle, inode,
 							goal, &error);
 			if (error)
 				goto cleanup;
Signature · 1 line
1.5.5.1.211.g65ea3.dirty
#2 lore raw

Re: [PATCH] ext4: Group meta-data blocks together.

Quoted 8 lines · Aneesh Kumar K.V

This adds a per inode meta-block prealloc space from which meta-data block requests are served. This help in making sure meta-data block are closer. This is needed to speedup unlink of the file. Any new prealloc space is allocated near the goal block specified. The goal block is the last block allocated for the file. So we don't keep the data-block and meta-data block far apart.

The result can be found at

http://www.radian.org/~kvaneesh/ext4/meta-group/

This patch need to be further improved by grouping the meta-data at FLEX_BG or block group level rather than per inode. I am sending it so that others can take a look at the changes

-aneesh

#3 lore raw

Re: [PATCH] ext4: Group meta-data blocks together.

Quoted 10 lines · Aneesh Kumar K.V
Quoted 8 lines · Aneesh Kumar K.V

This adds a per inode meta-block prealloc space from which meta-data block requests are served. This help in making sure meta-data block are closer. This is needed to speedup unlink of the file. Any new prealloc space is allocated near the goal block specified. The goal block is the last block allocated for the file. So we don't keep the data-block and meta-data block far apart.

Quoted 3 lines

The result can be found at

http://www.radian.org/~kvaneesh/ext4/meta-group/

Out of curiosity, do you have graphs similar to
http://www.radian.org/~kvaneesh/ext4/meta-group/ext4-noextents-metagroup.png

before and after your change?

Thanks,
-Eric

#4 lore raw

Re: [PATCH] ext4: Group meta-data blocks together.

Quoted 11 lines · Eric Sandeen
Quoted 10 lines · Aneesh Kumar K.V
Quoted 8 lines · Aneesh Kumar K.V

This adds a per inode meta-block prealloc space from which meta-data block requests are served. This help in making sure meta-data block are closer. This is needed to speedup unlink of the file. Any new prealloc space is allocated near the goal block specified. The goal block is the last block allocated for the file. So we don't keep the data-block and meta-data block far apart.

Quoted 9 lines
Quoted 3 lines

The result can be found at

http://www.radian.org/~kvaneesh/ext4/meta-group/

Out of curiosity, do you have graphs similar to
http://www.radian.org/~kvaneesh/ext4/meta-group/ext4-noextents-metagroup.png

before and after your change?

No, But I can do that.

-aneesh

#5 lore raw

Re: [PATCH] ext4: Group meta-data blocks together.

In reply to Eric Sandeen
Quoted 11 lines · Eric Sandeen
Quoted 10 lines · Aneesh Kumar K.V
Quoted 8 lines · Aneesh Kumar K.V

This adds a per inode meta-block prealloc space from which meta-data block requests are served. This help in making sure meta-data block are closer. This is needed to speedup unlink of the file. Any new prealloc space is allocated near the goal block specified. The goal block is the last block allocated for the file. So we don't keep the data-block and meta-data block far apart.

Quoted 8 lines
Quoted 3 lines

The result can be found at

http://www.radian.org/~kvaneesh/ext4/meta-group/

Out of curiosity, do you have graphs similar to
http://www.radian.org/~kvaneesh/ext4/meta-group/ext4-noextents-metagroup.png

before and after your change?

http://www.radian.org/~kvaneesh/ext4/meta-group/exp1/

-aneesh

#6 lore raw

Re: [PATCH] ext4: Group meta-data blocks together.

Quoted 13 lines · Aneesh Kumar K.V
Quoted 12 lines · Eric Sandeen
Quoted 11 lines · Aneesh Kumar K.V
Quoted 8 lines · Aneesh Kumar K.V

This adds a per inode meta-block prealloc space from which meta-data block requests are served. This help in making sure meta-data block are closer. This is needed to speedup unlink of the file. Any new prealloc space is allocated near the goal block specified. The goal block is the last block allocated for the file. So we don't keep the data-block and meta-data block far apart.

The result can be found at

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

http://www.radian.org/~kvaneesh/ext4/meta-group/

Out of curiosity, do you have graphs similar to
http://www.radian.org/~kvaneesh/ext4/meta-group/ext4-noextents-metagroup.png

before and after your change?

http://www.radian.org/~kvaneesh/ext4/meta-group/exp1/

Thanks!

On:
http://www.radian.org/~kvaneesh/ext4/meta-group/exp1/ext4-noextents-withoutpatch-rm.png

it seems interesting; do you know what's going on between ~40s and 100s?

Also:

between:
http://www.radian.org/~kvaneesh/ext4/meta-group/exp1/ext4-noextents-read.png
and
http://www.radian.org/~kvaneesh/ext4/meta-group/exp1/ext4-noextents-withoutpatch-read.png

it looks like about a 10% slowdown on the read....

-Eric