* [PATCH v3 2/3] block: rust: add `discard_granularity` option to `GenDiskBuilder`
@ 2026-12-04 11:43 ` Vitaly Wool
2026-12-04 13:57 ` Andreas Hindborg
2026-12-04 14:01 ` Andreas Hindborg
0 siblings, 2 replies; 3+ messages in thread
From: Vitaly Wool @ 2026-12-04 11:43 UTC (permalink / raw)
To: Jens Axboe, Andreas Hindborg
Cc: Boqun Feng, Miguel Ojeda, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Lorenzo Stoakes, Liam R. Howlett, linux-block,
rust-for-linux, linux-mm, linux-kernel, Igor Belousov,
Vitaly Wool
From: Igor Belousov <igor.b@beldev.am>
Allow Rust block drivers to set the discard granularity of their disks.
It defaults to the physical block size, which is too small for drivers
that can only deallocate larger units: the block layer splits discards
larger than the maximum discard size at multiples of the granularity,
so with a granularity smaller than the driver's unit, a split can fall
in the middle of a unit that neither part then covers in full.
Signed-off-by: Igor Belousov <igor.b@beldev.am>
Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se>
---
rust/kernel/block/mq/gen_disk.rs | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
index 6c25b86558f4..a6480dbf603e 100644
--- a/rust/kernel/block/mq/gen_disk.rs
+++ b/rust/kernel/block/mq/gen_disk.rs
@@ -50,6 +50,7 @@ pub struct GenDiskBuilder<T> {
physical_block_size: u32,
capacity_sectors: u64,
max_hw_discard_sectors: u32,
+ discard_granularity: u32,
#[cfg(CONFIG_BLK_DEV_ZONED)]
zoned: bool,
#[cfg(CONFIG_BLK_DEV_ZONED)]
@@ -72,6 +73,7 @@ fn default() -> Self {
physical_block_size: bindings::PAGE_SIZE as u32,
capacity_sectors: 0,
max_hw_discard_sectors: 0,
+ discard_granularity: 0,
#[cfg(CONFIG_BLK_DEV_ZONED)]
zoned: false,
#[cfg(CONFIG_BLK_DEV_ZONED)]
@@ -154,6 +156,16 @@ pub fn max_hw_discard_sectors(mut self, max_hw_discard_sectors: u32) -> Self {
self
}
+ /// Set the discard granularity of the device to be built, in bytes: the
+ /// smallest unit the device can deallocate. The block layer splits large
+ /// discards at multiples of it.
+ ///
+ /// Setting 0 (default) here makes it the physical block size.
+ pub fn discard_granularity(mut self, granularity: u32) -> Self {
+ self.discard_granularity = granularity;
+ self
+ }
+
/// Mark this device as a zoned block device.
#[cfg(CONFIG_BLK_DEV_ZONED)]
pub fn zoned(mut self, enable: bool) -> Self {
@@ -226,6 +238,7 @@ pub fn build(
lim.logical_block_size = self.logical_block_size;
lim.physical_block_size = self.physical_block_size;
lim.max_hw_discard_sectors = self.max_hw_discard_sectors;
+ lim.discard_granularity = self.discard_granularity;
lim.max_sectors = self.max_sectors;
lim.virt_boundary_mask = self.virt_boundary_mask;
lim.dma_alignment = self.dma_alignment;
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 2/3] block: rust: add `discard_granularity` option to `GenDiskBuilder`
2026-12-04 11:43 ` [PATCH v3 2/3] block: rust: add `discard_granularity` option to `GenDiskBuilder` Vitaly Wool
@ 2026-12-04 13:57 ` Andreas Hindborg
2026-12-04 14:01 ` Andreas Hindborg
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Hindborg @ 2026-12-04 13:57 UTC (permalink / raw)
To: Vitaly Wool, Jens Axboe
Cc: Boqun Feng, Miguel Ojeda, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Lorenzo Stoakes, Liam R. Howlett, linux-block,
rust-for-linux, linux-mm, linux-kernel, Igor Belousov,
Vitaly Wool
"Vitaly Wool" <vitaly.wool@konsulko.se> writes:
> From: Igor Belousov <igor.b@beldev.am>
>
> Allow Rust block drivers to set the discard granularity of their disks.
> It defaults to the physical block size, which is too small for drivers
> that can only deallocate larger units: the block layer splits discards
> larger than the maximum discard size at multiples of the granularity,
> so with a granularity smaller than the driver's unit, a split can fall
> in the middle of a unit that neither part then covers in full.
>
> Signed-off-by: Igor Belousov <igor.b@beldev.am>
> Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.se>
Seems I got it anyway, it is just missing the In-reply-to header or something.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 2/3] block: rust: add `discard_granularity` option to `GenDiskBuilder`
2026-12-04 11:43 ` [PATCH v3 2/3] block: rust: add `discard_granularity` option to `GenDiskBuilder` Vitaly Wool
2026-12-04 13:57 ` Andreas Hindborg
@ 2026-12-04 14:01 ` Andreas Hindborg
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Hindborg @ 2026-12-04 14:01 UTC (permalink / raw)
To: Vitaly Wool, Jens Axboe
Cc: Boqun Feng, Miguel Ojeda, Gary Guo, Björn Roy Baron,
Benno Lossin, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, Lorenzo Stoakes, Liam R. Howlett, linux-block,
rust-for-linux, linux-mm, linux-kernel, Igor Belousov,
Vitaly Wool
"Vitaly Wool" <vitaly.wool@konsulko.se> writes:
> From: Igor Belousov <igor.b@beldev.am>
>
> Allow Rust block drivers to set the discard granularity of their disks.
> It defaults to the physical block size, which is too small for drivers
> that can only deallocate larger units: the block layer splits discards
> larger than the maximum discard size at multiples of the granularity,
> so with a granularity smaller than the driver's unit, a split can fall
> in the middle of a unit that neither part then covers in full.
This change is part of the dependencies for `rufs`[1][2], the Rust UFS
driver [3].
There might be other things you need in that tree.
Best regards,
Andreas Hindborg
[1] https://github.com/SamsungDS/rufs/commit/dbdc0839f0e7eb89a6a203703791a6146827fead
[2] https://github.com/SamsungDS/rufs/commits/rfc/rufs-dependencies
[3] https://lore.kernel.org/r/20260912-rufs-private-v1-1-716db733e655@samsung.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 14:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <FHA1L3XkvQpys1jd3WBYnIx90PNsNAh2SZg5MiiQpj31c5Agu7964PMowq_wrj8ztMcjmpv5E2VYjsx_RK-XVA==@protonmail.internalid>
2026-12-04 11:43 ` [PATCH v3 2/3] block: rust: add `discard_granularity` option to `GenDiskBuilder` Vitaly Wool
2026-12-04 13:57 ` Andreas Hindborg
2026-12-04 14:01 ` Andreas Hindborg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®