linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com,
	linux-fsdevel@vger.kernel.org, brauner@kernel.org
Subject: Re: [PATCH v2 04/18] btrfs: move space cache settings into open_ctree
Date: Mon, 20 Nov 2023 16:54:26 -0500	[thread overview]
Message-ID: <20231120215426.GA1611727@perftesting> (raw)
In-Reply-To: <1f8c8d3f-8f7a-407b-8020-e961fe2f6024@oracle.com>

On Wed, Nov 15, 2023 at 08:06:02AM +0800, Anand Jain wrote:
> 
> > @@ -3287,6 +3287,12 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
> >   	fs_info->csums_per_leaf = BTRFS_MAX_ITEM_SIZE(fs_info) / fs_info->csum_size;
> >   	fs_info->stripesize = stripesize;
> > +	/*
> > +	 * Handle the space caching options appropriately now that we have the
> > +	 * super loaded and validated.
> > +	 */
> > +	btrfs_set_free_space_cache_settings(fs_info);
> > +
> >   	ret = btrfs_parse_options(fs_info, options, sb->s_flags);
> >   	if (ret)
> >   		goto fail_alloc;
> > @@ -3298,17 +3304,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
> >   	if (sectorsize < PAGE_SIZE) {
> >   		struct btrfs_subpage_info *subpage_info;
> > -		/*
> > -		 * V1 space cache has some hardcoded PAGE_SIZE usage, and is
> > -		 * going to be deprecated.
> > -		 *
> > -		 * Force to use v2 cache for subpage case.
> > -		 */
> > -		btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE);
> > -		btrfs_set_and_info(fs_info, FREE_SPACE_TREE,
> > -			"forcing free space tree for sector size %u with page size %lu",
> > -			sectorsize, PAGE_SIZE);
> > -
> >   		btrfs_warn(fs_info,
> >   		"read-write for sector size %u with page size %lu is experimental",
> >   			   sectorsize, PAGE_SIZE);
> > diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> > index 639601d346d0..aef7e67538a3 100644
> > --- a/fs/btrfs/super.c
> > +++ b/fs/btrfs/super.c
> > @@ -266,6 +266,31 @@ static bool check_options(struct btrfs_fs_info *info, unsigned long flags)
> >   	return true;
> >   }
> > +void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info)
> > +{
> > +	if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE))
> > +		btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
> > +	else if (btrfs_free_space_cache_v1_active(fs_info)) {
> > +		if (btrfs_is_zoned(fs_info)) {
> > +			btrfs_info(fs_info,
> > +			"zoned: clearing existing space cache");
> > +			btrfs_set_super_cache_generation(fs_info->super_copy, 0);
> > +		} else {
> > +			btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE);
> > +		}
> > +	}
> > +
> > +	if (fs_info->sectorsize < PAGE_SIZE) {
> > +		btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE);
> > +		if (!btrfs_test_opt(fs_info, FREE_SPACE_TREE)) {
> > +			btrfs_info(fs_info,
> > +				   "forcing free space tree for sector size %u with page size %lu",
> > +				   fs_info->sectorsize, PAGE_SIZE);
> > +			btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
> > +		}
> > +	}
> > +}
> > +
> >   static int parse_rescue_options(struct btrfs_fs_info *info, const char *options)
> >   {
> >   	char *opts;
> > @@ -345,18 +370,6 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
> >   	bool saved_compress_force;
> >   	int no_compress = 0;
> > -	if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE))
> > -		btrfs_set_opt(info->mount_opt, FREE_SPACE_TREE);
> > -	else if (btrfs_free_space_cache_v1_active(info)) {
> > -		if (btrfs_is_zoned(info)) {
> > -			btrfs_info(info,
> > -			"zoned: clearing existing space cache");
> > -			btrfs_set_super_cache_generation(info->super_copy, 0);
> > -		} else {
> > -			btrfs_set_opt(info->mount_opt, SPACE_CACHE);
> > -		}
> > -	}
> > -
> >   	/*
> >   	 * Even the options are empty, we still need to do extra check
> >   	 * against new flags
> 
> 
> btrfs_remount() calls btrfs_parse_options(), which previously handled
> space cache/tree flags set/reset. However, with the move of this
> functionality to a separate function, btrfs_set_free_space_cache_settings(),
> the btrfs_remount() thread no longer has the space cache/tree flags
> set/reset. The changelog provides no explanation for this change.
> Could this be a bug?
> 

All this bit does is set the mount_opt's based on the current state of the file
system, so if we're mounting with no "-o space_cache=*" option, we'll derive it
from wether FREE_SPACE_TREE is set or btrfs_free_space_cache_v1_active() returns
true.

So in your case if we mounted -o nospace_cache then we'll have cleared the
v1_active bit and this won't do anything and we'll get -o nospace_cache again.
The same goes for the free space tree, we're only allowed to change the disk
option for this in certain cases.  And in those cases it'll clear the compat
flag.

But this is definitely subtle, I'll expand the changelog.  Thanks,

Josef

  reply	other threads:[~2023-11-20 21:54 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08 19:08 [PATCH v2 00/18] btrfs: convert to the new mount API Josef Bacik
2023-11-08 19:08 ` [PATCH v2 01/18] fs: indicate request originates from old mount api Josef Bacik
2023-11-08 19:08 ` [PATCH v2 02/18] btrfs: split out the mount option validation code into its own helper Josef Bacik
2023-11-14  6:32   ` Anand Jain
2023-11-14 17:35     ` David Sterba
2023-11-08 19:08 ` [PATCH v2 03/18] btrfs: set default compress type at btrfs_init_fs_info time Josef Bacik
2023-11-08 19:08 ` [PATCH v2 04/18] btrfs: move space cache settings into open_ctree Josef Bacik
2023-11-15  0:06   ` Anand Jain
2023-11-20 21:54     ` Josef Bacik [this message]
2023-11-08 19:08 ` [PATCH v2 05/18] btrfs: do not allow free space tree rebuild on extent tree v2 Josef Bacik
2023-11-15  9:49   ` Anand Jain
2023-11-16 20:09     ` David Sterba
2023-11-08 19:08 ` [PATCH v2 06/18] btrfs: split out ro->rw and rw->ro helpers into their own functions Josef Bacik
2023-11-08 19:08 ` [PATCH v2 07/18] btrfs: add a NOSPACECACHE mount option flag Josef Bacik
2023-11-08 19:08 ` [PATCH v2 08/18] btrfs: add fs_parameter definitions Josef Bacik
2023-11-14 17:49   ` David Sterba
2023-11-08 19:08 ` [PATCH v2 09/18] btrfs: add parse_param callback for the new mount api Josef Bacik
2023-11-14 18:13   ` David Sterba
2023-11-22 16:12     ` Josef Bacik
2023-11-08 19:08 ` [PATCH v2 10/18] btrfs: add fs context handling functions Josef Bacik
2023-11-08 19:08 ` [PATCH v2 11/18] btrfs: add reconfigure callback for fs_context Josef Bacik
2023-11-14 18:23   ` David Sterba
2023-11-08 19:08 ` [PATCH v2 12/18] btrfs: add get_tree callback for new mount API Josef Bacik
2023-11-14 18:35   ` David Sterba
2023-11-08 19:08 ` [PATCH v2 13/18] btrfs: handle the ro->rw transition for mounting different subovls Josef Bacik
2023-11-08 19:08 ` [PATCH v2 14/18] btrfs: switch to the new mount API Josef Bacik
2023-11-08 19:08 ` [PATCH v2 15/18] btrfs: move the device specific mount options to super.c Josef Bacik
2023-11-08 19:08 ` [PATCH v2 16/18] btrfs: remove old mount API code Josef Bacik
2023-11-08 19:08 ` [PATCH v2 17/18] btrfs: move one shot mount option clearing to super.c Josef Bacik
2023-11-08 19:08 ` [PATCH v2 18/18] btrfs: set clear_cache if we use usebackuproot Josef Bacik
2023-11-08 23:02 ` [PATCH v2 00/18] btrfs: convert to the new mount API Neal Gompa
2023-11-09 11:55 ` Johannes Thumshirn
2023-11-09 12:55 ` Christian Brauner

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=20231120215426.GA1611727@perftesting \
    --to=josef@toxicpanda.com \
    --cc=anand.jain@oracle.com \
    --cc=brauner@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).