Skip to content

Commit

Permalink
[PATCH] zlib_inflate: Upgrade library code to a recent version
Browse files Browse the repository at this point in the history
Upgrade the zlib_inflate implementation in the kernel from a patched
version 1.1.3/4 to a patched 1.2.3.

The code in the kernel is about seven years old and I noticed that the
external zlib library's inflate performance was significantly faster (~50%)
than the code in the kernel on ARM (and faster again on x86_32).

For comparison the newer deflate code is 20% slower on ARM and 50% slower
on x86_32 but gives an approx 1% compression ratio improvement.  I don't
consider this to be an improvement for kernel use so have no plans to
change the zlib_deflate code.

Various changes have been made to the zlib code in the kernel, the most
significant being the extra functions/flush option used by ppp_deflate.
This update reimplements the features PPP needs to ensure it continues to
work.

This code has been tested on ARM under both JFFS2 (with zlib compression
enabled) and ppp_deflate and on x86_32.  JFFS2 sees an approx.  10% real
world file read speed improvement.

This patch also removes ZLIB_VERSION as it no longer has a correct value.
We don't need version checks anyway as the kernel's module handling will
take care of that for us.  This removal is also more in keeping with the
zlib author's wishes (http://www.zlib.net/zlib_faq.html#faq24) and I've
added something to the zlib.h header to note its a modified version.

Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Acked-by: Joern Engel <joern@wh.fh-wedel.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
rpurdie authored and Linus Torvalds committed Jun 22, 2006
1 parent 4f1bcaf commit 4f3865f
Show file tree
Hide file tree
Showing 24 changed files with 1,877 additions and 2,006 deletions.
4 changes: 2 additions & 2 deletions arch/powerpc/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ OBJCOPYFLAGS := contents,alloc,load,readonly,data
OBJCOPY_COFF_ARGS := -O aixcoff-rs6000 --set-start 0x500000
OBJCOPY_MIB_ARGS := -O aixcoff-rs6000 -R .stab -R .stabstr -R .comment

zlib := infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c
zlibheader := infblock.h infcodes.h inffast.h inftrees.h infutil.h
zlib := inffast.c inflate.c inftrees.c
zlibheader := inffast.h inffixed.h inflate.h inftrees.h infutil.h
zliblinuxheader := zlib.h zconf.h zutil.h

$(addprefix $(obj)/,$(zlib) main.o): $(addprefix $(obj)/,$(zliblinuxheader)) $(addprefix $(obj)/,$(zlibheader))
Expand Down
2 changes: 1 addition & 1 deletion arch/ppc/boot/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
CFLAGS_kbd.o := -Idrivers/char
CFLAGS_vreset.o := -Iarch/ppc/boot/include

zlib := infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c
zlib := inffast.c inflate.c inftrees.c

lib-y += $(zlib:.c=.o) div64.o
lib-$(CONFIG_VGA_CONSOLE) += vreset.o kbd.o
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/boot/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Makefile for some libs needed by zImage.
#

zlib := infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c
zlib := inffast.c inflate.c inftrees.c

lib-y += $(zlib:.c=.o) zmem.o

Expand Down
12 changes: 12 additions & 0 deletions include/linux/zconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif

/* default windowBits for decompression. MAX_WBITS is for compression only */
#ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS
#endif

/* default memLevel */
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif

/* Type declarations */
Expand Down
209 changes: 129 additions & 80 deletions include/linux/zlib.h

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions include/linux/zutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ typedef unsigned long ulg;

/* common constants */

#ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */

#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
/* default memLevel */

#define STORED_BLOCK 0
#define STATIC_TREES 1
#define DYN_TREES 2
Expand Down
25 changes: 2 additions & 23 deletions lib/zlib_deflate/deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,45 +164,24 @@ static const config configuration_table[10] = {
memset((char *)s->head, 0, (unsigned)(s->hash_size-1)*sizeof(*s->head));

/* ========================================================================= */
int zlib_deflateInit_(
z_streamp strm,
int level,
const char *version,
int stream_size
)
{
return zlib_deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS,
DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, version, stream_size);
/* To do: ignore strm->next_in if we use it as window */
}

/* ========================================================================= */
int zlib_deflateInit2_(
int zlib_deflateInit2(
z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy,
const char *version,
int stream_size
int strategy
)
{
deflate_state *s;
int noheader = 0;
static char* my_version = ZLIB_VERSION;
deflate_workspace *mem;

ush *overlay;
/* We overlay pending_buf and d_buf+l_buf. This works since the average
* output size for (length,distance) codes is <= 24 bits.
*/

if (version == NULL || version[0] != my_version[0] ||
stream_size != sizeof(z_stream)) {
return Z_VERSION_ERROR;
}
if (strm == NULL) return Z_STREAM_ERROR;

strm->msg = NULL;
Expand Down
3 changes: 1 addition & 2 deletions lib/zlib_deflate/deflate_syms.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

EXPORT_SYMBOL(zlib_deflate_workspacesize);
EXPORT_SYMBOL(zlib_deflate);
EXPORT_SYMBOL(zlib_deflateInit_);
EXPORT_SYMBOL(zlib_deflateInit2_);
EXPORT_SYMBOL(zlib_deflateInit2);
EXPORT_SYMBOL(zlib_deflateEnd);
EXPORT_SYMBOL(zlib_deflateReset);
MODULE_LICENSE("GPL");
4 changes: 2 additions & 2 deletions lib/zlib_inflate/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate.o

zlib_inflate-objs := infblock.o infcodes.o inffast.o inflate.o \
inflate_sync.o inftrees.o infutil.o inflate_syms.o
zlib_inflate-objs := inffast.o inflate.o \
inftrees.o inflate_syms.o
Loading

0 comments on commit 4f3865f

Please sign in to comment.