Add defclsyspri macro

Add a new defclsyspri macro which can be used to request the default
Linux scheduler priority.  Neither the minclsyspri or maxclsyspri map
to the default Linux kernel thread priority.  This makes it awkward to
create taskqs which run with the same priority as the rest of the kernel
threads on the system which can lead to performance issues.

All SPL callers which previously used minclsyspri or maxclsyspri have
been changed to use defclsyspri.  The vast majority of callers were
part of the test suite which won't have an external impact.  The few
places where it could impact performance the change was from maxclsyspri
to defclsyspri.  This makes it more likely the process will be scheduled
which may help performance.

To facilitate further performance analysis the spl_taskq_thread_priority
module option has been added.  When disabled (0) all newly created kernel
threads will use the default kernel thread priority.  When enabled (1)
the specified taskq priority will be used.  By default this value is
enabled (1).

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
This commit is contained in:
Brian Behlendorf 2015-07-23 11:21:08 -07:00
parent 9eb361aaa5
commit 62aa81a577
11 changed files with 48 additions and 25 deletions

View File

@ -95,6 +95,7 @@
*/ */
#define minclsyspri (MAX_RT_PRIO) #define minclsyspri (MAX_RT_PRIO)
#define maxclsyspri (MAX_PRIO-1) #define maxclsyspri (MAX_PRIO-1)
#define defclsyspri (DEFAULT_PRIO)
#ifndef NICE_TO_PRIO #ifndef NICE_TO_PRIO
#define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20) #define NICE_TO_PRIO(nice) (MAX_RT_PRIO + (nice) + 20)

View File

@ -129,7 +129,7 @@ extern int taskq_member(taskq_t *, void *);
#define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \ #define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \
taskq_create(name, nthreads, pri, min, max, flags) taskq_create(name, nthreads, pri, min, max, flags)
#define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \ #define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \
taskq_create(name, nthreads, maxclsyspri, min, max, flags) taskq_create(name, nthreads, defclsyspri, min, max, flags)
int spl_taskq_init(void); int spl_taskq_init(void);
void spl_taskq_fini(void); void spl_taskq_fini(void);

View File

@ -266,6 +266,21 @@ aid performance analysis or troubleshooting.
Default value: \fB1\fR Default value: \fB1\fR
.RE .RE
.sp
.ne 2
.na
\fBspl_taskq_thread_priority\fR (int)
.ad
.RS 12n
Allow newly created taskq threads to set a non-default scheduler priority.
When enabled the priority specified when a taskq is created will be applied
to all threads created by that taskq. When disabled all threads will use
the default Linux kernel thread priority. By default, this behavior is
enabled.
.sp
Default value: \fB1\fR
.RE
.sp .sp
.ne 2 .ne 2
.na .na

View File

@ -1725,7 +1725,7 @@ spl_kmem_cache_init(void)
init_rwsem(&spl_kmem_cache_sem); init_rwsem(&spl_kmem_cache_sem);
INIT_LIST_HEAD(&spl_kmem_cache_list); INIT_LIST_HEAD(&spl_kmem_cache_list);
spl_kmem_cache_taskq = taskq_create("spl_kmem_cache", spl_kmem_cache_taskq = taskq_create("spl_kmem_cache",
spl_kmem_cache_kmem_threads, maxclsyspri, spl_kmem_cache_kmem_threads, defclsyspri,
spl_kmem_cache_kmem_threads * 8, INT_MAX, spl_kmem_cache_kmem_threads * 8, INT_MAX,
TASKQ_PREPOPULATE | TASKQ_DYNAMIC); TASKQ_PREPOPULATE | TASKQ_DYNAMIC);
spl_register_shrinker(&spl_kmem_cache_shrinker); spl_register_shrinker(&spl_kmem_cache_shrinker);

View File

@ -36,6 +36,11 @@ int spl_taskq_thread_dynamic = 1;
module_param(spl_taskq_thread_dynamic, int, 0644); module_param(spl_taskq_thread_dynamic, int, 0644);
MODULE_PARM_DESC(spl_taskq_thread_dynamic, "Allow dynamic taskq threads"); MODULE_PARM_DESC(spl_taskq_thread_dynamic, "Allow dynamic taskq threads");
int spl_taskq_thread_priority = 1;
module_param(spl_taskq_thread_priority, int, 0644);
MODULE_PARM_DESC(spl_taskq_thread_priority,
"Allow non-default priority for taskq threads");
int spl_taskq_thread_sequential = 4; int spl_taskq_thread_sequential = 4;
module_param(spl_taskq_thread_sequential, int, 0644); module_param(spl_taskq_thread_sequential, int, 0644);
MODULE_PARM_DESC(spl_taskq_thread_sequential, MODULE_PARM_DESC(spl_taskq_thread_sequential,
@ -913,7 +918,9 @@ taskq_thread_create(taskq_t *tq)
kthread_bind(tqt->tqt_thread, last_used_cpu); kthread_bind(tqt->tqt_thread, last_used_cpu);
} }
set_user_nice(tqt->tqt_thread, PRIO_TO_NICE(tq->tq_pri)); if (spl_taskq_thread_priority)
set_user_nice(tqt->tqt_thread, PRIO_TO_NICE(tq->tq_pri));
wake_up_process(tqt->tqt_thread); wake_up_process(tqt->tqt_thread);
return (tqt); return (tqt);
@ -1070,12 +1077,12 @@ int
spl_taskq_init(void) spl_taskq_init(void)
{ {
system_taskq = taskq_create("spl_system_taskq", MAX(boot_ncpus, 64), system_taskq = taskq_create("spl_system_taskq", MAX(boot_ncpus, 64),
minclsyspri, boot_ncpus, INT_MAX, TASKQ_PREPOPULATE|TASKQ_DYNAMIC); defclsyspri, boot_ncpus, INT_MAX, TASKQ_PREPOPULATE|TASKQ_DYNAMIC);
if (system_taskq == NULL) if (system_taskq == NULL)
return (1); return (1);
dynamic_taskq = taskq_create("spl_dynamic_taskq", 1, dynamic_taskq = taskq_create("spl_dynamic_taskq", 1,
minclsyspri, boot_ncpus, INT_MAX, TASKQ_PREPOPULATE); defclsyspri, boot_ncpus, INT_MAX, TASKQ_PREPOPULATE);
if (dynamic_taskq == NULL) { if (dynamic_taskq == NULL) {
taskq_destroy(system_taskq); taskq_destroy(system_taskq);
return (1); return (1);

View File

@ -156,7 +156,7 @@ splat_atomic_test1(struct file *file, void *arg)
thr = (kthread_t *)thread_create(NULL, 0, splat_atomic_work, thr = (kthread_t *)thread_create(NULL, 0, splat_atomic_work,
&ap, 0, &p0, TS_RUN, &ap, 0, &p0, TS_RUN,
minclsyspri); defclsyspri);
if (thr == NULL) { if (thr == NULL) {
rc = -ESRCH; rc = -ESRCH;
mutex_exit(&ap.ap_lock); mutex_exit(&ap.ap_lock);

View File

@ -739,7 +739,7 @@ splat_kmem_cache_thread_test(struct file *file, void *arg, char *name,
for (i = 0; i < SPLAT_KMEM_THREADS; i++) { for (i = 0; i < SPLAT_KMEM_THREADS; i++) {
thr = thread_create(NULL, 0, thr = thread_create(NULL, 0,
splat_kmem_cache_test_thread, splat_kmem_cache_test_thread,
kcp, 0, &p0, TS_RUN, minclsyspri); kcp, 0, &p0, TS_RUN, defclsyspri);
if (thr == NULL) { if (thr == NULL) {
rc = -ESRCH; rc = -ESRCH;
goto out_cache; goto out_cache;

View File

@ -87,7 +87,7 @@ splat_mutex_test1(struct file *file, void *arg)
if (mp == NULL) if (mp == NULL)
return -ENOMEM; return -ENOMEM;
tq = taskq_create(SPLAT_MUTEX_TEST_TASKQ, 1, maxclsyspri, tq = taskq_create(SPLAT_MUTEX_TEST_TASKQ, 1, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE); 50, INT_MAX, TASKQ_PREPOPULATE);
if (tq == NULL) { if (tq == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
@ -196,7 +196,7 @@ splat_mutex_test2(struct file *file, void *arg)
/* Create several threads allowing tasks to race with each other */ /* Create several threads allowing tasks to race with each other */
tq = taskq_create(SPLAT_MUTEX_TEST_TASKQ, num_online_cpus(), tq = taskq_create(SPLAT_MUTEX_TEST_TASKQ, num_online_cpus(),
maxclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE); defclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE);
if (tq == NULL) { if (tq == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
@ -266,7 +266,7 @@ splat_mutex_test3(struct file *file, void *arg)
mp.mp_file = file; mp.mp_file = file;
mutex_init(&mp.mp_mtx, SPLAT_MUTEX_TEST_NAME, MUTEX_DEFAULT, NULL); mutex_init(&mp.mp_mtx, SPLAT_MUTEX_TEST_NAME, MUTEX_DEFAULT, NULL);
if ((tq = taskq_create(SPLAT_MUTEX_TEST_NAME, 1, maxclsyspri, if ((tq = taskq_create(SPLAT_MUTEX_TEST_NAME, 1, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) { 50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_MUTEX_TEST3_NAME, "Taskq '%s' " splat_vprint(file, SPLAT_MUTEX_TEST3_NAME, "Taskq '%s' "
"create failed\n", SPLAT_MUTEX_TEST3_NAME); "create failed\n", SPLAT_MUTEX_TEST3_NAME);

View File

@ -327,7 +327,7 @@ splat_rwlock_test2(struct file *file, void *arg)
/* Create several threads allowing tasks to race with each other */ /* Create several threads allowing tasks to race with each other */
tq = taskq_create(SPLAT_RWLOCK_TEST_TASKQ, num_online_cpus(), tq = taskq_create(SPLAT_RWLOCK_TEST_TASKQ, num_online_cpus(),
maxclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE); defclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE);
if (tq == NULL) { if (tq == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
@ -500,7 +500,7 @@ splat_rwlock_test4(struct file *file, void *arg)
if (rwp == NULL) if (rwp == NULL)
return -ENOMEM; return -ENOMEM;
tq = taskq_create(SPLAT_RWLOCK_TEST_TASKQ, 1, maxclsyspri, tq = taskq_create(SPLAT_RWLOCK_TEST_TASKQ, 1, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE); 50, INT_MAX, TASKQ_PREPOPULATE);
if (tq == NULL) { if (tq == NULL) {
rc = -ENOMEM; rc = -ENOMEM;

View File

@ -134,7 +134,7 @@ splat_taskq_test1_impl(struct file *file, void *arg, boolean_t prealloc)
"Taskq '%s' creating (%s dispatch)\n", "Taskq '%s' creating (%s dispatch)\n",
SPLAT_TASKQ_TEST1_NAME, SPLAT_TASKQ_TEST1_NAME,
prealloc ? "prealloc" : "dynamic"); prealloc ? "prealloc" : "dynamic");
if ((tq = taskq_create(SPLAT_TASKQ_TEST1_NAME, 1, maxclsyspri, if ((tq = taskq_create(SPLAT_TASKQ_TEST1_NAME, 1, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) { 50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST1_NAME, splat_vprint(file, SPLAT_TASKQ_TEST1_NAME,
"Taskq '%s' create failed\n", "Taskq '%s' create failed\n",
@ -269,7 +269,7 @@ splat_taskq_test2_impl(struct file *file, void *arg, boolean_t prealloc) {
prealloc ? "prealloc" : "dynamic"); prealloc ? "prealloc" : "dynamic");
if ((tq[i] = taskq_create(SPLAT_TASKQ_TEST2_NAME, if ((tq[i] = taskq_create(SPLAT_TASKQ_TEST2_NAME,
TEST2_THREADS_PER_TASKQ, TEST2_THREADS_PER_TASKQ,
maxclsyspri, 50, INT_MAX, defclsyspri, 50, INT_MAX,
TASKQ_PREPOPULATE)) == NULL) { TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST2_NAME, splat_vprint(file, SPLAT_TASKQ_TEST2_NAME,
"Taskq '%s/%d' create failed\n", "Taskq '%s/%d' create failed\n",
@ -494,7 +494,7 @@ splat_taskq_test4_common(struct file *file, void *arg, int minalloc,
SPLAT_TASKQ_TEST4_NAME, SPLAT_TASKQ_TEST4_NAME,
prealloc ? "prealloc" : "dynamic", prealloc ? "prealloc" : "dynamic",
minalloc, maxalloc, nr_tasks); minalloc, maxalloc, nr_tasks);
if ((tq = taskq_create(SPLAT_TASKQ_TEST4_NAME, 1, maxclsyspri, if ((tq = taskq_create(SPLAT_TASKQ_TEST4_NAME, 1, defclsyspri,
minalloc, maxalloc, TASKQ_PREPOPULATE)) == NULL) { minalloc, maxalloc, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST4_NAME, splat_vprint(file, SPLAT_TASKQ_TEST4_NAME,
"Taskq '%s' create failed\n", "Taskq '%s' create failed\n",
@ -712,7 +712,7 @@ splat_taskq_test5_impl(struct file *file, void *arg, boolean_t prealloc)
"Taskq '%s' creating (%s dispatch)\n", "Taskq '%s' creating (%s dispatch)\n",
SPLAT_TASKQ_TEST5_NAME, SPLAT_TASKQ_TEST5_NAME,
prealloc ? "prealloc" : "dynamic"); prealloc ? "prealloc" : "dynamic");
if ((tq = taskq_create(SPLAT_TASKQ_TEST5_NAME, 3, maxclsyspri, if ((tq = taskq_create(SPLAT_TASKQ_TEST5_NAME, 3, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) { 50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST5_NAME, splat_vprint(file, SPLAT_TASKQ_TEST5_NAME,
"Taskq '%s' create failed\n", "Taskq '%s' create failed\n",
@ -873,7 +873,7 @@ splat_taskq_test6_impl(struct file *file, void *arg, boolean_t prealloc)
"Taskq '%s' creating (%s dispatch)\n", "Taskq '%s' creating (%s dispatch)\n",
SPLAT_TASKQ_TEST6_NAME, SPLAT_TASKQ_TEST6_NAME,
prealloc ? "prealloc" : "dynamic"); prealloc ? "prealloc" : "dynamic");
if ((tq = taskq_create(SPLAT_TASKQ_TEST6_NAME, 3, maxclsyspri, if ((tq = taskq_create(SPLAT_TASKQ_TEST6_NAME, 3, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) { 50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST6_NAME, splat_vprint(file, SPLAT_TASKQ_TEST6_NAME,
"Taskq '%s' create failed\n", "Taskq '%s' create failed\n",
@ -1005,7 +1005,7 @@ splat_taskq_test7_impl(struct file *file, void *arg, boolean_t prealloc)
"Taskq '%s' creating (%s dispatch)\n", "Taskq '%s' creating (%s dispatch)\n",
SPLAT_TASKQ_TEST7_NAME, SPLAT_TASKQ_TEST7_NAME,
prealloc ? "prealloc" : "dynamic"); prealloc ? "prealloc" : "dynamic");
if ((tq = taskq_create(SPLAT_TASKQ_TEST7_NAME, 1, maxclsyspri, if ((tq = taskq_create(SPLAT_TASKQ_TEST7_NAME, 1, defclsyspri,
50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) { 50, INT_MAX, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST7_NAME, splat_vprint(file, SPLAT_TASKQ_TEST7_NAME,
"Taskq '%s' create failed\n", "Taskq '%s' create failed\n",
@ -1094,7 +1094,7 @@ splat_taskq_throughput(struct file *file, void *arg, const char *name,
splat_vprint(file, name, "Taskq '%s' creating (%d/%d/%d/%d)\n", splat_vprint(file, name, "Taskq '%s' creating (%d/%d/%d/%d)\n",
name, nthreads, minalloc, maxalloc, tasks); name, nthreads, minalloc, maxalloc, tasks);
if ((tq = taskq_create(name, nthreads, maxclsyspri, if ((tq = taskq_create(name, nthreads, defclsyspri,
minalloc, maxalloc, flags)) == NULL) { minalloc, maxalloc, flags)) == NULL) {
splat_vprint(file, name, "Taskq '%s' create failed\n", name); splat_vprint(file, name, "Taskq '%s' create failed\n", name);
rc = -EINVAL; rc = -EINVAL;
@ -1203,7 +1203,7 @@ splat_taskq_test9(struct file *file, void *arg)
splat_vprint(file, SPLAT_TASKQ_TEST9_NAME, splat_vprint(file, SPLAT_TASKQ_TEST9_NAME,
"Taskq '%s' creating (%s dispatch) (%d/%d/%d)\n", "Taskq '%s' creating (%s dispatch) (%d/%d/%d)\n",
SPLAT_TASKQ_TEST9_NAME, "delay", minalloc, maxalloc, nr_tasks); SPLAT_TASKQ_TEST9_NAME, "delay", minalloc, maxalloc, nr_tasks);
if ((tq = taskq_create(SPLAT_TASKQ_TEST9_NAME, 3, maxclsyspri, if ((tq = taskq_create(SPLAT_TASKQ_TEST9_NAME, 3, defclsyspri,
minalloc, maxalloc, TASKQ_PREPOPULATE)) == NULL) { minalloc, maxalloc, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST9_NAME, splat_vprint(file, SPLAT_TASKQ_TEST9_NAME,
"Taskq '%s' create failed\n", SPLAT_TASKQ_TEST9_NAME); "Taskq '%s' create failed\n", SPLAT_TASKQ_TEST9_NAME);
@ -1303,7 +1303,7 @@ splat_taskq_test10(struct file *file, void *arg)
splat_vprint(file, SPLAT_TASKQ_TEST10_NAME, splat_vprint(file, SPLAT_TASKQ_TEST10_NAME,
"Taskq '%s' creating (%s dispatch) (%d/%d/%d)\n", "Taskq '%s' creating (%s dispatch) (%d/%d/%d)\n",
SPLAT_TASKQ_TEST10_NAME, "delay", minalloc, maxalloc, nr_tasks); SPLAT_TASKQ_TEST10_NAME, "delay", minalloc, maxalloc, nr_tasks);
if ((tq = taskq_create(SPLAT_TASKQ_TEST10_NAME, 3, maxclsyspri, if ((tq = taskq_create(SPLAT_TASKQ_TEST10_NAME, 3, defclsyspri,
minalloc, maxalloc, TASKQ_PREPOPULATE)) == NULL) { minalloc, maxalloc, TASKQ_PREPOPULATE)) == NULL) {
splat_vprint(file, SPLAT_TASKQ_TEST10_NAME, splat_vprint(file, SPLAT_TASKQ_TEST10_NAME,
"Taskq '%s' create failed\n", SPLAT_TASKQ_TEST10_NAME); "Taskq '%s' create failed\n", SPLAT_TASKQ_TEST10_NAME);

View File

@ -112,7 +112,7 @@ splat_thread_test1(struct file *file, void *arg)
tp.tp_rc = 0; tp.tp_rc = 0;
thr = (kthread_t *)thread_create(NULL, 0, splat_thread_work1, &tp, 0, thr = (kthread_t *)thread_create(NULL, 0, splat_thread_work1, &tp, 0,
&p0, TS_RUN, minclsyspri); &p0, TS_RUN, defclsyspri);
/* Must never fail under Solaris, but we check anyway since this /* Must never fail under Solaris, but we check anyway since this
* can happen in the linux SPL, we may want to change this behavior */ * can happen in the linux SPL, we may want to change this behavior */
if (thr == NULL) if (thr == NULL)
@ -161,7 +161,7 @@ splat_thread_test2(struct file *file, void *arg)
tp.tp_rc = 0; tp.tp_rc = 0;
thr = (kthread_t *)thread_create(NULL, 0, splat_thread_work2, &tp, 0, thr = (kthread_t *)thread_create(NULL, 0, splat_thread_work2, &tp, 0,
&p0, TS_RUN, minclsyspri); &p0, TS_RUN, defclsyspri);
/* Must never fail under Solaris, but we check anyway since this /* Must never fail under Solaris, but we check anyway since this
* can happen in the linux SPL, we may want to change this behavior */ * can happen in the linux SPL, we may want to change this behavior */
if (thr == NULL) if (thr == NULL)
@ -278,7 +278,7 @@ splat_thread_test3(struct file *file, void *arg)
/* Start tsd wait threads */ /* Start tsd wait threads */
for (i = 0; i < SPLAT_THREAD_TEST_THREADS; i++) { for (i = 0; i < SPLAT_THREAD_TEST_THREADS; i++) {
if (thread_create(NULL, 0, splat_thread_work3_wait, if (thread_create(NULL, 0, splat_thread_work3_wait,
&tp, 0, &p0, TS_RUN, minclsyspri)) &tp, 0, &p0, TS_RUN, defclsyspri))
wait_count++; wait_count++;
} }
@ -295,7 +295,7 @@ splat_thread_test3(struct file *file, void *arg)
/* Start tsd exit threads */ /* Start tsd exit threads */
for (i = 0; i < SPLAT_THREAD_TEST_THREADS; i++) { for (i = 0; i < SPLAT_THREAD_TEST_THREADS; i++) {
if (thread_create(NULL, 0, splat_thread_work3_exit, if (thread_create(NULL, 0, splat_thread_work3_exit,
&tp, 0, &p0, TS_RUN, minclsyspri)) &tp, 0, &p0, TS_RUN, defclsyspri))
exit_count++; exit_count++;
} }