From nobody@FreeBSD.org  Thu Nov  1 04:07:21 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 69FFF464
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  1 Nov 2012 04:07:21 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 515F78FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  1 Nov 2012 04:07:21 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qA147KZ0003456
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 1 Nov 2012 04:07:20 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qA147KLd003455;
	Thu, 1 Nov 2012 04:07:20 GMT
	(envelope-from nobody)
Message-Id: <201211010407.qA147KLd003455@red.freebsd.org>
Date: Thu, 1 Nov 2012 04:07:20 GMT
From: Steven Hartland <steven.hartland@multiplay.co.uk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Upgrade requests used in ZFS trim map based on ashift (patch included)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173254
>Category:       kern
>Synopsis:       [zfs] [patch] Upgrade requests used in ZFS trim map based on ashift
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    smh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 01 04:10:01 UTC 2012
>Closed-Date:    Thu Dec 13 17:08:47 UTC 2012
>Last-Modified:  Thu Dec 13 17:08:47 UTC 2012
>Originator:     Steven Hartland
>Release:        8.3-RELEASE
>Organization:
Multiplay
>Environment:
FreeBSD dev 8.3-RELEASE-p4 FreeBSD 8.3-RELEASE-p4 #22: Mon Sep 17 17:18:32 UTC 2012     root@dev:/usr/obj/usr/src/sys/MULTIPLAY  amd64
>Description:
Upgrades trim free request sizes before inserting them into to free map, making range consolidation much more effective particularly for small deletes.

This reduces memory used by the free map as well as reducing the number of bio requests down to geom required to process all deletes.

In tests this achieved a factor of 10 reduction of trim ranges / geom call downs.
>How-To-Repeat:
N/A
>Fix:
Apply the attached patch

Patch attached with submission follows:

Upgrades trim free request sizes before inserting them into to free map,
making range consolidation much more effective particularly for small
deletes.

This reduces memory used by the free map as well as reducing the number
of bio requests down to geom required to process all deletes.

In tests this achieved a factor of 10 reduction of trim ranges / geom
call downs.
--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	2012-10-25 13:01:17.556311206 +0000
+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	2012-10-25 13:48:39.280408543 +0000
@@ -2324,7 +2324,7 @@
 
 /*
  * ==========================================================================
- * Read and write to physical devices
+ * Read, write and delete to physical devices
  * ==========================================================================
  */
 static int
--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c	2012-10-25 13:01:17.544310799 +0000
+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c	2012-10-25 14:41:49.391313700 +0000
@@ -263,14 +263,27 @@
 void
 trim_map_free(zio_t *zio)
 {
+	uint64_t size, align;
 	vdev_t *vd = zio->io_vd;
 	trim_map_t *tm = vd->vdev_trimmap;
 
 	if (zfs_notrim || vd->vdev_notrim || tm == NULL)
 		return;
 
+	/*
+	 * Upgrade size based on ashift which would be done by
+	 * zio_vdev_io_start later anyway.
+	 *
+	 * This makes free range consolidation much more effective
+	 * than it would otherwise be.
+	 */
+	size = zio->io_size;
+	align = 1ULL << vd->vdev_top->vdev_ashift;
+	if (P2PHASE(size, align) != 0)
+		size = P2ROUNDUP(size, align);
+
 	mutex_enter(&tm->tm_lock);
-	trim_map_free_locked(tm, zio->io_offset, zio->io_offset + zio->io_size,
+	trim_map_free_locked(tm, zio->io_offset, zio->io_offset + size,
 	    vd->vdev_spa->spa_syncing_txg);
 	mutex_exit(&tm->tm_lock);
 }
@@ -282,13 +295,25 @@
 	trim_map_t *tm = vd->vdev_trimmap;
 	trim_seg_t tsearch, *ts;
 	boolean_t left_over, right_over;
-	uint64_t start, end;
+	uint64_t start, end, align, size;
 
 	if (zfs_notrim || vd->vdev_notrim || tm == NULL)
 		return (B_TRUE);
 
+	/*
+	 * Upgrade size based on ashift which would be done by
+	 * zio_vdev_io_start later anyway.
+	 *
+	 * This ensures that entire blocks are invalidated by
+	 * writes
+	 */
+	align = 1ULL << vd->vdev_top->vdev_ashift;
+	size = zio->io_size;
+	if (P2PHASE(size, align) != 0)
+		size = P2ROUNDUP(size, align);
+
 	start = zio->io_offset;
-	end = start + zio->io_size;
+	end = start + size;
 	tsearch.ts_start = start;
 	tsearch.ts_end = end;
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Thu Nov 1 19:02:08 UTC 2012 
Responsible-Changed-Why:  
set synopsis and assign 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173254 

From: "Steven Hartland" <killing@multiplay.co.uk>
To: <bug-followup@freebsd.org>,
	<steven.hartland@multiplay.co.uk>
Cc:  
Subject: Re: kern/173254: [zfs] [patch] Upgrade requests used in ZFS trim map based on ashift
Date: Thu, 1 Nov 2012 23:15:56 -0000

 This is a multi-part message in MIME format.
 
 ------=_NextPart_000_0AC6_01CDB886.D8C9BA80
 Content-Type: text/plain;
 	format=flowed;
 	charset="Windows-1252";
 	reply-type=original
 Content-Transfer-Encoding: 7bit
 
 Updated patched which simplifies / optimises logic
 
 ================================================
 This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it. 
 
 In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337
 or return the E.mail to postmaster@multiplay.co.uk.
 ------=_NextPart_000_0AC6_01CDB886.D8C9BA80
 Content-Type: text/plain;
 	format=flowed;
 	name="zz-zfstrim-block-perf.txt";
 	reply-type=original
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="zz-zfstrim-block-perf.txt"
 
 Upgrades trim free request sizes before inserting them into to free map,=0A=
 making range consolidation much more effective particularly for small=0A=
 deletes.=0A=
 =0A=
 This reduces memory used by the free map as well as reducing the number=0A=
 of bio requests down to geom required to process all deletes.=0A=
 =0A=
 In tests this achieved a factor of 10 reduction of trim ranges / geom=0A=
 call downs.=0A=
 --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	2012-10-25 =
 13:01:17.556311206 +0000=0A=
 +++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	2012-10-25 =
 13:48:39.280408543 +0000=0A=
 @@ -2325,7 +2325,7 @@=0A=
  =0A=
  /*=0A=
   * =
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
 - * Read and write to physical devices=0A=
 + * Read, write and delete to physical devices=0A=
   * =
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
   */=0A=
  static int=0A=
 --- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c	2012-10-25 =
 13:01:17.544310799 +0000=0A=
 +++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c	2012-10-25 =
 14:41:49.391313700 +0000=0A=
 @@ -270,7 +270,15 @@=0A=
  		return;=0A=
  =0A=
  	mutex_enter(&tm->tm_lock);=0A=
 -	trim_map_free_locked(tm, zio->io_offset, zio->io_offset + zio->io_size,=0A=
 +	/*=0A=
 +	 * Upgrade size based on ashift which would be done by=0A=
 +	 * zio_vdev_io_start later anyway.=0A=
 +	 *=0A=
 +	 * This makes free range consolidation much more effective=0A=
 +	 * than it would otherwise be.=0A=
 +	 */=0A=
 +	trim_map_free_locked(tm, zio->io_offset, zio->io_offset + =0A=
 +	    P2ROUNDUP(zio->io_size, 1ULL << vd->vdev_top->vdev_ashift),=0A=
  	    vd->vdev_spa->spa_syncing_txg);=0A=
  	mutex_exit(&tm->tm_lock);=0A=
  }=0A=
 @@ -288,7 +301,14 @@=0A=
  		return (B_TRUE);=0A=
  =0A=
  	start =3D zio->io_offset;=0A=
 -	end =3D start + zio->io_size;=0A=
 +	/*=0A=
 +	 * Upgrade size based on ashift which would be done by=0A=
 +	 * zio_vdev_io_start later anyway.=0A=
 +	 *=0A=
 +	 * This ensures that entire blocks are invalidated by=0A=
 +	 * writes=0A=
 +	 */=0A=
 +	end =3D start + P2ROUNDUP(zio->io_size, 1ULL << =
 vd->vdev_top->vdev_ashift);=0A=
  	tsearch.ts_start =3D start;=0A=
  	tsearch.ts_end =3D end;=0A=
  =0A=
 
 ------=_NextPart_000_0AC6_01CDB886.D8C9BA80--
 
Responsible-Changed-From-To: freebsd-fs->smh 
Responsible-Changed-By: smh 
Responsible-Changed-When: Sat Nov 17 18:47:50 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173254 
State-Changed-From-To: open->closed 
State-Changed-By: smh 
State-Changed-When: Thu Dec 13 17:08:46 UTC 2012 
State-Changed-Why:  
patched in head/ with r244187 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173254 
>Unformatted:
