relan / exfat

Free exFAT file system implementation
GNU General Public License v2.0
789 stars 179 forks source link

Add TRIM support. #90

Closed ephemient closed 6 years ago

ephemient commented 6 years ago

See #85.

This has been lightly tested with filefrag (invoking bmap) and fstrim (ioctl(FITRIM)) on my Linux box sharing an exFAT partition with Windows.

relan commented 6 years ago

Looks very well, thanks! I have only minor remarks about portability (will review closely later).

I'd like to ask you to add TRIM to fsck too (somewhere here), it should be pretty straightforward.

ephemient commented 6 years ago

Do you mean mkfs (link) or fsck (text)?

I'm not sure mkfs needs TRIM support when a user can just run blkdiscard beforehand.

Offline TRIM in fsck seems a little more interesting, but it doesn't look like any other filesystems have this functionality. Maybe something to print out the allocation bitmap? (Like dumpe2fs or xfs_db.) Then a shell script can run blkdiscard or fallocate on the free extents.

relan commented 6 years ago

Do you mean mkfs (link) or fsck (text)?

mkfs, sorry for confusion.

I'm not sure mkfs needs TRIM support when a user can just run blkdiscard beforehand.

Yes, but most users will forget or don't even know about that.

Offline TRIM in fsck seems a little more interesting, but it doesn't look like any other filesystems have this functionality. Maybe something to print out the allocation bitmap?

dumpexfat utility can print used used sectors.

I think fsck does not need to do any TRIM as this is fully covered by fuse-exfat.

ephemient commented 6 years ago

I'm not sure mkfs needs TRIM support when a user can just run blkdiscard beforehand.

Yes, but most users will forget or don't even know about that.

IMO it's a bit dangerous to do by default, and periodic fstrim -a should already be configured on systems where it's desirable. But it's easy enough to add, I suppose.

relan commented 6 years ago

IMO it's a bit dangerous to do by default

Do you mean that there's a chance to recover data after mkfs if it wasn't trimmed?

ephemient commented 6 years ago

Primarily, I'd be concerned that TRIM on an encrypted block device can expose block usage patterns, secondly recovery, and finally, some devices where it might be be slow or buggy.

relan commented 6 years ago

I'd be concerned that TRIM on an encrypted block device can expose block usage patterns, secondly recovery, and finally, some devices where it might be be slow or buggy.

Makes sense. Let's leave trim on mkfs optional.

relan commented 6 years ago

I'm planning a big update, your changes will be included into it. Thanks!

sezuan commented 3 years ago

Is that supposed to work with current distributions? I compiled the trim branch and trim merged into master, but fstrim still fails saying that the discard operation is not supported. I guess all required headers were found:

checking linux/fs.h usability... yes
checking linux/fs.h presence... yes
checking for linux/fs.h... yes
checking for struct fstrim_range... yes