From a8a452d74b05cc73006adfc03d0358486cf21ef8 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 2 Aug 2010 13:44:56 -0700 Subject: [PATCH 1/5] Initial commit for fix-stack-inline topic branch --- .topdeps | 1 + .topmsg | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 .topdeps create mode 100644 .topmsg diff --git a/.topdeps b/.topdeps new file mode 100644 index 0000000000..1f7391f92b --- /dev/null +++ b/.topdeps @@ -0,0 +1 @@ +master diff --git a/.topmsg b/.topmsg new file mode 100644 index 0000000000..45849cfa12 --- /dev/null +++ b/.topmsg @@ -0,0 +1,8 @@ +From: Brian Behlendorf +Subject: [PATCH] fix stack inline + +Decrease stack usage for various call paths by forcing certain +functions to be inlined. By inlining the functions the overhead +of a new stack frame is removed at the cost of increased code size. + +Signed-off-by: Brian Behlendorf From ca5262f03091d6359ebdd4b985d169c208053a70 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 30 Jul 2010 13:34:50 -0700 Subject: [PATCH 2/5] Reduce stack by inlining spa_impl_load The spa_load function may call itself recursively through the spa_load_impl function. This call path of spa_load-> spa_load_impl->spa_load->spa_load_impl takes 640 bytes of stack. By forcing spa_load_impl to be inlined as part of spa_load the can be reduced to 448 bytes, for a savings of 192 bytes, --- module/zfs/spa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/zfs/spa.c b/module/zfs/spa.c index d7c5de0d35..9a8503e303 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -1652,7 +1652,8 @@ spa_load(spa_t *spa, spa_load_state_t state, spa_import_type_t type, * Load an existing storage pool, using the pool's builtin spa_config as a * source of configuration information. */ -static int +__attribute__((always_inline)) +static inline int spa_load_impl(spa_t *spa, uint64_t pool_guid, nvlist_t *config, spa_load_state_t state, spa_import_type_t type, boolean_t mosconfig, char **ereport) From dd72f3d647bae11d9fd5c3aa45ae6972de8cb319 Mon Sep 17 00:00:00 2001 From: Ned Bass Date: Thu, 29 Jul 2010 13:37:44 -0700 Subject: [PATCH 3/5] Inline zio_notify_parent() to reduce stack use Deep recursive call chains are contributing to segfaults in ztest due to heavy stack use. Inlining zio_notify_parent() helps reduce the stack depth of the zio_notify_parent() -> zio_execute() -> zio_done() recursive cycle. I am no longer seeing ztest segfaults in this code path with this change combined with the zio_done() stack reduction in the previous commit. Signed-off-by: Brian Behlendorf --- module/zfs/zio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 88d80af4e9..75807bd30e 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -435,7 +435,8 @@ zio_wait_for_children(zio_t *zio, enum zio_child child, enum zio_wait_type wait) return (waiting); } -static void +__attribute__((always_inline)) +static inline void zio_notify_parent(zio_t *pio, zio_t *zio, enum zio_wait_type wait) { uint64_t *countp = &pio->io_children[zio->io_child_type][wait]; From 526d004cf5b8bf0456650508116713bf6bb9fa61 Mon Sep 17 00:00:00 2001 From: Ned Bass Date: Thu, 29 Jul 2010 13:35:56 -0700 Subject: [PATCH 4/5] Inline dbuf_findbp() to reduce stack use Deep recursive call chains are contributing to segfaults in ztest due to heavy stack use. Inlining dbuf_findbp() helps reduce the stack depth of the dbuf_findbp() -> dbuf_hold_impl() cycle. However, segfaults are still occurring in this code path, so further reductions are still needed. Signed-off-by: Brian Behlendorf --- module/zfs/dbuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/zfs/dbuf.c b/module/zfs/dbuf.c index 42ae439972..248bee18bf 100644 --- a/module/zfs/dbuf.c +++ b/module/zfs/dbuf.c @@ -1490,7 +1490,8 @@ dbuf_clear(dmu_buf_impl_t *db) dbuf_rele(parent, db); } -static int +__attribute__((always_inline)) +static inline int dbuf_findbp(dnode_t *dn, int level, uint64_t blkid, int fail_sparse, dmu_buf_impl_t **parentp, blkptr_t **bpp) { From 411dd65af1a3f931cee72adc6b9817187ae112cf Mon Sep 17 00:00:00 2001 From: Ned Bass Date: Fri, 30 Jul 2010 15:23:29 -0700 Subject: [PATCH 5/5] Inline zio_execute() to reduce stack use Deep recursive call chains are contributing to segfaults in ztest due to heavy stack use. Inlining zio_execute() helps reduce the stack depth of the zio_notify_parent() -> zio_execute() -> zio_wait() recursive cycle. I am no longer seeing ztest segfaults in this code path with this change. Signed-off-by: Brian Behlendorf --- module/zfs/zio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 75807bd30e..cf9b99e56f 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -1119,7 +1119,8 @@ zio_interrupt(zio_t *zio) */ static zio_pipe_stage_t *zio_pipeline[]; -void +__attribute__((always_inline)) +inline void zio_execute(zio_t *zio) { zio->io_executor = curthread;