block: simplify with PAGE_SECTORS_SHIFT
Subsystems (7)
v3 cover block: simplify with PAGE_SECTORS_SHIFT
Just spinning these low hanging fruit patches I forgot about.
Changes on v3:
o Add tags for Reviews/acks
o rebase onto next-20230914
o Fixes as suggested by Johannes Thumshirn:
- drop not-needed parens on dm bufio
- use SECTOR_MASK instead of PAGE_SECTORS - 1 for the zram driver
o Drop shmem patches as they are already merged / modified
Changes on v2:
o keep iomap math visibly simple
o Add tags for Reviews/acks
o rebase onto next-20230525
Luis Chamberlain (4):
drbd: use PAGE_SECTORS_SHIFT and PAGE_SECTORS
iomap: simplify iomap_init() with PAGE_SECTORS dm bufio: simplify by using PAGE_SECTORS_SHIFT
zram: use generic PAGE_SECTORS and PAGE_SECTORS_SHIFT
drivers/block/drbd/drbd_bitmap.c | 4 ++-- drivers/block/zram/zram_drv.c | 15 ++++++--------- drivers/block/zram/zram_drv.h | 2 -- drivers/md/dm-bufio.c | 4 ++-- fs/iomap/buffered-io.c | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-)
Signature · 1 line
2.39.2
PATCH v3 1/4 drbd: use PAGE_SECTORS_SHIFT and PAGE_SECTORS
Replace common constants with generic versions.
This produces no functional changes.
--- drivers/block/drbd/drbd_bitmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_bitmap.c +2 -2
@@ -1000,7 +1000,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_hounsigned int len; first_bm_sect = device->ldev->md.md_offset + device->ldev->md.bm_offset; - on_disk_sector = first_bm_sect + (((sector_t )page_nr) << (PAGE_SHIFT -SECTOR_SHIFT )); + on_disk_sector = first_bm_sect + (((sector_t )page_nr) <<PAGE_SECTORS_SHIFT );/* this might happen with very small * flexible external meta data device,
@@ -1008,7 +1008,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho last_bm_sect =drbd_md_last_bitmap_sector (device->ldev);if (first_bm_sect <= on_disk_sector && last_bm_sect >= on_disk_sector) {sector_t len_sect = last_bm_sect - on_disk_sector +1 ; -if (len_sect <PAGE_SIZE /SECTOR_SIZE ) +if (len_sect <PAGE_SECTORS ) len = (unsigned int )len_sect*SECTOR_SIZE ;else len =PAGE_SIZE ;
Signature · 1 line
2.39.2
PATCH v3 2/4 iomap: simplify iomap_init() with PAGE_SECTORS
In reply to Luis ChamberlainReplace common constants with generic versions. This produces no functional changes.
--- fs/iomap/buffered-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/iomap/buffered-io.c +1 -1
@@ -1985,7 +1985,7 @@ EXPORT_SYMBOL_GPL(iomap_writepages);static int __init iomap_init (void ) { -return bioset_init (&iomap_ioend_bioset,4 * (PAGE_SIZE /SECTOR_SIZE ), +return bioset_init (&iomap_ioend_bioset,4 *PAGE_SECTORS , offsetof(struct iomap_ioend , io_inline_bio),BIOSET_NEED_BVECS ); }
Signature · 1 line
2.39.2
Re: [PATCH v3 2/4] iomap: simplify iomap_init() with PAGE_SECTORS
Looks good,
PATCH v3 3/4 dm bufio: simplify by using PAGE_SECTORS_SHIFT
In reply to Luis ChamberlainThe PAGE_SHIFT - SECTOR_SHIFT constant be replaced with PAGE_SECTORS_SHIFT defined in linux/blt_types.h, which is included by linux/blkdev.h.
This produces no functional changes.
--- drivers/md/dm-bufio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/dm-bufio.c +2 -2
@@ -1152,7 +1152,7 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask, gfp_mask & __GFP_NORETRY) { *data_mode =DATA_MODE_GET_FREE_PAGES ;return (void *)__get_free_pages (gfp_mask, - c->sectors_per_block_bits - (PAGE_SHIFT -SECTOR_SHIFT )); + c->sectors_per_block_bits -PAGE_SECTORS_SHIFT ); } *data_mode =DATA_MODE_VMALLOC ;
@@ -1173,7 +1173,7 @@ static void free_buffer_data(struct dm_bufio_client *c,case DATA_MODE_GET_FREE_PAGES :free_pages ((unsigned long )data, - c->sectors_per_block_bits - (PAGE_SHIFT -SECTOR_SHIFT )); + c->sectors_per_block_bits -PAGE_SECTORS_SHIFT );break ;case DATA_MODE_VMALLOC :
Signature · 1 line
2.39.2
Re: [PATCH v3 3/4] dm bufio: simplify by using PAGE_SECTORS_SHIFT
Looks good,
PATCH v3 4/4 zram: use generic PAGE_SECTORS and PAGE_SECTORS_SHIFT
In reply to Luis ChamberlainInstead of re-defining the already existing constants use the provided ones:
So replace:
o SECTORS_PER_PAGE_SHIFT with PAGE_SECTORS_SHIFT
o SECTORS_PER_PAGE with PAGE_SECTORS
o SECTORS_PER_PAGE - 1 with SECTOR_MASK
This produces no functional changes.
--- drivers/block/zram/zram_drv.c | 15 ++++++--------- drivers/block/zram/zram_drv.h | 2 -- 2 files changed, 6 insertions(+), 11 deletions(-)
drivers/block/zram/zram_drv.c +6 -9
@@ -1834,9 +1834,8 @@ static ssize_t recompress_store(struct device *dev,static void zram_bio_discard (struct zram *zram,struct bio *bio) {size_t n = bio->bi_iter.bi_size; -u32 index = bio->bi_iter.bi_sector >>SECTORS_PER_PAGE_SHIFT ; -u32 offset = (bio->bi_iter.bi_sector & (SECTORS_PER_PAGE -1 )) << -SECTOR_SHIFT ; +u32 index = bio->bi_iter.bi_sector >>PAGE_SECTORS_SHIFT ; +u32 offset = (bio->bi_iter.bi_sector &SECTOR_MASK ) <<SECTOR_SHIFT ;/* * zram manages data in physical block size units. Because logical block
@@ -1874,9 +1873,8 @@ static void zram_bio_read(struct zram *zram, struct bio *bio)struct bvec_iter iter = bio->bi_iter; do { - u32 index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; - u32 offset = (iter.bi_sector & (SECTORS_PER_PAGE - 1)) << - SECTOR_SHIFT; + u32 index = iter.bi_sector >> PAGE_SECTORS_SHIFT; + u32 offset = (iter.bi_sector & SECTOR_MASK) << SECTOR_SHIFT; struct bio_vec bv = bio_iter_iovec(bio, iter); bv.bv_len = min_t(u32, bv.bv_len, PAGE_SIZE - offset);
@@ -1905,9 +1903,8 @@ static void zram_bio_write(struct zram *zram, struct bio *bio)struct bvec_iter iter = bio->bi_iter; do { - u32 index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; - u32 offset = (iter.bi_sector & (SECTORS_PER_PAGE - 1)) << - SECTOR_SHIFT; + u32 index = iter.bi_sector >> PAGE_SECTORS_SHIFT; + u32 offset = (iter.bi_sector & SECTOR_MASK) << SECTOR_SHIFT; struct bio_vec bv = bio_iter_iovec(bio, iter); bv.bv_len = min_t(u32, bv.bv_len, PAGE_SIZE - offset);
drivers/block/zram/zram_drv.h +0 -2
@@ -21,8 +21,6 @@#include "zcomp.h" -#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT) -#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)#define ZRAM_LOGICAL_BLOCK_SHIFT 12#define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)#define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
Signature · 1 line
2.39.2
Re: [PATCH v3 4/4] zram: use generic PAGE_SECTORS and PAGE_SECTORS_SHIFT
Looks good,