From owner-freebsd-bugs@FreeBSD.ORG Fri Jan 23 12:51:20 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AAD1C16A4CE for ; Fri, 23 Jan 2004 12:51:20 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id F0C5C43D95 for ; Fri, 23 Jan 2004 12:50:25 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i0NKoPFR059552 for ; Fri, 23 Jan 2004 12:50:25 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i0NKoP7P059551; Fri, 23 Jan 2004 12:50:25 -0800 (PST) (envelope-from gnats) Date: Fri, 23 Jan 2004 12:50:25 -0800 (PST) Message-Id: <200401232050.i0NKoP7P059551@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Radim Kolar Subject: Re: kern/61691: very bad performance of realloc()/brk() X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Radim Kolar List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jan 2004 20:51:20 -0000 The following reply was made to PR kern/61691; it has been noted by GNATS. From: Radim Kolar To: Poul-Henning Kamp Cc: freebsd-bugs@FreeBSD.org, bug-followup@freebsd.org Subject: Re: kern/61691: very bad performance of realloc()/brk() Date: Fri, 23 Jan 2004 16:20:35 +0100 > You seem to be confused as to what responsibilities the programmer > has when it comes to practicing sensible memory management. I have run some benchmarks for you. There are doing 32 times realloc() in 1 MB chunks. I don't think that this is example of bad programming practice. The major problem is that realloc() copies data while Linux doesn't. FreeBSD 5.2 =========== It looks that brk() syscall is quite slow in FreeBSD when comparing against Linux. FreeBSD calls 32 times brk() and 10 times mmap+munmap (for page directory). (hsn@ttyv0):~/forkbomb% time ./forkbomb -l 32 -i 256 -M --quit 12:45 Safety alarm at 300 sec. enabled. Actions: alloc 32 MB (step 1024 kB) and touch it. Forkbomb 1.2 started. ./forkbomb -l 32 -i 256 -M --quit 4.58s user 5.28s system 74% cpu 13.159 total linux2.4+glibc2.3.2 =================== Linux does 1 times mmap + 31 times mremap syscall Safety alarm at 300 sec. enabled. Actions: alloc 32 MB (step 1024 kB) and touch it. Forkbomb 1.2 started. ./forkbomb -l 32 -i 256 -M --quit 0.00s user 0.30s system 107% cpu 0.280 total Well my pr-report/wish is: optimize realloc() function (which is about 3 pages long) to avoid copying data while brk() is sufficient , because the reallocated block is last block.