Skip to content

Commit fa399c3

Browse files
Matthew Wilcox (Oracle)akpm00
Matthew Wilcox (Oracle)
authored andcommitted
buffer: fix more functions for block size > PAGE_SIZE
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. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Luis Chamberlain <[email protected]> Cc: Pankaj Raghav <[email protected]> Cc: Ryusuke Konishi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b061940 commit fa399c3

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

fs/buffer.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,19 +1742,6 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
17421742
}
17431743
EXPORT_SYMBOL(clean_bdev_aliases);
17441744

1745-
/*
1746-
* Size is a power-of-two in the range 512..PAGE_SIZE,
1747-
* and the case we care about most is PAGE_SIZE.
1748-
*
1749-
* So this *could* possibly be written with those
1750-
* constraints in mind (relevant mostly if some
1751-
* architecture has a slow bit-scan instruction)
1752-
*/
1753-
static inline int block_size_bits(unsigned int blocksize)
1754-
{
1755-
return ilog2(blocksize);
1756-
}
1757-
17581745
static struct buffer_head *folio_create_buffers(struct folio *folio,
17591746
struct inode *inode,
17601747
unsigned int b_state)
@@ -1807,7 +1794,7 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio,
18071794
sector_t block;
18081795
sector_t last_block;
18091796
struct buffer_head *bh, *head;
1810-
unsigned int blocksize, bbits;
1797+
size_t blocksize;
18111798
int nr_underway = 0;
18121799
blk_opf_t write_flags = wbc_to_write_flags(wbc);
18131800

@@ -1826,10 +1813,9 @@ int __block_write_full_folio(struct inode *inode, struct folio *folio,
18261813

18271814
bh = head;
18281815
blocksize = bh->b_size;
1829-
bbits = block_size_bits(blocksize);
18301816

1831-
block = (sector_t)folio->index << (PAGE_SHIFT - bbits);
1832-
last_block = (i_size_read(inode) - 1) >> bbits;
1817+
block = div_u64(folio_pos(folio), blocksize);
1818+
last_block = div_u64(i_size_read(inode) - 1, blocksize);
18331819

18341820
/*
18351821
* 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)
23552341
struct inode *inode = folio->mapping->host;
23562342
sector_t iblock, lblock;
23572343
struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE];
2358-
unsigned int blocksize, bbits;
2344+
size_t blocksize;
23592345
int nr, i;
23602346
int fully_mapped = 1;
23612347
bool page_error = false;
@@ -2369,10 +2355,9 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block)
23692355

23702356
head = folio_create_buffers(folio, inode, 0);
23712357
blocksize = head->b_size;
2372-
bbits = block_size_bits(blocksize);
23732358

2374-
iblock = (sector_t)folio->index << (PAGE_SHIFT - bbits);
2375-
lblock = (limit+blocksize-1) >> bbits;
2359+
iblock = div_u64(folio_pos(folio), blocksize);
2360+
lblock = div_u64(limit + blocksize - 1, blocksize);
23762361
bh = head;
23772362
nr = 0;
23782363
i = 0;

0 commit comments

Comments
 (0)