Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Dave Chinner <dgc@kernel.org>
Cc: "linux-xfs@vger.kernel.org" <linux-xfs@vger.kernel.org>,
	 "Darrick J. Wong" <djwong@kernel.org>,
	John Garry <john.garry@linux.dev>
Subject: Re: [bug report] fstests generic/774 hang again
Date: Fri, 25 Sep 2026 10:32:44 +0900	[thread overview]
Message-ID: <arXOOv-OCEUs8xgQ@shinmob> (raw)
In-Reply-To: <arGqH7adMMyhM1pi@dread>

On Sep 22, 2026 / 08:05, Dave Chinner wrote:
> On Sat, Sep 19, 2026 at 08:53:39PM +0900, Shin'ichiro Kawasaki wrote:
[...]
> > diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> > index 426a67b813a..8d10ae22884 100644
> > --- a/fs/xfs/xfs_file.c
> > +++ b/fs/xfs/xfs_file.c
> > @@ -829,7 +829,7 @@ xfs_file_dio_write_atomic(
> >  	struct kiocb		*iocb,
> >  	struct iov_iter		*from)
> >  {
> > -	unsigned int		iolock = XFS_IOLOCK_SHARED;
> > +	unsigned int		iolock;
> >  	ssize_t			ret, ocount = iov_iter_count(from);
> >  	unsigned int		dio_flags = 0;
> >  	const struct iomap_ops	*dops;
> > @@ -844,6 +844,17 @@ xfs_file_dio_write_atomic(
> >  		dops = &xfs_direct_write_iomap_ops;
> >  
> >  retry:
> > +	/*
> > +	 * Concurrent atomic write COW submissions under ILOCK can run out
> > +	 * journal reservation resource and can deadlock with the IO
> > +	 * completions. To avoid the deadlock, serialize submissions of
> > +	 * atomic write COW by taking IOLOCK exclusively.
> > +	 */
> > +	if (dops == &xfs_atomic_write_cow_iomap_ops)
> > +		iolock = XFS_IOLOCK_EXCL;
> > +	else
> > +		iolock = XFS_IOLOCK_SHARED;
> > +
> >  	ret = xfs_ilock_iocb_for_write(iocb, &iolock);
> >  	if (ret)
> >  		return ret;
> 
> Urk, that's pretty nasty.
> 
> > @@ -853,7 +864,8 @@ xfs_file_dio_write_atomic(
> >  		goto out_unlock;
> >  
> >  	/* Demote similar to xfs_file_dio_write_aligned() */
> > -	if (iolock == XFS_IOLOCK_EXCL) {
> > +	if (iolock == XFS_IOLOCK_EXCL &&
> > +	    dops != &xfs_atomic_write_cow_iomap_ops) {
> >  		xfs_ilock_demote(ip, XFS_IOLOCK_EXCL);
> >  		iolock = XFS_IOLOCK_SHARED;
> >  	}
> 
> And at this point, we now have several atomic write cow ops specific
> operations in this function (locking, the retry loop, etc).
> 
> This feels much more like there should be a separate function for
> the software cow path, and the fast path simply calls it on
> ENOPROTOOPT from the dio submission. That gets rid of all the
> conditionals and looping from the fast path. i.e
> 
> 	if (ocount > xfs_inode_buftarg(ip)->bt_awu_maxocount)
> 		return xfs_file_dio_write_atomic_cow();
> 
> 	/* do normal DIO write */
> 
> 	if (error == -ENOPROTOOPT)
> 		return xfs_file_dio_write_atomic_cow();
> 	return error;
> 
> 
> That essentially makes xfs_file_dio_write_atomic() and
> xfs_file_dio_write_aligned() the same code, except for the above two
> checks, hence they could easily be collapsed back into a common
> implementation is:
> 
> 	if ((iocb->ki_flags & IOCB_ATOMIC) &&
> 	    ocount > xfs_inode_buftarg(ip)->bt_awu_maxocount)
> 		return xfs_file_dio_write_atomic_cow();
> 
> 	/* do normal DIO write */
> 
> 	if (error == -ENOPROTOOPT)
> 		return xfs_file_dio_write_atomic_cow();
> 	return error;
> 
> That seems like a much more natural breakdown that the current
> duplication of the DIO write submission code...

Thanks for the comment. I'll try to factor out the duplication based
on your idea.

On the other hand, Darrick suggested antoher solution approach to allocate
enough space before taking ILOCK by increasing tr_logcount. I wonder which
way is the better: "allocate enough space" or "take exclusive IOLOCK". I'll
do some experiment for the "allocate enough space" approach before working
on the dupliaction clean up.

  reply	other threads:[~2026-09-25  1:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15  9:34 [bug report] fstests generic/774 hang again Shin'ichiro Kawasaki
2026-09-15 10:00 ` John Garry
2026-09-15 11:48   ` Shin'ichiro Kawasaki
2026-09-15 14:48     ` John Garry
2026-09-15 14:50       ` Darrick J. Wong
2026-09-15 15:41         ` John Garry
2026-09-16 10:23           ` John Garry
2026-09-16 22:23             ` Dave Chinner
2026-09-17  8:28               ` John Garry
2026-09-17 21:20                 ` Dave Chinner
2026-09-17  6:30             ` Shin'ichiro Kawasaki
2026-09-16  2:53     ` Shin'ichiro Kawasaki
2026-09-16 21:45 ` Dave Chinner
2026-09-17  6:52   ` Shin'ichiro Kawasaki
2026-09-17 10:45     ` Shin'ichiro Kawasaki
2026-09-17 21:24       ` Dave Chinner
2026-09-19 11:53         ` Shin'ichiro Kawasaki
2026-09-21 22:05           ` Dave Chinner
2026-09-25  1:32             ` Shin'ichiro Kawasaki [this message]
2026-09-27 21:30               ` Dave Chinner
2026-09-28  2:45                 ` Darrick J. Wong
2026-09-22  0:28   ` Darrick J. Wong
2026-09-25  1:38     ` Shin'ichiro Kawasaki
2026-09-25 23:03       ` Darrick J. Wong

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=arXOOv-OCEUs8xgQ@shinmob \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=dgc@kernel.org \
    --cc=djwong@kernel.org \
    --cc=john.garry@linux.dev \
    --cc=linux-xfs@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