SSD + TRIM on 4.4.3 boot disk problem

Stephen Welker stephen.welker at nemostar.com.au
Wed Jun 8 19:22:38 PDT 2016


I believe I have discovered a problem with the implementation of SSD/TRIM on DragonFly BSD.

Under all versions back to v3.6 (may be earlier) turning TRIM on the boot or swap disk during the boot process is impossible.

In /etc/fstab it is possible to add the "trim" option to file system mount options. Then you need to set the sysctl variable "kern.cam.da.X.trim_enabled" to the numeric value "1" (X is the disk number). This then allows the disks to mounted with TRIM enabled.

The problem is two fold:

1. The sysctl variable "kern.cam.da.X.trim_enabled" is always set to "0".
2. The disks are mounted before the /etc/rc.d/sysctl script is run.

Thus the mount scripts complain of the "trim" option. In the case of the root partition, the boot process is aborted. With swap, it is ignored and a message is printed.

To fix the problem there are two options:

1. Change the order of rc.d scripts by moving rc.d/sysctl to an earlier invocation, or
2. Patch /sys/bus/cam/scsi/scsi_da.c to set the sysctl variable to the numeric value "1".

In implementing option 1, several other scripts will need to have their rcorder dependancies changed.

In implementing option 2, code in the following region will need to be changed (/sys/bus/cam/scsi/scsi_da.c):

1077         /* Only create the option if the device supports TRIM */
1078         if (softc->disk.d_info.d_trimflag) {
1079                 SYSCTL_ADD_INT(&softc->sysctl_ctx, 
1080                     SYSCTL_CHILDREN(softc->sysctl_tree),
1081                     OID_AUTO,
1082                     "trim_enabled",
1083                     CTLFLAG_RW,
1084                     &softc->trim_enabled,
1085                     0,
1086                     "Enable TRIM for this device (SSD))");
1087         }

My suggestion is to insert the following line of code after line 1078 (before the call to SYSCTL_ADD_INT()):

    softc->trim_enabled = 1;

This will ensure that the sysctl variable will have the correct value available at the time of mounting the disks in fstab. It also will allow the trim option to be set for swap.

Also, should /etc/rc.d/root have the remount of the root file system be changed from:

    mount -u -o rw /

to

    mount -u -o fstab /

to allow for the "trim" (or noatime, etc) options?

I have not filed a bug report until a discussion of the best approach to the solution is found first.

-- 
regards,
Stephen Welker.




More information about the Users mailing list