From owner-freebsd-threads@FreeBSD.ORG Fri Apr 13 23:50:12 2012 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CC194106566C for ; Fri, 13 Apr 2012 23:50:12 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A329E8FC17 for ; Fri, 13 Apr 2012 23:50:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q3DNoChQ086248 for ; Fri, 13 Apr 2012 23:50:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q3DNoCFd086247; Fri, 13 Apr 2012 23:50:12 GMT (envelope-from gnats) Resent-Date: Fri, 13 Apr 2012 23:50:12 GMT Resent-Message-Id: <201204132350.q3DNoCFd086247@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dmitry Marakasov Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B28EF1065670 for ; Fri, 13 Apr 2012 23:45:21 +0000 (UTC) (envelope-from amdmi3@amdmi3.ru) Received: from smtp.timeweb.ru (smtp.timeweb.ru [92.53.116.15]) by mx1.freebsd.org (Postfix) with ESMTP id 27A0F8FC21 for ; Fri, 13 Apr 2012 23:45:19 +0000 (UTC) Received: from [213.148.20.85] (helo=hive.panopticon) by smtp.timeweb.ru with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.76) (envelope-from ) id 1SIqAz-0003HF-2M for FreeBSD-gnats-submit@freebsd.org; Sat, 14 Apr 2012 03:45:13 +0400 Received: from hades.panopticon (hades.panopticon [192.168.0.32]) by hive.panopticon (Postfix) with ESMTP id AA2F2B84D for ; Sat, 14 Apr 2012 03:45:12 +0400 (MSK) Received: by hades.panopticon (Postfix, from userid 1000) id 9B8A0906; Sat, 14 Apr 2012 03:45:12 +0400 (MSK) Message-Id: <20120413234512.9B8A0906@hades.panopticon> Date: Sat, 14 Apr 2012 03:45:12 +0400 (MSK) From: Dmitry Marakasov To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: threads/166932: sleepqueue-related memory leak in libthr X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Dmitry Marakasov List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Apr 2012 23:50:13 -0000 >Number: 166932 >Category: threads >Synopsis: sleepqueue-related memory leak in libthr >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-threads >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Apr 13 23:50:12 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Dmitry Marakasov >Release: FreeBSD 9.0-RELEASE amd64 >Organization: >Environment: System: FreeBSD hades.panopticon 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 10 01:33:18 MSK 2012 root@hades.panopticon:/usr/obj/usr/src/sys/HADES amd64 >Description: Seems like there's a memory leak in libthr when threads are created and joined continously. See attached program. It creates and joins 16 threads, and repeats that multiple times. If LOOPS = 1, there's no leak regardless of how many threads are created. If LOOPS > 1, there's a leak of 64 bytes per each created thread. With 1024 loops it's approx. 1MB which is visible in valgrind output: ==41498== HEAP SUMMARY: ==41498== in use at exit: 1,065,912 bytes in 16,402 blocks ==41498== total heap usage: 16,403 allocs, 1 frees, 1,065,992 bytes allocated ==41498== ==41498== Searching for pointers to 16,402 not-freed blocks ==41498== Checked 34,403,992 bytes ==41498== ==41498== 1,047,552 bytes in 16,368 blocks are definitely lost in loss record 5 of 5 ==41498== at 0x1004654: calloc (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so) ==41498== by 0x12166A5: _sleepq_alloc (in /lib/libthr.so.3) ==41498== by 0x121A497: _thr_alloc (in /lib/libthr.so.3) ==41498== by 0x121311D: pthread_create (in /lib/libthr.so.3) ==41498== by 0x400673: main (in /tmp/a.out) ==41498== ==41498== LEAK SUMMARY: ==41498== definitely lost: 1,047,552 bytes in 16,368 blocks ==41498== indirectly lost: 0 bytes in 0 blocks ==41498== possibly lost: 0 bytes in 0 blocks ==41498== still reachable: 18,360 bytes in 34 blocks ==41498== suppressed: 0 bytes in 0 blocks And if LOOPS is set to some value high enough (say, 102400), the leak may be seen with naked eye (process eats over 140MB as seen in top). >How-To-Repeat: #include #define LOOPS 1024 #define THREADS 16 void* threadfunc(void* arg) { return NULL; } int main() { int loop, thread; pthread_t threads[THREADS]; for (loop = 0; loop < LOOPS; ++loop) { for (thread = 0; thread < THREADS; ++thread) pthread_create(&threads[thread], NULL, threadfunc, NULL); for (thread = 0; thread < THREADS; ++thread) pthread_join(threads[thread], NULL); } return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: