[Pdns-dev] Re: virtual memory issue and gmysql

Stephen Manchester smanches at craftyspace.com
Wed Oct 3 22:23:22 CEST 2007


I finally had time to create a patch file.  Apply this to  
distributor.hh and rebuild.   It just adds three lines to detach from  
the thread at the three exit points.


*** distributor.hh	2007-10-03 23:15:48.000000000 -0500
--- distributor.hh.fixed_vm_leak	2007-10-03 23:15:42.000000000 -0500
***************
*** 191,201 ****
--- 191,203 ----
         catch(const AhuException &e) {
           L<<Logger::Error<<"Backend error: "<<e.reason<<endl;
   	      delete b;
+         pthread_detach(pthread_self());
           return 0;
         }
         catch(...) {
           L<<Logger::Error<<Logger::NTLog<<"Caught unknown exception  
in Distributor thread "<<(unsigned long)pthread_self()<<endl;
   	      delete b;
+         pthread_detach(pthread_self());
           return 0;
         }

***************
*** 231,236 ****
--- 233,240 ----
     catch(...) {
       L<<Logger::Error<<Logger::NTLog<<"Caught an unknown exception  
when creating backend, probably"<<endl;
     }
+
+   pthread_detach(pthread_self());
     return 0;
   }



On Oct 3, 2007, at 6:04 PM, Patrick Domack wrote:

> Well, this is good news. I have attempted to figure this out, but  
> haven't programmed pthreads myself yet so I was just not sure what  
> I was all looking at :)
>
>
> Quoting Stephen Manchester <smanches at craftyspace.com>:
>
>> Christof was right on with this one.  I had tracked it down to an
>> exception causing the thread to exit, but didn't know why the memory
>> was still left around.  This explains it exactly.
>>
>> Distributor.hh needs pthread_detach(pthread_self()); in all locations
>> where the ::makeThread() function exits.  I have tested this and
>> confirmed it solves the VM memory leak.
>>
>> Thanks again Christof.  :p
>>
>> On Oct 3, 2007, at 1:09 PM, Christof Meerwald wrote:
>>
>>> On Wed, 3 Oct 2007 21:50:16 +0200, Christof Meerwald wrote:
>>>> So I strongly suspect that threads are being created but never
>>>> joined/detached.
>>>
>>> I have now also confirmed with a simple test-case that Linux  
>>> (NPTL) only
>>> cleans up the thread stack of terminated threads if they have  
>>> been detached
>>> or joined (one could, of course, argue that this implementation  
>>> detail could
>>> be improved as there is no need to keep the thread stack around  
>>> for zombie
>>> threads).
>>>
>>>
>>> Christof
>>>
>>> -- 
>>>
>>> http://cmeerw.org                              sip:cmeerw at  
>>> cmeerw.org
>>> mailto:cmeerw at cmeerw.org                   xmpp:cmeerw at  
>>> cmeerw.org
>>> _______________________________________________
>>> Pdns-dev mailing list
>>> Pdns-dev at mailman.powerdns.com
>>> http://mailman.powerdns.com/mailman/listinfo/pdns-dev
>>
>> _______________________________________________
>> Pdns-dev mailing list
>> Pdns-dev at mailman.powerdns.com
>> http://mailman.powerdns.com/mailman/listinfo/pdns-dev
>
>
>
> _______________________________________________
> Pdns-dev mailing list
> Pdns-dev at mailman.powerdns.com
> http://mailman.powerdns.com/mailman/listinfo/pdns-dev



More information about the Pdns-dev mailing list