<div dir="ltr"><div>This is a bit harder to fix, because we really don't want there to be any TRIM support turned on by default.<br><br></div><div>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.<br><br></div><div>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.<br><br></div><div>I haven't gone through all the layers of trim enablement but that's the basic idea.<br></div><div><br></div>-Matt<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 8, 2016 at 7:22 PM, Stephen Welker <span dir="ltr"><<a href="mailto:stephen.welker@nemostar.com.au" target="_blank">stephen.welker@nemostar.com.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I believe I have discovered a problem with the implementation of SSD/TRIM on DragonFly BSD.<br>
<br>
Under all versions back to v3.6 (may be earlier) turning TRIM on the boot or swap disk during the boot process is impossible.<br>
<br>
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.<br>
<br>
The problem is two fold:<br>
<br>
1. The sysctl variable "kern.cam.da.X.trim_enabled" is always set to "0".<br>
2. The disks are mounted before the /etc/rc.d/sysctl script is run.<br>
<br>
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.<br>
<br>
To fix the problem there are two options:<br>
<br>
1. Change the order of rc.d scripts by moving rc.d/sysctl to an earlier invocation, or<br>
2. Patch /sys/bus/cam/scsi/scsi_da.c to set the sysctl variable to the numeric value "1".<br>
<br>
In implementing option 1, several other scripts will need to have their rcorder dependancies changed.<br>
<br>
In implementing option 2, code in the following region will need to be changed (/sys/bus/cam/scsi/scsi_da.c):<br>
<br>
1077         /* Only create the option if the device supports TRIM */<br>
1078         if (softc->disk.d_info.d_trimflag) {<br>
1079                 SYSCTL_ADD_INT(&softc->sysctl_ctx,<br>
1080                     SYSCTL_CHILDREN(softc->sysctl_tree),<br>
1081                     OID_AUTO,<br>
1082                     "trim_enabled",<br>
1083                     CTLFLAG_RW,<br>
1084                     &softc->trim_enabled,<br>
1085                     0,<br>
1086                     "Enable TRIM for this device (SSD))");<br>
1087         }<br>
<br>
My suggestion is to insert the following line of code after line 1078 (before the call to SYSCTL_ADD_INT()):<br>
<br>
    softc->trim_enabled = 1;<br>
<br>
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.<br>
<br>
Also, should /etc/rc.d/root have the remount of the root file system be changed from:<br>
<br>
    mount -u -o rw /<br>
<br>
to<br>
<br>
    mount -u -o fstab /<br>
<br>
to allow for the "trim" (or noatime, etc) options?<br>
<br>
I have not filed a bug report until a discussion of the best approach to the solution is found first.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
regards,<br>
Stephen Welker.<br>
<br>
</font></span></blockquote></div><br></div>