Created attachment 59418 [details] code to reproduce problem Environment ----------- ubuntu 24.04 libstdc++ 13.2 from ubuntu repos but also 14.2 and judging by libstdc++ github mirror the latest head also has this problem sudo apt install libtbb-dev ## this is obviously required Problem ------- when calling `std::sort(std::execution::par_unseq` repeatedly it leaks memory, and will ultimately deplete the machine and get killed by the kernel. the attached
Created attachment 59419 [details] patch which solves the problem this patch applies cleanly to libstdc++ 13.2 and 14.2 and also to head I believe. It solves the problem. The code change is from here: https://github.com/oneapi-src/oneDPL/pull/1589/files By one of the people on the TBB / oneDPL team. it cannot be applied to TBB ( I did ask there) because the bug is in the "glue/interface" code between libstdc++ and TBB and managed by libstdc++
Sorry, premature submit on original report comment. continuing... The attached sort_leak.cpp (59418) shows the problem. Single threaded sort is fine, par_unseq is not. output: Single threaded sort: VM: 14544 RSS: 11648 (kB) VM: 14616 RSS: 11588 (kB) VM: 14616 RSS: 11588 (kB) VM: 14616 RSS: 11588 (kB) VM: 14616 RSS: 11588 (kB) par_unseq sort: VM: 29372 RSS: 17860 (kB) VM: 33468 RSS: 19652 (kB) VM: 33468 RSS: 21316 (kB) VM: 37564 RSS: 23108 (kB) VM: 37564 RSS: 24772 (kB) Related bug reports: Issue filed by me on oneTBB: https://github.com/oneapi-src/oneTBB/issues/1533 my repo with demo code, instructions and references should they be needed: https://github.com/oneapi-src/oneTBB/issues/1533 Pull request on oneDPL which fixes it https://github.com/oneapi-src/oneDPL/pull/1589/files (that is what my patch is based on) Solution -------- As stated above, the attached patch (59419) fixes the issue
Realised the link to my repo with demo code was incorrect. Here is the correct one: https://github.com/oschonrock/tbbleak
Is there anything I can do to help move this forward?
Jonathan already self-assigned it which indicates he's planning to work on it soon, FWIW (that doesn't happen for all libstdc++ bugs automatically). But if you're interested in trying a patch, he might be able to give you advice if you want to learn (which is welcome).
(In reply to Sam James from comment #5) > But if you're interested in trying a patch, he might be able to give you > advice if you want to learn (which is welcome). Ah, sorry, I see you already did -- maybe submit it formally?
I did some additional testing on older distributions. On debian 11, bullseye, oldstable, we have gcc version 10.2.1 20210110 (Debian 10.2.1-6) I noticed that my patch DID NOT apply and the leak is NOT present with libstc++ as is. $ ./build/gcc/release/sort_leak Single threaded sort: VM: 13900 RSS: 11012 (kB) VM: 13968 RSS: 11288 (kB) VM: 13968 RSS: 11288 (kB) VM: 13968 RSS: 11288 (kB) VM: 13968 RSS: 11288 (kB) par_unseq sort: VM: 94268 RSS: 15684 (kB) VM: 94268 RSS: 15684 (kB) VM: 94268 RSS: 15684 (kB) VM: 94268 RSS: 15684 (kB) VM: 94268 RSS: 15684 (kB)
GCC 10 is not supported upstream, so we don't care about it anyway.
I suppose the point is that it makes it a regression.
Sorry, should have made that clear.. yes, appears to be a regression between gcc-10 and gcc-12
I can reproduce this with GCC 15.2 on Ubuntu 25.10 via: https://github.com/oschonrock/tbbleak ./build.sh -- The CXX compiler identification is GNU 15.2.0 ... ./build/gcc/relwithdebinfo/sort_leak Single threaded sort: VM: 17492 RSS: 12140 (kB) VM: 17496 RSS: 12176 (kB) VM: 17496 RSS: 12176 (kB) VM: 17496 RSS: 12176 (kB) VM: 17496 RSS: 12176 (kB) par_unseq sort: VM: 332764 RSS: 17820 (kB) VM: 332764 RSS: 19612 (kB) VM: 332764 RSS: 21148 (kB) VM: 345052 RSS: 23068 (kB) VM: 345052 RSS: 24860 (kB)
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:d8f1655a781a76f5c86b3545b181b2005e585d29 commit r16-3824-gd8f1655a781a76f5c86b3545b181b2005e585d29 Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Sep 12 12:49:39 2025 +0100 libstdc++: Fix memory leak in PSTL TBB backend [PR117276] Backport of upstream patch: https://github.com/uxlfoundation/oneDPL/pull/1589 libstdc++-v3/ChangeLog: PR libstdc++/117276 * include/pstl/parallel_backend_tbb.h (__func_task::finalize): Make deallocation unconditional.
Thanks for the reminder, fixed on trunk only so far.
(In reply to Jonathan Wakely from comment #13) > Thanks for the reminder, fixed on trunk only so far. Great to see this get fixed. Thanks Jonathan.
The releases/gcc-15 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:210b7a0d8cae48268b69a331249e702495cf2639 commit r15-10320-g210b7a0d8cae48268b69a331249e702495cf2639 Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Sep 12 12:49:39 2025 +0100 libstdc++: Fix memory leak in PSTL TBB backend [PR117276] Backport of upstream patch: https://github.com/uxlfoundation/oneDPL/pull/1589 libstdc++-v3/ChangeLog: PR libstdc++/117276 * include/pstl/parallel_backend_tbb.h (__func_task::finalize): Make deallocation unconditional. (cherry picked from commit d8f1655a781a76f5c86b3545b181b2005e585d29)
The releases/gcc-14 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:83926770efa15d5e0a1e265d26012bdd623fd75e commit r14-12026-g83926770efa15d5e0a1e265d26012bdd623fd75e Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Sep 12 12:49:39 2025 +0100 libstdc++: Fix memory leak in PSTL TBB backend [PR117276] Backport of upstream patch: https://github.com/uxlfoundation/oneDPL/pull/1589 libstdc++-v3/ChangeLog: PR libstdc++/117276 * include/pstl/parallel_backend_tbb.h (__func_task::finalize): Make deallocation unconditional. (cherry picked from commit d8f1655a781a76f5c86b3545b181b2005e585d29)
*** Bug 113504 has been marked as a duplicate of this bug. ***
The releases/gcc-13 branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:0caeca8cd77e23c8155e0f7c14de3aabac53b941 commit r13-10050-g0caeca8cd77e23c8155e0f7c14de3aabac53b941 Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Sep 12 12:49:39 2025 +0100 libstdc++: Fix memory leak in PSTL TBB backend [PR117276] Backport of upstream patch: https://github.com/uxlfoundation/oneDPL/pull/1589 libstdc++-v3/ChangeLog: PR libstdc++/117276 * include/pstl/parallel_backend_tbb.h (__func_task::finalize): Make deallocation unconditional. (cherry picked from commit d8f1655a781a76f5c86b3545b181b2005e585d29)
Fixed for 13.5, 14.4, 15.3