Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Nikolay Borisov <nborisov@suse.com>
Cc: Filipe Manana <fdmanana@kernel.org>,
	dai.ngo@oracle.com, linux-btrfs <linux-btrfs@vger.kernel.org>,
	gniebler@suse.com,
	"linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>
Subject: Re: bug in btrfs during low memory testing.
Date: Wed, 6 Jul 2022 13:09:53 +0100	[thread overview]
Message-ID: <YsV7kfglS4EEQTJU@casper.infradead.org> (raw)
In-Reply-To: <148c0ac2-add4-69e8-ced7-49772841720b@suse.com>

On Wed, Jul 06, 2022 at 09:36:42AM +0300, Nikolay Borisov wrote:
> On 5.07.22 г. 23:29 ч., Matthew Wilcox wrote:
> > On Tue, Jul 05, 2022 at 09:26:47PM +0100, Filipe Manana wrote:
> > > In this case we can actually call xa_insert() without holding that
> > > spinlock, it's safe against other concurrent calls to
> > > btrfs_get_or_create_delayed_node(), btrfs_get_delayed_node(),
> > > btrfs_kill_delayed_inode_items(), etc.
> > > 
> > > However, looking at xa_insert() we have:
> > > 
> > >          xa_lock(xa);
> > >          err = __xa_insert(xa, index, entry, gfp);
> > >          xa_unlock(xa);
> > > 
> > > And xa_lock() is defined as:
> > > 
> > >          #define xa_lock(xa)             spin_lock(&(xa)->xa_lock)
> > > 
> > > So we'll always be under a spinlock even if we change btrfs to not
> > > take the root->inode_lock spinlock.
> > > 
> > > This seems more like a general problem outside btrfs' control.
> > > So CC'ing Willy to double check.
> > 
> > No, the XArray knows about its own spinlock.  It'll drop it if it needs
> > to allocate memory and the GFP flags indicate that the caller can sleep.
> > It doesn't know about your spinlock, so it can't do the same thing for
> > you ;-)
> 
> 
> In order to catch (and prevent) further offensive can we perhaps have
> something like that in xa_insert:
> 
> 
> diff --git a/include/linux/xarray.h b/include/linux/xarray.h
> index c29e11b2c073..63c00b2945a2 100644
> --- a/include/linux/xarray.h
> +++ b/include/linux/xarray.h
> @@ -770,6 +770,9 @@ static inline int __must_check xa_insert(struct xarray
> *xa,
>  {
>         int err;
> 
> +       if (gfpflags_allow_blocking(gfp))
> +               might_sleep()
> +
>         xa_lock(xa);
>         err = __xa_insert(xa, index, entry, gfp);
>         xa_unlock(xa);

I think you mean:

	might_alloc(gfp);

And yes, I think that makes a lot of sense.  Quite a few similar places
to do ... I'll take care of it.

  reply	other threads:[~2022-07-06 12:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05 19:37 bug in btrfs during low memory testing dai.ngo
2022-07-05 20:26 ` Filipe Manana
2022-07-05 20:29   ` Matthew Wilcox
2022-07-05 20:33     ` Filipe Manana
2022-07-06  6:36     ` Nikolay Borisov
2022-07-06 12:09       ` Matthew Wilcox [this message]
2022-07-06 12:13         ` Nikolay Borisov

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=YsV7kfglS4EEQTJU@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=dai.ngo@oracle.com \
    --cc=fdmanana@kernel.org \
    --cc=gniebler@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=nborisov@suse.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