linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
	"Darrick J . Wong" <darrick.wong@oracle.com>,
	Dave Chinner <david@fromorbit.com>,
	Christoph Hellwig <hch@lst.de>,
	Matthew Wilcox <willy@infradead.org>,
	linux-xfs <linux-xfs@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [POC][PATCH] xfs: reduce ilock contention on buffered randrw workload
Date: Mon, 20 Jun 2022 11:11:36 +0200	[thread overview]
Message-ID: <20220620091136.4uosazpwkmt65a5d@quack3.lan> (raw)
In-Reply-To: <CAOQ4uxjvx33KRSm-HX2AjL=aB5yO=FeWokZ1usDKW7+R4Ednhg@mail.gmail.com>

On Sat 18-06-22 11:38:30, Amir Goldstein wrote:
> On Fri, Jun 17, 2022 at 6:11 PM Jan Kara <jack@suse.cz> wrote:
> >
> > On Fri 17-06-22 17:48:08, Amir Goldstein wrote:
> > > On Tue, Apr 9, 2019 at 11:26 AM Jan Kara <jack@suse.cz> wrote:
> > > >
> > > > On Mon 08-04-19 20:41:09, Amir Goldstein wrote:
> > > > > On Mon, Apr 8, 2019 at 5:11 PM Jan Kara <jack@suse.cz> wrote:
> > > > > >
> > > > > > On Mon 08-04-19 12:02:34, Amir Goldstein wrote:
> > > > > > > On Mon, Apr 8, 2019 at 2:27 AM Dave Chinner <david@fromorbit.com> wrote:
> > > > > > > >
> > > > > > > > On Fri, Apr 05, 2019 at 05:02:33PM +0300, Amir Goldstein wrote:
> > > > > > > > > On Fri, Apr 5, 2019 at 12:17 AM Dave Chinner <david@fromorbit.com> wrote:
> > > > > > > > > >
> > > > > > > > > > On Thu, Apr 04, 2019 at 07:57:37PM +0300, Amir Goldstein wrote:
> > > > > > > > > > > This patch improves performance of mixed random rw workload
> > > > > > > > > > > on xfs without relaxing the atomic buffered read/write guaranty
> > > > > > > > > > > that xfs has always provided.
> > > > > > > > > > >
> > > > > > > > > > > We achieve that by calling generic_file_read_iter() twice.
> > > > > > > > > > > Once with a discard iterator to warm up page cache before taking
> > > > > > > > > > > the shared ilock and once again under shared ilock.
> > > > > > > > > >
> > > > > > > > > > This will race with thing like truncate, hole punching, etc that
> > > > > > > > > > serialise IO and invalidate the page cache for data integrity
> > > > > > > > > > reasons under the IOLOCK. These rely on there being no IO to the
> > > > > > > > > > inode in progress at all to work correctly, which this patch
> > > > > > > > > > violates. IOWs, while this is fast, it is not safe and so not a
> > > > > > > > > > viable approach to solving the problem.
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > > This statement leaves me wondering, if ext4 does not takes
> > > > > > > > > i_rwsem on generic_file_read_iter(), how does ext4 (or any other
> > > > > > > > > fs for that matter) guaranty buffered read synchronization with
> > > > > > > > > truncate, hole punching etc?
> > > > > > > > > The answer in ext4 case is i_mmap_sem, which is read locked
> > > > > > > > > in the page fault handler.
> > > > > > > >
> > > > > > > > Nope, the  i_mmap_sem is for serialisation of /page faults/ against
> > > > > > > > truncate, holepunching, etc. Completely irrelevant to the read()
> > > > > > > > path.
> > > > > > > >
> > > > > > >
> > > > > > > I'm at lost here. Why are page faults completely irrelevant to read()
> > > > > > > path? Aren't full pages supposed to be faulted in on read() after
> > > > > > > truncate_pagecache_range()?
> > > > > >
> > > > > > During read(2), pages are not "faulted in". Just look at
> > > > > > what generic_file_buffered_read() does. It uses completely separate code to
> > > > > > add page to page cache, trigger readahead, and possibly call ->readpage() to
> > > > > > fill the page with data. "fault" path (handled by filemap_fault()) applies
> > > > > > only to accesses from userspace to mmaps.
> > > > > >
> > > > >
> > > > > Oh! thanks for fixing my blind spot.
> > > > > So if you agree with Dave that ext4, and who knows what other fs,
> > > > > are vulnerable to populating page cache with stale "uptodate" data,
> > > >
> > > > Not that many filesystems support punching holes but you're right.
> > > >
> > > > > then it seems to me that also xfs is vulnerable via readahead(2) and
> > > > > posix_fadvise().
> > > >
> > > > Yes, this is correct AFAICT.
> > > >
> > > > > Mind you, I recently added an fadvise f_op, so it could be used by
> > > > > xfs to synchronize with IOLOCK.
> > > >
> > > > And yes, this should work.
> > > >
> > > > > Perhaps a better solution would be for truncate_pagecache_range()
> > > > > to leave zeroed or Unwritten (i.e. lazy zeroed by read) pages in page
> > > > > cache. When we have shared pages for files, these pages could be
> > > > > deduped.
> > > >
> > > > No, I wouldn't really mess with sharing pages due to this. It would be hard
> > > > to make that scale resonably and would be rather complex. We really need a
> > > > proper and reasonably simple synchronization mechanism between operations
> > > > removing blocks from inode and operations filling in page cache of the
> > > > inode. Page lock was supposed to provide this but doesn't quite work
> > > > because hole punching first remove pagecache pages and then go removing all
> > > > blocks.
> > > >
> > > > So I agree with Dave that going for range lock is really the cleanest way
> > > > forward here without causing big regressions for mixed rw workloads. I'm
> > > > just thinking how to best do that without introducing lot of boilerplate
> > > > code into each filesystem.
> > >
> > > Hi Jan, Dave,
> > >
> > > Trying to circle back to this after 3 years!
> > > Seeing that there is no progress with range locks and
> > > that the mixed rw workloads performance issue still very much exists.
> > >
> > > Is the situation now different than 3 years ago with invalidate_lock?
> >
> > Yes, I've implemented invalidate_lock exactly to fix the issues you've
> > pointed out without regressing the mixed rw workloads (because
> > invalidate_lock is taken in shared mode only for reads and usually not at
> > all for writes).
> >
> > > Would my approach of pre-warm page cache before taking IOLOCK
> > > be safe if page cache is pre-warmed with invalidate_lock held?
> >
> > Why would it be needed? But yes, with invalidate_lock you could presumably
> > make that idea safe...
> 
> To remind you, the context in which I pointed you to the punch hole race
> issue in "other file systems" was a discussion about trying to relax the
> "atomic write" POSIX semantics [1] of xfs.

Ah, I see. Sorry, I already forgot :-|

> There was a lot of discussions around range locks and changing the
> fairness of rwsem readers and writer, but none of this changes the fact
> that as long as the lock is file wide (and it does not look like that is
> going to change in the near future), it is better for lock contention to
> perform the serialization on page cache read/write and not on disk
> read/write.
> 
> Therefore, *if* it is acceptable to pre-warn page cache for buffered read
> under invalidate_lock, that is a simple way to bring the xfs performance with
> random rw mix workload on par with ext4 performance without losing the
> atomic write POSIX semantics. So everyone can be happy?

So to spell out your proposal so that we are on the same page: you want to
use invalidate_lock + page locks to achieve "writes are atomic wrt reads"
property XFS currently has without holding i_rwsem in shared mode during
reads. Am I getting it correct?

How exactly do you imagine the synchronization of buffered read against
buffered write would work? Lock all pages for the read range in the page
cache? You'd need to be careful to not bring the machine OOM when someone
asks to read a huge range...

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2022-06-20  9:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-04 16:57 [POC][PATCH] xfs: reduce ilock contention on buffered randrw workload Amir Goldstein
2019-04-04 21:17 ` Dave Chinner
2019-04-05 14:02   ` Amir Goldstein
2019-04-07 23:27     ` Dave Chinner
2019-04-08  9:02       ` Amir Goldstein
2019-04-08 14:11         ` Jan Kara
2019-04-08 17:41           ` Amir Goldstein
2019-04-09  8:26             ` Jan Kara
2022-06-17 14:48               ` Amir Goldstein
2022-06-17 15:11                 ` Jan Kara
2022-06-18  8:38                   ` Amir Goldstein
2022-06-20  9:11                     ` Jan Kara [this message]
2022-06-21  7:49                       ` Amir Goldstein
2022-06-21  8:59                         ` Jan Kara
2022-06-21 12:53                           ` Amir Goldstein
2022-06-22  3:23                             ` Matthew Wilcox
2022-06-22  9:00                               ` Amir Goldstein
2022-06-22  9:34                                 ` Jan Kara
2022-06-22 16:26                                   ` Amir Goldstein
2022-09-13 14:40                             ` Amir Goldstein
2022-09-14 16:01                               ` Darrick J. Wong
2022-09-14 16:29                                 ` Amir Goldstein
2022-09-14 17:39                                   ` Darrick J. Wong
2022-09-19 23:09                                     ` Dave Chinner
2022-09-20  2:24                                       ` Dave Chinner
2022-09-20  3:08                                         ` Amir Goldstein
2022-09-21 11:20                                           ` Amir Goldstein
2019-04-08 11:03       ` Jan Kara
2019-04-22 10:55         ` Boaz Harrosh
2019-04-08 10:33   ` Jan Kara
2019-04-08 16:37     ` Davidlohr Bueso
2019-04-11  1:11       ` Dave Chinner
2019-04-16 12:22         ` Dave Chinner
2019-04-18  3:10           ` Dave Chinner
2019-04-18 18:21             ` Davidlohr Bueso
2019-04-20 23:54               ` Dave Chinner
2019-05-03  4:17                 ` Dave Chinner
2019-05-03  5:17                   ` Dave Chinner

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=20220620091136.4uosazpwkmt65a5d@quack3.lan \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=willy@infradead.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).