Message ID | 20190619141249.23001-1-rgoldwyn@suse.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: Simplify update space_info in __reserve_metadata_bytes() | expand |
On 19.06.19 г. 17:12 ч., Goldwyn Rodrigues wrote: > From: Goldwyn Rodrigues <rgoldwyn@suse.com> > > Simplification. > We don't need an if-else-if structure where we can use a > simple OR since both conditions are performing the > same action. The short-circuit for OR will ensure that if > the first condition is true, can_overcommit() is not > called. > > Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> > --- > fs/btrfs/extent-tree.c | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index c7adff343ba9..84a33cbb1e68 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -5158,17 +5158,13 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info, > used = btrfs_space_info_used(space_info, true); > > /* > - * If we have enough space then hooray, make our reservation and carry > - * on. If not see if we can overcommit, and if we can, hooray carry on. > + * Carry on if we have enough space (short-circuit) OR call > + * can_overcommit() to ensure we can overcommit to carry on. > * If not things get more complicated. > */ > - if (used + orig_bytes <= space_info->total_bytes) { > - update_bytes_may_use(space_info, orig_bytes); > - trace_btrfs_space_reservation(fs_info, "space_info", > - space_info->flags, orig_bytes, 1); > - ret = 0; > - } else if (can_overcommit(fs_info, space_info, orig_bytes, flush, > - system_chunk)) { > + if ((used + orig_bytes <= space_info->total_bytes) || > + can_overcommit(fs_info, space_info, orig_bytes, flush, > + system_chunk)) { > update_bytes_may_use(space_info, orig_bytes); > trace_btrfs_space_reservation(fs_info, "space_info", > space_info->flags, orig_bytes, 1); >
On Wed, Jun 19, 2019 at 09:12:49AM -0500, Goldwyn Rodrigues wrote: > From: Goldwyn Rodrigues <rgoldwyn@suse.com> > > Simplification. > We don't need an if-else-if structure where we can use a > simple OR since both conditions are performing the > same action. The short-circuit for OR will ensure that if > the first condition is true, can_overcommit() is not > called. > > Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Added to misc-next, thanks.
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index c7adff343ba9..84a33cbb1e68 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5158,17 +5158,13 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info, used = btrfs_space_info_used(space_info, true); /* - * If we have enough space then hooray, make our reservation and carry - * on. If not see if we can overcommit, and if we can, hooray carry on. + * Carry on if we have enough space (short-circuit) OR call + * can_overcommit() to ensure we can overcommit to carry on. * If not things get more complicated. */ - if (used + orig_bytes <= space_info->total_bytes) { - update_bytes_may_use(space_info, orig_bytes); - trace_btrfs_space_reservation(fs_info, "space_info", - space_info->flags, orig_bytes, 1); - ret = 0; - } else if (can_overcommit(fs_info, space_info, orig_bytes, flush, - system_chunk)) { + if ((used + orig_bytes <= space_info->total_bytes) || + can_overcommit(fs_info, space_info, orig_bytes, flush, + system_chunk)) { update_bytes_may_use(space_info, orig_bytes); trace_btrfs_space_reservation(fs_info, "space_info", space_info->flags, orig_bytes, 1);