Skip to contentSkip to conversation

target: enable discard if supported by underlying block device

RFC PATCH In review David Disseldorp 3 participants 5 messages Dec 19, 2017 – Jan 13, 2018 SCSI target

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 target: enable discard if supported by underlying block device

The initial commit of LIO (v4.0.0-rc6) came with support for SCSI UNMAP disabled. This was justified in the LIO wiki with:
Many SATA SSDs have issues handling UNMAP properly, so it is disabled per default in LIO.
Since this time, some critical discard bugs have been fixed, e.g. f3f5da624e0a ("block: Do a full clone when splitting discard bios").

Block layer backed logical units are capable of deferring to the block layer when determining UNMAP attributes, but this logic currently leaves the emulate_tpu (UNMAP) and emulate_tpws (WRITE_SAME with UNMAP=1) flags disabled.
With this change, emulate_tpu and emulate_tpws are set for block layer backed logical units based on underlying block device discard support.

---
 drivers/target/target_core_device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/target/target_core_device.c +2 -0
index e8dd6da164b2..65dab7c2460a 100644
@@ -856,6 +856,8 @@ bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
 	attrib->unmap_granularity_alignment = q->limits.discard_alignment /
 								block_size;
 	attrib->unmap_zeroes_data = (q->limits.max_write_zeroes_sectors);
+	attrib->emulate_tpu = 1;
+	attrib->emulate_tpws = 1;
 	return true;
 }
 EXPORT_SYMBOL(target_configure_unmap_from_queue);
Signature · 1 line
2.13.6
#1 lore raw

Ping, any thoughts on this one? I think it makes sense to enable unmap in this case.

Cheers, David

Quoted 32 lines · David Disseldorp

The initial commit of LIO (v4.0.0-rc6) came with support for SCSI UNMAP disabled. This was justified in the LIO wiki with:
Many SATA SSDs have issues handling UNMAP properly, so it is disabled per default in LIO.
Since this time, some critical discard bugs have been fixed, e.g. f3f5da624e0a ("block: Do a full clone when splitting discard bios").

Block layer backed logical units are capable of deferring to the block layer when determining UNMAP attributes, but this logic currently leaves the emulate_tpu (UNMAP) and emulate_tpws (WRITE_SAME with UNMAP=1) flags disabled.
With this change, emulate_tpu and emulate_tpws are set for block layer backed logical units based on underlying block device discard support.

---
 drivers/target/target_core_device.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/target/target_core_device.c +2 -0
index e8dd6da164b2..65dab7c2460a 100644
@@ -856,6 +856,8 @@ bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
 	attrib->unmap_granularity_alignment = q->limits.discard_alignment /
 								block_size;
 	attrib->unmap_zeroes_data = (q->limits.max_write_zeroes_sectors);
+	attrib->emulate_tpu = 1;
+	attrib->emulate_tpws = 1;
 	return true;
 }
 EXPORT_SYMBOL(target_configure_unmap_from_queue);
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Disseldorp
Quoted 11 lines · David Disseldorp

The initial commit of LIO (v4.0.0-rc6) came with support for SCSI UNMAP disabled. This was justified in the LIO wiki with:
Many SATA SSDs have issues handling UNMAP properly, so it is disabled per default in LIO.
Since this time, some critical discard bugs have been fixed, e.g. f3f5da624e0a ("block: Do a full clone when splitting discard bios").

Block layer backed logical units are capable of deferring to the block layer when determining UNMAP attributes, but this logic currently leaves the emulate_tpu (UNMAP) and emulate_tpws (WRITE_SAME with UNMAP=1) flags disabled.

Is there any cases where the user set tpu/tpws to off on purpose to work around a backing device or initiator side issue? If so, I think the only concern would be for non-rtslib based apps. If they did the attrib setting stage after device creation but before the config stage, then this patch would overwrite those settings.

For rtslib based apps, if the user had set tpu/tpws values to off on purpose, it looks like the user requested values will still be used since the attrib setting stage is done after the configure.

If we do not support non rtslib based apps then the patch is nice for users and looks ok.

#3 lore raw
In reply to David Disseldorp

Thanks for the feedback, Mike.

Quoted 10 lines · Mike Christie
Quoted 4 lines

Block layer backed logical units are capable of deferring to the block layer when determining UNMAP attributes, but this logic currently leaves the emulate_tpu (UNMAP) and emulate_tpws (WRITE_SAME with UNMAP=1) flags disabled.

Is there any cases where the user set tpu/tpws to off on purpose to work around a backing device or initiator side issue? If so, I think the only concern would be for non-rtslib based apps. If they did the attrib setting stage after device creation but before the config stage, then this patch would overwrite those settings.

I'm not aware of any such cases, but yes, good point. If this is a concern, then another option would be to change the DA_EMULATE_TPU/TPWS defaults unconditionally (for all backstores), but I that'd lead to other consequences (e.g. on FSes that don't support PUNCH_HOLE).

Quoted 6 lines

For rtslib based apps, if the user had set tpu/tpws values to off on purpose, it looks like the user requested values will still be used since the attrib setting stage is done after the configure.

If we do not support non rtslib based apps then the patch is nice for users and looks ok.

FWIW, I frequently use LIO via configfs directly (without rtslib), so would like to ensure continued compatibility.

Quoted 1 line

Cheers, David

#4 lore raw
In reply to David Disseldorp

Hi David & MNC,

Quoted 15 lines · David Disseldorp

Thanks for the feedback, Mike.

Quoted 10 lines · Mike Christie
Quoted 4 lines

Block layer backed logical units are capable of deferring to the block layer when determining UNMAP attributes, but this logic currently leaves the emulate_tpu (UNMAP) and emulate_tpws (WRITE_SAME with UNMAP=1) flags disabled.

Is there any cases where the user set tpu/tpws to off on purpose to work around a backing device or initiator side issue? If so, I think the only concern would be for non-rtslib based apps. If they did the attrib setting stage after device creation but before the config stage, then this patch would overwrite those settings.

Quoted 5 lines

I'm not aware of any such cases, but yes, good point. If this is a concern, then another option would be to change the DA_EMULATE_TPU/TPWS defaults unconditionally (for all backstores), but I that'd lead to other consequences (e.g. on FSes that don't support PUNCH_HOLE).

I'm reluctant to enable tpu/tpws by default, even when underlying device claims to support it. Primarily because of two issues:

First for IBLOCK, blkdev_issue_discard() does synchronous bio completion. As-is, this causes iscsi-target RX kthreads to block for extended periods of time resulting in NOPs triggering connection reinstatement, et al.

In practice though, out-of-tree bio based backend drivers which actually enable UNMAP + WRITE_SAME w/ UNMAP=1 always end up adding some submit_bio() + async completion mechanism for production usage.

Second, even in my experience with async REQ_OP_DISCARD completion using fast struct block_devices, it's still not very hard for a host (like ESX/VMFS for example) to run into SCSI timeouts with heavy small block I/O + UNMAP workloads.

So enabling this by default for all cases still makes me nervous, without any async REQ_OP_DISCARD completion in place for upstream.