aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorJim Keniston <jkenisto@linux.vnet.ibm.com>2011-03-22 19:35:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-22 20:44:17 -0400
commit565d76cb7d5fd7cb010fd690602280a69ab116ef (patch)
treebeff4279da00976e10145820c22e699192056973 /crypto
parentb12d12596992f608f5506a8dabe4d1299594bd1e (diff)
zlib: slim down zlib_deflate() workspace when possible
Instead of always creating a huge (268K) deflate_workspace with the maximum compression parameters (windowBits=15, memLevel=8), allow the caller to obtain a smaller workspace by specifying smaller parameter values. For example, when capturing oops and panic reports to a medium with limited capacity, such as NVRAM, compression may be the only way to capture the whole report. In this case, a small workspace (24K works fine) is a win, whether you allocate the workspace when you need it (i.e., during an oops or panic) or at boot time. I've verified that this patch works with all accepted values of windowBits (positive and negative), memLevel, and compression level. Signed-off-by: Jim Keniston <jkenisto@us.ibm.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: David Miller <davem@davemloft.net> Cc: Chris Mason <chris.mason@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/deflate.c3
-rw-r--r--crypto/zlib.c18
2 files changed, 13 insertions, 8 deletions
diff --git a/crypto/deflate.c b/crypto/deflate.c
index cbc7a33a9600..b5ccae29be74 100644
--- a/crypto/deflate.c
+++ b/crypto/deflate.c
@@ -48,7 +48,8 @@ static int deflate_comp_init(struct deflate_ctx *ctx)
48 int ret = 0; 48 int ret = 0;
49 struct z_stream_s *stream = &ctx->comp_stream; 49 struct z_stream_s *stream = &ctx->comp_stream;
50 50
51 stream->workspace = vzalloc(zlib_deflate_workspacesize()); 51 stream->workspace = vzalloc(zlib_deflate_workspacesize(
52 -DEFLATE_DEF_WINBITS, DEFLATE_DEF_MEMLEVEL));
52 if (!stream->workspace) { 53 if (!stream->workspace) {
53 ret = -ENOMEM; 54 ret = -ENOMEM;
54 goto out; 55 goto out;
diff --git a/crypto/zlib.c b/crypto/zlib.c
index 739b8fca4cea..d11d761a5e41 100644
--- a/crypto/zlib.c
+++ b/crypto/zlib.c
@@ -85,6 +85,7 @@ static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
85 struct zlib_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm)); 85 struct zlib_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
86 struct z_stream_s *stream = &ctx->comp_stream; 86 struct z_stream_s *stream = &ctx->comp_stream;
87 struct nlattr *tb[ZLIB_COMP_MAX + 1]; 87 struct nlattr *tb[ZLIB_COMP_MAX + 1];
88 int window_bits, mem_level;
88 size_t workspacesize; 89 size_t workspacesize;
89 int ret; 90 int ret;
90 91
@@ -94,7 +95,14 @@ static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
94 95
95 zlib_comp_exit(ctx); 96 zlib_comp_exit(ctx);
96 97
97 workspacesize = zlib_deflate_workspacesize(); 98 window_bits = tb[ZLIB_COMP_WINDOWBITS]
99 ? nla_get_u32(tb[ZLIB_COMP_WINDOWBITS])
100 : MAX_WBITS;
101 mem_level = tb[ZLIB_COMP_MEMLEVEL]
102 ? nla_get_u32(tb[ZLIB_COMP_MEMLEVEL])
103 : DEF_MEM_LEVEL;
104
105 workspacesize = zlib_deflate_workspacesize(window_bits, mem_level);
98 stream->workspace = vzalloc(workspacesize); 106 stream->workspace = vzalloc(workspacesize);
99 if (!stream->workspace) 107 if (!stream->workspace)
100 return -ENOMEM; 108 return -ENOMEM;
@@ -106,12 +114,8 @@ static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
106 tb[ZLIB_COMP_METHOD] 114 tb[ZLIB_COMP_METHOD]
107 ? nla_get_u32(tb[ZLIB_COMP_METHOD]) 115 ? nla_get_u32(tb[ZLIB_COMP_METHOD])
108 : Z_DEFLATED, 116 : Z_DEFLATED,
109 tb[ZLIB_COMP_WINDOWBITS] 117 window_bits,
110 ? nla_get_u32(tb[ZLIB_COMP_WINDOWBITS]) 118 mem_level,
111 : MAX_WBITS,
112 tb[ZLIB_COMP_MEMLEVEL]
113 ? nla_get_u32(tb[ZLIB_COMP_MEMLEVEL])
114 : DEF_MEM_LEVEL,
115 tb[ZLIB_COMP_STRATEGY] 119 tb[ZLIB_COMP_STRATEGY]
116 ? nla_get_u32(tb[ZLIB_COMP_STRATEGY]) 120 ? nla_get_u32(tb[ZLIB_COMP_STRATEGY])
117 : Z_DEFAULT_STRATEGY); 121 : Z_DEFAULT_STRATEGY);