2022-11-09 13:50:52

by Christoph Böhmwalder

[permalink] [raw]
Subject: [PATCH 0/3] Miscellaneous DRBD updates for 6.2

Here are some various updates for DRBD.
The first two are related to the handling of discards in DRBD, and the
third is a resend of [0].

[0] https://lore.kernel.org/all/[email protected]/

Christoph Böhmwalder (2):
drbd: use blk_queue_max_discard_sectors helper
drbd: Store op in drbd_peer_request

Philipp Reisner (1):
drbd: disable discard support if granularity > max

drivers/block/drbd/drbd_int.h | 8 ++-
drivers/block/drbd/drbd_nl.c | 23 +++++++--
drivers/block/drbd/drbd_receiver.c | 81 +++++++++++++++++-------------
drivers/block/drbd/drbd_worker.c | 4 +-
4 files changed, 71 insertions(+), 45 deletions(-)

--
2.38.1



2022-11-09 13:59:13

by Christoph Böhmwalder

[permalink] [raw]
Subject: [PATCH 2/3] drbd: disable discard support if granularity > max

From: Philipp Reisner <[email protected]>

The discard_granularity describes the minimum unit of a discard.
If that is larger than the maximal discard size, we need to disable
discards completely.

Reviewed-by: Joel Colledge <[email protected]>
Signed-off-by: Philipp Reisner <[email protected]>
Signed-off-by: Christoph Böhmwalder <[email protected]>
---
drivers/block/drbd/drbd_nl.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 249eba7d21c2..63f589926d85 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -1256,6 +1256,18 @@ static void fixup_write_zeroes(struct drbd_device *device, struct request_queue
q->limits.max_write_zeroes_sectors = 0;
}

+static void fixup_discard_support(struct drbd_device *device, struct request_queue *q)
+{
+ unsigned int max_discard = device->rq_queue->limits.max_discard_sectors;
+ unsigned int discard_granularity =
+ device->rq_queue->limits.discard_granularity >> SECTOR_SHIFT;
+
+ if (discard_granularity > max_discard) {
+ blk_queue_discard_granularity(q, 0);
+ blk_queue_max_discard_sectors(q, 0);
+ }
+}
+
static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backing_dev *bdev,
unsigned int max_bio_size, struct o_qlim *o)
{
@@ -1288,6 +1300,7 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backi
disk_update_readahead(device->vdisk);
}
fixup_write_zeroes(device, q);
+ fixup_discard_support(device, q);
}

void drbd_reconsider_queue_parameters(struct drbd_device *device, struct drbd_backing_dev *bdev, struct o_qlim *o)
--
2.38.1


2022-11-09 14:06:44

by Christoph Böhmwalder

[permalink] [raw]
Subject: [PATCH 1/3] drbd: use blk_queue_max_discard_sectors helper

We currently only set q->limits.max_discard_sectors, but that is not
enough. Another field, max_hw_discard_sectors, was introduced in
commit 0034af036554 ("block: make /sys/block/<dev>/queue/discard_max_bytes
writeable").

The difference is that max_discard_sectors can be changed from user
space via sysfs, while max_hw_discard_sectors is the "hardware" upper
limit.

So use this helper, which sets both.

This is also a fixup for commit 998e9cbcd615 ("drbd: cleanup
decide_on_discard_support"): if discards are not supported, that does
not necessarily mean we also want to disable write_zeroes.

Fixes: 998e9cbcd615 ("drbd: cleanup decide_on_discard_support")
Reviewed-by: Joel Colledge <[email protected]>
Signed-off-by: Christoph Böhmwalder <[email protected]>
---
drivers/block/drbd/drbd_nl.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
index 864c98e74875..249eba7d21c2 100644
--- a/drivers/block/drbd/drbd_nl.c
+++ b/drivers/block/drbd/drbd_nl.c
@@ -1210,6 +1210,7 @@ static void decide_on_discard_support(struct drbd_device *device,
struct drbd_connection *connection =
first_peer_device(device)->connection;
struct request_queue *q = device->rq_queue;
+ unsigned int max_discard_sectors;

if (bdev && !bdev_max_discard_sectors(bdev->backing_bdev))
goto not_supported;
@@ -1230,15 +1231,14 @@ static void decide_on_discard_support(struct drbd_device *device,
* topology on all peers.
*/
blk_queue_discard_granularity(q, 512);
- q->limits.max_discard_sectors = drbd_max_discard_sectors(connection);
- q->limits.max_write_zeroes_sectors =
- drbd_max_discard_sectors(connection);
+ max_discard_sectors = drbd_max_discard_sectors(connection);
+ blk_queue_max_discard_sectors(q, max_discard_sectors);
+ blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
return;

not_supported:
blk_queue_discard_granularity(q, 0);
- q->limits.max_discard_sectors = 0;
- q->limits.max_write_zeroes_sectors = 0;
+ blk_queue_max_discard_sectors(q, 0);
}

static void fixup_write_zeroes(struct drbd_device *device, struct request_queue *q)
--
2.38.1


2022-11-09 20:08:10

by Chaitanya Kulkarni

[permalink] [raw]
Subject: Re: [PATCH 1/3] drbd: use blk_queue_max_discard_sectors helper

On 11/9/22 05:34, Christoph Böhmwalder wrote:
> We currently only set q->limits.max_discard_sectors, but that is not
> enough. Another field, max_hw_discard_sectors, was introduced in
> commit 0034af036554 ("block: make /sys/block/<dev>/queue/discard_max_bytes
> writeable").
>
> The difference is that max_discard_sectors can be changed from user
> space via sysfs, while max_hw_discard_sectors is the "hardware" upper
> limit.
>
> So use this helper, which sets both.
>
> This is also a fixup for commit 998e9cbcd615 ("drbd: cleanup
> decide_on_discard_support"): if discards are not supported, that does
> not necessarily mean we also want to disable write_zeroes.
>
> Fixes: 998e9cbcd615 ("drbd: cleanup decide_on_discard_support")
> Reviewed-by: Joel Colledge <[email protected]>
> Signed-off-by: Christoph Böhmwalder <[email protected]>
> ---

Using helper is absolutely right way of setting up discard
values...

Reviewed-by: Chaitanya Kulkarni <[email protected]>

-ck