https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110156

            Bug ID: 110156
           Summary: libgomp leaking when executed in a thread
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophe.beauregard at ec dot gc.ca
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Created attachment 55277
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55277&action=edit
Simple test program

We discovered a situation where the bullseye version of GraphicsMagick suddenly
caused an application to explode in VSS memory use (capping at about 20G) and a
much slower RSS leak. The VSS memory consumption is the memory mapped thread
arenas that apparently aren't being reused. The RSS leak will eventually result
in an OOM situation when the process is run for long enough.

It's possible to force the thread arenas to free up by explicitly calling
omp_pause_resource_all() at thread termination, but I'm not certain that's a
100% fix, and IMHO it's far more than an application *should* be aware of about
something buried inside a library.

The issue seems to be reliably reproducible on a system configuration with
multiple sockets and multiple cores, including VMs (even when run on
single-socket hosts).

I get the same results against gcc-9, 10, and a two-day-old git clone. The
following is from a 2-socket-4-core Haswell VM running Debian bullseye:

cpb@bullseye64:~$ gcc --version
gcc (GCC) 14.0.0 20230606 (experimental)
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cpb@bullseye64:~$ gcc -o gomparena gomparena.c -fopenmp
cpb@bullseye64:~$ ./gomparena   
1686141812
   VSZ   RSS USER     COMMAND
297820  2128 cpb      ./gomparena
4
1686141813
   VSZ   RSS USER     COMMAND
494428  2152 cpb      ./gomparena
7
1686141814
   VSZ   RSS USER     COMMAND
691036  2316 cpb      ./gomparena
10
1686141815
   VSZ   RSS USER     COMMAND
887644  2328 cpb      ./gomparena
13
1686141816
   VSZ   RSS USER     COMMAND
1149788 2340 cpb      ./gomparena
17
1686141817
   VSZ   RSS USER     COMMAND
1346396 2356 cpb      ./gomparena
20
1686141819
   VSZ   RSS USER     COMMAND
1543004 2372 cpb      ./gomparena
23
1686141820
   VSZ   RSS USER     COMMAND
1739612 2388 cpb      ./gomparena
26
1686141821
   VSZ   RSS USER     COMMAND
1936220 2404 cpb      ./gomparena
29
1686141822
   VSZ   RSS USER     COMMAND
2132828 2420 cpb      ./gomparena
32

On a two-socket-20-core machine, ten iterations hits the 20G/300-ish thread
arena max.

Reply via email to