btrfs: separate out the extent state and extent buffer init code

In order to help separate the extent buffer from the extent io tree code
we need to break up the init functions.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2022-09-09 17:53:18 -04:00 committed by David Sterba
parent cdca85b092
commit a62a3bd954
4 changed files with 31 additions and 14 deletions

View File

@ -108,8 +108,8 @@ static inline int lock_extent(struct extent_io_tree *tree, u64 start, u64 end)
int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end);
int __init extent_io_init(void);
void __cold extent_io_exit(void);
int __init extent_state_init_cachep(void);
void __cold extent_state_free_cachep(void);
u64 count_range_bits(struct extent_io_tree *tree,
u64 *start, u64 search_end,

View File

@ -230,7 +230,7 @@ static void submit_write_bio(struct extent_page_data *epd, int ret)
}
}
int __init extent_io_init(void)
int __init extent_state_init_cachep(void)
{
extent_state_cache = kmem_cache_create("btrfs_extent_state",
sizeof(struct extent_state), 0,
@ -238,18 +238,27 @@ int __init extent_io_init(void)
if (!extent_state_cache)
return -ENOMEM;
return 0;
}
int __init extent_buffer_init_cachep(void)
{
extent_buffer_cache = kmem_cache_create("btrfs_extent_buffer",
sizeof(struct extent_buffer), 0,
SLAB_MEM_SPREAD, NULL);
if (!extent_buffer_cache) {
kmem_cache_destroy(extent_state_cache);
if (!extent_buffer_cache)
return -ENOMEM;
}
return 0;
}
void __cold extent_io_exit(void)
void __cold extent_state_free_cachep(void)
{
btrfs_extent_state_leak_debug_check();
kmem_cache_destroy(extent_state_cache);
}
void __cold extent_buffer_free_cachep(void)
{
/*
* Make sure all delayed rcu free are flushed before we
@ -257,8 +266,6 @@ void __cold extent_io_exit(void)
*/
rcu_barrier();
kmem_cache_destroy(extent_buffer_cache);
btrfs_extent_state_leak_debug_check();
kmem_cache_destroy(extent_state_cache);
}
/*

View File

@ -64,6 +64,9 @@ struct btrfs_fs_info;
struct io_failure_record;
struct extent_io_tree;
int __init extent_buffer_init_cachep(void);
void __cold extent_buffer_free_cachep(void);
typedef void (submit_bio_hook_t)(struct inode *inode, struct bio *bio,
int mirror_num,
enum btrfs_compression_type compress_type);

View File

@ -2736,13 +2736,17 @@ static int __init init_btrfs_fs(void)
if (err)
goto free_compress;
err = extent_io_init();
err = extent_state_init_cachep();
if (err)
goto free_cachep;
err = extent_buffer_init_cachep();
if (err)
goto free_extent_cachep;
err = btrfs_bioset_init();
if (err)
goto free_extent_io;
goto free_eb_cachep;
err = extent_map_init();
if (err)
@ -2800,8 +2804,10 @@ free_extent_map:
extent_map_exit();
free_bioset:
btrfs_bioset_exit();
free_extent_io:
extent_io_exit();
free_eb_cachep:
extent_buffer_free_cachep();
free_extent_cachep:
extent_state_free_cachep();
free_cachep:
btrfs_destroy_cachep();
free_compress:
@ -2821,7 +2827,8 @@ static void __exit exit_btrfs_fs(void)
ordered_data_exit();
extent_map_exit();
btrfs_bioset_exit();
extent_io_exit();
extent_state_free_cachep();
extent_buffer_free_cachep();
btrfs_interface_exit();
unregister_filesystem(&btrfs_fs_type);
btrfs_exit_sysfs();