svn commit: r208147 - in head/sys/cddl: compat/opensolaris/kern compat/opensolaris/sys contrib/opensolaris/uts/common/fs/zfs contrib/opensolaris/uts/common/fs/zfs/sys

Pawel Jakub Dawidek pjd at FreeBSD.org
Sun May 16 15:12:35 UTC 2010


Author: pjd
Date: Sun May 16 15:12:34 2010
New Revision: 208147
URL: http://svn.freebsd.org/changeset/base/208147

Log:
  Add task structure to zio and use it instead of allocating one.
  This eliminates the only place where we can sleep when calling zio_interrupt().
  As a side-effect this can actually improve performance a little as we
  allocate one less thing for every I/O.
  
  Prodded by:	kib
  MFC after:	1 week

Added:
  head/sys/cddl/compat/opensolaris/sys/taskq.h   (contents, props changed)
Modified:
  head/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c

Modified: head/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c
==============================================================================
--- head/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c	Sun May 16 14:53:43 2010	(r208146)
+++ head/sys/cddl/compat/opensolaris/kern/opensolaris_taskq.c	Sun May 16 15:12:34 2010	(r208147)
@@ -40,12 +40,6 @@ __FBSDID("$FreeBSD$");
 
 static uma_zone_t taskq_zone;
 
-struct ostask {
-	struct task	ost_task;
-	task_func_t	*ost_func;
-	void		*ost_arg;
-};
-
 taskq_t *system_taskq = NULL;
 
 static void
@@ -140,3 +134,32 @@ taskq_dispatch(taskq_t *tq, task_func_t 
 
 	return ((taskqid_t)(void *)task);
 }
+
+#define	TASKQ_MAGIC	0x74541c
+
+static void
+taskq_run_safe(void *arg, int pending __unused)
+{
+	struct ostask *task = arg;
+
+	ASSERT(task->ost_magic == TASKQ_MAGIC);
+	task->ost_func(task->ost_arg);
+	task->ost_magic = 0;
+}
+
+taskqid_t
+taskq_dispatch_safe(taskq_t *tq, task_func_t func, void *arg,
+    struct ostask *task)
+{
+
+	ASSERT(task->ost_magic != TASKQ_MAGIC);
+
+	task->ost_magic = TASKQ_MAGIC;
+	task->ost_func = func;
+	task->ost_arg = arg;
+
+	TASK_INIT(&task->ost_task, 0, taskq_run_safe, task);
+	taskqueue_enqueue(tq->tq_queue, &task->ost_task);
+
+	return ((taskqid_t)(void *)task);
+}

Added: head/sys/cddl/compat/opensolaris/sys/taskq.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/cddl/compat/opensolaris/sys/taskq.h	Sun May 16 15:12:34 2010	(r208147)
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 2010 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _OPENSOLARIS_SYS_TASKQ_H_
+#define	_OPENSOLARIS_SYS_TASKQ_H_
+
+#include_next <sys/taskq.h>
+
+struct ostask {
+	struct task	 ost_task;
+	task_func_t	*ost_func;
+	void		*ost_arg;
+	int		 ost_magic;
+};
+
+taskqid_t taskq_dispatch_safe(taskq_t *tq, task_func_t func, void *arg,
+    struct ostask *task);
+
+#endif	/* _OPENSOLARIS_SYS_TASKQ_H_ */

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h	Sun May 16 14:53:43 2010	(r208146)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h	Sun May 16 15:12:34 2010	(r208147)
@@ -316,6 +316,9 @@ struct zio {
 
 	/* FMA state */
 	uint64_t	io_ena;
+
+	/* FreeBSD only. */
+	struct ostask	io_task;
 };
 
 extern zio_t *zio_null(zio_t *pio, spa_t *spa,

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	Sun May 16 14:53:43 2010	(r208146)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c	Sun May 16 15:12:34 2010	(r208147)
@@ -908,8 +908,8 @@ zio_taskq_dispatch(zio_t *zio, enum zio_
 	if (t == ZIO_TYPE_WRITE && zio->io_vd && zio->io_vd->vdev_aux)
 		t = ZIO_TYPE_NULL;
 
-	(void) taskq_dispatch(zio->io_spa->spa_zio_taskq[t][q],
-	    (task_func_t *)zio_execute, zio, TQ_SLEEP);
+	(void) taskq_dispatch_safe(zio->io_spa->spa_zio_taskq[t][q],
+	    (task_func_t *)zio_execute, zio, &zio->io_task);
 }
 
 static boolean_t
@@ -2220,9 +2220,9 @@ zio_done(zio_t *zio)
 			 * Reexecution is potentially a huge amount of work.
 			 * Hand it off to the otherwise-unused claim taskq.
 			 */
-			(void) taskq_dispatch(
+			(void) taskq_dispatch_safe(
 			    spa->spa_zio_taskq[ZIO_TYPE_CLAIM][ZIO_TASKQ_ISSUE],
-			    (task_func_t *)zio_reexecute, zio, TQ_SLEEP);
+			    (task_func_t *)zio_reexecute, zio, &zio->io_task);
 		}
 		return (ZIO_PIPELINE_STOP);
 	}


More information about the svn-src-all mailing list