Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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/20231109210608.2252323-8-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Pankaj Raghav <p.raghav@samsung.com>
Cc: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
fa399c31 b0619401

+6 -21
+6 -21
fs/buffer.c
··· 1742 1742 } 1743 1743 EXPORT_SYMBOL(clean_bdev_aliases); 1744 1744 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 - 1758 1745 static struct buffer_head *folio_create_buffers(struct folio *folio, 1759 1746 struct inode *inode, 1760 1747 unsigned int b_state) ··· 1794 1807 sector_t block; 1795 1808 sector_t last_block; 1796 1809 struct buffer_head *bh, *head; 1797 - unsigned int blocksize, bbits; 1810 + size_t blocksize; 1798 1811 int nr_underway = 0; 1799 1812 blk_opf_t write_flags = wbc_to_write_flags(wbc); 1800 1813 ··· 1813 1826 1814 1827 bh = head; 1815 1828 blocksize = bh->b_size; 1816 - bbits = block_size_bits(blocksize); 1817 1829 1818 - block = (sector_t)folio->index << (PAGE_SHIFT - bbits); 1819 - last_block = (i_size_read(inode) - 1) >> bbits; 1830 + block = div_u64(folio_pos(folio), blocksize); 1831 + last_block = div_u64(i_size_read(inode) - 1, blocksize); 1820 1832 1821 1833 /* 1822 1834 * Get all the dirty buffers mapped to disk addresses and ··· 2341 2355 struct inode *inode = folio->mapping->host; 2342 2356 sector_t iblock, lblock; 2343 2357 struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE]; 2344 - unsigned int blocksize, bbits; 2358 + size_t blocksize; 2345 2359 int nr, i; 2346 2360 int fully_mapped = 1; 2347 2361 bool page_error = false; ··· 2355 2369 2356 2370 head = folio_create_buffers(folio, inode, 0); 2357 2371 blocksize = head->b_size; 2358 - bbits = block_size_bits(blocksize); 2359 2372 2360 - iblock = (sector_t)folio->index << (PAGE_SHIFT - bbits); 2361 - lblock = (limit+blocksize-1) >> bbits; 2373 + iblock = div_u64(folio_pos(folio), blocksize); 2374 + lblock = div_u64(limit + blocksize - 1, blocksize); 2362 2375 bh = head; 2363 2376 nr = 0; 2364 2377 i = 0;