Bug 12624 - Memory leak in pthreadpool
Summary: Memory leak in pthreadpool
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Karolin Seeger
QA Contact: Samba QA Contact
Depends on:
Reported: 2017-03-10 09:02 UTC by Ralph Böhme
Modified: 2017-04-17 15:12 UTC (History)
2 users (show)

See Also:

Patch for 4.6 cherry-picked from master (2.76 KB, patch)
2017-03-12 15:32 UTC, Ralph Böhme
slow: review? (metze)
vl: review+

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph Böhme 2017-03-10 09:02:46 UTC
When copying large files from the server to the client with aio enabled we noticed that smbd kept growing RSS and VSZ.

valgrind reported:

    ==2503== 4,093,440 bytes in 6,560 blocks are possibly lost in loss record 460 of 460
    ==2503==    at 0x4C299CE: calloc (vg_replace_malloc.c:711)
    ==2503==    by 0x4011C24: _dl_allocate_tls (in /usr/lib64/ld-2.17.so)
    ==2503==    by 0x4E3C960: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.17.so)
    ==2503==    by 0x9B298AE: pthreadpool_add_job (in /usr/lib64/samba/libmessages-dgm-samba4.so)
    ==2503==    by 0x9B29FDC: pthreadpool_tevent_job_send (in /usr/lib64/samba/libmessages-dgm-samba4.so)
    ==2503==    by 0x56A78EF: ??? (in /usr/lib64/samba/libsmbd-base-samba4.so)
    ==2503==    by 0x55D86B7: smb_vfs_call_pread_send (in /usr/lib64/samba/libsmbd-base-samba4.so)
    ==2503==    by 0x55F7543: schedule_smb2_aio_read (in /usr/lib64/samba/libsmbd-base-samba4.so)
    ==2503==    by 0x5608F57: smbd_smb2_request_process_read (in /usr/lib64/samba/libsmbd-base-samba4.so)
    ==2503==    by 0x55FCB6C: smbd_smb2_request_dispatch (in /usr/lib64/samba/libsmbd-base-samba4.so)
    ==2503==    by 0x55FD7DC: ??? (in /usr/lib64/samba/libsmbd-base-samba4.so)
    ==2503==    by 0x641B977: ??? (in /usr/lib64/samba/libtevent.so.0.9.31)

The problem seems to be caused by worked threads that are not properly started in detached state and thus their tls is not reclaimed upon thread termination.

In pthreadpool.c we prepare a pthread attribute with PTHREAD_CREATE_DETACHED, but we don't pass it to pthread_create().

Have patch, need bugnumber.
Comment 1 Ralph Böhme 2017-03-12 15:32:05 UTC
Created attachment 13047 [details]
Patch for 4.6 cherry-picked from master

For the records: this is a 4.6 only issue.
Comment 2 Karolin Seeger 2017-03-13 08:29:41 UTC
Pushed to autobuild-v4-6-test.
Comment 3 Karolin Seeger 2017-03-14 09:48:32 UTC
(In reply to Karolin Seeger from comment #2)
Pushed to v4-6-test.
Closing out bug report.

Comment 4 Ralph Böhme 2017-04-15 20:03:36 UTC
Karolin, looks like this one never hit the 4.6 branches, can you please check? Thanks!
Comment 5 Stefan Metzmacher 2017-04-17 15:12:07 UTC
See commit 1ad29ae69d3463eb92b39c41216bfdc35f232c09 in v4-6-test,
it will be released with the next (first) maintenance release of 4.6.