From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Hannes Reinecke <hare@suse.de>,
Luis Chamberlain <mcgrof@kernel.org>,
Pankaj Raghav <p.raghav@samsung.com>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH v2 7/7] buffer: Fix more functions for block size > PAGE_SIZE
Date: Thu, 9 Nov 2023 21:06:08 +0000 [thread overview]
Message-ID: <20231109210608.2252323-8-willy@infradead.org> (raw)
In-Reply-To: <20231109210608.2252323-1-willy@infradead.org>
Both __block_write_full_folio() and block_read_full_folio() assumed
that block size <= PAGE_SIZE. Replace the shift with a divide, which
is probably cheaper than first calculating the shift. That lets us
remove block_size_bits() as these were the last callers.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/buffer.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index ef444ab53a9b..4eb44ccdc6be 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1742,19 +1742,6 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
}
EXPORT_SYMBOL(clean_bdev_aliases);
-/*
- * Size is a power-of-two in the range 512..PAGE_SIZE,
- * and the case we care about most is PAGE_SIZE.
- *
- * So this *could* possibly be written with those
- * constraints in mind (relevant mostly if some
- * architecture has a slow bit-scan instruction)
- */
-static inline int block_size_bits(unsigned int blocksize)
-{
- return ilog2(blocksize);
-}
-
static struct buffer_head *folio_create_buffers(struct folio *folio,
struct inode *inode,
unsigned int b_state)
@@ -1807,7 +1794,7 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio,
sector_t block;
sector_t last_block;
struct buffer_head *bh, *head;
- unsigned int blocksize, bbits;
+ size_t blocksize;
int nr_underway = 0;
blk_opf_t write_flags = wbc_to_write_flags(wbc);
@@ -1826,10 +1813,9 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio,
bh = head;
blocksize = bh->b_size;
- bbits = block_size_bits(blocksize);
- block = (sector_t)folio->index << (PAGE_SHIFT - bbits);
- last_block = (i_size_read(inode) - 1) >> bbits;
+ block = div_u64(folio_pos(folio), blocksize);
+ last_block = div_u64(i_size_read(inode) - 1, blocksize);
/*
* Get all the dirty buffers mapped to disk addresses and
@@ -2355,7 +2341,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block)
struct inode *inode = folio->mapping->host;
sector_t iblock, lblock;
struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE];
- unsigned int blocksize, bbits;
+ size_t blocksize;
int nr, i;
int fully_mapped = 1;
bool page_error = false;
@@ -2369,10 +2355,9 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block)
head = folio_create_buffers(folio, inode, 0);
blocksize = head->b_size;
- bbits = block_size_bits(blocksize);
- iblock = (sector_t)folio->index << (PAGE_SHIFT - bbits);
- lblock = (limit+blocksize-1) >> bbits;
+ iblock = div_u64(folio_pos(folio), blocksize);
+ lblock = div_u64(limit + blocksize - 1, blocksize);
bh = head;
nr = 0;
i = 0;
--
2.42.0
next prev parent reply other threads:[~2023-11-09 21:06 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
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 ` Matthew Wilcox (Oracle) [this message]
2023-11-10 4:50 ` [PATCH v2 7/7] buffer: Fix more functions for block size > PAGE_SIZE 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=20231109210608.2252323-8-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=hare@suse.de \
--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).