From: Zheng Liu <gnehzuil.liu@gmail.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org, Zheng Liu <wenqing.lz@taobao.com>,
Dmitry Monakhov <dmonakhov@openvz.org>
Subject: Re: [PATCH v2 1/5] ext4: improve ext4_es_can_be_merged() to avoid a potential overflow
Date: Mon, 11 Mar 2013 14:03:31 +0800 [thread overview]
Message-ID: <20130311060331.GB3867@gmail.com> (raw)
In-Reply-To: <20130311004358.GA10090@thunk.org>
On Sun, Mar 10, 2013 at 08:43:58PM -0400, Theodore Ts'o wrote:
> On Wed, Mar 06, 2013 at 10:17:11PM +0800, Zheng Liu wrote:
> > + if (ext4_es_status(es1) ^ ext4_es_status(es2))
> > return 0;
> >
> > - if (ext4_es_status(es1) != ext4_es_status(es2))
>
> Did you have a reason why changed != to ^?
Honestly, no. Just because subconsciously I think bit operation is
faster than other operations, and in ext4_can_extents_be_merged() it
also use '^'. So I guess there is an optimization.
>
> It's identical from a functional perspective, but it's less obvious to
> future readers of the code what's going on. I tried checking to see
> if GCC did any better optimizing the code, but it doesn't seem to make
> any difference. I'm going to switch it back to !=....
Obviously I'm wrong. Thanks for checking it.
>
> > + /* we need to check delayed extent is without unwritten status */
> > + if (ext4_es_is_delayed(es1) && !ext4_es_is_unwritten(es1))
> > + return 1;
>
> I'm not sure why we need to check the unwritten status? Under what
> circumstances would we have an extent marked as under delayed
> allocation but also unwritten?
We could do some buffered writes into a hole. So the extent will be
with delayed status. Before these extents are written out, user might
uses fallocate(2) to preallocate some blocks at the same offset. Then
these extents are marked as unwritten status. But we still need to keep
delayed status because later these extents will be written out and we
will update reserved space according to these extents, especially in a
bigalloc file system.
>
> - Ted
>
> This is how I've restructured this function for now mainly to make it
> easier to understand;
>
> static int ext4_es_can_be_merged(struct extent_status *es1,
> struct extent_status *es2)
> {
> if (ext4_es_status(es1) != ext4_es_status(es2))
> return 0;
>
> if (((__u64) es1->es_len) + es2->es_len > 0xFFFFFFFFULL)
> return 0;
>
> if (((__u64) es1->es_lblk) + es1->es_len != es2->es_lblk)
> return 0;
>
> if ((ext4_es_is_written(es1) || ext4_es_is_unwritten(es1)) &&
> (ext4_es_pblock(es1) + es1->es_len == ext4_es_pblock(es2)))
> return 1;
>
> if (ext4_es_is_hole(es1))
> return 1;
>
> /* we need to check delayed extent is without unwritten status */
> if (ext4_es_is_delayed(es1) && !ext4_es_is_unwritten(es1))
> return 1;
>
> return 0;
> }
It looks good to me.
Thanks,
- Zheng
next prev parent reply other threads:[~2013-03-11 5:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-06 14:17 [PATCH v2 0/5] ext4: try to fix up es regressions Zheng Liu
2013-03-06 14:17 ` [PATCH v2 1/5] ext4: improve ext4_es_can_be_merged() to avoid a potential overflow Zheng Liu
2013-03-11 0:43 ` Theodore Ts'o
2013-03-11 6:03 ` Zheng Liu [this message]
2013-03-06 14:17 ` [PATCH v2 2/5] ext4: add self-testing infrastructure to do a sanity check Zheng Liu
2013-03-07 15:41 ` Dmitry Monakhov
2013-03-08 13:01 ` Zheng Liu
2013-03-11 1:01 ` Theodore Ts'o
2013-03-06 14:17 ` [PATCH v2 3/5] ext4: fix wrong m_len value after unwritten extent conversion Zheng Liu
2013-03-07 15:42 ` Dmitry Monakhov
2013-03-11 1:07 ` Theodore Ts'o
2013-03-11 5:47 ` Zheng Liu
2013-03-13 1:57 ` Theodore Ts'o
2013-03-13 2:14 ` Theodore Ts'o
2013-03-13 8:53 ` Zheng Liu
2013-03-06 14:17 ` [PATCH v2 4/5] ext4: update extent status tree after an extent is zeroed out Zheng Liu
2013-03-07 15:55 ` Dmitry Monakhov
2013-03-08 13:14 ` Zheng Liu
2013-03-06 14:17 ` [PATCH v2 5/5] ext4: fix wrong the number of the allocted blocks in ext4_split_extent Zheng Liu
2013-03-06 22:58 ` Dev branch regressions Theodore Ts'o
2013-03-07 2:40 ` Zheng Liu
2013-03-07 6:47 ` Lukáš Czerner
2013-03-07 11:54 ` Zheng Liu
2013-03-07 16:08 ` [PATCH v2 0/5] ext4: try to fix up es regressions Dmitry Monakhov
2013-03-08 13:18 ` Zheng Liu
2013-03-11 2:11 ` Theodore Ts'o
2013-03-11 6:23 ` Zheng Liu
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=20130311060331.GB3867@gmail.com \
--to=gnehzuil.liu@gmail.com \
--cc=dmonakhov@openvz.org \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=wenqing.lz@taobao.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;
as well as URLs for NNTP newsgroup(s).