From 0c11631b026b2e9dd40cefb72313970cc1eb389c Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 28 Jun 2010 10:00:12 -0700 Subject: [PATCH 1/4] Fix for fix-stack-dmu_objset_snapshot should be 'sn' not '&sn' I missed a instanse of removing the & operator when reducing the stack usage in this function. This unfortunately doesn't cause a compile warning but it is does cause ztest failures. Anyway, update the topic branch to correct this mistake. --- module/zfs/dmu_objset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/zfs/dmu_objset.c b/module/zfs/dmu_objset.c index 32bb614c81..ba024584fa 100644 --- a/module/zfs/dmu_objset.c +++ b/module/zfs/dmu_objset.c @@ -913,7 +913,7 @@ dmu_objset_snapshot(char *fsname, char *snapname, if (dst->dst_err) dsl_dataset_name(ds, sn->failed); zil_resume(dmu_objset_zil(os)); - dmu_objset_rele(os, &sn); + dmu_objset_rele(os, sn); } if (err) From 6914386b8590fed6be580170481b1cf9016a59b6 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 28 Jun 2010 10:11:12 -0700 Subject: [PATCH 2/4] Never sleep under taskq_dispatch() There are cases where under Linux it is not safe to sleep in taskq_dispatch(). Rather than adding Linux specific code to detect these cases I opted to keep it simple and just never allow a sleep here. The impact of this should be minimal. --- module/zfs/zio.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/module/zfs/zio.c b/module/zfs/zio.c index db9bb65fdd..341f00306a 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -1048,10 +1048,7 @@ zio_taskq_dispatch(zio_t *zio, enum zio_taskq_type q, boolean_t cutinline) { spa_t *spa = zio->io_spa; zio_type_t t = zio->io_type; - int flags; - - flags = (cutinline ? TQ_FRONT : 0); - flags |= ((q == ZIO_TASKQ_INTERRUPT) ? TQ_NOSLEEP : TQ_SLEEP); + int flags = TQ_NOSLEEP | (cutinline ? TQ_FRONT : 0); /* * If we're a config writer or a probe, the normal issue and From a2e73b751657526c49af0e0598e656df0f877a1f Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Sun, 27 Jun 2010 15:06:49 -0700 Subject: [PATCH 3/4] Allow joinable threads There was previous discussion of a race with joinable threads but to be honest I can neither exactly remember the race, or recrease the issue. I believe it may have had to do with pthread_create() returning without having set kt->tid since this was done in the created thread. If that was the race then I've 'fixed' it by ensuring the thread id is set in the thread AND as the first pthread_create() argument. Why this wasn't done originally I'm not sure, with luck Ricardo remembers. Additionally, explicitly set a PAGESIZE guard frame at the end of the stack to aid in detecting stack overflow. And add some conditional logic to set STACK_SIZE correctly for Solaris. --- lib/libzpool/include/sys/zfs_context.h | 4 ++++ lib/libzpool/kernel.c | 25 ++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/libzpool/include/sys/zfs_context.h b/lib/libzpool/include/sys/zfs_context.h index db93a89b8b..e62c75a188 100644 --- a/lib/libzpool/include/sys/zfs_context.h +++ b/lib/libzpool/include/sys/zfs_context.h @@ -198,7 +198,11 @@ _NOTE(CONSTCOND) } while (0) * Threads */ #define TS_RUN 0x00000002 +#ifdef _linux_ #define STACK_SIZE 8192 /* Linux x86 and amd64 */ +#else +#define STACK_SIZE 24576 /* Solaris */ +#endif /* in libzpool, p0 exists only to have its address taken */ typedef struct proc { diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index 6f9e383a87..a992bec9ab 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -145,14 +145,9 @@ zk_thread_create(caddr_t stk, size_t stksize, thread_func_t func, void *arg, size_t len, proc_t *pp, int state, pri_t pri) { kthread_t *kt; - pthread_t tid; pthread_attr_t attr; size_t stack; - /* - * Due to a race when getting/setting the thread ID, currently only - * detached threads are supported. - */ ASSERT3S(state & ~TS_RUN, ==, 0); kt = umem_zalloc(sizeof(kthread_t), UMEM_NOFAIL); @@ -160,23 +155,23 @@ zk_thread_create(caddr_t stk, size_t stksize, thread_func_t func, void *arg, kt->t_arg = arg; /* - * The Solaris kernel stack size in x86/x64 is 8K, so we reduce the - * default stack size in userspace, for sanity checking. + * The Solaris kernel stack size is 24k for x86/x86_64. + * The Linux kernel stack size is 8k for x86/x86_64. * - * PTHREAD_STACK_MIN is the stack required for a NULL procedure in - * userspace. - * - * XXX: Stack size for other architectures is not being taken into - * account. + * We reduce the default stack size in userspace, to ensure + * we observe stack overruns in user space as well as in + * kernel space. PTHREAD_STACK_MIN is the minimum stack + * required for a NULL procedure in user space and is added + * in to the stack requirements. */ stack = PTHREAD_STACK_MIN + MAX(stksize, STACK_SIZE); VERIFY3S(pthread_attr_init(&attr), ==, 0); VERIFY3S(pthread_attr_setstacksize(&attr, stack), ==, 0); - VERIFY3S(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED), - ==, 0); + VERIFY3S(pthread_attr_setguardsize(&attr, PAGESIZE), ==, 0); - VERIFY3S(pthread_create(&tid, &attr, &zk_thread_helper, kt), ==, 0); + VERIFY3S(pthread_create(&kt->t_tid, &attr, &zk_thread_helper, kt), + ==, 0); VERIFY3S(pthread_attr_destroy(&attr), ==, 0); From 52bb0d8e75b0de049832b986fd06d6ca950fc4c5 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 21 Jun 2010 21:31:41 -0700 Subject: [PATCH 4/4] Ensure zio_bad_cksum_t is initialized This may not strictly be needed but it does keep gcc happy. We should keep our eye on this though if the extra bcopy significantly impacts performance. It may. --- module/zfs/vdev_raidz.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/module/zfs/vdev_raidz.c b/module/zfs/vdev_raidz.c index 64c1564bfd..cbabb84020 100644 --- a/module/zfs/vdev_raidz.c +++ b/module/zfs/vdev_raidz.c @@ -1638,8 +1638,11 @@ raidz_checksum_verify(zio_t *zio) { zio_bad_cksum_t zbc; raidz_map_t *rm = zio->io_vsd; + int ret; - int ret = zio_checksum_error(zio, &zbc); + bzero(&zbc, sizeof (zio_bad_cksum_t)); + + ret = zio_checksum_error(zio, &zbc); if (ret != 0 && zbc.zbc_injected != 0) rm->rm_ecksuminjected = 1;