From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/3 V2] xfs: replace do_mod with native operations
Date: Fri, 8 Jun 2018 17:31:17 +1000 [thread overview]
Message-ID: <20180608073117.GA10363@dastard> (raw)
In-Reply-To: <20180608061909.GA12715@infradead.org>
On Thu, Jun 07, 2018 at 11:19:09PM -0700, Christoph Hellwig wrote:
> On Fri, Jun 08, 2018 at 10:43:57AM +1000, Dave Chinner wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> >
> > do_mod() is a hold-over from when we have different sizes for file
> > offsets and and other internal values for 40 bit XFS filesystems.
> > Hence depending on build flags variables passed to do_mod() could
> > change size. We no longer support those small format filesystems and
> > hence everything is of fixed size theses days, even on 32 bit
> > platforms.
> >
> > As such, we can convert all the do_mod() callers to platform
> > optimised modulus operations as defined by linux/math64.h.
> > Individual conversions depend on the types of variables being used.
>
> I have to admit the XFS helpers are much more intuitive.
I've always found them opaque and clunky, especially with the return
value casts they seem to be frequently (but not consistently)
associated with.
> > 7 files changed, 66 insertions(+), 50 deletions(-)
>
> And the diffstat agrees with me.
No, it's doesn't, actually. The diffstat changes because I separated
calculations from logic operations, just like we do catching and
checking error returns from functions. i.e. the code goes from
this horrible mess or assignments, casts and calculations
intermingled with flow/logic decisions:
if ((args.mod = (xfs_extlen_t)do_mod(ap->offset, args.prod)))
args.mod = (xfs_extlen_t)(args.prod - args.mod);
Into a clear separation of calculation and logic statements like this:
div_u64_rem(ap->offset, args.prod, &args.mod);
if (args.mod)
args.mod = args.prod - args.mod;
That is also our preferred style for all the code (e.g. for catching
and checking errors). Yes, that means a slight growth in code size,
but I'll take that any day of the week if it means the code is
easier to read....
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2018-06-08 7:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-07 5:27 [PATCH 0/3] xfs: minor cleanups Dave Chinner
2018-06-07 5:27 ` [PATCH 1/3] xfs: move various type verifiers to common file Dave Chinner
2018-06-07 11:41 ` Brian Foster
2018-06-07 15:23 ` Darrick J. Wong
2018-06-08 6:24 ` Christoph Hellwig
2018-06-07 5:27 ` [PATCH 2/3] xfs: replace do_mod with native operations Dave Chinner
2018-06-07 11:42 ` Brian Foster
2018-06-07 16:01 ` Darrick J. Wong
2018-06-07 22:23 ` Dave Chinner
2018-06-07 15:54 ` Darrick J. Wong
2018-06-07 22:28 ` Dave Chinner
2018-06-08 0:43 ` [PATCH 2/3 V2] " Dave Chinner
2018-06-08 6:19 ` Christoph Hellwig
2018-06-08 7:31 ` Dave Chinner [this message]
2018-06-07 5:27 ` [PATCH 3/3] xfs: clean up MIN/MAX Dave Chinner
2018-06-07 11:42 ` Brian Foster
2018-06-08 6:23 ` Christoph Hellwig
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=20180608073117.GA10363@dastard \
--to=david@fromorbit.com \
--cc=hch@infradead.org \
--cc=linux-xfs@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