[PATCH RFC 0/7]
Subsystems (2)
cover [PATCH RFC 0/7]
This patchset can be fetched from github:
https://github.com/adam900710/btrfs-progs/tree/skinny_bg_tree
Which is based on david/devel branch.
HEAD is:bdb42fb63382e8aca6bd02fd04a28e415408d4ea (david/devel) btrfs-progs: tests: Test backup root retention logic
This patchset provides the needed user space infrastructure for SKINNY_BG_TREE feature.
Since it's an new incompatible feature, unlike SKINNY_METADATA, btrfs-progs is needed to convert existing fs (unmounted) to new format.
Or determined at mkfs time.
For the performance improvement, please check the kernel patchset cover letter or the last patch.
(SPOILER ALERT: It's super-duper fast, even faster than regular bg tree)
The chanllege here is, even we have some patches merged into devel branch, due to the change of definition of key->offset for block group item, we have to refactor more functions to implement SKINNY_BG_TREE.
Qu Wenruo (7):
btrfs-progs: check/lowmem: Lookup block group item in a seperate
function
btrfs-progs: Enable read-write ability for 'skinny_bg_tree' feature
btrfs-progs: mkfs: Introduce -O skinny-bg-tree
btrfs-progs: dump-tree/dump-super: Introduce support for skinny bg
tree
btrfs-progs: Refactor btrfs_new_block_group_record() to accept
parameters directly
btrfs-progs: check: Introduce support for bg-tree feature
btrfs-progs: btrfstune: Allow to enable bg-tree feature offline
Documentation/btrfstune.asciidoc | 6 + btrfsck.h | 4 +- btrfstune.c | 45 +++++- check/common.h | 4 +- check/main.c | 63 ++++++-- check/mode-lowmem.c | 137 ++++++++++++---- cmds/inspect-dump-super.c | 3 +- cmds/inspect-dump-tree.c | 5 + cmds/rescue-chunk-recover.c | 6 +- common/fsfeatures.c | 6 + ctree.h | 18 ++- disk-io.c | 21 ++- extent-tree.c | 269 +++++++++++++++++++++++++++++-- mkfs/common.c | 5 +- mkfs/main.c | 25 +++ print-tree.c | 4 + transaction.c | 1 + 17 files changed, 549 insertions(+), 73 deletions(-)
Signature · 1 line
2.23.0
RFC PATCH 1/7 btrfs-progs: check/lowmem: Lookup block group item in a seperate function
In check_chunk_item() we search extent tree for block group item.
Refactor this part into a separate function, find_block_group_item(), so that later skinny-bg-tree feature can reuse it.
--- check/mode-lowmem.c | 74 ++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 27 deletions(-)
check/mode-lowmem.c +47 -27
@@ -4472,6 +4472,50 @@ next:return 0 ; } +/* +* Find the block group item with @bytenr, @len and @type +* +* Return 0 if found. +* Return -ENOENT if not found. +* Return <0 for fatal error. +*/ +static int find_block_group_item (struct btrfs_fs_info *fs_info, +struct btrfs_path *path,u64 bytenr,u64 len, +u64 type) +{ +struct btrfs_block_group_item bgi; +struct btrfs_key key; +int ret; + + key.objectid = bytenr; + key.type =BTRFS_BLOCK_GROUP_ITEM_KEY ; + key.offset = len; + + ret =btrfs_search_slot (NULL , fs_info->extent_root, &key, path,0 ,0 ); +if (ret <0 ) +return ret; +if (ret >0 ) { + ret = -ENOENT ; +error ("chunk [%llu %llu) doesn't have related block group item" , + bytenr, bytenr + len); + goto out; + } +read_extent_buffer (path->nodes[0 ], &bgi, +btrfs_item_ptr_offset (path->nodes[0 ], path->slots[0 ]), +sizeof (bgi)); +if (btrfs_block_group_flags (&bgi) != type) { +error ( +"chunk [%llu %llu) type mismatch with block group, block group has 0x%llx chunk has %llx" , + bytenr, bytenr + len,btrfs_block_group_flags (&bgi), + type); + ret = -EUCLEAN ; + } + +out: +btrfs_release_path (path); +return ret; +} +/* * Check a chunk item. * Including checking all referred dev_extents and block group
@@ -4479,16 +4523,12 @@ next:static int check_chunk_item (struct btrfs_fs_info *fs_info,struct extent_buffer *eb,int slot) { -struct btrfs_root *extent_root = fs_info->extent_root;struct btrfs_root *dev_root = fs_info->dev_root;struct btrfs_path path;struct btrfs_key chunk_key; -struct btrfs_key bg_key;struct btrfs_key devext_key;struct btrfs_chunk *chunk;struct extent_buffer *leaf; -struct btrfs_block_group_item *bi; -struct btrfs_block_group_item bg_item;struct btrfs_dev_extent *ptr;u64 length;u64 chunk_end;
@@ -4515,31 +4555,11 @@ static int check_chunk_item(struct btrfs_fs_info *fs_info, } type =btrfs_chunk_type (eb, chunk); - bg_key.objectid = chunk_key.offset; - bg_key.type =BTRFS_BLOCK_GROUP_ITEM_KEY ; - bg_key.offset = length; -btrfs_init_path (&path); - ret =btrfs_search_slot (NULL , extent_root, &bg_key, &path,0 ,0 ); -if (ret) { -error ( -"chunk[%llu %llu) did not find the related block group item" , - chunk_key.offset, chunk_end); + ret =find_block_group_item (fs_info, &path, chunk_key.offset, length, + type); +if (ret <0 ) err |=REFERENCER_MISSING ; - }else { - leaf = path.nodes[0 ]; - bi =btrfs_item_ptr (leaf, path.slots[0 ], - struct btrfs_block_group_item); -read_extent_buffer (leaf, &bg_item, (unsigned long )bi, -sizeof (bg_item)); -if (btrfs_block_group_flags (&bg_item) != type) { -error ( -"chunk[%llu %llu) related block group item flags mismatch, wanted: %llu, have: %llu" , - chunk_key.offset, chunk_end, type, -btrfs_block_group_flags (&bg_item)); - err |=REFERENCER_MISSING ; - } - } num_stripes =btrfs_chunk_num_stripes (eb, chunk); stripe_len =btrfs_stripe_length (fs_info, eb, chunk);
Signature · 1 line
2.23.0
RFC PATCH 2/7 btrfs-progs: Enable read-write ability for 'skinny_bg_tree' feature
In reply to Qu WenruoAllow btrfs-progs to open, read and write 'skinny_bg_tree' enabled fs.
The modification itself is not large, as block groups items are only used at 4 timing:
1) open_ctree()
We only need to populate fs_info->bg_root and read block group items from fs_info->bg_root.
The obvious change is, we don't need to do btrfs_search_slot() for each block group item, but btrfs_next_item() is enough.
This should hugely reduce open_ctree() execution duration.
2) btrfs_commit_transaction()
We need to write back dirty block group items back to bg_root.
The modification here is to insert new block group item if we can't find one existing in bg_root, and delete the old one in extent tree if we're converting to skinny_bg_tree feature.
3) btrfs_make_block_group()
For skinny_bg_tree feature, we insert key only, with key.offset == used.
This modification needs extra handling for converting case, where block group items can be either in extent tree or bg tree.
4) free_block_group_item()
Just delete the block group item in extent tree or bg tree.
--- ctree.h | 17 +++- disk-io.c | 21 ++++- extent-tree.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 251 insertions(+), 17 deletions(-)
ctree.h +16 -1
@@ -89,6 +89,9 @@ struct btrfs_free_space_ctl;/* tracks free space in block groups. */ #define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL +/* store BLOCK_GROUP_ITEMS in a seperate tree */ +#define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL +/* device stats in the device tree */ #define BTRFS_DEV_STATS_OBJECTID 0ULL
@@ -492,6 +495,7 @@ struct btrfs_super_block {#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)#define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10) +#define BTRFS_FEATURE_INCOMPAT_SKINNY_BG_TREE (1ULL << 11)#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
@@ -515,7 +519,8 @@ struct btrfs_super_block {BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \BTRFS_FEATURE_INCOMPAT_NO_HOLES | \ - BTRFS_FEATURE_INCOMPAT_METADATA_UUID) +BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \ + BTRFS_FEATURE_INCOMPAT_SKINNY_BG_TREE)/* * A leaf is full of items. offset and size tell us where to find
@@ -1125,6 +1130,7 @@ struct btrfs_fs_info {struct btrfs_root *quota_root;struct btrfs_root *free_space_root;struct btrfs_root *uuid_root; +struct btrfs_root *bg_root;struct rb_root fs_root_tree;
@@ -1176,6 +1182,8 @@ struct btrfs_fs_info { unsigned int avoid_meta_chunk_alloc:1; unsigned int avoid_sys_chunk_alloc:1; unsigned int finalize_on_close:1; +/* Converting from bg in extent tree to skinny bg tree */ + unsigned int convert_to_bg_tree:1;int transaction_aborted;
@@ -1332,6 +1340,13 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)*/ #define BTRFS_BLOCK_GROUP_ITEM_KEY 192 +/* +* More optimized block group item, use key.objectid for block group bytenr, +* key.offset for used bytes. +* No item data needed. +*/ +#define BTRFS_SKINNY_BLOCK_GROUP_ITEM_KEY 193 +/* * Every block group is represented in the free space tree by a free space info * item, which stores some accounting information. It is keyed on
disk-io.c +20 -1
@@ -731,6 +731,8 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,if (location->objectid ==BTRFS_FREE_SPACE_TREE_OBJECTID )return fs_info->free_space_root ? fs_info->free_space_root :ERR_PTR (-ENOENT ); +if (location->objectid ==BTRFS_BLOCK_GROUP_TREE_OBJECTID ) +return fs_info->bg_root ? fs_info->bg_root :ERR_PTR (-ENOENT );BUG_ON (location->objectid ==BTRFS_TREE_RELOC_OBJECTID || location->offset != (u64)-1 );
@@ -783,6 +785,7 @@ struct btrfs_fs_info *btrfs_new_fs_info(int writable, u64 sb_bytenr) fs_info->quota_root =calloc (1 ,sizeof (struct btrfs_root )); fs_info->free_space_root =calloc (1 ,sizeof (struct btrfs_root )); fs_info->uuid_root =calloc (1 ,sizeof (struct btrfs_root )); + fs_info->bg_root =calloc (1 ,sizeof (struct btrfs_root )); fs_info->super_copy =calloc (1 ,BTRFS_SUPER_INFO_SIZE ); if (!fs_info->tree_root || !fs_info->extent_root ||
@@ -932,7 +935,6 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, root_tree_bytenr =btrfs_backup_tree_root (backup); generation =btrfs_backup_tree_root_gen (backup); } - root->node =read_tree_block (fs_info, root_tree_bytenr, generation);if (!extent_buffer_uptodate (root->node)) {fprintf (stderr,"Couldn't read tree root\n" );
@@ -945,6 +947,21 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,return ret; fs_info->extent_root->track_dirty =1 ; +if (btrfs_fs_incompat (fs_info,SKINNY_BG_TREE )) { + ret =setup_root_or_create_block (fs_info, flags, + fs_info->bg_root, +BTRFS_BLOCK_GROUP_TREE_OBJECTID ,"bg" ); +if (ret <0 ) { +error ("Couldn't setup bg tree" ); +return ret; + } + fs_info->bg_root->track_dirty =1 ; + fs_info->bg_root->ref_cows =0 ; + }else { +free (fs_info->bg_root); + fs_info->bg_root =NULL ; + } + ret =find_and_setup_root (root, fs_info,BTRFS_DEV_TREE_OBJECTID , fs_info->dev_root);if (ret) {
@@ -1035,6 +1052,8 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info)free_extent_buffer (fs_info->extent_root->node);if (fs_info->tree_root)free_extent_buffer (fs_info->tree_root->node); +if (fs_info->bg_root) +free_extent_buffer (fs_info->bg_root->node);if (fs_info->log_root_tree)free_extent_buffer (fs_info->log_root_tree->node);if (fs_info->chunk_root)
extent-tree.c +215 -15
306 lines not on this page · raw message
Signature · 1 line
2.23.0
RFC PATCH 3/7 btrfs-progs: mkfs: Introduce -O skinny-bg-tree
In reply to Qu WenruoThis allow mkfs.btrfs to create a btrfs with skinny-bg-tree feature.
This patch introduce a global function, btrfs_convert_to_bg_tree() in extent-tree.c, to do the work.
The workflow is pretty simple:
- Create a new tree block for bg tree
- Set the SKINNY_BG_TREE feature for superblock
- Set the fs_info->convert_to_bg_tree flag
- Mark all block group items as dirty
- Commit transaction
* With fs_info->convert_to_skinny_bg_tree set, we will try to delete the BLOCK_GROUP_ITEM in extent tree first, then write the new BLOCK_GROUP_ITEM into bg tree.
This btrfs_convert_to_skinny_bg_tree() will be used in mkfs after the basic fs is created.
--- common/fsfeatures.c | 6 ++++++ ctree.h | 1 + extent-tree.c | 39 +++++++++++++++++++++++++++++++++++++++ mkfs/common.c | 5 ++++- mkfs/main.c | 25 +++++++++++++++++++++++++ transaction.c | 1 + 6 files changed, 76 insertions(+), 1 deletion(-)
common/fsfeatures.c +6 -0
@@ -86,6 +86,12 @@ static const struct btrfs_fs_feature { VERSION_TO_STRING2(4,0), NULL, 0, "no explicit hole extents for files" }, + {"skinny-bg-tree" ,BTRFS_FEATURE_INCOMPAT_SKINNY_BG_TREE , +"skinny_bg_tree" , +VERSION_TO_STRING2 (5 ,6 ), +NULL ,0 , +NULL ,0 , + "store optimized block group items in dedicated tree" },/* Keep this one last */ { "list-all", BTRFS_FEATURE_LIST_ALL, NULL } };
ctree.h +1 -0
@@ -2862,5 +2862,6 @@ int btrfs_read_file(struct btrfs_root *root, u64 ino, u64 start, int len,/* extent-tree.c */ int btrfs_run_delayed_refs (struct btrfs_trans_handle *trans,unsigned long nr); +int btrfs_convert_to_skinny_bg_tree (struct btrfs_trans_handle *trans);#endif
extent-tree.c +39 -0
@@ -1524,6 +1524,45 @@ int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,return __btrfs_mod_ref (trans, root, buf, record_parent,0 ); } +int btrfs_convert_to_skinny_bg_tree (struct btrfs_trans_handle *trans) +{ +struct btrfs_fs_info *fs_info = trans->fs_info; +struct btrfs_block_group_cache *bg; +struct btrfs_root *bg_root; +u64 features =btrfs_super_incompat_flags (fs_info->super_copy); +int ret; + +/* create bg tree first */ + bg_root =btrfs_create_tree (trans, fs_info,BTRFS_BLOCK_GROUP_TREE_OBJECTID ); +if (IS_ERR (bg_root)) { + ret =PTR_ERR (bg_root); + errno = -ret; +error ("failed to create bg tree: %m" ); +return ret; + } + fs_info->bg_root = bg_root; + fs_info->bg_root->track_dirty =1 ; + fs_info->bg_root->ref_cows =0 ; +add_root_to_dirty_list (bg_root); + +/* set BG_TREE feature and mark the fs into bg_tree convert status */ +btrfs_set_super_incompat_flags (fs_info->super_copy, + features |BTRFS_FEATURE_INCOMPAT_SKINNY_BG_TREE ); + fs_info->convert_to_bg_tree =1 ; + +/* +* Mark all block groups dirty so they will get converted to bg tree at +* commit transaction time +*/ +for (bg =btrfs_lookup_first_block_group (fs_info,0 ); bg; + bg =btrfs_lookup_first_block_group (fs_info, + bg->key.objectid + bg->key.offset)) +set_extent_bits (&fs_info->block_group_cache, bg->key.objectid, + bg->key.objectid + bg->key.offset -1 , +BLOCK_GROUP_DIRTY ); +return 0 ; +} +static int write_one_skinny_block_group (struct btrfs_trans_handle *trans,struct btrfs_path *path,struct btrfs_block_group_cache *cache)
mkfs/common.c +4 -1
@@ -112,6 +112,9 @@ static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg,return ret; } +/* These features will not be set in the temporary fs */ +#define MASKED_FEATURES (~(BTRFS_FEATURE_INCOMPAT_SKINNY_BG_TREE)) +/* * @fs_uuid - if NULL, generates a UUID, returns back the new filesystem UUID *
@@ -205,7 +208,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)btrfs_set_super_csum_type (&super, cfg->csum_type);btrfs_set_super_chunk_root_generation (&super,1 );btrfs_set_super_cache_generation (&super,-1 ); -btrfs_set_super_incompat_flags (&super, cfg->features); +btrfs_set_super_incompat_flags (&super, cfg->features &MASKED_FEATURES );if (cfg->label)__strncpy_null (super.label, cfg->label,BTRFS_LABEL_SIZE -1 );
mkfs/main.c +25 -0
@@ -1344,6 +1344,31 @@ raid_groups: goto out; } +/* +* Bg tree are converted after temp chunks cleaned up, or we can +* populate temp chunks. +*/ +if (mkfs_cfg.features &BTRFS_FEATURE_INCOMPAT_SKINNY_BG_TREE ) { + trans =btrfs_start_transaction (fs_info->tree_root,1 ); +if (IS_ERR (trans)) { +error ("failed to start transaction: %d" , ret); + goto out; + } + ret =btrfs_convert_to_skinny_bg_tree (trans); +if (ret <0 ) { + errno = -ret; +error ( +"bg-tree feature will not be enabled, due to error: %m" ); +btrfs_abort_transaction (trans, ret); + goto out; + } + ret =btrfs_commit_transaction (trans, fs_info->tree_root); +if (ret <0 ) { +error ("failed to commit transaction: %d" , ret); + goto out; + } + } +if (source_dir_set) { ret =btrfs_mkfs_fill_dir (source_dir, root, verbose);if (ret) {
transaction.c +1 -0
@@ -225,6 +225,7 @@ commit_tree: root->commit_root =NULL ; fs_info->running_transaction =NULL ; fs_info->last_trans_committed = transid; + fs_info->convert_to_bg_tree =0 ;list_for_each_entry (sinfo, &fs_info->space_info, list) {if (sinfo->bytes_reserved) { warning(
Signature · 1 line
2.23.0
RFC PATCH 4/7 btrfs-progs: dump-tree/dump-super: Introduce support for skinny bg tree
In reply to Qu WenruoJust a new tree called BLOCK_GROUP_TREE.
The new type (SKINNY_BLOCK_GROUP_ITEM) doesn't has any item, thus no need to add any extra output.
--- cmds/inspect-dump-super.c | 3 ++- cmds/inspect-dump-tree.c | 5 +++++ print-tree.c | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-)
cmds/inspect-dump-super.c +2 -1
@@ -227,7 +227,8 @@ static struct readable_flag_entry incompat_flags_array[] = {DEF_INCOMPAT_FLAG_ENTRY (RAID56 ),DEF_INCOMPAT_FLAG_ENTRY (SKINNY_METADATA ),DEF_INCOMPAT_FLAG_ENTRY (NO_HOLES ), - DEF_INCOMPAT_FLAG_ENTRY(METADATA_UUID) +DEF_INCOMPAT_FLAG_ENTRY (METADATA_UUID ), + DEF_INCOMPAT_FLAG_ENTRY(SKINNY_BG_TREE) };static const int incompat_flags_num =sizeof (incompat_flags_array) /sizeof (struct readable_flag_entry );
cmds/inspect-dump-tree.c +5 -0
@@ -152,6 +152,7 @@ static u64 treeid_from_string(const char *str, const char **end) { "QUOTA", BTRFS_QUOTA_TREE_OBJECTID }, { "UUID", BTRFS_UUID_TREE_OBJECTID }, { "FREE_SPACE", BTRFS_FREE_SPACE_TREE_OBJECTID }, + { "BG", BTRFS_BLOCK_GROUP_TREE_OBJECTID}, { "TREE_LOG_FIXUP", BTRFS_TREE_LOG_FIXUP_OBJECTID }, { "TREE_LOG", BTRFS_TREE_LOG_OBJECTID }, { "TREE_RELOC", BTRFS_TREE_RELOC_OBJECTID },
@@ -663,6 +664,10 @@ again:if (!skip)printf ("free space" );break ; +case BTRFS_BLOCK_GROUP_TREE_OBJECTID : +if (!skip) +printf ("block group" ); +break ;case BTRFS_MULTIPLE_OBJECTIDS :if (!skip) {printf ("multiple" );
print-tree.c +4 -0
@@ -656,6 +656,7 @@ void print_key_type(FILE *stream, u64 objectid, u8 type) [BTRFS_EXTENT_CSUM_KEY] = "EXTENT_CSUM", [BTRFS_EXTENT_DATA_KEY] = "EXTENT_DATA", [BTRFS_BLOCK_GROUP_ITEM_KEY] = "BLOCK_GROUP_ITEM", + [BTRFS_SKINNY_BLOCK_GROUP_ITEM_KEY] = "SKINNY_BLOCK_GROUP_ITEM", [BTRFS_FREE_SPACE_INFO_KEY] = "FREE_SPACE_INFO", [BTRFS_FREE_SPACE_EXTENT_KEY] = "FREE_SPACE_EXTENT", [BTRFS_FREE_SPACE_BITMAP_KEY] = "FREE_SPACE_BITMAP",
@@ -775,6 +776,9 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)case BTRFS_FREE_SPACE_TREE_OBJECTID :fprintf (stream,"FREE_SPACE_TREE" );break ; +case BTRFS_BLOCK_GROUP_TREE_OBJECTID : +fprintf (stream,"BLOCK_GROUP_TREE" ); +break ;case BTRFS_MULTIPLE_OBJECTIDS :fprintf (stream,"MULTIPLE" );break ;
Signature · 1 line
2.23.0
RFC PATCH 5/7 btrfs-progs: Refactor btrfs_new_block_group_record() to accept parameters directly
In reply to Qu WenruoCurrently btrfs_new_block_group_record() needs to extract numbers from key and block group item manually.
This is not generic enough to handle skinny-bg-tree feature. So change let btrfs_new_block_group_record() to accept @bytenr, @len and @flags directly, so later skinny-bg-tree feature can reuse it in original mode.
--- btrfsck.h | 4 ++-- check/common.h | 4 ++-- check/main.c | 25 +++++++++++++------------ cmds/rescue-chunk-recover.c | 6 +++++- 4 files changed, 22 insertions(+), 17 deletions(-)
btrfsck.h +2 -2
@@ -189,8 +189,8 @@ struct chunk_record *btrfs_new_chunk_record(struct extent_buffer *leaf,struct btrfs_key *key, int slot);struct block_group_record * -btrfs_new_block_group_record (struct extent_buffer *leaf,struct btrfs_key *key, -int slot); +btrfs_new_block_group_record (struct extent_buffer *leaf,u64 bytenr,u64 len, +u64 flags);struct device_extent_record *btrfs_new_device_extent_record (struct extent_buffer *leaf,struct btrfs_key *key,int slot);
check/common.h +2 -2
@@ -166,8 +166,8 @@ struct chunk_record *btrfs_new_chunk_record(struct extent_buffer *leaf,struct btrfs_key *key, int slot);struct block_group_record * -btrfs_new_block_group_record (struct extent_buffer *leaf,struct btrfs_key *key, -int slot); +btrfs_new_block_group_record (struct extent_buffer *leaf,u64 bytenr,u64 len, +u64 flags);struct device_extent_record *btrfs_new_device_extent_record (struct extent_buffer *leaf,struct btrfs_key *key,int slot);
check/main.c +13 -12
@@ -5193,10 +5193,9 @@ static int process_device_item(struct rb_root *dev_cache, }struct block_group_record * -btrfs_new_block_group_record (struct extent_buffer *leaf,struct btrfs_key *key, -int slot) +btrfs_new_block_group_record (struct extent_buffer *leaf,u64 bytenr,u64 len, +u64 flags) { -struct btrfs_block_group_item *ptr;struct block_group_record *rec; rec =calloc (1 ,sizeof (*rec));
@@ -5205,17 +5204,15 @@ btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,exit (-1 ); } - rec->cache.start = key->objectid; - rec->cache.size = key->offset; + rec->cache.start = bytenr; + rec->cache.size = len; rec->generation =btrfs_header_generation (leaf); - rec->objectid = key->objectid; - rec->type = key->type; - rec->offset = key->offset; - - ptr = btrfs_item_ptr(leaf, slot, struct btrfs_block_group_item); - rec->flags =btrfs_disk_block_group_flags (leaf, ptr); + rec->objectid = bytenr; + rec->type =BTRFS_BLOCK_GROUP_ITEM_KEY ; + rec->offset = len; + rec->flags = flags;INIT_LIST_HEAD (&rec->list);
@@ -5226,10 +5223,14 @@ static int process_block_group_item(struct block_group_tree *block_group_cache,struct btrfs_key *key, struct extent_buffer *eb, int slot) { + struct btrfs_block_group_item bgi;struct block_group_record *rec;int ret =0 ; - rec =btrfs_new_block_group_record (eb, key, slot); +read_extent_buffer (eb, &bgi,btrfs_item_ptr_offset (eb, slot), +sizeof (bgi)); + rec =btrfs_new_block_group_record (eb, key->objectid, key->offset, +btrfs_block_group_flags (&bgi)); ret =insert_block_group_record (block_group_cache, rec);if (ret) { fprintf(stderr, "Block Group[%llu, %llu] existed.\n",
cmds/rescue-chunk-recover.c +5 -1
@@ -226,12 +226,16 @@ static int process_block_group_item(struct block_group_tree *bg_cache,struct extent_buffer *leaf, struct btrfs_key *key, int slot) { + struct btrfs_block_group_item bgi;struct block_group_record *rec;struct block_group_record *exist;struct cache_extent *cache;int ret =0 ; - rec =btrfs_new_block_group_record (leaf, key, slot); +read_extent_buffer (leaf, &bgi,btrfs_item_ptr_offset (leaf, slot), +sizeof (bgi)); + rec =btrfs_new_block_group_record (leaf, key->objectid, key->offset, +btrfs_block_group_flags (&bgi));if (!rec->cache.size) goto free_out; again:
Signature · 1 line
2.23.0
RFC PATCH 6/7 btrfs-progs: check: Introduce support for bg-tree feature
In reply to Qu WenruoJust some minor modification.
- original mode:
* skinny block group item can only occur in bg tree
* check skinny block group item
Introduce a new function, process_skinny_bgi(), for this check.
- lowmem mode:
* search skinny block group items in bg tree if SKINNY_BG_TREE feature is set.
* check skinny block group item
This is done by reusing check_block_group_item().
--- check/main.c | 38 +++++++++++++++++++++++++++ check/mode-lowmem.c | 63 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 93 insertions(+), 8 deletions(-)
check/main.c +38 -0
@@ -5241,6 +5241,32 @@ static int process_block_group_item(struct block_group_tree *block_group_cache,return ret; } +static int process_skinny_bgi (struct block_group_tree *block_group_cache, +struct btrfs_key *key,struct extent_buffer *eb) +{ +struct btrfs_mapping_tree *map_tree = &global_info->mapping_tree; +struct block_group_record *rec; +struct cache_extent *ce; +struct map_lookup *map; +int ret; + + ce =search_cache_extent (&map_tree->cache_tree, key->objectid); +/* For mismatch case, we just skip this bgi */ +if (ce->start != key->objectid) +return 0 ; + + map = container_of(ce, struct map_lookup, ce); + rec =btrfs_new_block_group_record (eb, key->objectid, ce->size, + map->type); + ret =insert_block_group_record (block_group_cache, rec); +if (ret) { +error ("block group [%llu, %llu) existed." , + ce->start, ce->start + ce->size); +free (rec); + } +return ret; +} +struct device_extent_record *btrfs_new_device_extent_record (struct extent_buffer *leaf,struct btrfs_key *key,int slot)
@@ -6106,6 +6132,10 @@ static int check_type_with_root(u64 rootid, u8 key_type)if (rootid !=BTRFS_EXTENT_TREE_OBJECTID ) goto err;break ; +case BTRFS_SKINNY_BLOCK_GROUP_ITEM_KEY : +if (rootid !=BTRFS_BLOCK_GROUP_TREE_OBJECTID ) + goto err; +break ;case BTRFS_ROOT_ITEM_KEY :if (rootid !=BTRFS_ROOT_TREE_OBJECTID ) goto err;
@@ -6309,6 +6339,14 @@ static int run_next_block(struct btrfs_root *root, &key, buf, i);continue ; } +if (key.type ==BTRFS_SKINNY_BLOCK_GROUP_ITEM_KEY ) { + ret =process_skinny_bgi (block_group_cache, + &key, buf); +/* -ENOMEM */ +if (ret <0 ) + goto out; +continue ; + }if (key.type ==BTRFS_DEV_EXTENT_KEY ) {process_device_extent_item (dev_extent_cache, &key, buf, i);
check/mode-lowmem.c +55 -8
107 lines not on this page · raw message
Signature · 1 line
2.23.0
RFC PATCH 7/7 btrfs-progs: btrfstune: Allow to enable bg-tree feature offline
In reply to Qu WenruoAdd a new option '-b' for btrfstune, to enable bg-tree feature for a unmounted fs.
This feature will convert all BLOCK_GROUP_ITEMs in extent tree to bg tree, by reusing the existing btrfs_convert_to_bg_tree() function.
--- Documentation/btrfstune.asciidoc | 6 +++++ btrfstune.c | 45 ++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-)
Documentation/btrfstune.asciidoc +6 -0
@@ -26,6 +26,12 @@ means. Please refer to the 'FILESYSTEM FEATURES' in `btrfs`(5). OPTIONS ------- +-b:: +(since kernel: 5.x) ++ +enable skinny-bg-tree feature (faster mount time for large fs), enabled by mkfs +feature 'skinny-bg-tree'. + -f:: Allow dangerous changes, e.g. clear the seeding flag or change fsid. Make sure that you are aware of the dangers.
btrfstune.c +43 -2
86 lines not on this page · raw message
Signature · 1 line
2.23.0