svn commit: r248574 - in head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys

Steven Hartland smh at FreeBSD.org
Thu Mar 21 10:16:12 UTC 2013


Author: smh
Date: Thu Mar 21 10:16:10 2013
New Revision: 248574
URL: http://svnweb.freebsd.org/changeset/base/248574

Log:
  Improve TXG handling in the TRIM module.
  This patch adds some improvements to the way the trim module considers
  TXGs:
  
   - Free ZIOs are registered with the TXG from the ZIO itself, not the
     current SPA syncing TXG (which may be out of date);
   - L2ARC are registered with a zero TXG number, as L2ARC has no concept
     of TXGs;
   - The TXG limit for issuing TRIMs is now computed from the last synced
     TXG, not the currently syncing TXG. Indeed, under extremely unlikely
     race conditions, there is a risk we could trim blocks which have been
     freed in a TXG that has not finished syncing, resulting in potential
     data corruption in case of a crash.
  
  Reviewed by:	pjd (mentor)
  Approved by:	pjd (mentor)
  Obtained from:	https://github.com/dechamps/zfs/commit/5b46ad40d9081d75505d6f3bf04ac652445df366
  MFC after:	2 weeks

Modified:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/trim_map.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c	Thu Mar 21 10:02:32 2013	(r248573)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c	Thu Mar 21 10:16:10 2013	(r248574)
@@ -1693,7 +1693,7 @@ arc_hdr_destroy(arc_buf_hdr_t *hdr)
 
 		if (l2hdr != NULL) {
 			trim_map_free(l2hdr->b_dev->l2ad_vdev, l2hdr->b_daddr,
-			    hdr->b_size);
+			    hdr->b_size, 0);
 			list_remove(l2hdr->b_dev->l2ad_buflist, hdr);
 			ARCSTAT_INCR(arcstat_l2_size, -hdr->b_size);
 			kmem_free(l2hdr, sizeof (l2arc_buf_hdr_t));
@@ -3532,7 +3532,7 @@ arc_release(arc_buf_t *buf, void *tag)
 
 	if (l2hdr) {
 		trim_map_free(l2hdr->b_dev->l2ad_vdev, l2hdr->b_daddr,
-		    hdr->b_size);
+		    hdr->b_size, 0);
 		list_remove(l2hdr->b_dev->l2ad_buflist, hdr);
 		kmem_free(l2hdr, sizeof (l2arc_buf_hdr_t));
 		ARCSTAT_INCR(arcstat_l2_size, -buf_size);
@@ -4448,7 +4448,7 @@ l2arc_write_done(zio_t *zio)
 			abl2 = ab->b_l2hdr;
 			ab->b_l2hdr = NULL;
 			trim_map_free(abl2->b_dev->l2ad_vdev, abl2->b_daddr,
-			    ab->b_size);
+			    ab->b_size, 0);
 			kmem_free(abl2, sizeof (l2arc_buf_hdr_t));
 			ARCSTAT_INCR(arcstat_l2_size, -ab->b_size);
 		}

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/trim_map.h
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/trim_map.h	Thu Mar 21 10:02:32 2013	(r248573)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/trim_map.h	Thu Mar 21 10:16:10 2013	(r248574)
@@ -36,7 +36,7 @@ extern "C" {
 
 extern void trim_map_create(vdev_t *vd);
 extern void trim_map_destroy(vdev_t *vd);
-extern void trim_map_free(vdev_t *vd, uint64_t offset, uint64_t size);
+extern void trim_map_free(vdev_t *vd, uint64_t offset, uint64_t size, uint64_t txg);
 extern boolean_t trim_map_write_start(zio_t *zio);
 extern void trim_map_write_done(zio_t *zio);
 

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c	Thu Mar 21 10:02:32 2013	(r248573)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/trim_map.c	Thu Mar 21 10:16:10 2013	(r248574)
@@ -272,7 +272,7 @@ trim_map_free_locked(trim_map_t *tm, uin
 }
 
 void
-trim_map_free(vdev_t *vd, uint64_t offset, uint64_t size)
+trim_map_free(vdev_t *vd, uint64_t offset, uint64_t size, uint64_t txg)
 {
 	trim_map_t *tm = vd->vdev_trimmap;
 
@@ -280,8 +280,7 @@ trim_map_free(vdev_t *vd, uint64_t offse
 		return;
 
 	mutex_enter(&tm->tm_lock);
-	trim_map_free_locked(tm, offset, TRIM_ZIO_END(vd, offset, size),
-	    vd->vdev_spa->spa_syncing_txg);
+	trim_map_free_locked(tm, offset, TRIM_ZIO_END(vd, offset, size), txg);
 	mutex_exit(&tm->tm_lock);
 }
 
@@ -387,7 +386,7 @@ trim_map_vdev_commit(spa_t *spa, zio_t *
 	if (tm == NULL)
 		return;
 
-	txglimit = MIN(spa->spa_syncing_txg, spa_freeze_txg(spa)) -
+	txglimit = MIN(spa_last_synced_txg(spa), spa_freeze_txg(spa)) -
 	    trim_txg_limit;
 
 	mutex_enter(&tm->tm_lock);
@@ -444,7 +443,7 @@ trim_map_commit(spa_t *spa, zio_t *zio, 
 {
 	int c;
 
-	if (vd == NULL || spa->spa_syncing_txg <= trim_txg_limit)
+	if (vd == NULL || spa_last_synced_txg(spa) <= trim_txg_limit)
 		return;
 
 	if (vd->vdev_ops->vdev_op_leaf) {

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	Thu Mar 21 10:02:32 2013	(r248573)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	Thu Mar 21 10:16:10 2013	(r248574)
@@ -2475,7 +2475,7 @@ zio_vdev_io_start(zio_t *zio)
 	}
 
 	if (vd->vdev_ops->vdev_op_leaf && zio->io_type == ZIO_TYPE_FREE) {
-		trim_map_free(vd, zio->io_offset, zio->io_size);
+		trim_map_free(vd, zio->io_offset, zio->io_size, zio->io_txg);
 		return (ZIO_PIPELINE_CONTINUE);
 	}
 


More information about the svn-src-all mailing list