From: Matthew Wilcox <willy@infradead.org>
To: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Hannes Reinecke <hare@suse.de>,
Luis Chamberlain <mcgrof@kernel.org>,
Pankaj Raghav <p.raghav@samsung.com>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v2 5/7] buffer: Fix various functions for block size > PAGE_SIZE
Date: Fri, 10 Nov 2023 13:36:28 +0000 [thread overview]
Message-ID: <ZU4x3IAGmLx457p0@casper.infradead.org> (raw)
In-Reply-To: <CAKFNMokuZFWqoX_1uWm0-vTcbo_gESkNpv8J8Pw1G-Vwd=-D+w@mail.gmail.com>
On Fri, Nov 10, 2023 at 04:48:02PM +0900, Ryusuke Konishi wrote:
> On Fri, Nov 10, 2023 at 6:06 AM Matthew Wilcox (Oracle) wrote:
> > +++ b/fs/buffer.c
> > @@ -199,7 +199,7 @@ __find_get_block_slow(struct block_device *bdev, sector_t block)
> > int all_mapped = 1;
> > static DEFINE_RATELIMIT_STATE(last_warned, HZ, 1);
> >
> > - index = block >> (PAGE_SHIFT - bd_inode->i_blkbits);
> > + index = ((loff_t)block << bd_inode->i_blkbits) / PAGE_SIZE;
>
> Multiple 64-bit divisions are used in this patch, but why not use two
> stage shifts as shown below if there is no left shift overflow and the
> sign bit will not be set ?
>
> index = ((loff_t)block << bd_inode->i_blkbits) >> PAGE_SHIFT;
Here's what the compiler turns that into:
3223: 49 8b 86 80 00 00 00 mov 0x80(%r14),%rax
322a: 4c 89 ee mov %r13,%rsi
322d: ba 01 00 00 00 mov $0x1,%edx
3232: 0f b6 88 c2 00 00 00 movzbl 0xc2(%rax),%ecx
^ this is where we load i_blkbits into ecx
3239: 48 89 45 d0 mov %rax,-0x30(%rbp)
323d: 4c 8b 60 30 mov 0x30(%rax),%r12
3241: 48 d3 e6 shl %cl,%rsi
^ shift left by %cl (the bottom byte of ecx)
3244: 31 c9 xor %ecx,%ecx
3246: 48 c1 ee 0c shr $0xc,%rsi
^ shift right by 12
324a: 4c 89 e7 mov %r12,%rdi
324d: e8 00 00 00 00 call 3252 <__find_get_block+0x82>
324e: R_X86_64_PLT32 __filemap_get_folio-0x4
next prev parent reply other threads:[~2023-11-10 13:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 21:06 [PATCH v2 0/7] More buffer_head cleanups Matthew Wilcox (Oracle)
2023-11-09 21:06 ` [PATCH v2 1/7] buffer: Return bool from grow_dev_folio() Matthew Wilcox (Oracle)
2023-11-10 3:43 ` Ryusuke Konishi
2023-12-30 9:23 ` Matthew Wilcox
2023-12-30 12:22 ` Ryusuke Konishi
2023-11-09 21:06 ` [PATCH v2 2/7] buffer: Calculate block number inside folio_init_buffers() Matthew Wilcox (Oracle)
2023-11-09 21:06 ` [PATCH v2 3/7] buffer: Fix grow_buffers() for block size > PAGE_SIZE Matthew Wilcox (Oracle)
2023-11-10 6:37 ` Ryusuke Konishi
2023-11-10 11:29 ` Ryusuke Konishi
2023-11-10 13:23 ` Matthew Wilcox
2023-11-12 4:52 ` kernel test robot
2023-11-13 17:10 ` Andrew Morton
2023-11-13 17:20 ` Nathan Chancellor
2023-11-15 11:14 ` Naresh Kamboju
2023-11-09 21:06 ` [PATCH v2 4/7] buffer: Cast block to loff_t before shifting it Matthew Wilcox (Oracle)
2023-11-09 21:06 ` [PATCH v2 5/7] buffer: Fix various functions for block size > PAGE_SIZE Matthew Wilcox (Oracle)
2023-11-10 7:48 ` Ryusuke Konishi
2023-11-10 13:36 ` Matthew Wilcox [this message]
2023-11-10 15:23 ` Ryusuke Konishi
2023-11-09 21:06 ` [PATCH v2 6/7] buffer: Handle large folios in __block_write_begin_int() Matthew Wilcox (Oracle)
2023-11-09 21:06 ` [PATCH v2 7/7] buffer: Fix more functions for block size > PAGE_SIZE Matthew Wilcox (Oracle)
2023-11-10 4:50 ` Eric Biggers
2023-11-10 14:26 ` Matthew Wilcox
2023-11-11 18:06 ` Eric Biggers
2023-11-12 4:52 ` Matthew Wilcox
2023-11-12 6:00 ` Eric Biggers
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=ZU4x3IAGmLx457p0@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=hare@suse.de \
--cc=konishi.ryusuke@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=p.raghav@samsung.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).