From owner-freebsd-amd64@FreeBSD.ORG Wed Apr 7 05:41:04 2004 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 146EE16A4CF for ; Wed, 7 Apr 2004 05:41:04 -0700 (PDT) Received: from cri.ensmp.fr (orgenoy.ensmp.fr [193.48.171.195]) by mx1.FreeBSD.org (Postfix) with ESMTP id D2F4B43D31 for ; Wed, 7 Apr 2004 05:41:02 -0700 (PDT) (envelope-from silber@cri.ensmp.fr) Received: from cri.ensmp.fr (silber@stockholm.cri.ensmp.fr [10.2.14.153]) by cri.ensmp.fr (8.11.2/8.11.2/mx-cri-CRI) with ESMTP id i37Ce0n21992 for ; Wed, 7 Apr 2004 14:40:00 +0200 (MEST) Message-ID: <4073F699.6010402@cri.ensmp.fr> Date: Wed, 07 Apr 2004 14:39:53 +0200 From: Georges-Andre Silber User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031021 X-Accept-Language: en MIME-Version: 1.0 To: freebsd-amd64@freebsd.org Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: malloc: bug or feature ? X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Apr 2004 12:41:04 -0000 Hello, On my bi/opteron HDAMA workstation running FreeBSD 5.2-CURRENT AMD64 with 8GB RAM + 16GB Swap, I have a strange result for a test program I wrote in C: #include #include #include #define ITEM 100000000L int main (int ac, char* av[]) { unsigned long int memsize; void *mem; memsize = 0UL; while (1) { mem = malloc (ITEM); assert (mem != NULL); memsize += ITEM; } } As you can see, I just call malloc() until it returns NULL. The problem is that when total memory allocated reaches a value close to MAXDSIZE, it leads to a 'segmentation fault'. I ran the program through gdb: -bash-2.05b$ gcc -g taille.c -bash-2.05b$ ls a.out taille.c -bash-2.05b$ gdb a.out GNU gdb 20040323 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-portbld-freebsd5.2"... (gdb) run Starting program: /home/silber/a.out Program received signal SIGSEGV, Segmentation fault. 0x0000000200eec000 in ?? () (gdb) up #1 0x0000000200681d79 in ldexp () from /lib/libc.so.5 (gdb) up #2 0x00000002006821fd in ldexp () from /lib/libc.so.5 (gdb) up #3 0x00000002006823e1 in ldexp () from /lib/libc.so.5 (gdb) up #4 0x0000000200682789 in ldexp () from /lib/libc.so.5 (gdb) up #5 0x0000000200682840 in malloc () from /lib/libc.so.5 (gdb) up #6 0x00000000004006a9 in main (ac=1, av=0x7fffffffec38) at taille.c:12 12 mem = malloc (ITEM); (gdb) -------------------------------------------------------------------- tcsh> limit cputime unlimited filesize unlimited datasize 8388608 kbytes stacksize 524288 kbytes coredumpsize unlimited memoryuse unlimited vmemoryuse unlimited descriptors 11095 memorylocked unlimited maxproc 5547 sbsize unlimited tcsh> uname -a FreeBSD surville.cri.ensmp.fr 5.2-CURRENT FreeBSD 5.2-CURRENT #2: Wed Apr 7 13:20:40 CEST 2004 root@surville.cri.ensmp.fr:/usr/src/sys/amd64/compile/SURVILLE amd64 Is it a 'normal' behaviour of malloc()? Shouldn't malloc() return NULL? Georges Silber.