Opened 3 years ago

Last modified 9 months ago

#7876 in-progress enhancement

TRIM support for SSDs

Reported by: polari Owned by: axeld
Priority: normal Milestone: R1
Component: File Systems/BFS Version: R1/Development
Keywords: Cc: kallisti5
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

Haiku/BFS should support the TRIM command for solid state drives. http://en.wikipedia.org/wiki/TRIM

Change History (8)

comment:1 Changed 2 years ago by pulkomandy

I just bought an SSD to speed up building Haiku sourcecode a bit.

Any hint on where to work on this in Haiku's architecture ? block cache ? file cache ? filesystem ?

comment:2 Changed 2 years ago by bonefish

Only the file system knows, when it no longer uses a block. So an API must be provided that can be used by the file system. The file cache doesn't know about disks at all, so you don't want to touch that one at all. The block cache does, but its use is optional. So, for convenience, the block cache API can be extended (or maybe doesn't even need to -- there already is a block_cache_discard()), but it cannot be the only API.

What is needed in either case is a new ioctl operation (maybe plus a nicer-to-use wrapper function) that gets propagated to the driver which can issue the command to the hardware. I'm not really familiar with the disk I/O stack (several modules are involved). I believe the simplified call chain is "device -> bus manager -> driver", but since both the ATA and the SCSI stack are involved plus (IIRC) a few helper modules, the chain is probably more than twice as long. Maybe someone who is more familiar with this stuff can give some further hints.

It might also be worthwhile to have a way to query whether trimming is supported, so the invocations can be omitted when not needed. In the case either a second ioctl operation could be added or an existing querying operation could be extended (there isn't any usable padding in the device_geometry structure used by B_GET_GEOMETRY, though).

comment:3 Changed 23 months ago by kallisti5

  • Cc kallisti5 added

For tracking:

  • hrev43845 - PulkoMandy added the ATA "data_set_management_support" (trim) flag to ata_device_infoblock
  • hrev44228 - I added a trace dump of the data_set_management_support to the ahci driver (which seems to be the only add-on using ata_device_infoblock at the moment)

comment:4 Changed 14 months ago by kallisti5

  • hrev44238 - I added a the SCSI_OP_WRITE_SAME command to the ahci driver to perform a trim request. (doesn't actually perform the trim yet though... just check for support and raise a syslog event)
Last edited 14 months ago by kallisti5 (previous) (diff)

comment:5 Changed 9 months ago by axeld

I'm working on a support pretty much like fstrim in Linux. I have no idea how to test it, though, as I don't have a spare SSD or partition on it. Anyone has any idea?

comment:6 Changed 9 months ago by axeld

  • Status changed from new to in-progress

comment:7 Changed 9 months ago by anevilyak

I'd be willing to test on my ssd here if you want to supply a patch once ready.

comment:8 Changed 9 months ago by kallisti5

I have a 24GB PCIe SSD in my Ultrabook that is dedicated to Haiku (and supports TRIM)

As loss of data on the 24GB SSD is a pain but non-catastrophic, count me in as well.

Note: See TracTickets for help on using tickets.