From mak@webcrawler.com  Sat Sep 13 11:18:24 1997
Received: from mail.webcrawler.com (mail.webcrawler.com [204.62.245.201])
          by hub.freebsd.org (8.8.7/8.8.7) with SMTP id LAA18470
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 13 Sep 1997 11:18:23 -0700 (PDT)
Received: (qmail 12749 invoked by uid 982); 13 Sep 1997 18:14:44 -0000
Message-Id: <19970913181444.12748.qmail@mail.webcrawler.com>
Date: 13 Sep 1997 18:14:44 -0000
From: m.koster@webcrawler.com
Reply-To: mak@webcrawler.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: realloc causes excessive swapping (more info for bin/4524)
X-Send-Pr-Version: 3.2

>Number:         4526
>Category:       bin
>Synopsis:       realloc causes excessive swapping (more info for bin/4524)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 13 11:20:01 PDT 1997
>Closed-Date:    Sat Sep 13 22:12:15 MEST 1997
>Last-Modified:  Sat Sep 13 14:30:01 PDT 1997
>Originator:     Martijn Koster
>Release:        FreeBSD 2.2-STABLE i386
>Organization:
Excite, Inc.
>Environment:

	FreeBSD 2.2-STABLE #0: Wed Sep 10 12:00:23 PDT 1997

>Description:

        This provides more information for bin/4524

	Repeatedly calling realloc causes much more memory to be used
        then you'd expect. For example, when procmail tried reading an
        8M message, this was sufficient to run a 64M (128M swap) machine
        doing nothing else out of swap (and into the ground :-)

>How-To-Repeat:

        This code reproduced the problem outside procmail:

 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>

 int
 main(int argc, char* argv[])
 {
    size_t size = 0;
    char *p = NULL;
    int max = 8404992;

    if (argc > 2) {
        fprintf(stderr, "Usage: %s maxmem\n", argv[0]);
        exit(-1);
    }
    if (argc > 1)
        max = atoi(argv[1]);

    while(1) {

        size += 16384;
        if (size > max)
            break;

        fprintf(stderr, "realloc(%u)\n", size);
        if ((p = realloc(p, size)) == NULL) {
            fprintf(stderr, "out of memory\n");
            exit(-1);
        }
    }

    {
        int c;
        printf("done. press return to quit\n");
        read(0, &c, 1);
    }
 }

>Fix:
	
	Recompiling the code with the malloc.c from freebsd-current

        * $Id: malloc.c,v 1.32 1997/08/31 05:59:39 phk Exp $

        fixed things (as did recompiling libc with that malloc.c)
        Now the program is killed after getting much further than before;
        (I assume when it hits its resource limits) instead of
        impacting the machine.

        This fix was previously reported by jfieber@indiana.edu back in June

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: joerg 
State-Changed-When: Sat Sep 13 22:12:15 MEST 1997 
State-Changed-Why:  

Dup for # 4524, additioanl information redirected there. 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: mak@webcrawler.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/4526: realloc causes excessive swapping (more info for bin/4524) 
Date: Sat, 13 Sep 1997 22:10:07 +0200

 >
 >	Repeatedly calling realloc causes much more memory to be used
 >        then you'd expect. For example, when procmail tried reading an
 >        8M message, this was sufficient to run a 64M (128M swap) machine
 >        doing nothing else out of swap (and into the ground :-)
 > [...]
 >>Fix:
 >	
 >	Recompiling the code with the malloc.c from freebsd-current
 >
 
 And remember to try this:
 
 	ln -s H /etc/malloc.conf
 
 (It's default in -current since middle august).
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
>Unformatted:
