We have trim command that can send TRIM for device/partition/file.
SWAP partitions have no fs and never get TRIM command on "data delete", this may decrease some SSD~s performance.
trim command may be executed before swapon (after dumpon) to fix this.
We now have this in -CURRENT as of r349286, thanks to Doug Moore. I can't see any reason not to MFC the change to stable/12 for 12.1.
Small patch to make it work with geli. Trimming triggered detach-on-last-close.
--- sbin/swapon/swapon.c (revision 350115)
+++ sbin/swapon/swapon.c (working copy)
@@ -436,7 +436,8 @@
struct stat sb;
char *dname, *args;
- int error;
+ const char *ret;
+ int error, fd;
error = stat(name, &sb);
@@ -469,7 +470,13 @@
} while (0);
- return (swap_on_off_sfile(name, doingall));
+ /* Hold geli device open to avoid triggering detach on last close. */
+ fd = open(name, O_WRONLY);
+ if (fd < 0)
+ errx(1, "Cannot open %s", name);
+ ret = swap_on_off_sfile(name, doingall);
+ return ret;
static const char *