Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Naohiro Aota <naohiro.aota@wdc.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: zoned: fix zone_unusable accounting on making BG RW again
Date: Wed, 10 Jul 2024 15:27:53 -0400	[thread overview]
Message-ID: <20240710192753.GB1167307@perftesting> (raw)
In-Reply-To: <1626ef0d42713eaa6e050a6a64be8a811446ad5a.1720624977.git.naohiro.aota@wdc.com>

On Thu, Jul 11, 2024 at 12:23:54AM +0900, Naohiro Aota wrote:
> When btrfs makes a block group read-only, it adds all free regions in the
> BG to space_info->bytes_readonly. That free space excludes reserved and
> pinned regions. OTOH, when btrfs makes the BG read-write again, it moves
> all the unused regions into the block group's zone_unusable. That unused
> region includes reserved and pinned regions. As a result, it counts too
> much zone_unusable bytes.
> 
> Fortunately (or unfortunately), having erroneous zone_unusable does not
> affect the calculation of space_info->bytes_readonly, because free
> space (num_bytes in btrfs_dec_block_group_ro) calculation is done based on
> the erroneous zone_unusable and it reduces the num_bytes just to cancel the
> error.
> 
> This behavior can be easily discovered by adding a WARN_ON to check e.g,
> "bg->pinned > 0" in btrfs_dec_block_group_ro(), and running fstests test
> case like btrfs/282.
> 
> Fix it by properly considering pinned and reserved in
> btrfs_dec_block_group_ro(). Also, add a WARN_ON and introduce
> btrfs_space_info_update_bytes_zone_unusable() to catch a similar mistake.
> 
> Fixes: 169e0da91a21 ("btrfs: zoned: track unusable bytes for zones")
> CC: stable@vger.kernel.org # 5.15+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef

  reply	other threads:[~2024-07-10 19:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-10 15:23 [PATCH] btrfs: zoned: fix zone_unusable accounting on making BG RW again Naohiro Aota
2024-07-10 19:27 ` Josef Bacik [this message]
2024-07-11  6:14 ` Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240710192753.GB1167307@perftesting \
    --to=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=naohiro.aota@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox