pthreads dynamic memory in fbsd vs. the same in linux
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 [EMAIL PROTECTED]:/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 2731 (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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: pthreads dynamic memory in fbsd vs. the same in linux
Could you post the code too, perchance? On Thu, 10 Feb 2005 10:55:04 +0200, Andriy Tkachuk [EMAIL PROTECTED] wrote: 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 [EMAIL PROTECTED]:/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 2731 (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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: pthreads dynamic memory in fbsd vs. the same in linux
i sent the mail with attachement. anyway, the code: (probably the better list would be -threads. sorry folks for flame. i subscribed today to -threads, so please reply to it if no mind.) cat test2.cc #include pthread.h #include stdio.h #include unistd.h #include sys/time.h #include string using std::string; #define COUNT_THREADS 500 pthread_t thread[COUNT_THREADS]; char mode; int iters; void f() { struct timeval t1,t2; void* p[iters]; string s; sleep(2); while (1) { gettimeofday(t1, NULL); if (mode == 's') { s = ; for (int i=0; iiters; i++) s += 'a'; } if (mode == 'S') { string s; for (int i=0; iiters; i++) s = 'a'; } if (mode == 'f') for (int i=0; iiters; i++) gettimeofday(t2, NULL); if (mode == 'm') { for (int i=0; iiters; i++) p[i] = malloc(10); for (int i=0; iiters; i++) free(p[i]); } if (mode == 'n') { for (int i=0; iiters; i++) p[i] = (char*) new char(10); for (int i=0; iiters; i++) delete (char*) p[i]; } gettimeofday(t2, NULL); int usec_d = t2.tv_usec-t1.tv_usec; int sec_d = t2.tv_sec-t1.tv_sec; if (usec_d0) { sec_d--; usec_d += 100; } printf( %u.%06u \n, sec_d, usec_d); } } int main(int argc, char *argv[]) { mode = argv[1][0]; iters = atoi(argv[2]); for (int i=0; iCOUNT_THREADS; i++) { pthread_create ( (thread[i]), NULL, (void*(*)(void*))f, NULL ); printf(thread %i created\n, i); } while(1) { sleep(1); } } On Thursday 10 February 2005 15:46, Coleman Kane wrote: Could you post the code too, perchance? On Thu, 10 Feb 2005 10:55:04 +0200, Andriy Tkachuk [EMAIL PROTECTED] wrote: 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 [EMAIL PROTECTED]:/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 2731 (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 ___ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-hackers@freebsd.org mailing list