Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Chris Mason <clm@fb.com>
Cc: linux-btrfs@vger.kernel.org, dsterba@suse.com,
	josef@toxicpanda.com, boris@bur.io
Subject: Re: [PATCH] btrfs: properly enable async discard when switching from RO->RW
Date: Tue, 6 Jun 2023 19:42:38 +0200	[thread overview]
Message-ID: <20230606174238.GN25292@twin.jikos.cz> (raw)
In-Reply-To: <20230605190315.2121377-1-clm@fb.com>

On Mon, Jun 05, 2023 at 12:03:15PM -0700, Chris Mason wrote:
> async discard uses the BTRFS_FS_DISCARD_RUNNING bit in the fs_info to force
> discards off when the filesystem has aborted or we're generally not able
> to run discards.  This gets flipped on when we're mounted rw, and also
> when we go from ro->rw.
> 
> Commit 63a7cb13071842 enabled async discard by default, and this meant
> mount -o ro /dev/xxx /yyy had async discards turned on.
> 
> Unfortunately, this meant our check in btrfs_remount_cleanup() would see
> that discards are already on:
> 
>     /* If we toggled discard async */
>     if (!btrfs_raw_test_opt(old_opts, DISCARD_ASYNC) &&
> 	btrfs_test_opt(fs_info, DISCARD_ASYNC))
> 	    btrfs_discard_resume(fs_info);
> 
> So, we'd never call btrfs_discard_resume() when remounting the root
> filesystem from ro->rw.
> 
> drgn shows this really nicely:
> 
> import os
> import sys
> 
> from drgn.helpers.linux.fs import path_lookup
> from drgn import NULL, Object, Type, cast
> 
> def btrfs_sb(sb):
>     return cast("struct btrfs_fs_info *", sb.s_fs_info)
> 
> if len(sys.argv) == 1:
>     path = "/"
> else:
>     path = sys.argv[1]
> 
> fs_info = cast("struct btrfs_fs_info *", path_lookup(prog, path).mnt.mnt_sb.s_fs_info)
> 
> BTRFS_FS_DISCARD_RUNNING = 1 << prog['BTRFS_FS_DISCARD_RUNNING']
> if fs_info.flags & BTRFS_FS_DISCARD_RUNNING:
>     print("discard running flag is on")
> else:
>     print("discard running flag is off")
> 
> [root]# mount | grep nvme
> /dev/nvme0n1p3 on / type btrfs
> (rw,relatime,compress-force=zstd:3,ssd,discard=async,space_cache=v2,subvolid=5,subvol=/)
> 
> [root]# ./discard_running.drgn
> discard running flag is off
> 
> [root]# mount -o remount,discard=sync /
> [root]# mount -o remount,discard=async /
> [root]# ./discard_running.drgn
> discard running flag is on
> 
> The fix used here is calling btrfs_discard_resume() when we're going
> from ro->rw.  It already checks to make sure the async discard flag is
> on, so it'll do the right thing.
> 
> Fixes: 63a7cb13071842 ("btrfs: auto enable discard=async when possible")
> 
> Reviewed-by: Boris Burkov <boris@bur.io>
> Signed-off-by: Chris Mason <clm@fb.com>

Added to misc-next, thanks.

      reply	other threads:[~2023-06-06 17:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 19:03 [PATCH] btrfs: properly enable async discard when switching from RO->RW Chris Mason
2023-06-06 17:42 ` David Sterba [this message]

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=20230606174238.GN25292@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=boris@bur.io \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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