From: Ted Ts'o <tytso@mit.edu>
To: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 5/6] ext4: Drop i_state_flags on architectures with 64-bit longs
Date: Thu, 6 Jan 2011 12:55:26 -0500 [thread overview]
Message-ID: <20110106175526.GA2857@thunk.org> (raw)
In-Reply-To: <B0A77358-77C0-41DB-8281-FC7CEA4BC826@dilger.ca>
On Thu, Jan 06, 2011 at 12:23:53AM -0700, Andreas Dilger wrote:
> > Yeah, I did think of this, but it seemed like extra/needless work that
> > I was trying to optimize away. It's still not safe to do:
> >
> > #define EXT4_CLEAR_STATE_FLAGS(ei) (ei)->i_flags &= 0xffffffffULL;
> >
> > ... since we're not atomically updating i_flags.
>
> This code would only be used on a 64-bit arch, so it should be
> updating the whole word at once (unlike a 32-bit arch).
Masking off the low 32-bits is a read / mask / write set of operations
on RISCy architectures. Even on an Intel architecture, unless you
specifically use the LOCK prefix on the AND operation, you can still
risk racing with another CPU while you do the mask operation. So no,
it's not atomic.
This is why we did a wholesale replacement of explicit C bit
operations on ei->i_flags and replaced them with
ext4_{set/get/clear}_inode_flags. And why in the jbd/jbd2 layer, we
take an explicit spinlock before modifying j_flags. (An obvious thing
to try doing to reduce spinlock contention on big 48-core machines is
to replace do a similar replacement in the jbd2 layer; on my todo
list.)
> > I did think about putting the #ifdef BITS_PER_LONG < 64 inline in the
> > code, but that's ugly.
>
> I'm missing the point of that - isn't the EXT4_CLEAR_STATE_FLAGS() macro
> masking already conditional on 64-bit architectures?
Sorry, I must not have been clear. I was referring to putting in an
inline #if statement into the C code as being ugly.
> The one call in ext4_do_update_inode() that is masking i_flags is redundant,
> since the cpu_to_le32() macro is itself either masking the value before
> swabbing, and/or it is truncated by the assignment to i_flags.
(Actually, I think the C compiler will likely notice that the earlier
i_flags is redudant, and optimize it out.)
I could have replaced things with this instead:
#if BITS_PER_LONG < 64
ei->i_state_flags = 0
#endif
That's more "correct", but it's ugly. On the other hand, it does make
explicit what is going on, instead of hiding it in a header file.
Whether we think it's better depends on how likely that people will
get confused in the future. If we think it's likely this section of
code will be regularly modified, then we can keep it explicit to
minimize the chances that a future change in the code will move things
around and I don't notice when I'm reviewing the patch.
If we think the section of code is less likely to be changed, then
hiding this detail could make it easier for the casual reader to
understand the code.
To be honoest, it's a minor point either way. I don't have strong
feelings about how this gets done one way or another; I just had to
pick one, and I went with the latter approach. I'm certainly willing
to be pursuaded otherwise that the chances that someone could fall
into the pitfall would be huge.
- Ted
next prev parent reply other threads:[~2011-01-06 17:55 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-05 1:01 [PATCH 0/6] Shrinking the size of ext4_inode_info Theodore Ts'o
2011-01-05 1:01 ` [PATCH 1/6] ext4: replace i_delalloc_reserved_flag with EXT4_STATE_DELALLOC_RESERVED Theodore Ts'o
2011-01-05 1:01 ` [PATCH 2/6] ext4: Use ext4_lblk_t instead of sector_t for logical blocks Theodore Ts'o
2011-01-05 1:01 ` [PATCH 3/6] ext4: Drop ec_type from the ext4_ext_cache structure Theodore Ts'o
2011-01-05 1:01 ` [PATCH 4/6] ext4: reorder ext4_inode_info structure elements to remove unneeded padding Theodore Ts'o
2011-01-05 1:01 ` [PATCH 5/6] ext4: Drop i_state_flags on architectures with 64-bit longs Theodore Ts'o
2011-01-05 18:43 ` Andreas Dilger
2011-01-05 20:29 ` Ted Ts'o
2011-01-06 7:23 ` Andreas Dilger
2011-01-06 17:55 ` Ted Ts'o [this message]
2011-01-06 21:15 ` [PATCH] " Theodore Ts'o
2011-01-05 1:01 ` [PATCH 6/6] ext4: Dynamically allocate the jbd2_inode in ext4_inode_info as necessary Theodore Ts'o
2011-01-05 9:26 ` Amir Goldstein
2011-01-05 20:21 ` Ted Ts'o
2011-01-05 19:26 ` Andreas Dilger
2011-01-05 20:21 ` Ted Ts'o
2011-01-06 22:14 ` Ted Ts'o
2011-01-07 2:36 ` [PATCH -v2] " Theodore Ts'o
2011-01-07 20:46 ` Amir Goldstein
2011-01-07 22:40 ` Ted Ts'o
2011-01-11 21:50 ` [PATCH 6/6] " Ted Ts'o
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=20110106175526.GA2857@thunk.org \
--to=tytso@mit.edu \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@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).