usr/src/uts/common/fs/zfs/spa.c
changeset 3697 5340a4d98e0b
parent 3377 a2fa338530c1
child 3912 f6891a60bd72
--- a/usr/src/uts/common/fs/zfs/spa.c	Thu Feb 22 10:42:15 2007 -0800
+++ b/usr/src/uts/common/fs/zfs/spa.c	Thu Feb 22 13:40:56 2007 -0800
@@ -2179,17 +2179,6 @@
  * ==========================================================================
  */
 
-void
-spa_scrub_throttle(spa_t *spa, int direction)
-{
-	mutex_enter(&spa->spa_scrub_lock);
-	spa->spa_scrub_throttled += direction;
-	ASSERT(spa->spa_scrub_throttled >= 0);
-	if (spa->spa_scrub_throttled == 0)
-		cv_broadcast(&spa->spa_scrub_io_cv);
-	mutex_exit(&spa->spa_scrub_lock);
-}
-
 static void
 spa_scrub_io_done(zio_t *zio)
 {
@@ -2205,10 +2194,12 @@
 		vd->vdev_stat.vs_scrub_errors++;
 		mutex_exit(&vd->vdev_stat_lock);
 	}
-	if (--spa->spa_scrub_inflight == 0) {
+
+	if (--spa->spa_scrub_inflight < spa->spa_scrub_maxinflight)
 		cv_broadcast(&spa->spa_scrub_io_cv);
-		ASSERT(spa->spa_scrub_throttled == 0);
-	}
+
+	ASSERT(spa->spa_scrub_inflight >= 0);
+
 	mutex_exit(&spa->spa_scrub_lock);
 }
 
@@ -2217,12 +2208,20 @@
     zbookmark_t *zb)
 {
 	size_t size = BP_GET_LSIZE(bp);
-	void *data = zio_data_buf_alloc(size);
+	void *data;
 
 	mutex_enter(&spa->spa_scrub_lock);
+	/*
+	 * Do not give too much work to vdev(s).
+	 */
+	while (spa->spa_scrub_inflight >= spa->spa_scrub_maxinflight) {
+		cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock);
+	}
 	spa->spa_scrub_inflight++;
 	mutex_exit(&spa->spa_scrub_lock);
 
+	data = zio_data_buf_alloc(size);
+
 	if (zb->zb_level == -1 && BP_GET_TYPE(bp) != DMU_OT_OBJSET)
 		flags |= ZIO_FLAG_SPECULATIVE;	/* intent log block */
 
@@ -2333,7 +2332,6 @@
 	spa->spa_scrub_errors = 0;
 	spa->spa_scrub_active = 1;
 	ASSERT(spa->spa_scrub_inflight == 0);
-	ASSERT(spa->spa_scrub_throttled == 0);
 
 	while (!spa->spa_scrub_stop) {
 		CALLB_CPR_SAFE_BEGIN(&cprinfo);
@@ -2353,9 +2351,6 @@
 		mutex_enter(&spa->spa_scrub_lock);
 		if (error != EAGAIN)
 			break;
-
-		while (spa->spa_scrub_throttled > 0)
-			cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock);
 	}
 
 	while (spa->spa_scrub_inflight)