ext4: use pre-allocated es in __es_insert_extent()
Pass a extent_status pointer prealloc to __es_insert_extent(). If the pointer is non-null, it is used directly when a new extent_status is needed to avoid memory allocation failures. Suggested-by: Jan Kara <jack@suse.cz> Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20230424033846.4732-5-libaokun1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
73a2f03365
commit
95f0b32033
@ -144,7 +144,8 @@
|
||||
static struct kmem_cache *ext4_es_cachep;
|
||||
static struct kmem_cache *ext4_pending_cachep;
|
||||
|
||||
static int __es_insert_extent(struct inode *inode, struct extent_status *newes);
|
||||
static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
|
||||
struct extent_status *prealloc);
|
||||
static int __es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
|
||||
ext4_lblk_t end, int *reserved);
|
||||
static int es_reclaim_extents(struct ext4_inode_info *ei, int *nr_to_scan);
|
||||
@ -766,7 +767,8 @@ static inline void ext4_es_insert_extent_check(struct inode *inode,
|
||||
}
|
||||
#endif
|
||||
|
||||
static int __es_insert_extent(struct inode *inode, struct extent_status *newes)
|
||||
static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
|
||||
struct extent_status *prealloc)
|
||||
{
|
||||
struct ext4_es_tree *tree = &EXT4_I(inode)->i_es_tree;
|
||||
struct rb_node **p = &tree->root.rb_node;
|
||||
@ -806,7 +808,10 @@ static int __es_insert_extent(struct inode *inode, struct extent_status *newes)
|
||||
}
|
||||
}
|
||||
|
||||
es = __es_alloc_extent(false);
|
||||
if (prealloc)
|
||||
es = prealloc;
|
||||
else
|
||||
es = __es_alloc_extent(false);
|
||||
if (!es)
|
||||
return -ENOMEM;
|
||||
ext4_es_init_extent(inode, es, newes->es_lblk, newes->es_len,
|
||||
@ -866,7 +871,7 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
|
||||
if (err != 0)
|
||||
goto error;
|
||||
retry:
|
||||
err = __es_insert_extent(inode, &newes);
|
||||
err = __es_insert_extent(inode, &newes, NULL);
|
||||
if (err == -ENOMEM && __es_shrink(EXT4_SB(inode->i_sb),
|
||||
128, EXT4_I(inode)))
|
||||
goto retry;
|
||||
@ -916,7 +921,7 @@ void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
|
||||
|
||||
es = __es_tree_search(&EXT4_I(inode)->i_es_tree.root, lblk);
|
||||
if (!es || es->es_lblk > end)
|
||||
__es_insert_extent(inode, &newes);
|
||||
__es_insert_extent(inode, &newes, NULL);
|
||||
write_unlock(&EXT4_I(inode)->i_es_lock);
|
||||
}
|
||||
|
||||
@ -1362,7 +1367,7 @@ retry:
|
||||
orig_es.es_len - len2;
|
||||
ext4_es_store_pblock_status(&newes, block,
|
||||
ext4_es_status(&orig_es));
|
||||
err = __es_insert_extent(inode, &newes);
|
||||
err = __es_insert_extent(inode, &newes, NULL);
|
||||
if (err) {
|
||||
es->es_lblk = orig_es.es_lblk;
|
||||
es->es_len = orig_es.es_len;
|
||||
@ -2016,7 +2021,7 @@ int ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk,
|
||||
if (err != 0)
|
||||
goto error;
|
||||
retry:
|
||||
err = __es_insert_extent(inode, &newes);
|
||||
err = __es_insert_extent(inode, &newes, NULL);
|
||||
if (err == -ENOMEM && __es_shrink(EXT4_SB(inode->i_sb),
|
||||
128, EXT4_I(inode)))
|
||||
goto retry;
|
||||
|
Loading…
Reference in New Issue
Block a user