From owner-freebsd-questions@FreeBSD.ORG Wed May 19 23:42:18 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4C18016A4CE for ; Wed, 19 May 2004 23:42:18 -0700 (PDT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id C533543D54 for ; Wed, 19 May 2004 23:42:17 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.10/8.12.10) id i4K6g0KA010205 for freebsd-questions@freebsd.org; Thu, 20 May 2004 01:42:00 -0500 (CDT) (envelope-from dan) Date: Thu, 20 May 2004 01:42:00 -0500 From: Dan Nelson To: freebsd-questions@freebsd.org Message-ID: <20040520064200.GB86452@dan.emsphone.com> References: <20040520050918.GA85327%till@score.is.tsukuba.ac.jp> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="/04w6evG8XlLl3ft" Content-Disposition: inline In-Reply-To: <20040520050918.GA85327%till@score.is.tsukuba.ac.jp> X-OS: FreeBSD 5.2-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i Subject: Re: memory allocation/deallocation (malloc experts needed) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2004 06:42:18 -0000 --/04w6evG8XlLl3ft Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In the last episode (May 20), Till Plewe said: > My problem is essentially that freeing large numbers of small chunks > of memory can be very slow. I have run into this problem twice so > far. Do you have a testcase? The attached program mallocs 1 million 128-byte blocks, then frees them. With MALLOC_OPTIONS set to jz (i.e. no filling of freed memory), it takes .184 seconds to free them all. With it set to J, it takes 1 second. CPU: Intel Pentium III (909.96-MHz 686-class CPU) -- Dan Nelson dnelson@allantgroup.com --/04w6evG8XlLl3ft Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="malloctime.c" #include #include #include #include #define NUM 1048576 #define SIZE 128 void *mypointers[NUM]; struct timeval elap; struct rusage r_s, r_e; int main(void) { int i; printf("malloc:"); fflush(stdout); for (i = 0; i < NUM; i++) { mypointers[i] = malloc(SIZE); } printf("done.\nfree:"); fflush(stdout); getrusage(RUSAGE_SELF, &r_s); for (i = 0; i < NUM; i++) { free(mypointers[i]); } getrusage(RUSAGE_SELF, &r_e); timersub(&r_e.ru_utime, &r_s.ru_utime, &elap); printf("done. %ld.%06ld\n", elap.tv_sec, elap.tv_usec); return 0; } --/04w6evG8XlLl3ft--