linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Yangtao Li <frank.li@vivo.com>,
	tytso@mit.edu, adilger.kernel@dilger.ca,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ext4: convert to DIV_ROUND_UP() in mpage_process_page_bufs()
Date: Fri, 10 Mar 2023 06:46:12 +0000	[thread overview]
Message-ID: <20230310064612.GQ3390869@ZenIV> (raw)
In-Reply-To: <ZArRq/25a5Gt+YMB@sol.localdomain>

On Thu, Mar 09, 2023 at 10:43:55PM -0800, Eric Biggers wrote:
> On Fri, Mar 10, 2023 at 06:37:29AM +0000, Al Viro wrote:
> > On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote:
> > > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote:
> > > > Just for better readability, no code logic change.
> > > > 
> > > > Signed-off-by: Yangtao Li <frank.li@vivo.com>
> > > > ---
> > > >  fs/ext4/inode.c | 3 +--
> > > >  1 file changed, 1 insertion(+), 2 deletions(-)
> > > > 
> > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> > > > index d251d705c276..d121cde74522 100644
> > > > --- a/fs/ext4/inode.c
> > > > +++ b/fs/ext4/inode.c
> > > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd,
> > > >  {
> > > >  	struct inode *inode = mpd->inode;
> > > >  	int err;
> > > > -	ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1)
> > > > -							>> inode->i_blkbits;
> > > > +	ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode));
> > > >  
> > > 
> > > Please don't do this.  This makes the code compile down to a division, which is
> > > far less efficient.  I've verified this by checking the assembly generated.
> > 
> > Which compiler is doing that?
> 
> $ gcc --version
> gcc (GCC) 12.2.1 20230201
> 
> i_blocksize(inode) is not a constant, so this should not be particularly
> surprising.  One might hope that a / (1 << b) would be optimized into a >> b,
> but that doesn't seem to happen.

It really ought to be a / (1u << b), though...

  reply	other threads:[~2023-03-10  6:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10  6:07 [PATCH] ext4: convert to DIV_ROUND_UP() in mpage_process_page_bufs() Yangtao Li
2023-03-10  6:17 ` Eric Biggers
2023-03-10  6:27   ` Yangtao Li
2023-03-10  6:35     ` Gao Xiang
2023-03-10  6:37       ` Gao Xiang
2023-03-10  6:41     ` Eric Biggers
2023-03-10  6:37   ` Al Viro
2023-03-10  6:43     ` Al Viro
2023-03-10  6:43     ` Eric Biggers
2023-03-10  6:46       ` Al Viro [this message]
2023-03-10  6:54         ` Eric Biggers
2023-03-10  7:05           ` Al Viro
2023-03-10  7:12             ` Al Viro
2023-03-10 21:47               ` Eric Biggers
2023-03-10 19:07 ` kernel test robot
2023-03-10 19:38 ` kernel test robot
2023-03-10 23:21 ` Theodore Ts'o
2023-03-13  9:25   ` David Laight

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=20230310064612.GQ3390869@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=adilger.kernel@dilger.ca \
    --cc=ebiggers@kernel.org \
    --cc=frank.li@vivo.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).