Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Dec 2019 18:16:44 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r355813 - in head/sys/cam: ata scsi
Message-ID:  <201912161816.xBGIGijv078938@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Mon Dec 16 18:16:44 2019
New Revision: 355813
URL: https://svnweb.freebsd.org/changeset/base/355813

Log:
  Implement a system-wide limit or da and ada devices for delete.
  
  Excesively large TRIMs can result in timeouts, which cause big
  problems. Limit trims to 1GB to mititgate these issues.
  
  Reviewed by: scottl
  Differential Revision: https://reviews.freebsd.org/D22809

Modified:
  head/sys/cam/ata/ata_da.c
  head/sys/cam/scsi/scsi_da.c

Modified: head/sys/cam/ata/ata_da.c
==============================================================================
--- head/sys/cam/ata/ata_da.c	Mon Dec 16 18:05:28 2019	(r355812)
+++ head/sys/cam/ata/ata_da.c	Mon Dec 16 18:16:44 2019	(r355813)
@@ -858,6 +858,10 @@ static void		adaresume(void *arg);
 #define	ADA_DEFAULT_WRITE_CACHE	1
 #endif
 
+#ifndef	ADA_DEFAULT_MAX_DELETE
+#define	ADA_DEFAULT_MAX_DELETE	(1 * 1024 * 1024 * 1024)	/* 1GB max trim by default */
+#endif
+
 #define	ADA_RA	(softc->read_ahead >= 0 ? \
 		 softc->read_ahead : ada_read_ahead)
 #define	ADA_WC	(softc->write_cache >= 0 ? \
@@ -878,6 +882,7 @@ static int ada_spindown_shutdown = ADA_DEFAULT_SPINDOW
 static int ada_spindown_suspend = ADA_DEFAULT_SPINDOWN_SUSPEND;
 static int ada_read_ahead = ADA_DEFAULT_READ_AHEAD;
 static int ada_write_cache = ADA_DEFAULT_WRITE_CACHE;
+static int64_t ada_default_max_delete = ADA_DEFAULT_MAX_DELETE;
 
 static SYSCTL_NODE(_kern_cam, OID_AUTO, ada, CTLFLAG_RD, 0,
             "CAM Direct Access Disk driver");
@@ -895,6 +900,9 @@ SYSCTL_INT(_kern_cam_ada, OID_AUTO, read_ahead, CTLFLA
            &ada_read_ahead, 0, "Enable disk read-ahead");
 SYSCTL_INT(_kern_cam_ada, OID_AUTO, write_cache, CTLFLAG_RWTUN,
            &ada_write_cache, 0, "Enable disk write cache");
+SYSCTL_QUAD(_kern_cam_ada, OID_AUTO, default_max_delete, CTLFLAG_RWTUN,
+    &ada_default_max_delete, 0,
+    "Default system wide maximum delete");
 
 /*
  * ADA_ORDEREDTAG_INTERVAL determines how often, relative
@@ -3392,6 +3400,8 @@ adasetgeom(struct ada_softc *softc, struct ccb_getdev 
 		softc->disk->d_delmaxsize = 256 * softc->params.secsize;
 	} else
 		softc->disk->d_delmaxsize = maxio;
+	if (softc->disk->d_delmaxsize > ada_default_max_delete)
+		softc->disk->d_delmaxsize = ada_default_max_delete;
 	if ((softc->cpi.hba_misc & PIM_UNMAPPED) != 0) {
 		d_flags |= DISKFLAG_UNMAPPED_BIO;
 		softc->unmappedio = 1;

Modified: head/sys/cam/scsi/scsi_da.c
==============================================================================
--- head/sys/cam/scsi/scsi_da.c	Mon Dec 16 18:05:28 2019	(r355812)
+++ head/sys/cam/scsi/scsi_da.c	Mon Dec 16 18:16:44 2019	(r355813)
@@ -1516,12 +1516,17 @@ static callout_func_t	damediapoll;
 #define	DA_DEFAULT_SEND_ORDERED	1
 #endif
 
+#ifndef	DA_DEFAULT_MAX_DELETE
+#define	DA_DEFAULT_MAX_DELETE	(1 * 1024 * 1024 * 1024)	/* 1GB max trim by default */
+#endif
+
 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
 static int da_retry_count = DA_DEFAULT_RETRY;
 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
 static int da_disable_wp_detection = 0;
+static int64_t da_default_max_delete = DA_DEFAULT_MAX_DELETE;
 
 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
             "CAM Direct Access Disk driver");
@@ -1536,6 +1541,9 @@ SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFL
 SYSCTL_INT(_kern_cam_da, OID_AUTO, disable_wp_detection, CTLFLAG_RWTUN,
            &da_disable_wp_detection, 0,
 	   "Disable detection of write-protected disks");
+SYSCTL_INT64(_kern_cam_da, OID_AUTO, default_max_delete, CTLFLAG_RWTUN,
+    &da_default_max_delete, 0,
+    "Default system wide maximum delete");
 
 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
     CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
@@ -2500,8 +2508,8 @@ dadeletemaxsize(struct da_softc *softc, da_delete_meth
 		return 0;
 	}
 
-	return (off_t)softc->params.secsize *
-	    omin(sectors, softc->params.sectors);
+	return (off_t)MIN(da_default_max_delete, softc->params.secsize *
+	    omin(sectors, softc->params.sectors));
 }
 
 static void



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912161816.xBGIGijv078938>