From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 10 08:55:10 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6CBDB16A515 for ; Thu, 10 Feb 2005 08:55:10 +0000 (GMT) Received: from mail.emict.com (brig.emict.com [212.90.172.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id D5C8C43D48 for ; Thu, 10 Feb 2005 08:55:08 +0000 (GMT) (envelope-from ant@emict.com) Received: from [10.0.0.232] (unknown [10.0.0.232]) by mail.emict.com (Postfix) with ESMTP id B6C232618A for ; Thu, 10 Feb 2005 10:55:05 +0200 (EET) From: Andriy Tkachuk Organization: eMICT To: freebsd-hackers@freebsd.org Date: Thu, 10 Feb 2005 10:55:04 +0200 User-Agent: KMail/1.7 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_oFyCC2umUu8FZHl" Message-Id: <200502101055.04949.ant@emict.com> X-Mailman-Approved-At: Thu, 10 Feb 2005 13:30:16 +0000 X-Content-Filtered-By: Mailman/MimeDel 2.1.1 Subject: pthreads & dynamic memory in fbsd vs. the same in linux X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Feb 2005 08:55:10 -0000 --Boundary-00=_oFyCC2umUu8FZHl Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi folks. I noticed the strange stick of pthreads (amount ~ 500) when allocating dynamic memory by malloc or new in my system: > uname -a FreeBSD ant.emict.com 5.3-STABLE FreeBSD 5.3-STABLE #0: Wed Feb 9 17:30:11 EET 2005 ant@ant:/lin/fbsd_obj/usr/src/sys/ANT i386 It's interesting that the same program behaves differently when it is compiled in linux and run on my fbsd machine in linux_base-7.1_7 . > ldd test2-linux test2-linux: libpthread.so.0 => /lib/libpthread.so.0 (0x28065000) libstdc++-libc6.2-2.so.3 => /usr/lib/libstdc++-libc6.2-2.so.3 (0x2807c000) libm.so.6 => /lib/libm.so.6 (0x280bf000) libc.so.6 => /lib/libc.so.6 (0x280e1000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2804c000) > ldd a.out a.out: libpthread.so.1 => /usr/lib/libpthread.so.1 (0x28075000) libstdc++.so.4 => /usr/lib/libstdc++.so.4 (0x28099000) libm.so.3 => /lib/libm.so.3 (0x2816b000) libc.so.5 => /lib/libc.so.5 (0x28184000) Each thread allocates the amount of memory by 10 bytes in loop. The number of iterations is specified in cmdline arg. The program prints the time each thread is spent allocating memory in loop. Let's look on results. > ./a.out n 1000 # 1000 iterations of new operator. Every new allocates 10bytes. thread 0 created thread 1 created thread 2 created thread 3 created thread 4 created ... thread 497 created thread 498 created thread 499 created 0.001114 0.001022 0.001021 0.001011 0.001014 0.001010 0.001013 0.001050 0.001035 0.001011 0.001013 0.001010 0.001013 0.001010 0.001029 0.001075 0.001053 0.001011 0.001014 0.001011 0.001030 0.001010 0.001015 0.001042 0.001019 0.001011 0.001014 0.001012 0.001013 0.001010 0.001014 0.361604 3.225090 3.225458 3.225696 3.225925 3.226152 3.226380 3.226608 3.226833 3.227062 3.227290 3.227517 3.227744 3.227972 3.228202 3.228451 3.228681 3.228912 3.229140 3.229367 The same, but in linux_base-7.1_7 : > ./test2-linux n 1000 thread 0 created thread 1 created ... thread 498 created thread 499 created 0.000467 0.000403 0.000402 ... 0.000391 0.000391 0.000395 ... 0.000395 0.010564 0.000398 0.000394 The program source is attached. In linux program is compiled by $ gcc -v Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) in fbsd: > gcc -v Using built-in specs. Configured with: FreeBSD/i386 system compiler Thread model: posix gcc version 3.4.2 [FreeBSD] 20040728 --Boundary-00=_oFyCC2umUu8FZHl--