public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Ben Myers <bpm@sgi.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 09/21] xfs: add version 3 inode format with CRCs
Date: Wed, 27 Mar 2013 12:48:28 +1100	[thread overview]
Message-ID: <20130327014828.GN6369@dastard> (raw)
In-Reply-To: <20130327005307.GK30652@sgi.com>

On Tue, Mar 26, 2013 at 07:53:07PM -0500, Ben Myers wrote:
> Hi Dave,
> 
> On Wed, Mar 27, 2013 at 09:56:00AM +1100, Dave Chinner wrote:
> > On Fri, Mar 15, 2013 at 12:11:04PM +1100, Dave Chinner wrote:
> > > On Thu, Mar 14, 2013 at 11:03:21AM -0500, Ben Myers wrote:
> > > > On Tue, Mar 12, 2013 at 11:30:42PM +1100, Dave Chinner wrote:
> > > > >  		xfs_buf_zero(fbuf, 0, ninodes << mp->m_sb.sb_inodelog);
> > > > >  		for (i = 0; i < ninodes; i++) {
> > > > >  			int	ioffset = i << mp->m_sb.sb_inodelog;
> > > > > -			uint	isize = sizeof(struct xfs_dinode);
> > > > > +			uint	isize = xfs_dinode_size(version);
> > > > >  
> > > > >  			free = xfs_make_iptr(mp, fbuf, i);
> > > > >  			free->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
> > > > >  			free->di_version = version;
> > > > >  			free->di_gen = cpu_to_be32(gen);
> > > > >  			free->di_next_unlinked = cpu_to_be32(NULLAGINO);
> > > > > +
> > > > > +			if (version == 3) {
> > > > > +				free->di_ino = cpu_to_be64(ino);
> > > > > +				ino++;
> > > > > +				uuid_copy(&free->di_uuid, &mp->m_sb.sb_uuid);
> > > > > +				xfs_dinode_calc_crc(mp, free);
> > > > > +			}
> > > > > +
> > > > >  			xfs_trans_log_buf(tp, fbuf, ioffset, ioffset + isize - 1);
> > > > 
> > > > If I have it right, it's ok not to log the literal are here (even though the
> > > > crc was calculated including the literal area) because the log is protected by
> > > > its own crcs and recovery will recalculate the crc.
> > > 
> > > Prior to CRCs it's OK not to log the literal areas because the
> > > contents really don't matter. The entire buffer is zeroed because
> > > it's faster than zeroing individual inode cores one by one and it
> > > ensures that we can always tell a freshly allocated inode block with
> > > xfs_db because the literal areas are all zero (i.e. good for
> > > debugging). But these are conveniences, not a necessity, and hence
> > > the advantage of not logging the literal areas reduces the overhead
> > > of logging inode allocations *significantly*.
> > > 
> > > > What do we have in the
> > > > literal area after log replay in that case?
> > > 
> > > For non-CRC inode buffers, it doesn't matter.
> > > 
> > > But you are right that it does matter for CRC enabled inode buffers
> > > as it will result in the CRC in the inode core being incorrect. I'l
> > > havea think about this - there are a couple of potential ways of
> > > solving the problem, and I need to think about them a bit first.
> > 
> > Ben, FYI: I've taken the easy way out for this - log the entire
> > inode buffer rather than just the inode core. The CRC means we are
> > dependent on having all the inode logged so that seems to be the
> > simplest way to deal with this problem overall, even though it
> > increases the amount of metadata logged for inode creates
> > substantially.
> > 
> > I'll address this potential performance issue in future with new
> > inode create and unlink transactions that allow us to avoid logging
> > buffers for all inode modifications. There are other good reasons
> > for doing this as well (e.g. avoid the subtly broken special
> > handling of physical inode buffer logging vs logical inode logging
> > in log recovery), so I think this is best to just take the simple
> > option here....
> 
> It seems like this is a more general problem with fresh on-disk
> structures.  When we calculate crc and log only part of a buffer we are
> prone to the crc being incorrect after log replay because the unlogged
> portions of the buffer are still undefined.  They aren't the 0s we
> calculated crcs with.

But it doesn't matter for all other metadata as we don't log CRC
fields except in the inode/dquot at allocation. It is the exception
rather than the rule.

> I have a couple suggestions:
> 
> 1) We could read the undefined garbage from disk before we initialize
> the structure and then calculate the crc.  That way if we log only parts
> of the result the crc would still match after a crash.

The overhead of reading every inode cluster from disk during
allocation will drop create performance by orders of magnitude. i.e.
far worse in terms of performance than logging the entire buffer.

> 2) Create a new transaction to write a known pattern over the
> entire buffer, then initialize the buffer with that pattern,
> calculate the crc, and still log only the parts of the buffer
> which were modified.  In the non-crash case we still need to
> arrange for the buffer to be patterned after the log wraps, but it
> has the advantage of not having to log large structures just to
> zero them.

We need to ensure we log the entire object if we are logging the CRC
of the object. In this case, the initialisation and calculation of
the CRC needs to be atomic, so it needs to be a single transactions.
That's what logging the entire buffer does.

In all cases except inode and dquot initialisation, CRCs are not
logged and so there is no concern about whether we are logging
unused regions or not as the eventual CRC calculations during log
recovery do not depend on the contents of unlogged regions being
known.  i.e. for buffer based objects, this is what happens:

	get a new buffer
	initialise new buffer
	modify new buffer
	log changed areas
	changed regions get written to log
<time passes>
	metadata writeback started
	verify metadata
	CRC+LSN calculated and inserted into buffer
	buffer written with CRC+LSN as unlogged changes.

So, if we crash while time is passing before metadata writeback,
recovery does this:

	read modifications out of log
	read buffer off disk *without verification* as we can't
					trust the contents at all.
	write modifications into buffer
	attach verifier to buffer
<time passes, other mods to the buffer are replayed>
	metadata writeback started
	verify metadata
	CRC+LSN calculated and inserted into buffer
	buffer written with CRC+LSN as unlogged changes.

IOWs, for everything logged exclusively as a buffer, partial logging
of intialised regions is a non-issue as CRCs are not logged and do
not play a part in log recovery.

The fact is that inodes are special little snowflakes in that they
are initialised physically in a buffer and then modified logically
in transactions. As such, the CRC is calculated at the time of
logical->physical transition in memory, not at the time of physical
IO like is done for all other buffers.

Hence source of the problem here is that inodes are allocated via
physical logging rather than logically, and as such we are logging
the CRC internal to the inode. Hence we have to care about ensuring
that we physically log the entire modified region that the CRC
covers.  i.e. this is a condition specific to inode and dquot
initialisation, not a general problem for all metadata logged in
buffers.

And seeing as I've mentioned dquots, I'll point out that
xfs_qm_init_dquot_blk() doesn't do partial logging of the physical
buffer used for initialisation - it just logs the entire buffer,
exactly as I'm proposing to do here for inodes.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2013-03-27  1:48 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-12 12:30 [PATCH 00/21] xfs: metadata CRCs, third version Dave Chinner
2013-03-12 12:30 ` [PATCH 01/21] xfs: ensure we capture IO errors correctly Dave Chinner
2013-03-12 12:30 ` [PATCH 02/21] xfs: increase hexdump output in xfs_corruption_error Dave Chinner
2013-03-14 21:18   ` Ben Myers
2013-03-15  1:13     ` Dave Chinner
2013-03-12 12:30 ` [PATCH 03/21] xfs: take inode version into account in XFS_LITINO Dave Chinner
2013-03-12 12:30 ` [PATCH 04/21] xfs: add support for large btree blocks Dave Chinner
2013-03-12 12:30 ` [PATCH 05/21] xfs: add CRC checks to the AGF Dave Chinner
2013-03-12 12:30 ` [PATCH 06/21] xfs: add CRC checks to the AGFL Dave Chinner
2013-03-12 12:30 ` [PATCH 07/21] xfs: add CRC checks to the AGI Dave Chinner
2013-03-12 12:30 ` [PATCH 08/21] xfs: add CRC checks for quota blocks Dave Chinner
2013-03-12 12:30 ` [PATCH 09/21] xfs: add version 3 inode format with CRCs Dave Chinner
2013-03-14 16:03   ` Ben Myers
2013-03-14 19:01     ` Ben Myers
2013-03-15  1:11     ` Dave Chinner
2013-03-26 22:56       ` Dave Chinner
2013-03-27  0:53         ` Ben Myers
2013-03-27  1:48           ` Dave Chinner [this message]
2013-04-02 22:44             ` Ben Myers
2013-04-03  4:08               ` Dave Chinner
2013-04-02 22:49   ` Ben Myers
2013-03-12 12:30 ` [PATCH 10/21] xfs: add CRC checks to remote symlinks Dave Chinner
2013-03-20 21:14   ` Ben Myers
2013-03-21  1:22     ` Dave Chinner
2013-03-21 14:59       ` Ben Myers
2013-03-20 22:03   ` Ben Myers
2013-03-21  1:32     ` Dave Chinner
2013-03-12 12:30 ` [PATCH 11/21] xfs: add CRC checks to block format directory blocks Dave Chinner
2013-03-26 18:39   ` Ben Myers
2013-03-26 21:40     ` Dave Chinner
2013-03-12 12:30 ` [PATCH 12/21] xfs: add CRC checking to dir2 free blocks Dave Chinner
2013-03-28 23:40   ` Ben Myers
2013-03-29  3:13     ` Dave Chinner
2013-03-12 12:30 ` [PATCH 13/21] xfs: add CRC checking to dir2 data blocks Dave Chinner
2013-04-03 22:13   ` Ben Myers
2013-03-12 12:30 ` [PATCH 14/21] xfs: add CRC checking to dir2 leaf blocks Dave Chinner
2013-03-12 12:30 ` [PATCH 15/21] xfs: shortform directory offsets change for dir3 format Dave Chinner
2013-03-12 12:30 ` [PATCH 16/21] xfs: add CRCs to dir2/da node blocks Dave Chinner
2013-03-12 12:30 ` [PATCH 17/21] xfs: add CRCs to attr leaf blocks Dave Chinner
2013-03-12 12:30 ` [PATCH 18/21] xfs: split remote attribute code out Dave Chinner
2013-03-12 12:30 ` [PATCH 19/21] xfs: add CRC protection to remote attributes Dave Chinner
2013-03-12 12:30 ` [PATCH 20/21] xfs: add buffer types to directory and attribute buffers Dave Chinner
2013-03-12 12:30 ` [PATCH 21/21] xfs: add CRC checks to the superblock Dave Chinner
2013-03-26 20:58   ` Chandra Seetharaman
2013-03-27  1:06     ` Dave Chinner
2013-03-27 23:07       ` Chandra Seetharaman
2013-03-28  1:36         ` Dave Chinner
2013-03-12 12:43 ` [PATCH 22/21] xfs: Fix magic number assert in xfs_dir3_leaf_log_bests Dave Chinner
2013-03-13  0:29 ` [PATCH 23/21] xfs: fix endian issues reported by sparse Dave Chinner
2013-03-13  1:34 ` [PATCH 24/21] xfs: buffer type overruns blf_flags field Dave Chinner
2013-03-14 21:41 ` [PATCH 00/21] xfs: metadata CRCs, third version Ben Myers

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=20130327014828.GN6369@dastard \
    --to=david@fromorbit.com \
    --cc=bpm@sgi.com \
    --cc=xfs@oss.sgi.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