2023-04-21 19:59:37

by Luis Chamberlain

[permalink] [raw]
Subject: [PATCH 0/5] block: simplify with PAGE_SECTORS_SHIFT

A bit of block drivers have their own incantations with
PAGE_SHIFT - SECTOR_SHIFT. Just simplfy and use PAGE_SECTORS_SHIFT
all over.

Based on linux-next next-20230421.

Luis Chamberlain (5):
dm integrity: simplify by using PAGE_SECTORS_SHIFT
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 | 12 ++++++------
drivers/block/zram/zram_drv.h | 2 --
drivers/md/dm-bufio.c | 4 ++--
drivers/md/dm-integrity.c | 10 +++++-----
fs/iomap/buffered-io.c | 2 +-
6 files changed, 16 insertions(+), 18 deletions(-)

--
2.39.2


2023-04-21 20:00:00

by Luis Chamberlain

[permalink] [raw]
Subject: [PATCH 4/5] dm bufio: simplify by using PAGE_SECTORS_SHIFT

The 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.

Signed-off-by: Luis Chamberlain <[email protected]>
---
drivers/md/dm-bufio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index eea977662e81..08c4730e1819 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -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;
@@ -1190,7 +1190,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:
--
2.39.2

2023-04-21 20:00:08

by Luis Chamberlain

[permalink] [raw]
Subject: [PATCH 1/5] dm integrity: simplify by using PAGE_SECTORS_SHIFT

The 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.

Signed-off-by: Luis Chamberlain <[email protected]>
---
drivers/md/dm-integrity.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 31838b13ea54..a179265970dd 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -752,7 +752,7 @@ static void page_list_location(struct dm_integrity_c *ic, unsigned int section,

sector = section * ic->journal_section_sectors + offset;

- *pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT);
+ *pl_index = sector >> (PAGE_SECTORS_SHIFT);
*pl_offset = (sector << SECTOR_SHIFT) & (PAGE_SIZE - 1);
}

@@ -1077,7 +1077,7 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, blk_opf_t opf,
return;
}

- pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT);
+ pl_index = sector >> (PAGE_SECTORS_SHIFT);
pl_offset = (sector << SECTOR_SHIFT) & (PAGE_SIZE - 1);

io_req.bi_opf = opf;
@@ -1201,7 +1201,7 @@ static void copy_from_journal(struct dm_integrity_c *ic, unsigned int section, u

sector = section * ic->journal_section_sectors + JOURNAL_BLOCK_SECTORS + offset;

- pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT);
+ pl_index = sector >> (PAGE_SECTORS_SHIFT);
pl_offset = (sector << SECTOR_SHIFT) & (PAGE_SIZE - 1);

io_req.bi_opf = REQ_OP_WRITE;
@@ -3765,7 +3765,7 @@ static int create_journal(struct dm_integrity_c *ic, char **error)
ic->commit_ids[3] = cpu_to_le64(0x4444444444444444ULL);

journal_pages = roundup((__u64)ic->journal_sections * ic->journal_section_sectors,
- PAGE_SIZE >> SECTOR_SHIFT) >> (PAGE_SHIFT - SECTOR_SHIFT);
+ PAGE_SIZE >> SECTOR_SHIFT) >> (PAGE_SECTORS_SHIFT);
journal_desc_size = journal_pages * sizeof(struct page_list);
if (journal_pages >= totalram_pages() - totalhigh_pages() || journal_desc_size > ULONG_MAX) {
*error = "Journal doesn't fit into memory";
@@ -4542,7 +4542,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned int argc, char **argv
spin_lock_init(&bbs->bio_queue_lock);

sector = i * (BITMAP_BLOCK_SIZE >> SECTOR_SHIFT);
- pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT);
+ pl_index = sector >> (PAGE_SECTORS_SHIFT);
pl_offset = (sector << SECTOR_SHIFT) & (PAGE_SIZE - 1);

bbs->bitmap = lowmem_page_address(ic->journal[pl_index].page) + pl_offset;
--
2.39.2

2023-04-21 20:47:25

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH 1/5] dm integrity: simplify by using PAGE_SECTORS_SHIFT

On Fri, Apr 21, 2023 at 12:58:03PM -0700, Luis Chamberlain wrote:
> - *pl_index = sector >> (PAGE_SHIFT - SECTOR_SHIFT);
> + *pl_index = sector >> (PAGE_SECTORS_SHIFT);

You could/should remove the () around PAGE_SECTORS_SHIFT

(throughout)