Date: Fri, 20 Feb 2015 09:19:35 -0600 From: Matthew Grooms <mgrooms@shrew.net> To: freebsd-stable@freebsd.org Subject: Re: pthread leaky with resources? Message-ID: <54E75087.7080100@shrew.net> In-Reply-To: <Pine.GSO.4.64.1502201010580.16244@sea.ntplx.net> References: <54E65E05.2040101@shrew.net> <20150220100446.GL34251@kib.kiev.ua> <54E74D17.6020209@shrew.net> <Pine.GSO.4.64.1502201010580.16244@sea.ntplx.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2/20/2015 9:15 AM, Daniel Eischen wrote: > On Fri, 20 Feb 2015, Matthew Grooms wrote: > >> On 2/20/2015 4:04 AM, Konstantin Belousov wrote: >>> Threading library caches thread structures and some related objects. >>> This is needed to correctly handle kernel notifications about threads >>> exit and to avoid thread id reuse, besides usual argument for using >>> cache >>> to improve creation speed. >>> >>> Also, the thread stacks are cached, each stack being 2MB probably >>> accounts >>> for most of the memory usage columns in the top output above. >> >> Konstantin, >> >> Thanks for the reply. That seems reasonable. But surely these >> resources need to be reclaimed at some point after a thread >> gracefully exits. Otherwise any software that creates short lived >> threads will eventually run out of system resources and periodically >> require a restart. The test program I included does nothing but >> create threads that gracefully exit. Do you have another explanation >> as to why a program would indefinitely grow in size that way? > > When a thread is created, it will first try to reuse cached resources > before allocating new resources. > > If you are creating 200 threads, for instance, try destroying those 200 > threads, then create 200 new threads. You shouldn't see much change in > resources, as libpthread should use the cached resources. If you see > a double in the amount of resources used, then that would seem like a > bug. > Daniel, Thanks for the response. Let me do some more testing. I know that OS developer time is a precious resource. If I can find more evidence of the problem I will present it. Thanks, -Matthew
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54E75087.7080100>