From: Brian Behlendorf Date: Thu, 9 Jul 2009 17:07:52 +0000 (-0700) Subject: Add basic support for TASKQ_THREADS_CPU_PCT taskq flag which is X-Git-Tag: zfs-0.8.0-rc1~152^2~687 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=915404bd509e5231c134042560d86e3ac86c1ab4;p=zfs Add basic support for TASKQ_THREADS_CPU_PCT taskq flag which is used to scale the number of threads based on the number of online CPUs. As CPUs are added/removed we should rescale the thread count appropriately, but currently this is only done at create. --- diff --git a/include/sys/taskq.h b/include/sys/taskq.h index 0b8623103..603fde680 100644 --- a/include/sys/taskq.h +++ b/include/sys/taskq.h @@ -44,6 +44,7 @@ extern "C" { #define TASKQ_PREPOPULATE 0x00000001 #define TASKQ_CPR_SAFE 0x00000002 #define TASKQ_DYNAMIC 0x00000004 +#define TASKQ_THREADS_CPU_PCT 0x00000008 typedef unsigned long taskqid_t; typedef void (task_func_t)(void *); diff --git a/module/spl/spl-taskq.c b/module/spl/spl-taskq.c index 5960761f4..7575aa3b0 100644 --- a/module/spl/spl-taskq.c +++ b/module/spl/spl-taskq.c @@ -375,6 +375,15 @@ __taskq_create(const char *name, int nthreads, pri_t pri, ASSERT(maxalloc <= INT_MAX); ASSERT(!(flags & (TASKQ_CPR_SAFE | TASKQ_DYNAMIC))); /* Unsupported */ + /* Scale the number of threads using nthreads as a percentage */ + if (flags & TASKQ_THREADS_CPU_PCT) { + ASSERT(nthreads <= 100); + ASSERT(nthreads >= 0); + nthreads = MIN(nthreads, 100); + nthreads = MAX(nthreads, 0); + nthreads = MAX((num_online_cpus() * nthreads) / 100, 1); + } + tq = kmem_alloc(sizeof(*tq), KM_SLEEP); if (tq == NULL) RETURN(NULL);