ext4: change unit of extent's ee_len from block to cluster
cover ext4: change unit of extent's ee_len from block to cluster
From: Robin Dong <[email protected]>
Hi,
This patch series change unit of ee_len (of extent) from "block" to "cluster". Changing the unit of ee_len will reduce the space occupied by meta data.
PATCH 1/8 ext4: get blocks from ext4_ext_get_actual_len
From: Robin Dong <[email protected]>
Since ee_len's unit change to cluster, it need to transform from clusters to blocks when use ext4_ext_get_actual_len.
--- fs/ext4/ext4_extents.h | 2 +- fs/ext4/extents.c | 164 ++++++++++++++++++++++++++++-------------------- 2 files changed, 97 insertions(+), 69 deletions(-)
fs/ext4/ext4_extents.h +1 -1
@@ -71,7 +71,7 @@*/ struct ext4_extent {__le32 ee_block;/* first logical block extent covers */ -__le16 ee_len;/* number of blocks covered by extent */ +__le16 ee_len;/* number of clusters covered by extent */ __le16 ee_start_hi;/* high 16 bits of physical block */ __le32 ee_start_lo;/* low 32 bits of physical block */ };
fs/ext4/extents.c +96 -68
559 lines not on this page · raw message
Signature · 1 line
1.7.3.2
Re: [PATCH 1/8 bigalloc] ext4: get blocks from ext4_ext_get_actual_len
Quoted 4 lines · Robin Dong
From: Robin Dong <[email protected]>
Since ee_len's unit change to cluster, it need to transform from clusters to blocks when use
ext4_ext_get_actual_len.
Robin,
thanks for working on and submitting these patches so quickly.
fs/ext4/ext4_extents.h line 74
Quoted 4 lines
struct
ext4_extent{
__le32ee_block; /* first logical block extent covers */fs/ext4/ext4_extents.h +1
-1-__le16 ee_len;/* number of blocks covered by extent */ +__le16 ee_len;/* number of clusters covered by extent */
It would make sense that ee_block should also be changed to be measured in units of clusters instead of blocks, since there is no value to using extents with cluster size if they are not also cluster aligned.
I think this would also simplify some of the code.
Review
Quoted 3 lines
static int
ext4_valid_extent(struct inode *inode, struct ext4_extent *ext){(quoted diff) +1
-0+ struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
Why allocate "*sbi" on the stack in all of these functions for a single use? This provides no benefit, but can increase the stack usage considerably due to repeated allocations.
fs/ext4/extents.c ext4_ext_max_entries(struct inode *inode, int depth) · line 308
Quoted 2 lines
ext4_fsblk_t block = ext4_ext_pblock(ext);fs/ext4/extents.c +1
-0+int len =EXT4_C2B (sbi,ext4_ext_get_actual_len (ext));
It probably makes more sense to pass "sb" or "sbi" as a parameter to ext4_ext_get_actual_len() and then have it return the proper length in blocks (i.e. call EXT4_C2B() internally), which will simplify all of the callers and avoid potential bugs if some code does not use it.
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, · line 1538
Quoted 7 lines
fs/ext4/extents.c +1
-1@@ -1523,7 +1534,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, ext1_ee_len =ext4_ext_get_actual_len (ex1); ext2_ee_len =ext4_ext_get_actual_len (ex2); -if (le32_to_cpu (ex1->ee_block) + ext1_ee_len != +if (le32_to_cpu (ex1->ee_block) +EXT4_C2B (sbi, ext1_ee_len) !=le32_to_cpu (ex2->ee_block))
If both ee_len and ee_block are in the same units (blocks or clusters), then there is no need to convert units for this function at all.
Cheers, Andreas
Re: [PATCH 1/8 bigalloc] ext4: get blocks from ext4_ext_get_actual_len
Quoted 14 lines · Andreas Dilger
Quoted 4 lines · Robin Dong
From: Robin Dong <[email protected]>
Since ee_len's unit change to cluster, it need to transform from clusters to blocks when use
ext4_ext_get_actual_len.Robin,
thanks for working on and submitting these patches so quickly.Quoted 4 lines
struct
ext4_extent{
__le32ee_block; /* first logical block extent covers */
-__le16ee_len; /* number of blocks covered by extent */
+__le16ee_len; /* number of clusters covered by extent */
Quoted 5 lines
It would make sense that
ee_blockshould also be changed to be measured in units of clusters instead of blocks, since there is no value to using extents with cluster size if they are not also cluster aligned.I think this would also simplify some of the code.
Actually, after these patches are applied, both logical block and physical block are all cluster sized. So I have a suggestion that we can simply tell users that ext4 can use large size block rather than cluster.
Yongqiang.
Quoted 40 lines
Quoted 4 lines
static int
ext4_valid_extent(struct inode *inode, struct ext4_extent *ext){
+ structext4_sb_info*sbi =EXT4_SB(inode->i_sb);Why allocate "*sbi" on the stack in all of these functions for a single use? This provides no benefit, but can increase the stack usage considerably due to repeated allocations.
Quoted 2 lines
ext4_fsblk_tblock =ext4_ext_pblock(ext);
+ int len =EXT4_C2B(sbi, ext4_ext_get_actual_len(ext));It probably makes more sense to pass "sb" or "sbi" as a parameter to
ext4_ext_get_actual_len()and then have it return the proper length in blocks (i.e. callEXT4_C2B()internally), which will simplify all of the callers and avoid potential bugs if some code does not use it.fs/ext4/extents.c ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, · line 1538
Quoted 7 lines
fs/ext4/extents.c +1
-1@@ -1523,7 +1534,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, ext1_ee_len = ext4_ext_get_actual_len(ex1); ext2_ee_len = ext4_ext_get_actual_len(ex2); - if (le32_to_cpu(ex1->ee_block) + ext1_ee_len != + if (le32_to_cpu(ex1->ee_block) + EXT4_C2B(sbi, ext1_ee_len) != le32_to_cpu(ex2->ee_block))If both
ee_lenandee_blockare in the same units (blocks or clusters), then there is no need to convert units for this function at all.Cheers, Andreas
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 6 lines
Best Wishes Yongqiang Yang -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/8 bigalloc] ext4: get blocks from ext4_ext_get_actual_len
Quoted 19 lines · Yongqiang Yang
Quoted 18 lines · Andreas Dilger
Quoted 4 lines · Robin Dong
From: Robin Dong <[email protected]>
Since ee_len's unit change to cluster, it need to transform from clusters to blocks when use
ext4_ext_get_actual_len.Robin,
thanks for working on and submitting these patches so quickly.fs/ext4/ext4_extents.h line 74
Quoted 4 lines
struct
ext4_extent{
__le32ee_block; /* first logical block extent covers */fs/ext4/ext4_extents.h +1
-1-__le16 ee_len;/* number of blocks covered by extent */ +__le16 ee_len;/* number of clusters covered by extent */ It would make sense that
ee_blockshould also be changed to be measured in units of clusters instead of blocks, since there is no value to using extents with cluster size if they are not also cluster aligned.
Quoted 6 lines
Quoted 1 line
I think this would also simplify some of the code.
Actually, after these patches are applied, both logical block and physical block are all cluster sized. So I have a suggestion that we can simply tell users that ext4 can use large size block rather than cluster.
I hadn't actually looked at the later patches in the series yet. In that case, I'm happy to allow bigalloc to continue with its current approach of cluster size > blocksize, but extents are measured in blocks, and use the support support you've added for blocksize > PAGE_SIZE by scaling the in-memory "block" addresses to match PAGE_SIZE (along with other fixes here to handle zeroing of neighbouring pages in the block).
Essentially, this would be very similar to internally setting the cluster size to blocksize >> PAGE_SHIFT even though this isn't set in the superblock at format time.
The other comments below should still be addressed.
Quoted 20 lines
Quoted 20 lines
Quoted 3 lines
static int
ext4_valid_extent(struct inode *inode, struct ext4_extent *ext){
+ structext4_sb_info*sbi =EXT4_SB(inode->i_sb);Why allocate "*sbi" on the stack in all of these functions for a single use? This provides no benefit, but can increase the stack usage considerably due to repeated allocations.
Quoted 2 lines
ext4_fsblk_t block = ext4_ext_pblock(ext);+ int len =
EXT4_C2B(sbi, ext4_ext_get_actual_len(ext));It probably makes more sense to pass "sb" or "sbi" as a parameter to
ext4_ext_get_actual_len()and then have it return the proper length in blocks (i.e. callEXT4_C2B()internally), which will simplify all of the callers and avoid potential bugs if some code does not use it.Quoted 4 lines
fs/ext4/extents.c +0
-0@@ -1523,7 +1534,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, ext1_ee_len =ext4_ext_get_actual_len (ex1); ext2_ee_len =ext4_ext_get_actual_len (ex2);
Quoted 6 lines
Quoted 6 lines
fs/ext4/extents.c ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, · line 1538
Quoted 3 lines
fs/ext4/extents.c +1
-1-if (le32_to_cpu (ex1->ee_block) + ext1_ee_len != +if (le32_to_cpu (ex1->ee_block) +EXT4_C2B (sbi, ext1_ee_len) !=le32_to_cpu (ex2->ee_block))If both
ee_lenandee_blockare in the same units (blocks or clusters), then there is no need to convert units for this function at all.
Cheers, Andreas
PATCH 2/8 ext4: change ext4_ext_map_blocks to allocate clusters instead of blocks
In reply to Robin DongFrom: Robin Dong <[email protected]>
We need to align to a cluster when users allocate just one block.
--- fs/ext4/extents.c | 47 +++++++++++++---------------------------------- 1 files changed, 13 insertions(+), 34 deletions(-)
fs/ext4/extents.c +13 -34
@@ -3962,20 +3962,13 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,* Okay, we need to do block allocation. */ map->m_flags &= ~EXT4_MAP_FROM_CLUSTER ; - newex.ee_block =cpu_to_le32 (map->m_lblk); + newex.ee_block =cpu_to_le32 (map->m_lblk & ~(sbi->s_cluster_ratio-1 )); cluster_offset = map->m_lblk & (sbi->s_cluster_ratio-1 ); -/* -* If we are doing bigalloc, check to see if the extent returned -* by ext4_ext_find_extent() implies a cluster we can use. -*/ -if (cluster_offset && ex && -get_implied_cluster_alloc (inode->i_sb, map, ex, path)) { - ar.len = allocated = map->m_len; - newblock = map->m_pblk; - map->m_flags |=EXT4_MAP_FROM_CLUSTER ; - goto got_allocated_blocks; - } +if (ex) +BUG_ON ((le32_to_cpu (ex->ee_block) + +EXT4_C2B (sbi, ex->ee_len)) > + (map->m_lblk & ~(sbi->s_cluster_ratio-1 )));/* find neighbour allocated blocks */ ar.lleft = map->m_lblk;
@@ -3988,16 +3981,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,if (err) goto out2; -/* Check if the extent after searching to the right implies a -* cluster we can use. */ -if ((sbi->s_cluster_ratio >1 ) && ex2 && -get_implied_cluster_alloc (inode->i_sb, map, ex2, path)) { - ar.len = allocated = map->m_len; - newblock = map->m_pblk; - map->m_flags |=EXT4_MAP_FROM_CLUSTER ; - goto got_allocated_blocks; - } -/* * See if request is beyond maximum number of blocks we can have in * a single extent. For an initialized extent this limit is
@@ -4012,10 +3995,10 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, map->m_len =EXT_UNINIT_MAX_LEN ;/* Check if we can really insert (m_lblk)::(m_lblk + m_len) extent */ - newex.ee_len =cpu_to_le16 (map->m_len); + newex.ee_len =cpu_to_le16 (EXT4_NUM_B2C (sbi, map->m_len)); err =ext4_ext_check_overlap (sbi, inode, &newex, path);if (err) - allocated =EXT4_C2B (sbi,ext4_ext_get_actual_len (&newex)); + allocated =ext4_ext_get_actual_len (&newex);else allocated = map->m_len;
@@ -4049,14 +4032,11 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, ar.goal, newblock, allocated); free_on_err =1 ; allocated_clusters = ar.len; - ar.len =EXT4_C2B (sbi, ar.len) - offset; -if (ar.len > allocated) - ar.len = allocated; got_allocated_blocks:/* try to insert new extent into found leaf and return */ -ext4_ext_store_pblock (&newex, newblock + offset); - newex.ee_len =cpu_to_le16 (ar.len); +ext4_ext_store_pblock (&newex, newblock); + newex.ee_len =cpu_to_le16 (allocated_clusters);/* Mark uninitialized */ if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ){ext4_ext_mark_uninitialized (&newex);
@@ -4079,7 +4059,8 @@ got_allocated_blocks: map->m_flags |=EXT4_MAP_UNINIT ; } - err =check_eofblocks_fl (handle, inode, map->m_lblk, path, ar.len); + err =check_eofblocks_fl (handle, inode, map->m_lblk, path, +EXT4_C2B (sbi, allocated_clusters));if (!err) err =ext4_ext_insert_extent (handle, inode, path, &newex, flags);
@@ -4099,8 +4080,6 @@ got_allocated_blocks:/* previous routine could use block we allocated */ newblock =ext4_ext_pblock (&newex); allocated =EXT4_C2B (sbi,ext4_ext_get_actual_len (&newex)); -if (allocated > map->m_len) - allocated = map->m_len; map->m_flags |=EXT4_MAP_NEW ;/*
@@ -4187,7 +4166,7 @@ got_allocated_blocks:* when it is _not_ an uninitialized extent. */ if ((flags &EXT4_GET_BLOCKS_UNINIT_EXT ) ==0 ) { -ext4_ext_put_in_cache (inode, map->m_lblk, allocated, newblock); +ext4_ext_put_in_cache (inode, ar.logical, allocated, newblock);ext4_update_inode_fsync_trans (handle, inode,1 ); }else ext4_update_inode_fsync_trans (handle, inode,0 );
@@ -4196,7 +4175,7 @@ out: allocated = map->m_len;ext4_ext_show_leaf (inode, path); map->m_flags |=EXT4_MAP_MAPPED ; - map->m_pblk = newblock; + map->m_pblk = newblock + offset; map->m_len = allocated; out2:if (path) {
Signature · 1 line
1.7.3.2
PATCH 3/8 ext4: remove unused functions and tags
In reply to Robin DongFrom: Robin Dong <[email protected]>
remove unused functions and tags.
--- fs/ext4/extents.c | 108 ----------------------------------------------------- 1 files changed, 0 insertions(+), 108 deletions(-)
fs/ext4/extents.c +0 -108
@@ -3619,111 +3619,6 @@ out2: }/* -* get_implied_cluster_alloc - check to see if the requested -* allocation (in the map structure) overlaps with a cluster already -* allocated in an extent. -* @sb The filesystem superblock structure -* @map The requested lblk->pblk mapping -* @ex The extent structure which might contain an implied -* cluster allocation -* -* This function is called by ext4_ext_map_blocks() after we failed to -* find blocks that were already in the inode's extent tree. Hence, -* we know that the beginning of the requested region cannot overlap -* the extent from the inode's extent tree. There are three cases we -* want to catch. The first is this case: -* -* |--- cluster # N--| -* |--- extent ---| |---- requested region ---| -* |==========| -* -* The second case that we need to test for is this one: -* -* |--------- cluster # N ----------------| -* |--- requested region --| |------- extent ----| -* |=======================| -* -* The third case is when the requested region lies between two extents -* within the same cluster: -* |------------- cluster # N-------------| -* |----- ex -----| |---- ex_right ----| -* |------ requested region ------| -* |================| -* -* In each of the above cases, we need to set the map->m_pblk and -* map->m_len so it corresponds to the return the extent labelled as -* "|====|" from cluster #N, since it is already in use for data in -* cluster EXT4_B2C(sbi, map->m_lblk). We will then return 1 to -* signal to ext4_ext_map_blocks() that map->m_pblk should be treated -* as a new "allocated" block region. Otherwise, we will return 0 and -* ext4_ext_map_blocks() will then allocate one or more new clusters -* by calling ext4_mb_new_blocks(). -*/ -static int get_implied_cluster_alloc (struct super_block *sb, -struct ext4_map_blocks *map, -struct ext4_extent *ex, -struct ext4_ext_path *path) -{ -struct ext4_sb_info *sbi =EXT4_SB (sb); -ext4_lblk_t c_offset = map->m_lblk & (sbi->s_cluster_ratio-1 ); -ext4_lblk_t ex_cluster_start, ex_cluster_end; -ext4_lblk_t rr_cluster_start, rr_cluster_end; -ext4_lblk_t ee_block =le32_to_cpu (ex->ee_block); -ext4_fsblk_t ee_start =ext4_ext_pblock (ex); -unsigned int ee_len =EXT4_C2B (sbi,ext4_ext_get_actual_len (ex)); - -/* The extent passed in that we are trying to match */ - ex_cluster_start =EXT4_B2C (sbi, ee_block); - ex_cluster_end =EXT4_B2C (sbi, ee_block + ee_len -1 ); - -/* The requested region passed into ext4_map_blocks() */ - rr_cluster_start =EXT4_B2C (sbi, map->m_lblk); - rr_cluster_end =EXT4_B2C (sbi, map->m_lblk + map->m_len -1 ); - -if ((rr_cluster_start == ex_cluster_end) || - (rr_cluster_start == ex_cluster_start)) { -if (rr_cluster_start == ex_cluster_end) - ee_start += ee_len -1 ; - map->m_pblk = (ee_start & ~(sbi->s_cluster_ratio -1 )) + - c_offset; - map->m_len =min (map->m_len, - (unsigned ) sbi->s_cluster_ratio - c_offset); -/* -* Check for and handle this case: -* -* |--------- cluster # N-------------| -* |------- extent ----| -* |--- requested region ---| -* |===========| -*/ - -if (map->m_lblk < ee_block) - map->m_len =min (map->m_len, ee_block - map->m_lblk); - -/* -* Check for the case where there is already another allocated -* block to the right of 'ex' but before the end of the cluster. -* -* |------------- cluster # N-------------| -* |----- ex -----| |---- ex_right ----| -* |------ requested region ------| -* |================| -*/ -if (map->m_lblk > ee_block) { -ext4_lblk_t next =ext4_ext_next_allocated_block (path); - map->m_len =min (map->m_len, next - map->m_lblk); - } - -trace_ext4_get_implied_cluster_alloc_exit (sb, map,1 ); -return 1 ; - } - -trace_ext4_get_implied_cluster_alloc_exit (sb, map,0 ); -return 0 ; -} - - -/* * Block allocation/map/preallocation routine for extents based files * *
@@ -3755,7 +3650,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,unsigned int result =0 ;struct ext4_allocation_request ar;ext4_io_end_t *io =EXT4_I (inode)->cur_aio_dio; -ext4_lblk_t cluster_offset;struct ext4_map_blocks punch_map; ext_debug("blocks %u/%u requested for inode %lu\n",
@@ -3963,7 +3857,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,*/ map->m_flags &= ~EXT4_MAP_FROM_CLUSTER ; newex.ee_block =cpu_to_le32 (map->m_lblk & ~(sbi->s_cluster_ratio-1 )); - cluster_offset = map->m_lblk & (sbi->s_cluster_ratio-1 );if (ex) BUG_ON((le32_to_cpu(ex->ee_block) +
@@ -4033,7 +3926,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, free_on_err =1 ; allocated_clusters = ar.len; -got_allocated_blocks:/* try to insert new extent into found leaf and return */ ext4_ext_store_pblock (&newex, newblock); newex.ee_len =cpu_to_le16 (allocated_clusters);
Signature · 1 line
1.7.3.2
PATCH 4/8 ext4: zeroout extra pages when users write one page
In reply to Robin DongFrom: Robin Dong <[email protected]>
When users write one page which in the middle of a cluster, we need to zero the anthor pages around it.
--- fs/ext4/ext4.h | 18 +++++ fs/ext4/extents.c | 2 +- fs/ext4/inode.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 197 insertions(+), 13 deletions(-)
fs/ext4/ext4.h +18 -0
@@ -670,6 +670,15 @@ struct move_extent {#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)#define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS) +#define EXT4_MAX_CLUSTERSIZE 1048576 +#define EXT4_MAX_CTXT_PAGES (EXT4_MAX_CLUSTERSIZE / PAGE_CACHE_SIZE) + +/* tracking cluster write pages */ +struct ext4_write_cluster_ctxt { +unsigned long w_num_pages; +struct page *w_pages[EXT4_MAX_CTXT_PAGES ]; +}; +/* * Extended fields will fit into an inode if the filesystem was formatted * with large inodes (-I 256 or larger) and there are not currently any EAs
@@ -1844,6 +1853,15 @@ extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,extern int ext4_trim_fs (struct super_block *,struct fstrim_range *);/* inode.c */ +int walk_page_buffers (handle_t *handle,struct buffer_head *head, +unsigned from,unsigned to,int *partial, +int (*fn)(handle_t *handle,struct buffer_head *bh)); +int do_journal_get_write_access (handle_t *handle,struct buffer_head *bh); +struct ext4_write_cluster_ctxt *ext4_alloc_write_cluster_ctxt (void ); +void ext4_free_write_cluster_ctxt (struct ext4_write_cluster_ctxt *ewcc); +int ext4_zero_cluster_page (struct inode *inode,int index, +struct ext4_write_cluster_ctxt *ewcc,unsigned flags); +struct buffer_head *ext4_getblk (handle_t *,struct inode *,ext4_lblk_t ,int ,int *); struct buffer_head *ext4_bread(handle_t *, struct inode *,
fs/ext4/extents.c +1 -1
@@ -3860,7 +3860,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,if (ex)BUG_ON ((le32_to_cpu (ex->ee_block) + -EXT4_C2B (sbi, ex->ee_len)) > +EXT4_C2B (sbi,ext4_ext_get_actual_len (ex))) > (map->m_lblk & ~(sbi->s_cluster_ratio-1 )));/* find neighbour allocated blocks */
fs/ext4/inode.c +178 -12
279 lines not on this page · raw message
Signature · 1 line
1.7.3.2
PATCH 5/8 ext4: zero out extra pages when truncate file
In reply to Robin DongFrom: Robin Dong <[email protected]>
When truncate file to be larger, we need to zero out the pages which beyond the old i_size.
--- fs/ext4/ext4.h | 4 +- fs/ext4/extents.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 13 ++++---- fs/ext4/ioctl.c | 2 +- fs/ext4/super.c | 2 +- fs/ext4/truncate.h | 2 +- 6 files changed, 89 insertions(+), 12 deletions(-)
fs/ext4/ext4.h +2 -2
@@ -1881,7 +1881,7 @@ extern void ext4_dirty_inode(struct inode *, int);extern int ext4_change_inode_journal_flag (struct inode *,int );extern int ext4_get_inode_loc (struct inode *,struct ext4_iloc *);extern int ext4_can_truncate (struct inode *inode); -extern void ext4_truncate (struct inode *); +extern void ext4_truncate (struct inode *,loff_t oldsize);extern int ext4_punch_hole (struct file *file,loff_t offset,loff_t length);extern int ext4_truncate_restart_trans (handle_t *,struct inode *,int nblocks);extern void ext4_set_inode_flags (struct inode *);
@@ -2262,7 +2262,7 @@ extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks, int chunk);extern int ext4_ext_map_blocks (handle_t *handle,struct inode *inode,struct ext4_map_blocks *map,int flags); -extern void ext4_ext_truncate (struct inode *); +extern void ext4_ext_truncate (struct inode *,loff_t oldsize);extern int ext4_ext_punch_hole (struct file *file,loff_t offset,loff_t length);extern void ext4_ext_init (struct super_block *);
fs/ext4/extents.c +77 -1
99 lines not on this page · raw message
fs/ext4/inode.c +7 -6
@@ -213,7 +213,7 @@ void ext4_evict_inode(struct inode *inode) goto stop_handle; }if (inode->i_blocks) -ext4_truncate (inode); +ext4_truncate (inode,0 );/* * ext4_ext_truncate() doesn't reserve any slop when it
@@ -3343,7 +3343,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)* that's fine - as long as they are linked from the inode, the post-crash * ext4_truncate() run will find them and release them. */ -void ext4_truncate (struct inode *inode) +void ext4_truncate (struct inode *inode,loff_t old_size) {trace_ext4_truncate_enter (inode);
@@ -3356,7 +3356,7 @@ void ext4_truncate(struct inode *inode)ext4_set_inode_state (inode,EXT4_STATE_DA_ALLOC_CLOSE );if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) -ext4_ext_truncate (inode); +ext4_ext_truncate (inode, old_size);else ext4_ind_truncate (inode);
@@ -4123,11 +4123,12 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) }if (attr->ia_valid &ATTR_SIZE ) { -if (attr->ia_size !=i_size_read (inode)) { +loff_t old_size =i_size_read (inode); +if (attr->ia_size != old_size) {truncate_setsize (inode, attr->ia_size); -ext4_truncate (inode); +ext4_truncate (inode, old_size); }else if (ext4_test_inode_flag (inode,EXT4_INODE_EOFBLOCKS )) -ext4_truncate (inode); +ext4_truncate (inode,0 ); }if (!rc) {
fs/ext4/ioctl.c +1 -1
@@ -100,7 +100,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) goto flags_out; } }else if (oldflags &EXT4_EOFBLOCKS_FL ) -ext4_truncate (inode); +ext4_truncate (inode,0 ); handle =ext4_journal_start (inode,1 );if (IS_ERR (handle)) {
fs/ext4/super.c +1 -1
@@ -2229,7 +2229,7 @@ static void ext4_orphan_cleanup(struct super_block *sb, __func__, inode->i_ino, inode->i_size);jbd_debug (2 ,"truncating inode %lu to %lld bytes\n" , inode->i_ino, inode->i_size); -ext4_truncate (inode); +ext4_truncate (inode,0 ); nr_truncates++; }else { ext4_msg(sb, KERN_DEBUG,
fs/ext4/truncate.h +1 -1
@@ -11,7 +11,7 @@static inline void ext4_truncate_failed_write (struct inode *inode) {truncate_inode_pages (inode->i_mapping, inode->i_size); -ext4_truncate (inode); +ext4_truncate (inode,0 ); }/*
Signature · 1 line
1.7.3.2
PATCH 6/8 ext4: directories allocate a cluster when it need spaces
In reply to Robin DongFrom: Robin Dong <[email protected]>
allocate a cluster instead of a block when directories need new space.
--- fs/ext4/namei.c | 54 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 39 insertions(+), 15 deletions(-)
fs/ext4/namei.c +39 -15
@@ -49,6 +49,16 @@#define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS)#define NAMEI_RA_INDEX (c,b) (((c) * NAMEI_RA_BLOCKS) + (b)) +static void ext4_zero_append (handle_t *handle,struct inode *inode, +struct buffer_head *bh,ext4_lblk_t block) +{ +struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); + +if ((sbi->s_cluster_ratio >1 ) && + (block % sbi->s_cluster_ratio)) +memset (bh->b_data,0 , inode->i_sb->s_blocksize); +} +static struct buffer_head *ext4_append (handle_t *handle,struct inode *inode,ext4_lblk_t *block,int *err)
@@ -59,6 +69,7 @@ static struct buffer_head *ext4_append(handle_t *handle, bh =ext4_bread (handle, inode, *block,1 , err);if (bh) { +ext4_zero_append (handle, inode, bh, *block); inode->i_size += inode->i_sb->s_blocksize;EXT4_I (inode)->i_disksize = inode->i_size; *err =ext4_journal_get_write_access (handle, bh);
@@ -1811,10 +1822,12 @@ static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode) {handle_t *handle;struct inode *inode; -struct buffer_head *dir_block =NULL ; +struct buffer_head *first_block =NULL ; +struct buffer_head *dir_block[EXT4_MAX_CTXT_PAGES ];struct ext4_dir_entry_2 *de; +struct ext4_sb_info *sbi =EXT4_SB (dir->i_sb);unsigned int blocksize = dir->i_sb->s_blocksize; -int err, retries =0 ; +int i, err, retries =0 ;if (EXT4_DIR_LINK_MAX (dir))return -EMLINK ;
@@ -1824,6 +1837,7 @@ static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode) retry: handle =ext4_journal_start (dir,EXT4_DATA_TRANS_BLOCKS (dir->i_sb) +EXT4_INDEX_EXTRA_TRANS_BLOCKS +3 + + sbi->s_cluster_ratio +EXT4_MAXQUOTAS_INIT_BLOCKS (dir->i_sb));if (IS_ERR (handle))return PTR_ERR (handle);
@@ -1840,14 +1854,20 @@ retry: inode->i_op = &ext4_dir_inode_operations; inode->i_fop = &ext4_dir_operations; inode->i_size =EXT4_I (inode)->i_disksize = inode->i_sb->s_blocksize; - dir_block =ext4_bread (handle, inode,0 ,1 , &err); -if (!dir_block) - goto out_clear_inode; -BUFFER_TRACE (dir_block,"get_write_access" ); - err =ext4_journal_get_write_access (handle, dir_block); -if (err) - goto out_clear_inode; - de = (struct ext4_dir_entry_2 *) dir_block->b_data; + +for (i =0 ; i < sbi->s_cluster_ratio; i++) { + dir_block[i] =ext4_bread (handle, inode, i,1 , &err); +if (!dir_block[i]) + goto out_clear_inode; +BUFFER_TRACE (dir_block[i],"get_write_access" ); +memset (dir_block[i]->b_data,0 , inode->i_sb->s_blocksize); +set_buffer_uptodate (dir_block[i]); + err =ext4_journal_get_write_access (handle, dir_block[i]); +if (err) + goto out_clear_inode; + } + first_block = dir_block[0 ]; + de = (struct ext4_dir_entry_2 *) first_block->b_data; de->inode =cpu_to_le32 (inode->i_ino); de->name_len =1 ; de->rec_len = ext4_rec_len_to_disk(EXT4_DIR_REC_LEN(de->name_len),
@@ -1862,10 +1882,13 @@ retry:strcpy (de->name,".." );ext4_set_de_type (dir->i_sb, de,S_IFDIR ); inode->i_nlink =2 ; -BUFFER_TRACE (dir_block,"call ext4_handle_dirty_metadata" ); - err =ext4_handle_dirty_metadata (handle, dir, dir_block); -if (err) - goto out_clear_inode; +BUFFER_TRACE (first_block,"call ext4_handle_dirty_metadata" ); + +for (i =0 ; i < sbi->s_cluster_ratio; i++) { + err =ext4_handle_dirty_metadata (handle, dir, dir_block[i]); +if (err) + goto out_clear_inode; + } err =ext4_mark_inode_dirty (handle, inode);if (!err) err =ext4_add_entry (handle, dentry, inode);
@@ -1885,7 +1908,8 @@ out_clear_inode:d_instantiate (dentry, inode);unlock_new_inode (inode); out_stop: -brelse (dir_block); +for (i =0 ; i < sbi->s_cluster_ratio; i++) +brelse (dir_block[i]);ext4_journal_stop (handle);if (err == -ENOSPC &&ext4_should_retry_alloc (dir->i_sb, &retries)) goto retry;
Signature · 1 line
1.7.3.2
PATCH 7/8 ext4: align fallocate size to a whole cluster
In reply to Robin DongFrom: Robin Dong <[email protected]>
align fallocate size to a whole cluster
--- fs/ext4/extents.c | 34 ++++++++++++++++++++++++++++++++-- 1 files changed, 32 insertions(+), 2 deletions(-)
fs/ext4/extents.c +32 -2
@@ -3490,8 +3490,11 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, struct ext4_ext_path *path, int flags, unsigned int allocated, ext4_fsblk_t newblock) { + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); +struct ext4_map_blocks convert_map;int ret =0 ;int err =0 ; +int offset;ext4_io_end_t *io =EXT4_I (inode)->cur_aio_dio; ext_debug("ext4_ext_handle_uninitialized_extents: inode %lu, logical"
@@ -3555,8 +3558,14 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode, }/* buffered write, writepage time, convert*/ - ret =ext4_ext_convert_to_initialized (handle, inode, map, path); + offset = map->m_lblk & (sbi->s_cluster_ratio -1 ); + convert_map.m_len = +EXT4_C2B (sbi,EXT4_NUM_B2C (sbi, offset + map->m_len)); + convert_map.m_lblk = map->m_lblk - offset; + ret =ext4_ext_convert_to_initialized (handle, inode, + &convert_map, path);if (ret >=0 ) { + ret = map->m_len;ext4_update_inode_fsync_trans (handle, inode,1 ); err =check_eofblocks_fl (handle, inode, map->m_lblk, path, map->m_len);
@@ -4270,8 +4279,9 @@ static void ext4_falloc_update_inode(struct inode *inode,long ext4_fallocate (struct file *file,int mode,loff_t offset,loff_t len) {struct inode *inode = file->f_path.dentry->d_inode; +struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);handle_t *handle; -loff_t new_size; +loff_t new_size, old_size;unsigned int max_blocks;int ret =0 ;int ret2 =0 ;
@@ -4301,6 +4311,8 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)*/ max_blocks = (EXT4_BLOCK_ALIGN (len + offset, blkbits) >> blkbits) - map.m_lblk; + + old_size =i_size_read (inode);/* * credits to insert 1 extent into extent tree */
@@ -4355,6 +4367,24 @@ retry: goto retry; }mutex_unlock (&inode->i_mutex); + +/* if the fallocate expand the file size, we need to zeroout +* extra pages in cluster */ +if (len + offset > old_size) { + credits =ext4_chunk_trans_blocks (inode, sbi->s_cluster_ratio); + handle =ext4_journal_start (inode, credits); +if (IS_ERR (handle)) { + ret =PTR_ERR (handle); + goto out; + } +ext4_ext_truncate_zero_pages (handle, inode, old_size); +if (IS_SYNC (inode)) +ext4_handle_sync (handle); +ext4_mark_inode_dirty (handle, inode); +ext4_journal_stop (handle); + } + +out:trace_ext4_fallocate_exit (inode, offset, max_blocks, ret >0 ? ret2 : ret);return ret >0 ? ret2 : ret;
Signature · 1 line
1.7.3.2
PATCH 8/8 ext4: make cluster works for mmap
In reply to Robin DongFrom: Robin Dong <[email protected]>
When users write a page in mmap regioin, it need to zero out other pages around it.
--- fs/ext4/inode.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 68 insertions(+), 1 deletions(-)
fs/ext4/inode.c +68 -1
@@ -4545,13 +4545,17 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)struct page *page = vmf->page;loff_t size;unsigned long len; -int ret; +int ret, i, uninit =0 ;struct file *file = vma->vm_file;struct inode *inode = file->f_path.dentry->d_inode; +struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);struct address_space *mapping = inode->i_mapping; +struct ext4_write_cluster_ctxt *ewcc =NULL ;handle_t *handle;get_block_t *get_block;int retries =0 ; +unsigned int flags =AOP_FLAG_NOFS ; +unsigned long from, to;/* * This check is racy but catches the common case. We rely on
@@ -4608,7 +4612,47 @@ retry_alloc: ret =VM_FAULT_SIGBUS ; goto out; } + + ewcc =ext4_alloc_write_cluster_ctxt (); +if (!ewcc) { + ret = -ENOMEM ; + goto out; + } + +if (sbi->s_cluster_ratio >1 ) { +/* We need to know whether the block is allocated already +*/ +struct ext4_map_blocks map; + map.m_lblk = page->index; + map.m_len =1 ; + ret =ext4_map_blocks (handle, inode, &map,0 ); + uninit = map.m_flags &EXT4_MAP_UNWRITTEN ; +if (ret <=0 || uninit) { + ret =ext4_prepare_cluster_left_pages (inode, + page->index, ewcc, flags); +if (ret) + goto err_out; + } + } + ret =__block_page_mkwrite (vma, vmf, get_block); +if (ret) + goto err_out; + +if (sbi->s_cluster_ratio >1 && uninit) { + ret =ext4_prepare_cluster_right_pages (inode, page->index, + ewcc, flags); +if (ret) + goto err_out; +for (i =0 ; i < ewcc->w_num_pages; i++) { +if (!ewcc->w_pages[i] || + !page_buffers (ewcc->w_pages[i])) +break ; +block_commit_write (ewcc->w_pages[i], +0 ,PAGE_CACHE_SIZE ); + } + } +if (!ret &&ext4_should_journal_data (inode)) {if (walk_page_buffers (handle,page_buffers (page),0 ,PAGE_CACHE_SIZE ,NULL , do_journal_get_write_access)) {
@@ -4616,13 +4660,36 @@ retry_alloc: ret =VM_FAULT_SIGBUS ; goto out; } + +for (i =0 ; i < ewcc->w_num_pages; i++) { + page = ewcc->w_pages[i]; +if (!page || !page_buffers (page)) +continue ; + from = page->index <<PAGE_CACHE_SHIFT ; + to = from +PAGE_CACHE_SIZE ; + ret =walk_page_buffers (handle,page_buffers (page), + from, to,NULL , do_journal_get_write_access); +if (ret) { + ret =VM_FAULT_SIGBUS ; + goto out; + } + }ext4_set_inode_state (inode,EXT4_STATE_JDATA ); } + +err_out: +if (ewcc) { +ext4_free_write_cluster_ctxt (ewcc); + ewcc =NULL ; + }ext4_journal_stop (handle);if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) goto retry_alloc; out_ret: ret =block_page_mkwrite_return (ret); + out: +if (ewcc) +ext4_free_write_cluster_ctxt (ewcc);return ret; }
Signature · 1 line
1.7.3.2