Message ID | 129622d0259e8e3209d4c9f9fe9a44e58a011b93.1603460665.git.josef@toxicpanda.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Block group caching fixes | expand |
On Fri, Oct 23, 2020 at 5:12 PM Josef Bacik <josef@toxicpanda.com> wrote: > > Currently unpin_extent_range happens in the transaction commit context, > so we are protected from ->last_byte_to_unpin changing while we're > unpinning, because any new transactions would have to wait for us to > complete before modifying ->last_byte_to_unpin. > > However in the future we may want to change how this works, for instance > with async unpinning or other such TODO items. To prepare for that > future explicitly protect ->last_byte_to_unpin with the commit_root_sem > so we are sure it won't change while we're doing our work. > > Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Ok, looks good, thanks. > --- > fs/btrfs/extent-tree.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index ee7bceace8b3..5d3564b077bf 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -2791,11 +2791,13 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info, > len = cache->start + cache->length - start; > len = min(len, end + 1 - start); > > + down_read(&fs_info->commit_root_sem); > if (start < cache->last_byte_to_unpin && return_free_space) { > u64 add_len = min(len, > cache->last_byte_to_unpin - start); > btrfs_add_free_space(cache, start, add_len); > } > + up_read(&fs_info->commit_root_sem); > > start += len; > total_unpinned += len; > -- > 2.26.2 >
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index ee7bceace8b3..5d3564b077bf 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2791,11 +2791,13 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info, len = cache->start + cache->length - start; len = min(len, end + 1 - start); + down_read(&fs_info->commit_root_sem); if (start < cache->last_byte_to_unpin && return_free_space) { u64 add_len = min(len, cache->last_byte_to_unpin - start); btrfs_add_free_space(cache, start, add_len); } + up_read(&fs_info->commit_root_sem); start += len; total_unpinned += len;
Currently unpin_extent_range happens in the transaction commit context, so we are protected from ->last_byte_to_unpin changing while we're unpinning, because any new transactions would have to wait for us to complete before modifying ->last_byte_to_unpin. However in the future we may want to change how this works, for instance with async unpinning or other such TODO items. To prepare for that future explicitly protect ->last_byte_to_unpin with the commit_root_sem so we are sure it won't change while we're doing our work. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/btrfs/extent-tree.c | 2 ++ 1 file changed, 2 insertions(+)