]> git.ozlabs.org Git - ppp.git/commitdiff
use vmalloc for large chunks,
authorPaul Mackerras <paulus@samba.org>
Tue, 4 Mar 1997 03:30:59 +0000 (03:30 +0000)
committerPaul Mackerras <paulus@samba.org>
Tue, 4 Mar 1997 03:30:59 +0000 (03:30 +0000)
fix problem with decompressing full-size packets.

linux/ppp_deflate.c

index 6f56e03703072a943d153c5fb4426134aebf1ff2..8afc5559804a989af6088b795414fa703bb5c1b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- *  ==FILEVERSION 960926==
+ *  ==FILEVERSION 961207==
  *
  * ppp_deflate.c - interface the zlib procedures for Deflate compression
  * and decompression (as used by gzip) to the PPP code.
  *
  * ppp_deflate.c - interface the zlib procedures for Deflate compression
  * and decompression (as used by gzip) to the PPP code.
@@ -32,6 +32,7 @@
  */
 
 #include <linux/module.h>
  */
 
 #include <linux/module.h>
+#include <linux/version.h>
 
 #include <endian.h>
 #include <linux/kernel.h>
 
 #include <endian.h>
 #include <linux/kernel.h>
@@ -53,7 +54,7 @@
 #include <asm/bitops.h>
 #include <asm/segment.h>
 
 #include <asm/bitops.h>
 #include <asm/segment.h>
 
-#include <net/if.h>
+#include <linux/if.h>
 
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
 
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
 
 #include <linux/ppp_defs.h>
 
 
 #include <linux/ppp_defs.h>
 
-#ifdef NEW_SKBUFF
+#if LINUX_VERSION_CODE < 0x02010E
 #include <linux/netprotocol.h>
 #endif
 
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
 #include <linux/netprotocol.h>
 #endif
 
 #include <netinet/ip.h>
 #include <netinet/tcp.h>
-#include <net/if_arp.h>
+#include <linux/if_arp.h>
 #include <linux/ppp-comp.h>
 
 #include "zlib.c"
 #include <linux/ppp-comp.h>
 
 #include "zlib.c"
@@ -191,6 +192,13 @@ MemChunk *freePool;
 #endif
 #endif /* USEMEMPOOL */
 
 #endif
 #endif /* USEMEMPOOL */
 
+struct chunk_header {
+    unsigned size;             /* amount of space following header */
+    int valloced;              /* allocated with valloc, not kmalloc */
+};
+
+#define MIN_VMALLOC    2048    /* use kmalloc for blocks < this */
+
 /*
  * Space allocation and freeing routines for use by zlib routines.
  */
 /*
  * Space allocation and freeing routines for use by zlib routines.
  */
@@ -201,7 +209,12 @@ zfree(arg, ptr, nbytes)
     unsigned int nbytes;
 {
 #if !USEMEMPOOL
     unsigned int nbytes;
 {
 #if !USEMEMPOOL
-    kfree(ptr);
+    struct chunk_header *hdr = ((struct chunk_header *)ptr) - 1;
+
+    if (hdr->valloced)
+       vfree(hdr);
+    else
+       kfree(hdr);
 #else
     MemPool *memPool = (MemPool *)arg;
     MemChunk *mprev = 0, *node;
 #else
     MemPool *memPool = (MemPool *)arg;
     MemChunk *mprev = 0, *node;
@@ -262,8 +275,22 @@ zalloc(arg, items, size)
 {
 #if !USEMEMPOOL
     struct ppp_deflate_state *state = arg;
 {
 #if !USEMEMPOOL
     struct ppp_deflate_state *state = arg;
+    struct chunk_header *hdr;
+    unsigned nbytes;
 
 
-    return kmalloc(items * size, state->in_alloc? GFP_KERNEL: GFP_ATOMIC);
+    nbytes = items * size + sizeof(*hdr);
+    if (state->in_alloc)
+       if (nbytes >= MIN_VMALLOC)
+           hdr = vmalloc(nbytes);
+       else
+           hdr = kmalloc(nbytes, GFP_KERNEL);
+    else
+       hdr = kmalloc(nbytes, GFP_ATOMIC);
+    if (hdr == 0)
+       return 0;
+    hdr->size = nbytes;
+    hdr->valloced = state->in_alloc && nbytes >= MIN_VMALLOC;
+    return (void *) (hdr + 1);
 #else
     MemPool *memPool = (MemPool *)arg;
     MemChunk *mprev = 0, *node;
 #else
     MemPool *memPool = (MemPool *)arg;
     MemChunk *mprev = 0, *node;
@@ -705,7 +732,7 @@ z_decompress(arg, ibuf, isize, obuf, osize)
     if (decode_proto)
        return DECOMP_ERROR;
 
     if (decode_proto)
        return DECOMP_ERROR;
 
-    olen = osize - state->strm.avail_out;
+    olen = osize + overflow - state->strm.avail_out;
     state->stats.unc_bytes += olen;
     state->stats.unc_packets++;
     state->stats.comp_bytes += isize;
     state->stats.unc_bytes += olen;
     state->stats.unc_packets++;
     state->stats.comp_bytes += isize;