All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Smith" <dpsmith@apertussolutions.com>
To: xen-devel@lists.xenproject.org
Cc: Jason Andryuk <jason.andryuk@amd.com>,
	"Daniel P. Smith" <dpsmith@apertussolutions.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>
Subject: [PATCH v2 3/6] gzip: remove custom memory allocator
Date: Wed, 17 Apr 2024 10:37:13 -0400	[thread overview]
Message-ID: <20240417143716.27189-4-dpsmith@apertussolutions.com> (raw)
In-Reply-To: <20240417143716.27189-1-dpsmith@apertussolutions.com>

All the other decompression routines use xmalloc_bytes(), thus there is no
reason for gzip to be handling its own allocation of memory. In fact, there is
a bug somewhere in the allocator as decompression started to break when adding
additional allocations. Instead of troubleshooting the allocator, replace it
with xmalloc_bytes().

Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com>
---
 xen/common/gzip/gunzip.c  | 17 ++------------
 xen/common/gzip/inflate.c | 47 ---------------------------------------
 2 files changed, 2 insertions(+), 62 deletions(-)

diff --git a/xen/common/gzip/gunzip.c b/xen/common/gzip/gunzip.c
index 1bcb007395ba..1b448d6e3655 100644
--- a/xen/common/gzip/gunzip.c
+++ b/xen/common/gzip/gunzip.c
@@ -4,12 +4,7 @@
 #include <xen/lib.h>
 #include <xen/mm.h>
 
-#define HEAPORDER 3
-
 static unsigned char *__initdata window;
-#define memptr long
-static memptr __initdata free_mem_ptr;
-static memptr __initdata free_mem_end_ptr;
 
 #define WSIZE           0x80000000U
 
@@ -24,6 +19,8 @@ static unsigned int __initdata outcnt;
 
 #define OF(args)        args
 
+#define malloc(a)       xmalloc_bytes(a)
+#define free(a)         xfree(a)
 #define memzero(s, n)   memset((s), 0, (n))
 
 typedef unsigned char   uch;
@@ -108,14 +105,6 @@ __init int perform_gunzip(char *output, char *image, unsigned long image_len)
         return 1;
 
     window = (unsigned char *)output;
-
-    free_mem_ptr = (unsigned long)alloc_xenheap_pages(HEAPORDER, 0);
-    if ( !free_mem_ptr )
-        return -ENOMEM;
-
-    free_mem_end_ptr = free_mem_ptr + (PAGE_SIZE << HEAPORDER);
-    init_allocator();
-
     inbuf = (unsigned char *)image;
     insize = image_len;
     inptr = 0;
@@ -132,8 +121,6 @@ __init int perform_gunzip(char *output, char *image, unsigned long image_len)
         rc = 0;
     }
 
-    free_xenheap_pages((void *)free_mem_ptr, HEAPORDER);
-
     return rc;
 }
 
diff --git a/xen/common/gzip/inflate.c b/xen/common/gzip/inflate.c
index 73ccfc2bdc6c..512d9bf0ee2e 100644
--- a/xen/common/gzip/inflate.c
+++ b/xen/common/gzip/inflate.c
@@ -228,53 +228,6 @@ static const ush mask_bits[] = {
 #define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE())<<k;k+=8;}}
 #define DUMPBITS(n) {b>>=(n);k-=(n);}
 
-#ifndef NO_INFLATE_MALLOC
-/*
- * A trivial malloc implementation, adapted from
- *  malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
- */
-
-static unsigned long __initdata malloc_ptr;
-static int __initdata malloc_count;
-
-static void __init init_allocator(void)
-{
-    malloc_ptr = free_mem_ptr;
-    malloc_count = 0;
-}
-
-static void *__init malloc(int size)
-{
-    void *p;
-
-    if (size < 0)
-        error("Malloc error");
-    if (!malloc_ptr)
-        malloc_ptr = free_mem_ptr;
-
-    malloc_ptr = (malloc_ptr + 3) & ~3;     /* Align */
-
-    p = (void *)malloc_ptr;
-    malloc_ptr += size;
-
-    if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
-        error("Out of memory");
-
-    malloc_count++;
-    return p;
-}
-
-static void __init free(void *where)
-{
-    malloc_count--;
-    if (!malloc_count)
-        malloc_ptr = free_mem_ptr;
-}
-#else
-#define malloc(a) kmalloc(a, GFP_KERNEL)
-#define free(a) kfree(a)
-#endif
-
 /*
  * Huffman code decoding is performed using a multi-level table lookup.
  * The fastest way to decode is to simply build a lookup table whose
-- 
2.30.2



  parent reply	other threads:[~2024-04-17 14:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 14:37 [PATCH v2 0/6] Clean up of gzip decompressor Daniel P. Smith
2024-04-17 14:37 ` [PATCH v2 1/6] gzip: drop unused define checks Daniel P. Smith
2024-04-17 16:27   ` Andrew Cooper
2024-04-18  7:47   ` Jan Beulich
2024-04-17 14:37 ` [PATCH v2 2/6] gzip: clean up comments and fix code alignment Daniel P. Smith
2024-04-17 14:37 ` Daniel P. Smith [this message]
2024-04-17 16:52   ` [PATCH v2 3/6] gzip: remove custom memory allocator Andrew Cooper
2024-04-17 14:37 ` [PATCH v2 4/6] gzip: refactor state tracking Daniel P. Smith
2024-04-17 18:45   ` Andrew Cooper
2024-04-17 14:37 ` [PATCH v2 5/6] gzip: move crc state into consilidated gzip state Daniel P. Smith
2024-04-17 17:00   ` Andrew Cooper
2024-04-17 14:37 ` [PATCH v2 6/6] gzip: drop huffman code table tracking Daniel P. Smith
2024-04-17 16:31   ` Andrew Cooper
2024-04-18  7:43 ` [PATCH v2 0/6] Clean up of gzip decompressor Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240417143716.27189-4-dpsmith@apertussolutions.com \
    --to=dpsmith@apertussolutions.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jason.andryuk@amd.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.