Message ID | 20230306120127.21375-5-hare@suse.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | brd: Allow to change block sizes | expand |
On Mon, Mar 06, 2023 at 01:01:26PM +0100, Hannes Reinecke wrote: > Use an arbitrary limit of 32M for the maximal blocksize so as not > to overflow the page cache. The page allocator tops out at MAX_ORDER (generally 4MB), so that might be a better limit. Also, this has nothing to do with the page cache, right?
On Mon, Mar 06, 2023 at 01:01:26PM +0100, Hannes Reinecke wrote: > Use an arbitrary limit of 32M for the maximal blocksize so as not > to overflow the page cache. > > Signed-off-by: Hannes Reinecke <hare@suse.de> > --- > drivers/block/brd.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/drivers/block/brd.c b/drivers/block/brd.c > index 11bac3c3f1b6..1ed114cd5cb0 100644 > --- a/drivers/block/brd.c > +++ b/drivers/block/brd.c > @@ -348,6 +348,7 @@ static int max_part = 1; > module_param(max_part, int, 0444); > MODULE_PARM_DESC(max_part, "Num Minors to reserve between devices"); > > +#define RD_MAX_SECTOR_SIZE 65536 > static unsigned int rd_blksize = PAGE_SIZE; > module_param(rd_blksize, uint, 0444); > MODULE_PARM_DESC(rd_blksize, "Blocksize of each RAM disk in bytes."); > @@ -410,15 +411,14 @@ static int brd_alloc(int i) > disk->private_data = brd; > strscpy(disk->disk_name, buf, DISK_NAME_LEN); > set_capacity(disk, rd_size * 2); > - > - /* > - * This is so fdisk will align partitions on 4k, because of > - * direct_access API needing 4k alignment, returning a PFN > - * (This is only a problem on very small devices <= 4M, > - * otherwise fdisk will align on 1M. Regardless this call > - * is harmless) > - */ > + > + if (rd_blksize > RD_MAX_SECTOR_SIZE) { rd_blkside is in bytes, but the above is ccomapring it to something in units of SECTOR_SIZE. > + /* Arbitrary limit maximum block size to 32M */ > + err = -EINVAL; > + goto out_cleanup_disk; > + } rd_blksize also needs to be >= 512, and a power of 2. > blk_queue_physical_block_size(disk->queue, rd_blksize); > + blk_queue_max_hw_sectors(disk->queue, RD_MAX_SECTOR_SIZE); > > /* Tell the block layer that this is not a rotational device */ > blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
On 3/6/23 18:40, Matthew Wilcox wrote: > On Mon, Mar 06, 2023 at 01:01:26PM +0100, Hannes Reinecke wrote: >> Use an arbitrary limit of 32M for the maximal blocksize so as not >> to overflow the page cache. > > The page allocator tops out at MAX_ORDER (generally 4MB), so that might > be a better limit. Also, this has nothing to do with the page cache, > right? Indeed. Sloppy description. Will be fixing it up. Cheers, Hannes
On 3/6/23 19:01, Keith Busch wrote: > On Mon, Mar 06, 2023 at 01:01:26PM +0100, Hannes Reinecke wrote: >> Use an arbitrary limit of 32M for the maximal blocksize so as not >> to overflow the page cache. >> >> Signed-off-by: Hannes Reinecke <hare@suse.de> >> --- >> drivers/block/brd.c | 16 ++++++++-------- >> 1 file changed, 8 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/block/brd.c b/drivers/block/brd.c >> index 11bac3c3f1b6..1ed114cd5cb0 100644 >> --- a/drivers/block/brd.c >> +++ b/drivers/block/brd.c >> @@ -348,6 +348,7 @@ static int max_part = 1; >> module_param(max_part, int, 0444); >> MODULE_PARM_DESC(max_part, "Num Minors to reserve between devices"); >> >> +#define RD_MAX_SECTOR_SIZE 65536 >> static unsigned int rd_blksize = PAGE_SIZE; >> module_param(rd_blksize, uint, 0444); >> MODULE_PARM_DESC(rd_blksize, "Blocksize of each RAM disk in bytes."); >> @@ -410,15 +411,14 @@ static int brd_alloc(int i) >> disk->private_data = brd; >> strscpy(disk->disk_name, buf, DISK_NAME_LEN); >> set_capacity(disk, rd_size * 2); >> - >> - /* >> - * This is so fdisk will align partitions on 4k, because of >> - * direct_access API needing 4k alignment, returning a PFN >> - * (This is only a problem on very small devices <= 4M, >> - * otherwise fdisk will align on 1M. Regardless this call >> - * is harmless) >> - */ >> + >> + if (rd_blksize > RD_MAX_SECTOR_SIZE) { > > rd_blkside is in bytes, but the above is ccomapring it to something in units of > SECTOR_SIZE. > Ok. >> + /* Arbitrary limit maximum block size to 32M */ >> + err = -EINVAL; >> + goto out_cleanup_disk; >> + } > > rd_blksize also needs to be >= 512, and a power of 2. > Yes; I'll be adding the checks accordingly. Cheers, Hannes
diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 11bac3c3f1b6..1ed114cd5cb0 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -348,6 +348,7 @@ static int max_part = 1; module_param(max_part, int, 0444); MODULE_PARM_DESC(max_part, "Num Minors to reserve between devices"); +#define RD_MAX_SECTOR_SIZE 65536 static unsigned int rd_blksize = PAGE_SIZE; module_param(rd_blksize, uint, 0444); MODULE_PARM_DESC(rd_blksize, "Blocksize of each RAM disk in bytes."); @@ -410,15 +411,14 @@ static int brd_alloc(int i) disk->private_data = brd; strscpy(disk->disk_name, buf, DISK_NAME_LEN); set_capacity(disk, rd_size * 2); - - /* - * This is so fdisk will align partitions on 4k, because of - * direct_access API needing 4k alignment, returning a PFN - * (This is only a problem on very small devices <= 4M, - * otherwise fdisk will align on 1M. Regardless this call - * is harmless) - */ + + if (rd_blksize > RD_MAX_SECTOR_SIZE) { + /* Arbitrary limit maximum block size to 32M */ + err = -EINVAL; + goto out_cleanup_disk; + } blk_queue_physical_block_size(disk->queue, rd_blksize); + blk_queue_max_hw_sectors(disk->queue, RD_MAX_SECTOR_SIZE); /* Tell the block layer that this is not a rotational device */ blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue);
Use an arbitrary limit of 32M for the maximal blocksize so as not to overflow the page cache. Signed-off-by: Hannes Reinecke <hare@suse.de> --- drivers/block/brd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)