From owner-freebsd-bugs Fri Nov 14 07:00:05 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id HAA04906 for bugs-outgoing; Fri, 14 Nov 1997 07:00:05 -0800 (PST) (envelope-from owner-freebsd-bugs) Received: (from gnats@localhost) by hub.freebsd.org (8.8.7/8.8.7) id HAA04877; Fri, 14 Nov 1997 07:00:02 -0800 (PST) (envelope-from gnats) Resent-Date: Fri, 14 Nov 1997 07:00:02 -0800 (PST) Resent-Message-Id: <199711141500.HAA04877@hub.freebsd.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@FreeBSD.ORG, mika@cs.caltech.edu Received: from vlsi.cs.caltech.edu (vlsi.cs.caltech.edu [131.215.131.129]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id GAA04827 for ; Fri, 14 Nov 1997 06:59:45 -0800 (PST) (envelope-from mika@obelix.cs.caltech.edu) Received: from obelix.cs.caltech.edu by vlsi.cs.caltech.edu (4.1/1.34.1) id AA13705; Fri, 14 Nov 97 06:59:42 PST Received: (from mika@localhost) by obelix.cs.caltech.edu (8.8.8/8.8.7) id GAA13129; Fri, 14 Nov 1997 06:59:31 -0800 (PST) Message-Id: <199711141459.GAA13129@obelix.cs.caltech.edu> Date: Fri, 14 Nov 1997 06:59:31 -0800 (PST) From: Mika Nystroem Reply-To: mika@cs.caltech.edu To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: bin/5043: malloc/realloc/free (unacceptably) dog-slow on FreeBSD-3.0 Sender: owner-freebsd-bugs@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >Number: 5043 >Category: bin >Synopsis: malloc/realloc/free (unacceptably) dog-slow on FreeBSD-3.0 >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Nov 14 07:00:01 PST 1997 >Last-Modified: >Originator: Mika Nystroem >Organization: Department of Computer Science California Institute of Technology >Release: FreeBSD 3.0-CURRENT i386 >Environment: FreeBSD-current-3.0/SMP, dual processor Pentium Pro 200 MHz. Little other system activity. >Description: malloc and free are S-L-O-W for reasonably large memory allocations. In an otherwise unmodified environment, the program #include main() { int i=0; char *x=NULL; x=malloc(1000); while(i++<1000000) { x=realloc(x,500); x=realloc(x,1000); } } takes (80)vitalstatistix:/ufs/work10/test>time a.out 4.171u 62.224s 1:12.21 91.9% 3+125k 0+0io 0pf+0w to run---almost all this time is spent in madvise() (called from ifree(), so it's in the free part, not the allocation part of the code...) This can be helped with setenv MALLOC_OPTIONS "h", after which the timings are (78)vitalstatistix:/ufs/work10/test>time a.out 10.536u 0.039s 0:10.91 96.7% 1+37k 0+0io 1pf+0w for the same program! On a similar NetBSD/i386 system, the same program has timings (82)varese:/ufs/work10/test>time a.out 4.403u 0.019s 0:04.44 99.3% 0+0k 0+0io 52pf+0w (all these timings are from unprofiled, unoptimized code) This problem surfaced on a real application that was using a lot of realloc calls in parsing routines. >How-To-Repeat: see above >Fix: either make MALLOC_OPTIONS "h" the default, or at very least make the implementation more clever about it. Or use the NetBSD malloc package instead. >Audit-Trail: >Unformatted: