1

I run this command:

sg_unmap -v -l 0 -n 1 DEVICE

and it doesn't fail but it also doesn't do anything. when I increase it to n=8 then it's trimming 8 lbas why it's working like that? I couldn't figure it out from the help file.

Is there a relation between minimum number of lbas to the device's properties?

Lio
  • 11

2 Answers2

1

There is no minimum as such. The drive will note down that the sector can be trimmed but it can only erase an entire block when all the sectors in it are marked as discarded.

Since the presented LBA is completely unrelated to the underlying physical LBA due to the flash controller's cell management, it could potentially mean you need to mark many sectors as trimmable before it will will find a entire erase block to purge.

1

There is not a minimum, but there is a granularity and an alignment. So if you ever try to unmap across an odd number of blocks that violates the alignment or granularity you could get an error (sense code). Also the UNMAP SCSI command internally uses a list of descriptors so that it can send different extents of the disk to unmap all in one command -- but each drive type will have a limit on the number of descriptors and the number of LBAs per descriptor. Some drives will let you unmap the entire usable LBA range and it will fit in one descriptor, some other drives (perhaps HUGE ones) will require you to send multiple UNMAP CDBs to cover the entire usable LBA range because you max out on descriptors per UNMAP command or LBAs per descriptor.

The best way to find the fields I'm referring to, since you're already using sg3_utils, is to look at the Block Limits VPD page (page b0h). See below for an example. It's not the best example because this device doesn't support UNMAP, only WRITE SAME w/ UNMAP bit, because it's a QEMU SATA drive (virtual disk). I'm a little fuzzy on this so if you need more details you'll want to check T10 SCSI Block Commands specification (aka SBC-3).

# sg_vpd -p 0xb0 /dev/sda
Block limits VPD page (SBC):
  Write same non-zero (WSNZ): 0
  Maximum compare and write length: 0 blocks [Command not implemented]
  Optimal transfer length granularity: 1 blocks
  Maximum transfer length: 0 blocks [not reported]
  Optimal transfer length: 0 blocks [not reported]
  Maximum prefetch transfer length: 0 blocks [ignored]
  Maximum unmap LBA count: 0 [Unmap command not implemented]
  Maximum unmap block descriptor count: 0 [Unmap command not implemented]
  Optimal unmap granularity: 1 blocks
  Unmap granularity alignment valid: false
  Unmap granularity alignment: 0 [invalid]
  Maximum write same length: 0x3fffc0 blocks
  Maximum atomic transfer length: 0 blocks [not reported]
  Atomic alignment: 0 [unaligned atomic writes permitted]
  Atomic transfer length granularity: 0 [no granularity requirement
  Maximum atomic transfer length with atomic boundary: 0 blocks [not reported]
  Maximum atomic boundary size: 0 blocks [can only write atomic 1 block]
#