From 04bae5ec95f7273105237159a882d5b72ec2b998 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Fri, 3 May 2024 12:53:34 -0400 Subject: [PATCH] Disable high priority ZIO threads on FreeBSD and Linux High priority threads are handling ZIL writes. While there is no ZIL compression, there is encryption, checksuming and RAIDZ math. We've found that on large systems 1 taskq with 5 threads can be a bottleneck for throughput, IOPS or both. Instead of just bumping number of threads with a risk of overloading CPUs and increasing latency, switch to using TQ_FRONT mechanism to increase sync write requests priority within standard write threads. Do not do it on Illumos, since its TQ_FRONT implementation is inherently unfair. FreeBSD and Linux don't have this problem, so we can do it there. Reviewed-by: Brian Behlendorf Reviewed-by: Rob Norris Signed-off-by: Alexander Motin Sponsored-By: iXsystems, Inc. Closes #16146 --- man/man4/zfs.4 | 2 +- module/zfs/spa.c | 11 ++++++++--- module/zfs/zio.c | 12 +++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/man/man4/zfs.4 b/man/man4/zfs.4 index 5edd80659e..6895a2a6d7 100644 --- a/man/man4/zfs.4 +++ b/man/man4/zfs.4 @@ -2367,7 +2367,7 @@ This is an advanced debugging parameter. Don't change this unless you understand what it does. Set values only apply to pools imported/created after that. . -.It Sy zio_taskq_write Ns = Ns Sy sync fixed,1,5 scale fixed,1,5 Pq charp +.It Sy zio_taskq_write Ns = Ns Sy sync null scale null Pq charp Set the queue and thread configuration for the IO write queues. This is an advanced debugging parameter. Don't change this unless you understand what it does. diff --git a/module/zfs/spa.c b/module/zfs/spa.c index ec2b674fb7..560fd67087 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -170,14 +170,19 @@ static const char *const zio_taskq_types[ZIO_TASKQ_TYPES] = { * that scales with the number of CPUs. * * The different taskq priorities are to handle the different contexts (issue - * and interrupt) and then to reserve threads for ZIO_PRIORITY_NOW I/Os that - * need to be handled with minimum delay. + * and interrupt) and then to reserve threads for high priority I/Os that + * need to be handled with minimum delay. Illumos taskq has unfair TQ_FRONT + * implementation, so separate high priority threads are used there. */ static zio_taskq_info_t zio_taskqs[ZIO_TYPES][ZIO_TASKQ_TYPES] = { /* ISSUE ISSUE_HIGH INTR INTR_HIGH */ { ZTI_ONE, ZTI_NULL, ZTI_ONE, ZTI_NULL }, /* NULL */ { ZTI_N(8), ZTI_NULL, ZTI_SCALE, ZTI_NULL }, /* READ */ +#ifdef illumos { ZTI_SYNC, ZTI_N(5), ZTI_SCALE, ZTI_N(5) }, /* WRITE */ +#else + { ZTI_SYNC, ZTI_NULL, ZTI_SCALE, ZTI_NULL }, /* WRITE */ +#endif { ZTI_SCALE, ZTI_NULL, ZTI_ONE, ZTI_NULL }, /* FREE */ { ZTI_ONE, ZTI_NULL, ZTI_ONE, ZTI_NULL }, /* CLAIM */ { ZTI_ONE, ZTI_NULL, ZTI_ONE, ZTI_NULL }, /* FLUSH */ @@ -1217,7 +1222,7 @@ spa_taskqs_fini(spa_t *spa, zio_type_t t, zio_taskq_type_t q) * * Example (the defaults for READ and WRITE) * zio_taskq_read='fixed,1,8 null scale null' - * zio_taskq_write='sync fixed,1,5 scale fixed,1,5' + * zio_taskq_write='sync null scale null' * * Each sets the entire row at a time. * diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 870343bf4f..65a0afaaa2 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -2041,12 +2041,14 @@ zio_taskq_dispatch(zio_t *zio, zio_taskq_type_t q, boolean_t cutinline) /* * If this is a high priority I/O, then use the high priority taskq if - * available. + * available or cut the line otherwise. */ - if ((zio->io_priority == ZIO_PRIORITY_NOW || - zio->io_priority == ZIO_PRIORITY_SYNC_WRITE) && - spa->spa_zio_taskq[t][q + 1].stqs_count != 0) - q++; + if (zio->io_priority == ZIO_PRIORITY_SYNC_WRITE) { + if (spa->spa_zio_taskq[t][q + 1].stqs_count != 0) + q++; + else + flags |= TQ_FRONT; + } ASSERT3U(q, <, ZIO_TASKQ_TYPES);