#3 Memory leak

open
nobody
None
8
2009-09-22
2009-09-22
No

Here is the valgrind output from the threadpool specific part of my daemon which grows to about 3G in an hour. Any help appreciated.

==11428== Thread 1:
==11428==
==11428== 7,200 bytes in 50 blocks are possibly lost in loss record 13 of 14
==11428== at 0x4021E22: calloc (vg_replace_malloc.c:397)
==11428== by 0x4010C7B: _dl_allocate_tls (in /lib/ld-2.7.so)
==11428== by 0x42CF672: pthread_create@@GLIBC_2.1 (in /lib/i686/cmov/libpthread-2.7.so)
==11428== by 0x4045F76: boost::thread::start_thread() (in /usr/lib/libboost_thread-mt.so.1.35.0)
==11428== by 0x80E0CC7: boost::thread::thread<boost::_bi::bind_t<void, boost::_mfi::mf0<void, boost::threadpool::detail::worker_thread<boost::threadpool:
:detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::
threadpool::resize_controller, boost::threadpool::wait_for_all_tasks> > >, boost::_bi::list1<boost::_bi::value<boost::shared_ptr<boost::threadpool::detail::
worker_thread<boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::
threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks> > > > > > >(boost::_bi::bind_t<void, boost::_mfi::mf0<
void, boost::threadpool::detail::worker_thread<boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::th
readpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks> > >, boost::_bi::list
1<boost::_bi::value<boost::shared_ptr<boost::threadpool::detail::worker_thread<boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<bo
ost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_
all_tasks> > > > > >) (thread.hpp:151)
==11428== by 0x80E0DE4: boost::threadpool::detail::worker_thread<boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>>::create_and_attach(boost::shared_ptr<boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks> > const&) (worker_thread.hpp:105)
==11428== by 0x80E4B93: boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>::resize(unsigned) volatile (pool_core.hpp:349)
==11428== by 0x80E4B93: boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>::resize(unsigned) volatile (pool_core.hpp:349)
==11428== by 0x80E5187: boost::threadpool::static_size<boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks> >::init(boost::threadpool::detail::pool_core<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler, boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>&, unsigned) (size_policies.hpp:75)
==11428== by 0x80E59EF: boost::threadpool::thread_pool<boost::function0<void, std::allocator<boost::function_base> >, boost::threadpool::fifo_scheduler,boost::threadpool::static_size, boost::threadpool::resize_controller, boost::threadpool::wait_for_all_tasks>::thread_pool(unsigned) (pool.hpp:103)
==11428== by 0x80E5D97: Server::Server(int volatile&, boost::shared_ptr<FileDescriptor>, boost::shared_ptr<Core>, unsigned, unsigned, unsigned, unsigned, unsigned, bool, std::string const&, std::string const&, std::string const&, unsigned) (server.h:84)

Discussion

  • Michael Moritz

    Michael Moritz - 2009-09-22

    Just as a follow up: The problem is caused by doing pool.resize at regular intervals. It doesn't matter whether the number of threads is increased or decreased.
    Just to outline my use of threadpool: I initialise with a number of threads (e.g. 50). Then incoming requests get passed on to the pool using schedule. At regular intervals a monitor thread wakes and checks the number of active requests and calls resize in order to either in- or decrease the threadpool by calling resize.
    Help would be much appreciated.

     
  • Michael Moritz

    Michael Moritz - 2009-09-22
    • priority: 5 --> 8
     
  • Anton Matosov

    Anton Matosov - 2009-12-07

    I have the same issue, so I have investigated it found a solution. I will provide the patch for the version 0.2.5 during this week

     

Log in to post a comment.