ext4: Group meta-data blocks together.
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.
Signed-off-by Aneesh Kumar K.V <[email protected]>
--- fs/ext4/balloc.c | 6 +- fs/ext4/ext4.h | 22 +++-- fs/ext4/ext4_i.h | 1 + fs/ext4/extents.c | 4 +- fs/ext4/mballoc.c | 266 ++++++++++++++++++++++++++++++++++++++++++++++++----- fs/ext4/mballoc.h | 7 +- fs/ext4/super.c | 1 + 7 files changed, 267 insertions(+), 40 deletions(-)
fs/ext4/balloc.c +4 -2
@@ -1930,6 +1930,7 @@ ext4_fsblk_t ext4_new_meta_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; }
@@ -1948,6 +1949,7 @@ ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode, 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;
@@ -1977,10 +1979,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 +12 -10
@@ -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 0x800struct ext4_allocation_request {/* target inode for block we're allocating */
fs/ext4/ext4_i.h +1 -0
@@ -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 +2 -2
@@ -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/mballoc.c +242 -24
390 lines not on this page · raw message
fs/ext4/mballoc.h +5 -2
@@ -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
@@ -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; }
Signature · 1 line
1.5.5.1.211.g65ea3.dirty