SSD + TRIM on 4.4.3 boot disk problem

Matthew Dillon dillon at backplane.com
Thu Jun 9 13:40:18 PDT 2016


This is a bit harder to fix, because we really don't want there to be any
TRIM support turned on by default.

I think the best solution is probably to have a loader tunable that the
kernel uses to set the default(s).  Loader tunables become kernel env
variables which the kernel uses to initialize various defaults long before
anything is mounted.

So, for example, the trim sysctl for /dev/daXX is installed in
/usr/src/sys/bus/cam/scsi/scsi_da.c  ... to set the default with a loader
tunable, one would want to use kgetenv() to set the default in
sc->trim_enabled just before the SYSCTL_ADD_INT() that installs trim.
Around line 1079.

I haven't gone through all the layers of trim enablement but that's the
basic idea.

-Matt

On Wed, Jun 8, 2016 at 7:22 PM, Stephen Welker <
stephen.welker at nemostar.com.au> wrote:

> 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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dragonflybsd.org/pipermail/users/attachments/20160609/47aeddff/attachment-0003.htm>


More information about the Users mailing list