From b8cc785fb63ce642a8b0ea615bc3b0c29189b520 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 14 Jun 2010 16:45:01 -0700 Subject: [PATCH] Add fix-stack-lzjb topic branch Reduce kernel stack usage by lzjb_compress() by moving uint16 array off the stack and on to the heap. The exact performance implications of this I have not measured but we absolutely need to keep stack usage to a minimum. If/when this becomes and issue we optimize. --- .topdeps | 1 + .topmsg | 9 +++++++++ module/zfs/lzjb.c | 11 ++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) 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..4f1c8f2635 --- /dev/null +++ b/.topmsg @@ -0,0 +1,9 @@ +From: Brian Behlendorf +Subject: [PATCH] fix stack lzjb + +Reduce kernel stack usage by lzjb_compress() by moving uint16 array +off the stack and on to the heap. The exact performance implications +of this I have not measured but we absolutely need to keep stack +usage to a minimum. If/when this becomes and issue we optimize. + +Signed-off-by: Brian Behlendorf diff --git a/module/zfs/lzjb.c b/module/zfs/lzjb.c index 10952f472b..1f2deb51a0 100644 --- a/module/zfs/lzjb.c +++ b/module/zfs/lzjb.c @@ -37,7 +37,7 @@ * compress to d_len or less. */ -#include +#include #define MATCH_BITS 6 #define MATCH_MIN 3 @@ -55,12 +55,15 @@ lzjb_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) int copymask = 1 << (NBBY - 1); int mlen, offset, hash; uint16_t *hp; - uint16_t lempel[LEMPEL_SIZE] = { 0 }; + uint16_t *lempel; + lempel = kmem_zalloc(LEMPEL_SIZE * sizeof (uint16_t), KM_SLEEP); while (src < (uchar_t *)s_start + s_len) { if ((copymask <<= 1) == (1 << NBBY)) { - if (dst >= (uchar_t *)d_start + d_len - 1 - 2 * NBBY) + if (dst >= (uchar_t *)d_start + d_len - 1 - 2 * NBBY) { + kmem_free(lempel, LEMPEL_SIZE*sizeof(uint16_t)); return (s_len); + } copymask = 1; copymap = dst; *dst++ = 0; @@ -90,6 +93,8 @@ lzjb_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n) *dst++ = *src++; } } + + kmem_free(lempel, LEMPEL_SIZE * sizeof (uint16_t)); return (dst - (uchar_t *)d_start); }