Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 May 2012 07:05:21 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r234914 - stable/8/sys/cam/ata
Message-ID:  <201205020705.q4275Lm3070355@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Wed May  2 07:05:20 2012
New Revision: 234914
URL: http://svn.freebsd.org/changeset/base/234914

Log:
  MFC r222643:
  When possible, join ranges of subsequest BIO_DELETE requests to handle more
  (up to 2048 instead of 256 or even 64) of them with single TRIM request.
  
  OCZ Vertex2/Vertex3 SSDs can handle no more then 64 ranges per TRIM request.
  Due to lack of BIO_DELETE clustering now, it means that we could delete no
  more then 2MB per request (on FS with 32K block) with limited request rate.
  This change increases delete rate on Vertex2 from 250MB/s to 950MB/s.
  
  MFC r222643:
  Increase maximum supported number of ranges per TRIM command from 256 to 512
  to use full potential of Intel X25-M SSDs. On synthetic test with 32K ranges
  it gives about 20% speedup, which probably costs more then 2K of RAM.

Modified:
  stable/8/sys/cam/ata/ata_da.c
Directory Properties:
  stable/8/sys/   (props changed)

Modified: stable/8/sys/cam/ata/ata_da.c
==============================================================================
--- stable/8/sys/cam/ata/ata_da.c	Wed May  2 06:58:44 2012	(r234913)
+++ stable/8/sys/cam/ata/ata_da.c	Wed May  2 07:05:20 2012	(r234914)
@@ -116,11 +116,12 @@ struct disk_params {
 	u_int64_t sectors;	/* Total number sectors */
 };
 
-#define TRIM_MAX_BLOCKS	4
-#define TRIM_MAX_RANGES	TRIM_MAX_BLOCKS * 64
+#define TRIM_MAX_BLOCKS	8
+#define TRIM_MAX_RANGES	(TRIM_MAX_BLOCKS * 64)
+#define TRIM_MAX_BIOS	(TRIM_MAX_RANGES * 4)
 struct trim_request {
 	uint8_t		data[TRIM_MAX_RANGES * 8];
-	struct bio	*bps[TRIM_MAX_RANGES];
+	struct bio	*bps[TRIM_MAX_BIOS];
 };
 
 struct ada_softc {
@@ -1109,7 +1110,8 @@ adastart(struct cam_periph *periph, unio
 		    (bp = bioq_first(&softc->trim_queue)) != 0) {
 			struct trim_request *req = &softc->trim_req;
 			struct bio *bp1;
-			int bps = 0, ranges = 0;
+			uint64_t lastlba = (uint64_t)-1;
+			int bps = 0, c, lastcount = 0, off, ranges = 0;
 
 			softc->trim_running = 1;
 			bzero(req, sizeof(*req));
@@ -1120,10 +1122,22 @@ adastart(struct cam_periph *periph, unio
 				    softc->params.secsize;
 
 				bioq_remove(&softc->trim_queue, bp1);
-				while (count > 0) {
-					int c = min(count, 0xffff);
-					int off = ranges * 8;
 
+				/* Try to extend the previous range. */
+				if (lba == lastlba) {
+					c = min(count, 0xffff - lastcount);
+					lastcount += c;
+					off = (ranges - 1) * 8;
+					req->data[off + 6] = lastcount & 0xff;
+					req->data[off + 7] =
+					    (lastcount >> 8) & 0xff;
+					count -= c;
+					lba += c;
+				}
+
+				while (count > 0) {
+					c = min(count, 0xffff);
+					off = ranges * 8;
 					req->data[off + 0] = lba & 0xff;
 					req->data[off + 1] = (lba >> 8) & 0xff;
 					req->data[off + 2] = (lba >> 16) & 0xff;
@@ -1134,11 +1148,14 @@ adastart(struct cam_periph *periph, unio
 					req->data[off + 7] = (c >> 8) & 0xff;
 					lba += c;
 					count -= c;
+					lastcount = c;
 					ranges++;
 				}
+				lastlba = lba;
 				req->bps[bps++] = bp1;
 				bp1 = bioq_first(&softc->trim_queue);
-				if (bp1 == NULL ||
+				if (bps >= TRIM_MAX_BIOS ||
+				    bp1 == NULL ||
 				    bp1->bio_bcount / softc->params.secsize >
 				    (softc->trim_max_ranges - ranges) * 0xffff)
 					break;
@@ -1430,8 +1447,7 @@ adadone(struct cam_periph *periph, union
 			    (struct trim_request *)ataio->data_ptr;
 			int i;
 
-			for (i = 1; i < softc->trim_max_ranges &&
-			    req->bps[i]; i++) {
+			for (i = 1; i < TRIM_MAX_BIOS && req->bps[i]; i++) {
 				struct bio *bp1 = req->bps[i];
 				
 				bp1->bio_resid = bp->bio_resid;



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