Re: [PATCH v2 3/3] btrfs: fix check_chunk_block_group_mappings() to actually iterate all chunks
From: ZhengYuan Huang
Date: Mon Mar 23 2026 - 23:01:06 EST
On Tue, Mar 24, 2026 at 1:52 AM David Sterba <dsterba@xxxxxxx> wrote:
> This is called during mount indirectly from open_ctree() and this is
> single threaded (partially), so the lock may not be needed. It would be
> needed if there's eg. caching thread possibly accessing the same
> structures, I haven't looked closely.
>
> > + for (node = rb_first_cached(&fs_info->mapping_tree); node;
> > + node = rb_next(node)) {
> > struct btrfs_chunk_map *map;
> > struct btrfs_block_group *bg;
> >
> > - /*
> > - * btrfs_find_chunk_map() will return the first chunk map
> > - * intersecting the range, so setting @length to 1 is enough to
> > - * get the first chunk.
> > - */
> > - map = btrfs_find_chunk_map(fs_info, start, 1);
> > - if (!map)
> > - break;
> > -
> > + map = rb_entry(node, struct btrfs_chunk_map, rb_node);
> > bg = btrfs_lookup_block_group(fs_info, map->start);
>
> What concerns me is this lookup. Previously the references avoided
> taking the big lock. The time the lock is held may add up significanly
> for all block groups but as said before it might not be necessary due to
> the mount context.
Thanks for the suggestion, I’ll take a closer look at the locking here.
If the lock turns out to be unnecessary in this context, I’ll drop it
and include the change in v3.
Thanks,
ZhengYuan Huang