drbd atomic queue limits conversion
Subsystems (2)
Hi Jens,
this is a standalone resend of the drbd queue limits conversion. Philipp said Linbit has reviewed and tested it, and they'll hopefully provide the formal tags for that in a bit.
Diffstat:
drbd_main.c | 13 ++- drbd_nl.c | 210 ++++++++++++++++++++++++++++-------------------------------- 2 files changed, 110 insertions(+), 113 deletions(-)
PATCH 1/7 drbd: pass the max_hw_sectors limit to blk_alloc_disk
Pass a queue_limits structure with the max_hw_sectors limit to blk_alloc_disk instead of updating the limit on the allocated gendisk.
--- drivers/block/drbd/drbd_main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/block/drbd/drbd_main.c +9 -4
@@ -2690,6 +2690,14 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigint id;int vnr = adm_ctx->volume;enum drbd_ret_code err =ERR_NOMEM ; +struct queue_limits lim = { +/* +* Setting the max_hw_sectors to an odd value of 8kibyte here. +* This triggers a max_bio_size message upon first attach or +* connect. +*/ + .max_hw_sectors =DRBD_MAX_BIO_SIZE_SAFE >>8 , + }; device =minor_to_device (minor);if (device)
@@ -2708,7 +2716,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigdrbd_init_set_defaults (device); - disk =blk_alloc_disk (NULL ,NUMA_NO_NODE ); + disk =blk_alloc_disk (&lim,NUMA_NO_NODE );if (IS_ERR (disk)) { err =PTR_ERR (disk); goto out_no_disk;
@@ -2729,9 +2737,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigblk_queue_flag_set (QUEUE_FLAG_STABLE_WRITES , disk->queue);blk_queue_write_cache (disk->queue, true, true); -/* Setting the max_hw_sectors to an odd value of 8kibyte here -This triggers a max_bio_size message upon first attach or connect */ -blk_queue_max_hw_sectors (disk->queue,DRBD_MAX_BIO_SIZE_SAFE >>8 ); device->md_io.page =alloc_page (GFP_KERNEL );if (!device->md_io.page)
Signature · 1 line
2.39.2
PATCH 2/7 drbd: refactor drbd_reconsider_queue_parameters
In reply to Christoph HellwigSplit out a drbd_max_peer_bio_size helper for the peer I/O size, and condense the various checks to a nested min3(..., max())) instead of using a lot of local variables.
--- drivers/block/drbd/drbd_nl.c | 84 +++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 35 deletions(-)
drivers/block/drbd/drbd_nl.c +49 -35
@@ -1189,6 +1189,33 @@ static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc)return 0 ; } +static unsigned int drbd_max_peer_bio_size (struct drbd_device *device) +{ +/* +* We may ignore peer limits if the peer is modern enough. From 8.3.8 +* onwards the peer can use multiple BIOs for a single peer_request. +*/ +if (device->state.conn <C_WF_REPORT_PARAMS ) +return device->peer_max_bio_size; + +if (first_peer_device (device)->connection->agreed_pro_version <94 ) +return min (device->peer_max_bio_size,DRBD_MAX_SIZE_H80_PACKET ); + +/* +* Correct old drbd (up to 8.3.7) if it believes it can do more than +* 32KiB. +*/ +if (first_peer_device (device)->connection->agreed_pro_version ==94 ) +return DRBD_MAX_SIZE_H80_PACKET ; + +/* +* drbd 8.3.8 onwards, before 8.4.0 +*/ +if (first_peer_device (device)->connection->agreed_pro_version <100 ) +return DRBD_MAX_BIO_SIZE_P95 ; +return DRBD_MAX_BIO_SIZE ; +} +static void blk_queue_discard_granularity (struct request_queue *q,unsigned int granularity) { q->limits.discard_granularity = granularity;
@@ -1303,48 +1330,35 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backifixup_discard_support (device, q); } -void drbd_reconsider_queue_parameters (struct drbd_device *device,struct drbd_backing_dev *bdev,struct o_qlim *o) +void drbd_reconsider_queue_parameters (struct drbd_device *device, +struct drbd_backing_dev *bdev,struct o_qlim *o) { -unsigned int now, new, local, peer; - - now =queue_max_hw_sectors (device->rq_queue) <<9 ; - local = device->local_max_bio_size;/* Eventually last known value, from volatile memory */ - peer = device->peer_max_bio_size;/* Eventually last known value, from meta data */ +unsigned int now =queue_max_hw_sectors (device->rq_queue) << +SECTOR_SHIFT ; +unsigned int new;if (bdev) { - local =queue_max_hw_sectors (bdev->backing_bdev->bd_disk->queue) <<9 ; - device->local_max_bio_size = local; - } - local =min (local,DRBD_MAX_BIO_SIZE ); - -/* We may ignore peer limits if the peer is modern enough. -Because new from 8.3.8 onwards the peer can use multiple -BIOs for a single peer_request */ -if (device->state.conn >=C_WF_REPORT_PARAMS ) { -if (first_peer_device (device)->connection->agreed_pro_version <94 ) - peer =min (device->peer_max_bio_size,DRBD_MAX_SIZE_H80_PACKET ); -/* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */ -else if (first_peer_device (device)->connection->agreed_pro_version ==94 ) - peer =DRBD_MAX_SIZE_H80_PACKET ; -else if (first_peer_device (device)->connection->agreed_pro_version <100 ) - peer =DRBD_MAX_BIO_SIZE_P95 ;/* drbd 8.3.8 onwards, before 8.4.0 */ -else - peer =DRBD_MAX_BIO_SIZE ; +struct request_queue *b = bdev->backing_bdev->bd_disk->queue; -/* We may later detach and re-attach on a disconnected Primary. -* Avoid this setting to jump back in that case. -* We want to store what we know the peer DRBD can handle, -* not what the peer IO backend can handle. */ -if (peer > device->peer_max_bio_size) - device->peer_max_bio_size = peer; + device->local_max_bio_size = +queue_max_hw_sectors (b) <<SECTOR_SHIFT ; } - new =min (local, peer); -if (device->state.role ==R_PRIMARY && new < now) -drbd_err (device,"ASSERT FAILED new < now; (%u < %u)\n" , new, now); - -if (new != now) +/* +* We may later detach and re-attach on a disconnected Primary. Avoid +* decreasing the value in this case. +* +* We want to store what we know the peer DRBD can handle, not what the +* peer IO backend can handle. +*/ + new =min3 (DRBD_MAX_BIO_SIZE , device->local_max_bio_size, +max (drbd_max_peer_bio_size (device), device->peer_max_bio_size)); +if (new != now) { +if (device->state.role ==R_PRIMARY && new < now) +drbd_err (device,"ASSERT FAILED new < now; (%u < %u)\n" , + new, now);drbd_info (device,"max BIO size = %u\n" , new); + }drbd_setup_queue_param (device, bdev, new, o); }
Signature · 1 line
2.39.2
PATCH 3/7 drbd: refactor the backing dev max_segments calculation
In reply to Christoph HellwigFactor out a drbd_backing_dev_max_segments helper that checks the backing device limitation.
--- drivers/block/drbd/drbd_nl.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/block/drbd/drbd_nl.c +17 -8
@@ -1295,30 +1295,39 @@ static void fixup_discard_support(struct drbd_device *device, struct request_que } } +/* This is the workaround for "bio would need to, but cannot, be split" */ +static unsigned int drbd_backing_dev_max_segments (struct drbd_device *device) +{ +unsigned int max_segments; + +rcu_read_lock (); + max_segments =rcu_dereference (device->ldev->disk_conf)->max_bio_bvecs; +rcu_read_unlock (); + +if (!max_segments) +return BLK_MAX_SEGMENTS ; +return max_segments; +} +static void drbd_setup_queue_param (struct drbd_device *device,struct drbd_backing_dev *bdev,unsigned int max_bio_size,struct o_qlim *o) {struct request_queue *const q = device->rq_queue;unsigned int max_hw_sectors = max_bio_size >>9 ; -unsigned int max_segments =0 ; +unsigned int max_segments =BLK_MAX_SEGMENTS ;struct request_queue *b =NULL ; -struct disk_conf *dc;if (bdev) { b = bdev->backing_bdev->bd_disk->queue; max_hw_sectors =min (queue_max_hw_sectors (b), max_bio_size >>9 ); -rcu_read_lock (); - dc =rcu_dereference (device->ldev->disk_conf); - max_segments = dc->max_bio_bvecs; -rcu_read_unlock (); + max_segments =drbd_backing_dev_max_segments (device);blk_set_stacking_limits (&q->limits); }blk_queue_max_hw_sectors (q, max_hw_sectors); -/* This is the workaround for "bio would need to, but cannot, be split" */ -blk_queue_max_segments (q, max_segments ? max_segments :BLK_MAX_SEGMENTS ); +blk_queue_max_segments (q, max_segments);blk_queue_segment_boundary (q,PAGE_SIZE -1 );decide_on_discard_support (device, bdev);
Signature · 1 line
2.39.2
PATCH 4/7 drbd: merge drbd_setup_queue_param into drbd_reconsider_queue_parameters
In reply to Christoph Hellwigdrbd_setup_queue_param is only called by drbd_reconsider_queue_parameters and there is no really clear boundary of responsibilities between the two.
--- drivers/block/drbd/drbd_nl.c | 56 ++++++++++++++---------------------- 1 file changed, 22 insertions(+), 34 deletions(-)
drivers/block/drbd/drbd_nl.c +22 -34
@@ -1309,45 +1309,16 @@ static unsigned int drbd_backing_dev_max_segments(struct drbd_device *device)return max_segments; } -static void drbd_setup_queue_param (struct drbd_device *device,struct drbd_backing_dev *bdev, -unsigned int max_bio_size,struct o_qlim *o) -{ -struct request_queue *const q = device->rq_queue; -unsigned int max_hw_sectors = max_bio_size >>9 ; -unsigned int max_segments =BLK_MAX_SEGMENTS ; -struct request_queue *b =NULL ; - -if (bdev) { - b = bdev->backing_bdev->bd_disk->queue; - - max_hw_sectors =min (queue_max_hw_sectors (b), max_bio_size >>9 ); - max_segments =drbd_backing_dev_max_segments (device); - -blk_set_stacking_limits (&q->limits); - } - -blk_queue_max_hw_sectors (q, max_hw_sectors); -blk_queue_max_segments (q, max_segments); -blk_queue_segment_boundary (q,PAGE_SIZE -1 ); -decide_on_discard_support (device, bdev); - -if (b) { -blk_stack_limits (&q->limits, &b->limits,0 ); -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) { -unsigned int now =queue_max_hw_sectors (device->rq_queue) << -SECTOR_SHIFT ; +struct request_queue *const q = device->rq_queue; +unsigned int now =queue_max_hw_sectors (q) <<9 ; +struct request_queue *b =NULL ;unsigned int new;if (bdev) { -struct request_queue *b = bdev->backing_bdev->bd_disk->queue; + b = bdev->backing_bdev->bd_disk->queue; device->local_max_bio_size =queue_max_hw_sectors (b) <<SECTOR_SHIFT ;
@@ -1369,7 +1340,24 @@ void drbd_reconsider_queue_parameters(struct drbd_device *device,drbd_info (device,"max BIO size = %u\n" , new); } -drbd_setup_queue_param (device, bdev, new, o); +if (bdev) { +blk_set_stacking_limits (&q->limits); +blk_queue_max_segments (q, +drbd_backing_dev_max_segments (device)); + }else { +blk_queue_max_segments (q,BLK_MAX_SEGMENTS ); + } + +blk_queue_max_hw_sectors (q, new >>SECTOR_SHIFT ); +blk_queue_segment_boundary (q,PAGE_SIZE -1 ); +decide_on_discard_support (device, bdev); + +if (bdev) { +blk_stack_limits (&q->limits, &b->limits,0 ); +disk_update_readahead (device->vdisk); + } +fixup_write_zeroes (device, q); +fixup_discard_support (device, q); }/* Starts the worker thread */
Signature · 1 line
2.39.2
PATCH 5/7 drbd: don't set max_write_zeroes_sectors in decide_on_discard_support
In reply to Christoph Hellwigfixup_write_zeroes always overrides the max_write_zeroes_sectors value a little further down the callchain, so don't bother to setup a limit in decide_on_discard_support.
--- drivers/block/drbd/drbd_nl.c | 1 - 1 file changed, 1 deletion(-)
drivers/block/drbd/drbd_nl.c +0 -1
@@ -1260,7 +1260,6 @@ static void decide_on_discard_support(struct drbd_device *device,blk_queue_discard_granularity (q,512 ); 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:
Signature · 1 line
2.39.2
PATCH 6/7 drbd: split out a drbd_discard_supported helper
In reply to Christoph HellwigAdd a helper to check if discard is supported for a given connection / backing device combination.
--- drivers/block/drbd/drbd_nl.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/block/drbd/drbd_nl.c +17 -8
@@ -1231,24 +1231,33 @@ static unsigned int drbd_max_discard_sectors(struct drbd_connection *connection)return AL_EXTENT_SIZE >>9 ; } -static void decide_on_discard_support (struct drbd_device *device, +static bool drbd_discard_supported (struct drbd_connection *connection,struct drbd_backing_dev *bdev) { -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; +return false;if (connection->cstate >=C_CONNECTED && !(connection->agreed_features &DRBD_FF_TRIM )) {drbd_info (connection,"peer DRBD too old, does not support TRIM: disabling discards\n" ); - goto not_supported; +return false; } +return true; +} + +static void decide_on_discard_support (struct drbd_device *device, +struct drbd_backing_dev *bdev) +{ +struct drbd_connection *connection = +first_peer_device (device)->connection; +struct request_queue *q = device->rq_queue; +unsigned int max_discard_sectors; + +if (!drbd_discard_supported (connection, bdev)) + goto not_supported; +/* * We don't care for the granularity, really. *
Signature · 1 line
2.39.2
PATCH 7/7 drbd: atomically update queue limits in drbd_reconsider_queue_parameters
In reply to Christoph HellwigSwitch drbd_reconsider_queue_parameters to set up the queue parameters in an on-stack queue_limits structure and apply the atomically. Remove various helpers that have become so trivial that they can be folded into drbd_reconsider_queue_parameters.
--- drivers/block/drbd/drbd_nl.c | 119 ++++++++++++++--------------------- 1 file changed, 46 insertions(+), 73 deletions(-)
drivers/block/drbd/drbd_nl.c +46 -73
@@ -1216,11 +1216,6 @@ static unsigned int drbd_max_peer_bio_size(struct drbd_device *device)return DRBD_MAX_BIO_SIZE ; } -static void blk_queue_discard_granularity (struct request_queue *q,unsigned int granularity) -{ - q->limits.discard_granularity = granularity; -} -static unsigned int drbd_max_discard_sectors (struct drbd_connection *connection) {/* when we introduced REQ_WRITE_SAME support, we also bumped
@@ -1247,62 +1242,6 @@ static bool drbd_discard_supported(struct drbd_connection *connection,return true; } -static void decide_on_discard_support (struct drbd_device *device, -struct drbd_backing_dev *bdev) -{ -struct drbd_connection *connection = -first_peer_device (device)->connection; -struct request_queue *q = device->rq_queue; -unsigned int max_discard_sectors; - -if (!drbd_discard_supported (connection, bdev)) - goto not_supported; - -/* -* We don't care for the granularity, really. -* -* Stacking limits below should fix it for the local device. Whether or -* not it is a suitable granularity on the remote device is not our -* problem, really. If you care, you need to use devices with similar -* topology on all peers. -*/ -blk_queue_discard_granularity (q,512 ); - max_discard_sectors =drbd_max_discard_sectors (connection); -blk_queue_max_discard_sectors (q, max_discard_sectors); -return ; - -not_supported: -blk_queue_discard_granularity (q,0 ); -blk_queue_max_discard_sectors (q,0 ); -} - -static void fixup_write_zeroes (struct drbd_device *device,struct request_queue *q) -{ -/* Fixup max_write_zeroes_sectors after blk_stack_limits(): -* if we can handle "zeroes" efficiently on the protocol, -* we want to do that, even if our backend does not announce -* max_write_zeroes_sectors itself. */ -struct drbd_connection *connection =first_peer_device (device)->connection; -/* If the peer announces WZEROES support, use it. Otherwise, rather -* send explicit zeroes than rely on some discard-zeroes-data magic. */ -if (connection->agreed_features &DRBD_FF_WZEROES ) - q->limits.max_write_zeroes_sectors =DRBD_MAX_BBIO_SECTORS ; -else - 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 ); - } -} -/* This is the workaround for "bio would need to, but cannot, be split" */ static unsigned int drbd_backing_dev_max_segments (struct drbd_device *device) {
@@ -1320,8 +1259,11 @@ static unsigned int drbd_backing_dev_max_segments(struct drbd_device *device)void drbd_reconsider_queue_parameters (struct drbd_device *device,struct drbd_backing_dev *bdev,struct o_qlim *o) { +struct drbd_connection *connection = +first_peer_device (device)->connection;struct request_queue *const q = device->rq_queue;unsigned int now =queue_max_hw_sectors (q) <<9 ; +struct queue_limits lim;struct request_queue *b =NULL ;unsigned int new;
@@ -1348,24 +1290,55 @@ void drbd_reconsider_queue_parameters(struct drbd_device *device,drbd_info (device,"max BIO size = %u\n" , new); } + lim =queue_limits_start_update (q);if (bdev) { -blk_set_stacking_limits (&q->limits); -blk_queue_max_segments (q, -drbd_backing_dev_max_segments (device)); +blk_set_stacking_limits (&lim); + lim.max_segments =drbd_backing_dev_max_segments (device); }else { -blk_queue_max_segments (q,BLK_MAX_SEGMENTS ); + lim.max_segments =BLK_MAX_SEGMENTS ; } -blk_queue_max_hw_sectors (q, new >>SECTOR_SHIFT ); -blk_queue_segment_boundary (q,PAGE_SIZE -1 ); -decide_on_discard_support (device, bdev); + lim.max_hw_sectors = new >>SECTOR_SHIFT ; + lim.seg_boundary_mask =PAGE_SIZE -1 ; -if (bdev) { -blk_stack_limits (&q->limits, &b->limits,0 ); -disk_update_readahead (device->vdisk); +/* +* We don't care for the granularity, really. +* +* Stacking limits below should fix it for the local device. Whether or +* not it is a suitable granularity on the remote device is not our +* problem, really. If you care, you need to use devices with similar +* topology on all peers. +*/ +if (drbd_discard_supported (connection, bdev)) { + lim.discard_granularity =512 ; + lim.max_hw_discard_sectors = +drbd_max_discard_sectors (connection); + }else { + lim.discard_granularity =0 ; + lim.max_hw_discard_sectors =0 ; } -fixup_write_zeroes (device, q); -fixup_discard_support (device, q); + +if (bdev) +blk_stack_limits (&lim, &b->limits,0 ); + +/* +* If we can handle "zeroes" efficiently on the protocol, we want to do +* that, even if our backend does not announce max_write_zeroes_sectors +* itself. +*/ +if (connection->agreed_features &DRBD_FF_WZEROES ) + lim.max_write_zeroes_sectors =DRBD_MAX_BBIO_SECTORS ; +else + lim.max_write_zeroes_sectors =0 ; + +if ((lim.discard_granularity >>SECTOR_SHIFT ) > + lim.max_hw_discard_sectors) { + lim.discard_granularity =0 ; + lim.max_hw_discard_sectors =0 ; + } + +if (queue_limits_commit_update (q, &lim)) +drbd_err (device,"setting new queue limits failed\n" ); }/* Starts the worker thread */
Signature · 1 line
2.39.2
Philipp Reisner
maintainercover drbd atomic queue limits conversion
In reply to Christoph HellwigHello Jens,
Here, with the Reviewed-by and Tested-by trailers.
Christoph Hellwig (7):
drbd: pass the max_hw_sectors limit to blk_alloc_disk
drbd: refactor drbd_reconsider_queue_parameters
drbd: refactor the backing dev max_segments calculation
drbd: merge drbd_setup_queue_param into
drbd_reconsider_queue_parameters
drbd: don't set max_write_zeroes_sectors in decide_on_discard_support
drbd: split out a drbd_discard_supported helper
drbd: atomically update queue limits in
drbd_reconsider_queue_parameters
drivers/block/drbd/drbd_main.c | 13 +- drivers/block/drbd/drbd_nl.c | 210 ++++++++++++++++----------------- 2 files changed, 110 insertions(+), 113 deletions(-)
Signature · 1 line
2.40.1
Quoted 13 lines · Philipp Reisner
Here, with the Reviewed-by and Tested-by trailers.
Christoph Hellwig (7):
drbd: pass themax_hw_sectorslimit toblk_alloc_disk
drbd: refactordrbd_reconsider_queue_parameters
drbd: refactor the backing devmax_segmentscalculation
drbd: mergedrbd_setup_queue_paraminto
drbd_reconsider_queue_parameters
drbd: don't setmax_write_zeroes_sectorsindecide_on_discard_support
drbd: split out adrbd_discard_supportedhelper
drbd: atomically update queue limits in
drbd_reconsider_queue_parameters
Quoted 1 line
[...]
Applied, thanks!
[1/7] drbd: pass the max_hw_sectors limit to blk_alloc_disk
commit: aa067325c05dc3a3aac588f40cacf8418f916cee
[2/7] drbd: refactor drbd_reconsider_queue_parameters
commit: 342d81fde24152adf9747e6e126c8c3179d1a54c
[3/7] drbd: refactor the backing dev max_segments calculation
commit: 2828908d5cc8396e7c91d04d67e03ed834234bcd
[4/7] drbd: merge drbd_setup_queue_param into drbd_reconsider_queue_parameters
commit: e16344e506314e35b1a5a8ccd7b88f4b1844ebb0
[5/7] drbd: don't set max_write_zeroes_sectors in decide_on_discard_support
commit: e3992e02c970f6eb803b98b9f733cad40f190161
[6/7] drbd: split out a drbd_discard_supported helper
commit: 5eaee6e9c8f9940ecee93678972774fb8dd450d5
[7/7] drbd: atomically update queue limits in drbd_reconsider_queue_parameters
commit: e6dfe748f09e37f77437bd337f891f5b57d5d5a2Best regards,
Signature · 1 line
Jens Axboe
Philipp Reisner
maintainerPATCH 1/7 drbd: pass the max_hw_sectors limit to blk_alloc_disk
In reply to Christoph HellwigFrom: Christoph Hellwig <[email protected]>
Pass a queue_limits structure with the max_hw_sectors limit to blk_alloc_disk instead of updating the limit on the allocated gendisk.
--- drivers/block/drbd/drbd_main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/block/drbd/drbd_main.c +9 -4
@@ -2690,6 +2690,14 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigint id;int vnr = adm_ctx->volume;enum drbd_ret_code err =ERR_NOMEM ; +struct queue_limits lim = { +/* +* Setting the max_hw_sectors to an odd value of 8kibyte here. +* This triggers a max_bio_size message upon first attach or +* connect. +*/ + .max_hw_sectors =DRBD_MAX_BIO_SIZE_SAFE >>8 , + }; device =minor_to_device (minor);if (device)
@@ -2708,7 +2716,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigdrbd_init_set_defaults (device); - disk =blk_alloc_disk (NULL ,NUMA_NO_NODE ); + disk =blk_alloc_disk (&lim,NUMA_NO_NODE );if (IS_ERR (disk)) { err =PTR_ERR (disk); goto out_no_disk;
@@ -2729,9 +2737,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsigblk_queue_flag_set (QUEUE_FLAG_STABLE_WRITES , disk->queue);blk_queue_write_cache (disk->queue, true, true); -/* Setting the max_hw_sectors to an odd value of 8kibyte here -This triggers a max_bio_size message upon first attach or connect */ -blk_queue_max_hw_sectors (disk->queue,DRBD_MAX_BIO_SIZE_SAFE >>8 ); device->md_io.page =alloc_page (GFP_KERNEL );if (!device->md_io.page)
Signature · 1 line
2.40.1
Philipp Reisner
maintainerPATCH 2/7 drbd: refactor drbd_reconsider_queue_parameters
In reply to Christoph HellwigFrom: Christoph Hellwig <[email protected]>
Split out a drbd_max_peer_bio_size helper for the peer I/O size, and condense the various checks to a nested min3(..., max())) instead of using a lot of local variables.
--- drivers/block/drbd/drbd_nl.c | 84 +++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 35 deletions(-)
drivers/block/drbd/drbd_nl.c +49 -35
@@ -1189,6 +1189,33 @@ static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc)return 0 ; } +static unsigned int drbd_max_peer_bio_size (struct drbd_device *device) +{ +/* +* We may ignore peer limits if the peer is modern enough. From 8.3.8 +* onwards the peer can use multiple BIOs for a single peer_request. +*/ +if (device->state.conn <C_WF_REPORT_PARAMS ) +return device->peer_max_bio_size; + +if (first_peer_device (device)->connection->agreed_pro_version <94 ) +return min (device->peer_max_bio_size,DRBD_MAX_SIZE_H80_PACKET ); + +/* +* Correct old drbd (up to 8.3.7) if it believes it can do more than +* 32KiB. +*/ +if (first_peer_device (device)->connection->agreed_pro_version ==94 ) +return DRBD_MAX_SIZE_H80_PACKET ; + +/* +* drbd 8.3.8 onwards, before 8.4.0 +*/ +if (first_peer_device (device)->connection->agreed_pro_version <100 ) +return DRBD_MAX_BIO_SIZE_P95 ; +return DRBD_MAX_BIO_SIZE ; +} +static void blk_queue_discard_granularity (struct request_queue *q,unsigned int granularity) { q->limits.discard_granularity = granularity;
@@ -1303,48 +1330,35 @@ static void drbd_setup_queue_param(struct drbd_device *device, struct drbd_backifixup_discard_support (device, q); } -void drbd_reconsider_queue_parameters (struct drbd_device *device,struct drbd_backing_dev *bdev,struct o_qlim *o) +void drbd_reconsider_queue_parameters (struct drbd_device *device, +struct drbd_backing_dev *bdev,struct o_qlim *o) { -unsigned int now, new, local, peer; - - now =queue_max_hw_sectors (device->rq_queue) <<9 ; - local = device->local_max_bio_size;/* Eventually last known value, from volatile memory */ - peer = device->peer_max_bio_size;/* Eventually last known value, from meta data */ +unsigned int now =queue_max_hw_sectors (device->rq_queue) << +SECTOR_SHIFT ; +unsigned int new;if (bdev) { - local =queue_max_hw_sectors (bdev->backing_bdev->bd_disk->queue) <<9 ; - device->local_max_bio_size = local; - } - local =min (local,DRBD_MAX_BIO_SIZE ); - -/* We may ignore peer limits if the peer is modern enough. -Because new from 8.3.8 onwards the peer can use multiple -BIOs for a single peer_request */ -if (device->state.conn >=C_WF_REPORT_PARAMS ) { -if (first_peer_device (device)->connection->agreed_pro_version <94 ) - peer =min (device->peer_max_bio_size,DRBD_MAX_SIZE_H80_PACKET ); -/* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */ -else if (first_peer_device (device)->connection->agreed_pro_version ==94 ) - peer =DRBD_MAX_SIZE_H80_PACKET ; -else if (first_peer_device (device)->connection->agreed_pro_version <100 ) - peer =DRBD_MAX_BIO_SIZE_P95 ;/* drbd 8.3.8 onwards, before 8.4.0 */ -else - peer =DRBD_MAX_BIO_SIZE ; +struct request_queue *b = bdev->backing_bdev->bd_disk->queue; -/* We may later detach and re-attach on a disconnected Primary. -* Avoid this setting to jump back in that case. -* We want to store what we know the peer DRBD can handle, -* not what the peer IO backend can handle. */ -if (peer > device->peer_max_bio_size) - device->peer_max_bio_size = peer; + device->local_max_bio_size = +queue_max_hw_sectors (b) <<SECTOR_SHIFT ; } - new =min (local, peer); -if (device->state.role ==R_PRIMARY && new < now) -drbd_err (device,"ASSERT FAILED new < now; (%u < %u)\n" , new, now); - -if (new != now) +/* +* We may later detach and re-attach on a disconnected Primary. Avoid +* decreasing the value in this case. +* +* We want to store what we know the peer DRBD can handle, not what the +* peer IO backend can handle. +*/ + new =min3 (DRBD_MAX_BIO_SIZE , device->local_max_bio_size, +max (drbd_max_peer_bio_size (device), device->peer_max_bio_size)); +if (new != now) { +if (device->state.role ==R_PRIMARY && new < now) +drbd_err (device,"ASSERT FAILED new < now; (%u < %u)\n" , + new, now);drbd_info (device,"max BIO size = %u\n" , new); + }drbd_setup_queue_param (device, bdev, new, o); }
Signature · 1 line
2.40.1
Philipp Reisner
maintainerPATCH 3/7 drbd: refactor the backing dev max_segments calculation
In reply to Christoph HellwigFrom: Christoph Hellwig <[email protected]>
Factor out a drbd_backing_dev_max_segments helper that checks the backing device limitation.
--- drivers/block/drbd/drbd_nl.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/block/drbd/drbd_nl.c +17 -8
@@ -1295,30 +1295,39 @@ static void fixup_discard_support(struct drbd_device *device, struct request_que } } +/* This is the workaround for "bio would need to, but cannot, be split" */ +static unsigned int drbd_backing_dev_max_segments (struct drbd_device *device) +{ +unsigned int max_segments; + +rcu_read_lock (); + max_segments =rcu_dereference (device->ldev->disk_conf)->max_bio_bvecs; +rcu_read_unlock (); + +if (!max_segments) +return BLK_MAX_SEGMENTS ; +return max_segments; +} +static void drbd_setup_queue_param (struct drbd_device *device,struct drbd_backing_dev *bdev,unsigned int max_bio_size,struct o_qlim *o) {struct request_queue *const q = device->rq_queue;unsigned int max_hw_sectors = max_bio_size >>9 ; -unsigned int max_segments =0 ; +unsigned int max_segments =BLK_MAX_SEGMENTS ;struct request_queue *b =NULL ; -struct disk_conf *dc;if (bdev) { b = bdev->backing_bdev->bd_disk->queue; max_hw_sectors =min (queue_max_hw_sectors (b), max_bio_size >>9 ); -rcu_read_lock (); - dc =rcu_dereference (device->ldev->disk_conf); - max_segments = dc->max_bio_bvecs; -rcu_read_unlock (); + max_segments =drbd_backing_dev_max_segments (device);blk_set_stacking_limits (&q->limits); }blk_queue_max_hw_sectors (q, max_hw_sectors); -/* This is the workaround for "bio would need to, but cannot, be split" */ -blk_queue_max_segments (q, max_segments ? max_segments :BLK_MAX_SEGMENTS ); +blk_queue_max_segments (q, max_segments);blk_queue_segment_boundary (q,PAGE_SIZE -1 );decide_on_discard_support (device, bdev);
Signature · 1 line
2.40.1
Philipp Reisner
maintainerPATCH 4/7 drbd: merge drbd_setup_queue_param into drbd_reconsider_queue_parameters
In reply to Christoph HellwigFrom: Christoph Hellwig <[email protected]>
drbd_setup_queue_param is only called by drbd_reconsider_queue_parameters and there is no really clear boundary of responsibilities between the two.
--- drivers/block/drbd/drbd_nl.c | 56 ++++++++++++++---------------------- 1 file changed, 22 insertions(+), 34 deletions(-)
drivers/block/drbd/drbd_nl.c +22 -34
@@ -1309,45 +1309,16 @@ static unsigned int drbd_backing_dev_max_segments(struct drbd_device *device)return max_segments; } -static void drbd_setup_queue_param (struct drbd_device *device,struct drbd_backing_dev *bdev, -unsigned int max_bio_size,struct o_qlim *o) -{ -struct request_queue *const q = device->rq_queue; -unsigned int max_hw_sectors = max_bio_size >>9 ; -unsigned int max_segments =BLK_MAX_SEGMENTS ; -struct request_queue *b =NULL ; - -if (bdev) { - b = bdev->backing_bdev->bd_disk->queue; - - max_hw_sectors =min (queue_max_hw_sectors (b), max_bio_size >>9 ); - max_segments =drbd_backing_dev_max_segments (device); - -blk_set_stacking_limits (&q->limits); - } - -blk_queue_max_hw_sectors (q, max_hw_sectors); -blk_queue_max_segments (q, max_segments); -blk_queue_segment_boundary (q,PAGE_SIZE -1 ); -decide_on_discard_support (device, bdev); - -if (b) { -blk_stack_limits (&q->limits, &b->limits,0 ); -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) { -unsigned int now =queue_max_hw_sectors (device->rq_queue) << -SECTOR_SHIFT ; +struct request_queue *const q = device->rq_queue; +unsigned int now =queue_max_hw_sectors (q) <<9 ; +struct request_queue *b =NULL ;unsigned int new;if (bdev) { -struct request_queue *b = bdev->backing_bdev->bd_disk->queue; + b = bdev->backing_bdev->bd_disk->queue; device->local_max_bio_size =queue_max_hw_sectors (b) <<SECTOR_SHIFT ;
@@ -1369,7 +1340,24 @@ void drbd_reconsider_queue_parameters(struct drbd_device *device,drbd_info (device,"max BIO size = %u\n" , new); } -drbd_setup_queue_param (device, bdev, new, o); +if (bdev) { +blk_set_stacking_limits (&q->limits); +blk_queue_max_segments (q, +drbd_backing_dev_max_segments (device)); + }else { +blk_queue_max_segments (q,BLK_MAX_SEGMENTS ); + } + +blk_queue_max_hw_sectors (q, new >>SECTOR_SHIFT ); +blk_queue_segment_boundary (q,PAGE_SIZE -1 ); +decide_on_discard_support (device, bdev); + +if (bdev) { +blk_stack_limits (&q->limits, &b->limits,0 ); +disk_update_readahead (device->vdisk); + } +fixup_write_zeroes (device, q); +fixup_discard_support (device, q); }/* Starts the worker thread */
Signature · 1 line
2.40.1
Philipp Reisner
maintainerPATCH 5/7 drbd: don't set max_write_zeroes_sectors in decide_on_discard_support
In reply to Christoph HellwigFrom: Christoph Hellwig <[email protected]>
fixup_write_zeroes always overrides the max_write_zeroes_sectors value a little further down the callchain, so don't bother to setup a limit in decide_on_discard_support.
--- drivers/block/drbd/drbd_nl.c | 1 - 1 file changed, 1 deletion(-)
drivers/block/drbd/drbd_nl.c +0 -1
@@ -1260,7 +1260,6 @@ static void decide_on_discard_support(struct drbd_device *device,blk_queue_discard_granularity (q,512 ); 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:
Signature · 1 line
2.40.1
Philipp Reisner
maintainerPATCH 6/7 drbd: split out a drbd_discard_supported helper
In reply to Christoph HellwigFrom: Christoph Hellwig <[email protected]>
Add a helper to check if discard is supported for a given connection / backing device combination.
--- drivers/block/drbd/drbd_nl.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/block/drbd/drbd_nl.c +17 -8
@@ -1231,24 +1231,33 @@ static unsigned int drbd_max_discard_sectors(struct drbd_connection *connection)return AL_EXTENT_SIZE >>9 ; } -static void decide_on_discard_support (struct drbd_device *device, +static bool drbd_discard_supported (struct drbd_connection *connection,struct drbd_backing_dev *bdev) { -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; +return false;if (connection->cstate >=C_CONNECTED && !(connection->agreed_features &DRBD_FF_TRIM )) {drbd_info (connection,"peer DRBD too old, does not support TRIM: disabling discards\n" ); - goto not_supported; +return false; } +return true; +} + +static void decide_on_discard_support (struct drbd_device *device, +struct drbd_backing_dev *bdev) +{ +struct drbd_connection *connection = +first_peer_device (device)->connection; +struct request_queue *q = device->rq_queue; +unsigned int max_discard_sectors; + +if (!drbd_discard_supported (connection, bdev)) + goto not_supported; +/* * We don't care for the granularity, really. *
Signature · 1 line
2.40.1
Philipp Reisner
maintainerPATCH 7/7 drbd: atomically update queue limits in drbd_reconsider_queue_parameters
In reply to Christoph HellwigFrom: Christoph Hellwig <[email protected]>
Switch drbd_reconsider_queue_parameters to set up the queue parameters in an on-stack queue_limits structure and apply the atomically. Remove various helpers that have become so trivial that they can be folded into drbd_reconsider_queue_parameters.
--- drivers/block/drbd/drbd_nl.c | 119 ++++++++++++++--------------------- 1 file changed, 46 insertions(+), 73 deletions(-)
drivers/block/drbd/drbd_nl.c +46 -73
@@ -1216,11 +1216,6 @@ static unsigned int drbd_max_peer_bio_size(struct drbd_device *device)return DRBD_MAX_BIO_SIZE ; } -static void blk_queue_discard_granularity (struct request_queue *q,unsigned int granularity) -{ - q->limits.discard_granularity = granularity; -} -static unsigned int drbd_max_discard_sectors (struct drbd_connection *connection) {/* when we introduced REQ_WRITE_SAME support, we also bumped
@@ -1247,62 +1242,6 @@ static bool drbd_discard_supported(struct drbd_connection *connection,return true; } -static void decide_on_discard_support (struct drbd_device *device, -struct drbd_backing_dev *bdev) -{ -struct drbd_connection *connection = -first_peer_device (device)->connection; -struct request_queue *q = device->rq_queue; -unsigned int max_discard_sectors; - -if (!drbd_discard_supported (connection, bdev)) - goto not_supported; - -/* -* We don't care for the granularity, really. -* -* Stacking limits below should fix it for the local device. Whether or -* not it is a suitable granularity on the remote device is not our -* problem, really. If you care, you need to use devices with similar -* topology on all peers. -*/ -blk_queue_discard_granularity (q,512 ); - max_discard_sectors =drbd_max_discard_sectors (connection); -blk_queue_max_discard_sectors (q, max_discard_sectors); -return ; - -not_supported: -blk_queue_discard_granularity (q,0 ); -blk_queue_max_discard_sectors (q,0 ); -} - -static void fixup_write_zeroes (struct drbd_device *device,struct request_queue *q) -{ -/* Fixup max_write_zeroes_sectors after blk_stack_limits(): -* if we can handle "zeroes" efficiently on the protocol, -* we want to do that, even if our backend does not announce -* max_write_zeroes_sectors itself. */ -struct drbd_connection *connection =first_peer_device (device)->connection; -/* If the peer announces WZEROES support, use it. Otherwise, rather -* send explicit zeroes than rely on some discard-zeroes-data magic. */ -if (connection->agreed_features &DRBD_FF_WZEROES ) - q->limits.max_write_zeroes_sectors =DRBD_MAX_BBIO_SECTORS ; -else - 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 ); - } -} -/* This is the workaround for "bio would need to, but cannot, be split" */ static unsigned int drbd_backing_dev_max_segments (struct drbd_device *device) {
@@ -1320,8 +1259,11 @@ static unsigned int drbd_backing_dev_max_segments(struct drbd_device *device)void drbd_reconsider_queue_parameters (struct drbd_device *device,struct drbd_backing_dev *bdev,struct o_qlim *o) { +struct drbd_connection *connection = +first_peer_device (device)->connection;struct request_queue *const q = device->rq_queue;unsigned int now =queue_max_hw_sectors (q) <<9 ; +struct queue_limits lim;struct request_queue *b =NULL ;unsigned int new;
@@ -1348,24 +1290,55 @@ void drbd_reconsider_queue_parameters(struct drbd_device *device,drbd_info (device,"max BIO size = %u\n" , new); } + lim =queue_limits_start_update (q);if (bdev) { -blk_set_stacking_limits (&q->limits); -blk_queue_max_segments (q, -drbd_backing_dev_max_segments (device)); +blk_set_stacking_limits (&lim); + lim.max_segments =drbd_backing_dev_max_segments (device); }else { -blk_queue_max_segments (q,BLK_MAX_SEGMENTS ); + lim.max_segments =BLK_MAX_SEGMENTS ; } -blk_queue_max_hw_sectors (q, new >>SECTOR_SHIFT ); -blk_queue_segment_boundary (q,PAGE_SIZE -1 ); -decide_on_discard_support (device, bdev); + lim.max_hw_sectors = new >>SECTOR_SHIFT ; + lim.seg_boundary_mask =PAGE_SIZE -1 ; -if (bdev) { -blk_stack_limits (&q->limits, &b->limits,0 ); -disk_update_readahead (device->vdisk); +/* +* We don't care for the granularity, really. +* +* Stacking limits below should fix it for the local device. Whether or +* not it is a suitable granularity on the remote device is not our +* problem, really. If you care, you need to use devices with similar +* topology on all peers. +*/ +if (drbd_discard_supported (connection, bdev)) { + lim.discard_granularity =512 ; + lim.max_hw_discard_sectors = +drbd_max_discard_sectors (connection); + }else { + lim.discard_granularity =0 ; + lim.max_hw_discard_sectors =0 ; } -fixup_write_zeroes (device, q); -fixup_discard_support (device, q); + +if (bdev) +blk_stack_limits (&lim, &b->limits,0 ); + +/* +* If we can handle "zeroes" efficiently on the protocol, we want to do +* that, even if our backend does not announce max_write_zeroes_sectors +* itself. +*/ +if (connection->agreed_features &DRBD_FF_WZEROES ) + lim.max_write_zeroes_sectors =DRBD_MAX_BBIO_SECTORS ; +else + lim.max_write_zeroes_sectors =0 ; + +if ((lim.discard_granularity >>SECTOR_SHIFT ) > + lim.max_hw_discard_sectors) { + lim.discard_granularity =0 ; + lim.max_hw_discard_sectors =0 ; + } + +if (queue_limits_commit_update (q, &lim)) +drbd_err (device,"setting new queue limits failed\n" ); }/* Starts the worker thread */
Signature · 1 line
2.40.1