From: Nick Piggin <npiggin@kernel.dk>
To: Christoph Hellwig <hch@infradead.org>
Cc: npiggin@kernel.dk, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [patch 3/7] fs: introduce inode writeback helpers
Date: Tue, 30 Nov 2010 11:22:04 +1100 [thread overview]
Message-ID: <20101130002204.GF3255@amd> (raw)
In-Reply-To: <20101129151327.GE26076@infradead.org>
On Mon, Nov 29, 2010 at 10:13:27AM -0500, Christoph Hellwig wrote:
> On Wed, Nov 24, 2010 at 01:06:13AM +1100, npiggin@kernel.dk wrote:
> > Inode dirty state cannot be securely tested without participating properly
> > in the inode writeback protocol. Some filesystems need to check this state,
> > so break out the code into helpers and make them available.
> >
> > This could also be used to reduce strange interactions between background
> > writeback and fsync. Currently if we fsync a single page in a file, the
> > entire file gets requeued to the back of the background IO list, even if
> > it is due for writeout and has a large number of pages. That's left for
> > a later time.
>
> Generally looks fine, but as Dave already mentioned I'd rather keep
> i_state manipulation outside the filesystems. This could be done with
I don't see a big problem with it. They already did load it previously
in way which required inode_lock (and was buggy in part because it
didn't take that lock).
> two wrappers like the following, which should also keep the churn
> inside fsync implementations downs:
>
> int fsync_begin(struct inode *inode, int datasync)
> {
> int ret = 0;
> unsigned mask = I_DIRTY_DATASYNC;
>
> if (!datasync)
> mask |= I_DIRTY_SYNC;
>
> spin_lock(&inode_lock);
> if (!inode_writeback_begin(inode, 1))
> goto out;
> if (!(inode->i_state & mask))
> goto out;
>
> inode->i_state &= ~(I_DIRTY_SYNC | I_DIRTY_DATASYNC);
> ret = 1;
> out:
> spin_unlock(&inode_lock);
> return ret;
> }
>
> static void fsync_end(struct inode *inode, int fail)
> {
> spin_lock(&inode_lock);
> if (fail)
> inode->i_state |= I_DIRTY_SYNC | I_DIRTY_DATASYNC;
> inode_writeback_end(inode);
> spin_unlock(&inode_lock);
> }
I prefer not to do that because it doesn't give any control over
setting or clearing the state flags (which might be done more
intelligently by the filesystem and so this function might be
unusable), and just restricts how filesystems use inode_writeback_begin
and inode lock.
Basically if you are doing anything slightly smart, you can start
inode_writeback_begin to exclude concurrent writeout, and if the
inode_lock is held, you can also prevent new changes to dirty bits
and thus keep the generic inode dirty bits in synch with your filesystem
private state.
In short, I don't see anything wrong with exporting
inode_writeback_begin and allowing i_state manipulation by filesystems
that want to do interesting things. And the wrappers AFAIKS don't add
that much -- it's not very long or difficult code.
> note that this one marks the inode fully dirty in case of a failure,
> which is a bit overkill but keeps the interface simpler. Given that
> failure is fsync is catastrophic anyway (filesystem corruption, etc)
> that seems fine to me.
>
> Alternatively we could add a fsync_helper that gets a function
> pointer with the ->write_inode signature and contains the above
> code before and after it. generic_file_fsync would pass the real
> ->write_inode while other filesystems could pass specific routines.
next prev parent reply other threads:[~2010-11-30 0:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-23 14:06 [patch 0/7] icache dirty / sync fixes npiggin
2010-11-23 14:06 ` [patch 1/7] fs: mark_inode_dirty barrier fix npiggin
2010-11-23 14:06 ` [patch 2/7] fs: simple fsync race fix npiggin
2010-11-29 14:58 ` Christoph Hellwig
2010-11-30 0:05 ` Nick Piggin
2010-11-23 14:06 ` [patch 3/7] fs: introduce inode writeback helpers npiggin
2010-11-29 15:13 ` Christoph Hellwig
2010-11-30 0:22 ` Nick Piggin [this message]
2010-11-23 14:06 ` [patch 4/7] fs: preserve inode dirty bits on failed metadata writeback npiggin
2010-11-29 14:59 ` Christoph Hellwig
2010-11-30 0:08 ` Nick Piggin
2010-11-23 14:06 ` [patch 5/7] fs: ext2 inode sync fix npiggin
2010-11-30 11:26 ` Boaz Harrosh
2010-11-23 14:06 ` [patch 6/7] fs: fsync optimisations npiggin
2010-11-29 15:03 ` Christoph Hellwig
2010-11-30 0:11 ` Nick Piggin
2010-11-23 14:06 ` [patch 7/7] fs: fix or note I_DIRTY handling bugs in filesystems npiggin
2010-11-23 15:04 ` Steven Whitehouse
2010-11-23 22:51 ` Dave Chinner
2010-11-24 0:23 ` Nick Piggin
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=20101130002204.GF3255@amd \
--to=npiggin@kernel.dk \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@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).