* [PATCH 0/2] Enable testing small DMA segment sizes @ 2026-03-23 20:29 Bart Van Assche 2026-03-23 20:29 ` [PATCH 1/2] block: Reduce BLK_MIN_SEGMENT_SIZE Bart Van Assche 2026-03-23 20:29 ` [PATCH 2/2] null_blk: Support configuring the maximum segment size Bart Van Assche 0 siblings, 2 replies; 4+ messages in thread From: Bart Van Assche @ 2026-03-23 20:29 UTC (permalink / raw) To: Jens Axboe Cc: linux-block, Christoph Hellwig, Damien Le Moal, Bart Van Assche Hi Jens, About one year ago support was merged for DMA segment sizes smaller than the virtual memory page size. No blktests exist yet for the new codepaths related to small segment size support. This patch series makes it possible to test these code paths on a system (e.g. a VM) with 4 KiB pages. The corresponding blktest patch is available here: https://lore.kernel.org/linux-block/20260323200751.1238583-1-bvanassche@acm.org/ Please consider this patch series for the next merge window. Thanks, Bart. Bart Van Assche (2): block: Reduce BLK_MIN_SEGMENT_SIZE null_blk: Support configuring the maximum segment size block/blk.h | 2 +- drivers/block/null_blk/main.c | 13 +++++++++++++ drivers/block/null_blk/null_blk.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] block: Reduce BLK_MIN_SEGMENT_SIZE 2026-03-23 20:29 [PATCH 0/2] Enable testing small DMA segment sizes Bart Van Assche @ 2026-03-23 20:29 ` Bart Van Assche 2026-03-23 20:29 ` [PATCH 2/2] null_blk: Support configuring the maximum segment size Bart Van Assche 1 sibling, 0 replies; 4+ messages in thread From: Bart Van Assche @ 2026-03-23 20:29 UTC (permalink / raw) To: Jens Axboe Cc: linux-block, Christoph Hellwig, Damien Le Moal, Bart Van Assche, Ming Lei The current value of BLK_MIN_SEGMENT_SIZE, 4096 bytes, makes it impossible to test small DMA segment size support on systems with a virtual memory page size of 4096 bytes. Hence reduce BLK_MIN_SEGMENT_SIZE to 512. There is nothing special about this value - any other value that is a divisor of 4096 and that doesn't cause lim->max_segments to be exceeded would also work. Cc: Ming Lei <ming.lei@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- block/blk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk.h b/block/blk.h index 7082dd5a87f9..7c792c012b0d 100644 --- a/block/blk.h +++ b/block/blk.h @@ -23,7 +23,7 @@ struct elv_change_ctx; #define BLK_DEF_MAX_SECTORS_CAP (SZ_4M >> SECTOR_SHIFT) #define BLK_DEV_MAX_SECTORS (LLONG_MAX >> 9) -#define BLK_MIN_SEGMENT_SIZE 4096 +#define BLK_MIN_SEGMENT_SIZE 512 /* Max future timer expiry for timeouts */ #define BLK_MAX_TIMEOUT (5 * HZ) ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] null_blk: Support configuring the maximum segment size 2026-03-23 20:29 [PATCH 0/2] Enable testing small DMA segment sizes Bart Van Assche 2026-03-23 20:29 ` [PATCH 1/2] block: Reduce BLK_MIN_SEGMENT_SIZE Bart Van Assche @ 2026-03-23 20:29 ` Bart Van Assche 2026-03-24 20:10 ` Damien Le Moal 1 sibling, 1 reply; 4+ messages in thread From: Bart Van Assche @ 2026-03-23 20:29 UTC (permalink / raw) To: Jens Axboe Cc: linux-block, Christoph Hellwig, Damien Le Moal, Bart Van Assche, Ming Lei, Damien Le Moal, Chaitanya Kulkarni, Keith Busch, Johannes Thumshirn, Hans Holmberg, Christophe JAILLET, Nilay Shroff, Kees Cook, Hannes Reinecke, Martin K. Petersen Add support for configuring the maximum segment size. The maximum segment size may be set to a value smaller than the virtual memory page size. Cc: Christoph Hellwig <hch@lst.de> Cc: Ming Lei <ming.lei@redhat.com> Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com> Cc: Chaitanya Kulkarni <kch@nvidia.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- drivers/block/null_blk/main.c | 13 +++++++++++++ drivers/block/null_blk/null_blk.h | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 677ac829ef80..bf63431f6820 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -169,6 +169,10 @@ static int g_max_sectors; module_param_named(max_sectors, g_max_sectors, int, 0444); MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); +static unsigned int g_max_segment_size = BLK_MAX_SEGMENT_SIZE; +module_param_named(max_segment_size, g_max_segment_size, int, 0444); +MODULE_PARM_DESC(max_segment_size, "Maximum size of a segment in bytes"); + static unsigned int nr_devices = 1; module_param(nr_devices, uint, 0444); MODULE_PARM_DESC(nr_devices, "Number of devices to register"); @@ -450,6 +454,7 @@ NULLB_DEVICE_ATTR(home_node, uint, NULL); NULLB_DEVICE_ATTR(queue_mode, uint, NULL); NULLB_DEVICE_ATTR(blocksize, uint, NULL); NULLB_DEVICE_ATTR(max_sectors, uint, NULL); +NULLB_DEVICE_ATTR(max_segment_size, uint, NULL); NULLB_DEVICE_ATTR(irqmode, uint, NULL); NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL); NULLB_DEVICE_ATTR(index, uint, NULL); @@ -608,6 +613,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { &nullb_device_attr_index, &nullb_device_attr_irqmode, &nullb_device_attr_max_sectors, + &nullb_device_attr_max_segment_size, &nullb_device_attr_mbps, &nullb_device_attr_memory_backed, &nullb_device_attr_no_sched, @@ -805,6 +811,7 @@ static struct nullb_device *null_alloc_dev(void) dev->queue_mode = g_queue_mode; dev->blocksize = g_bs; dev->max_sectors = g_max_sectors; + dev->max_segment_size = g_max_segment_size; dev->irqmode = g_irqmode; dev->hw_queue_depth = g_hw_queue_depth; dev->blocking = g_blocking; @@ -1251,6 +1258,9 @@ static blk_status_t null_transfer(struct nullb *nullb, struct page *page, unsigned int valid_len = len; void *p; + WARN_ONCE(len > dev->max_segment_size, "%u > %u\n", len, + dev->max_segment_size); + p = kmap_local_page(page) + off; if (!is_write) { if (dev->zoned) { @@ -1298,6 +1308,8 @@ static blk_status_t null_handle_data_transfer(struct nullb_cmd *cmd, spin_lock_irq(&nullb->lock); rq_for_each_segment(bvec, rq, iter) { len = bvec.bv_len; + len = min(bvec.bv_len, nullb->dev->max_segment_size); + bvec.bv_len = len; if (transferred_bytes + len > max_bytes) len = max_bytes - transferred_bytes; err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, @@ -1961,6 +1973,7 @@ static int null_add_dev(struct nullb_device *dev) .logical_block_size = dev->blocksize, .physical_block_size = dev->blocksize, .max_hw_sectors = dev->max_sectors, + .max_segment_size = dev->max_segment_size, .dma_alignment = 1, }; diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 6c4c4bbe7dad..43dc47789718 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -93,6 +93,7 @@ struct nullb_device { unsigned int queue_mode; /* block interface */ unsigned int blocksize; /* block size */ unsigned int max_sectors; /* Max sectors per command */ + unsigned int max_segment_size; /* Max size of a single DMA segment. */ unsigned int irqmode; /* IRQ completion handler */ unsigned int hw_queue_depth; /* queue depth */ unsigned int index; /* index of the disk, only valid with a disk */ ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] null_blk: Support configuring the maximum segment size 2026-03-23 20:29 ` [PATCH 2/2] null_blk: Support configuring the maximum segment size Bart Van Assche @ 2026-03-24 20:10 ` Damien Le Moal 0 siblings, 0 replies; 4+ messages in thread From: Damien Le Moal @ 2026-03-24 20:10 UTC (permalink / raw) To: Bart Van Assche, Jens Axboe Cc: linux-block, Christoph Hellwig, Ming Lei, Damien Le Moal, Chaitanya Kulkarni, Keith Busch, Johannes Thumshirn, Hans Holmberg, Christophe JAILLET, Nilay Shroff, Kees Cook, Hannes Reinecke, Martin K. Petersen On 2026/03/23 13:29, Bart Van Assche wrote: > Add support for configuring the maximum segment size. The maximum segment > size may be set to a value smaller than the virtual memory page size. > > Cc: Christoph Hellwig <hch@lst.de> > Cc: Ming Lei <ming.lei@redhat.com> > Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com> > Cc: Chaitanya Kulkarni <kch@nvidia.com> > Signed-off-by: Bart Van Assche <bvanassche@acm.org> > --- > drivers/block/null_blk/main.c | 13 +++++++++++++ > drivers/block/null_blk/null_blk.h | 1 + > 2 files changed, 14 insertions(+) > > diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c > index 677ac829ef80..bf63431f6820 100644 > --- a/drivers/block/null_blk/main.c > +++ b/drivers/block/null_blk/main.c > @@ -169,6 +169,10 @@ static int g_max_sectors; > module_param_named(max_sectors, g_max_sectors, int, 0444); > MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); > > +static unsigned int g_max_segment_size = BLK_MAX_SEGMENT_SIZE; > +module_param_named(max_segment_size, g_max_segment_size, int, 0444); > +MODULE_PARM_DESC(max_segment_size, "Maximum size of a segment in bytes"); Maximum size of a DMA segment in bytes ? (to be consistent with the code comment describing this. "segment" alone is not clear...) > + > static unsigned int nr_devices = 1; > module_param(nr_devices, uint, 0444); > MODULE_PARM_DESC(nr_devices, "Number of devices to register"); > @@ -450,6 +454,7 @@ NULLB_DEVICE_ATTR(home_node, uint, NULL); > NULLB_DEVICE_ATTR(queue_mode, uint, NULL); > NULLB_DEVICE_ATTR(blocksize, uint, NULL); > NULLB_DEVICE_ATTR(max_sectors, uint, NULL); > +NULLB_DEVICE_ATTR(max_segment_size, uint, NULL); > NULLB_DEVICE_ATTR(irqmode, uint, NULL); > NULLB_DEVICE_ATTR(hw_queue_depth, uint, NULL); > NULLB_DEVICE_ATTR(index, uint, NULL); > @@ -608,6 +613,7 @@ static struct configfs_attribute *nullb_device_attrs[] = { > &nullb_device_attr_index, > &nullb_device_attr_irqmode, > &nullb_device_attr_max_sectors, > + &nullb_device_attr_max_segment_size, > &nullb_device_attr_mbps, > &nullb_device_attr_memory_backed, > &nullb_device_attr_no_sched, > @@ -805,6 +811,7 @@ static struct nullb_device *null_alloc_dev(void) > dev->queue_mode = g_queue_mode; > dev->blocksize = g_bs; > dev->max_sectors = g_max_sectors; > + dev->max_segment_size = g_max_segment_size; > dev->irqmode = g_irqmode; > dev->hw_queue_depth = g_hw_queue_depth; > dev->blocking = g_blocking; > @@ -1251,6 +1258,9 @@ static blk_status_t null_transfer(struct nullb *nullb, struct page *page, > unsigned int valid_len = len; > void *p; > > + WARN_ONCE(len > dev->max_segment_size, "%u > %u\n", len, > + dev->max_segment_size); > + > p = kmap_local_page(page) + off; > if (!is_write) { > if (dev->zoned) { > @@ -1298,6 +1308,8 @@ static blk_status_t null_handle_data_transfer(struct nullb_cmd *cmd, > spin_lock_irq(&nullb->lock); > rq_for_each_segment(bvec, rq, iter) { > len = bvec.bv_len; > + len = min(bvec.bv_len, nullb->dev->max_segment_size); > + bvec.bv_len = len; > if (transferred_bytes + len > max_bytes) > len = max_bytes - transferred_bytes; > err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset, > @@ -1961,6 +1973,7 @@ static int null_add_dev(struct nullb_device *dev) > .logical_block_size = dev->blocksize, > .physical_block_size = dev->blocksize, > .max_hw_sectors = dev->max_sectors, > + .max_segment_size = dev->max_segment_size, > .dma_alignment = 1, > }; > > diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h > index 6c4c4bbe7dad..43dc47789718 100644 > --- a/drivers/block/null_blk/null_blk.h > +++ b/drivers/block/null_blk/null_blk.h > @@ -93,6 +93,7 @@ struct nullb_device { > unsigned int queue_mode; /* block interface */ > unsigned int blocksize; /* block size */ > unsigned int max_sectors; /* Max sectors per command */ > + unsigned int max_segment_size; /* Max size of a single DMA segment. */ > unsigned int irqmode; /* IRQ completion handler */ > unsigned int hw_queue_depth; /* queue depth */ > unsigned int index; /* index of the disk, only valid with a disk */ -- Damien Le Moal Western Digital Research ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-24 20:10 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-03-23 20:29 [PATCH 0/2] Enable testing small DMA segment sizes Bart Van Assche 2026-03-23 20:29 ` [PATCH 1/2] block: Reduce BLK_MIN_SEGMENT_SIZE Bart Van Assche 2026-03-23 20:29 ` [PATCH 2/2] null_blk: Support configuring the maximum segment size Bart Van Assche 2026-03-24 20:10 ` Damien Le Moal
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox