Re: Memory use... am I doing something wrong here?

From: James R Grinter <[email protected]>
Date: Fri, 27 Jun 1997 15:46:22 +0100

On Fri 27 Jun, 1997, Jonathan Larmour <JLarmour@origin-at.co.uk> wrote:
>malloc implementation isn't very good. Do you have mallinfo() on your
>system (its automatically used by cachemgr if it is)?
>
>Perhaps you could try compiling squid with GNUmalloc.

We've had a lot of good results with the "phkmalloc" that is now
shipping in FreeBSD's libc (not it's libgnumalloc.a which is obviously
one of the gnu malloc.)

Go to your nearest FreeBSD archive/mirror site, and pick out malloc.c
from usr/src/usr.lib/libc/malloc/.

If you're not compiling on a 4.4BSD system you'll probably need to
patch the code slightly (patch that works for me is attached below) to
compile it. No guarantees though, I don't for instance know how well
this would work under Linux. It's worked well for me under Irix 6.2.

-- jrg.

*** malloc.c.orig Fri May 16 12:39:31 1997
--- malloc.c Fri May 16 17:16:00 1997
***************
*** 66,71 ****
--- 66,72 ----
   * No user serviceable parts behind this point.
   */
  #include <stdio.h>
+ #include <fcntl.h>
  #include <stdlib.h>
  #include <string.h>
  #include <unistd.h>
***************
*** 279,285 ****
--- 280,288 ----
  }
  #endif /* MALLOC_STATS */
  
+ #ifdef __FreeBSD__
  extern char *__progname;
+ #endif
  
  static void
  wrterror(char *p)
***************
*** 286,292 ****
--- 289,297 ----
  {
      char *q = " error: ";
      suicide = 1;
+ #ifdef __FreeBSD__
      write(2, __progname, strlen(__progname));
+ #endif
      write(2, malloc_func, strlen(malloc_func));
      write(2, q, strlen(q));
      write(2, p, strlen(p));
***************
*** 303,309 ****
--- 308,316 ----
      char *q = " warning: ";
      if (malloc_abort)
          wrterror(p);
+ #ifdef __FreeBSD__
      write(2, __progname, strlen(__progname));
+ #endif
      write(2, malloc_func, strlen(malloc_func));
      write(2, q, strlen(q));
      write(2, p, strlen(p));
***************
*** 359,364 ****
--- 366,372 ----
  {
      struct pginfo **new, **old;
      int i, oldlen;
+ static int fd = -1; /* for "anonymous" file area */
  
      /* Make it this many pages */
      i = index * sizeof *page_dir;
***************
*** 384,391 ****
       */
  
      /* Get new pages */
      new = (struct pginfo**) mmap(0, i * malloc_pagesize, PROT_READ|PROT_WRITE,
! MAP_ANON|MAP_PRIVATE, -1, 0);
      if (new == (struct pginfo **)-1)
          return 0;
  
--- 392,403 ----
       */
  
      /* Get new pages */
+ if (fd < 0) {
+ fd = open("/dev/zero", O_RDWR);
+ if(fd < 0) return 0;
+ }
      new = (struct pginfo**) mmap(0, i * malloc_pagesize, PROT_READ|PROT_WRITE,
! MAP_PRIVATE, fd, 0);
      if (new == (struct pginfo **)-1)
          return 0;
  
***************
*** 413,420 ****
  {
      char *p, b[64];
      int i, j;
  
-
  #ifdef EXTRA_SANITY
      malloc_junk = 1;
  #endif /* EXTRA_SANITY */
--- 425,432 ----
  {
      char *p, b[64];
      int i, j;
+ static int fd = -1; /* for "anonymous" file area */
  
  #ifdef EXTRA_SANITY
      malloc_junk = 1;
  #endif /* EXTRA_SANITY */
***************
*** 474,481 ****
  #endif /* MALLOC_STATS */
  
      /* Allocate one page for the page directory */
      page_dir = (struct pginfo **) mmap(0, malloc_pagesize, PROT_READ|PROT_WRITE,
! MAP_ANON|MAP_PRIVATE, -1, 0);
      if (page_dir == (struct pginfo **) -1)
          wrterror("mmap(2) failed, check limits.\n");
  
--- 486,497 ----
  #endif /* MALLOC_STATS */
  
      /* Allocate one page for the page directory */
+ if (fd < 0) {
+ fd = open("/dev/zero", O_RDWR);
+ /* if(fd < 0) return 0; XXX: can't return failure here -- jrg */
+ }
      page_dir = (struct pginfo **) mmap(0, malloc_pagesize, PROT_READ|PROT_WRITE,
! MAP_PRIVATE, fd, 0);
      if (page_dir == (struct pginfo **) -1)
          wrterror("mmap(2) failed, check limits.\n");
  
***************
*** 880,886 ****
          memset(ptr, SOME_JUNK, l);
  
      if (malloc_hint)
! madvise(ptr, l, MADV_FREE);
  
      tail = (char *)ptr+l;
  
--- 896,902 ----
          memset(ptr, SOME_JUNK, l);
  
      if (malloc_hint)
! madvise(ptr, l, MADV_DONTNEED);
  
      tail = (char *)ptr+l;
  
Received on Fri Jun 27 1997 - 07:46:59 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:35:35 MST