Bug 238343 - [FEATURE REQUEST] auto run trim for swap devices before swapon
Summary: [FEATURE REQUEST] auto run trim for swap devices before swapon
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Doug Moore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-05 16:41 UTC by rozhuk.im
Modified: 2019-07-19 18:32 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rozhuk.im 2019-06-05 16:41:46 UTC
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.
Comment 1 Mark Johnston freebsd_committer 2019-06-23 19:35:30 UTC
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.
Comment 2 sigsys 2019-07-19 18:32:08 UTC
Small patch to make it work with geli.  Trimming triggered detach-on-last-close.

Index: sbin/swapon/swapon.c
===================================================================
--- 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);
+	close(fd);
+	return ret;
 }
 
 static const char *