public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel'
@ 2009-05-17 7:26 to dot my dot trociny at gmail dot com
2009-05-19 7:31 ` [Bug libgomp/40174] " jakub at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: to dot my dot trociny at gmail dot com @ 2009-05-17 7:26 UTC (permalink / raw)
To: gcc-bugs
#include <omp.h>
int n = 4, m = 2;
int main () {
for (;;) {
int i;
#pragma omp parallel for num_threads(m)
for(i = 0; i < 1; i++) {}
#pragma omp parallel for num_threads(n)
for(i = 0; i < 1; i++) {}
}
return 0;
}
When run on freebsd, this test shows constant growth of virtual memory usage.
Memory growth is observed only when m != n.
The problem is in libgomp/team.c. gomp_thread_start() does gomp_sem_init()
but gomp_sem_destroy() is never called. FreeBSD implementation of sem_init()
allocates some memory for semaphore. This patch solves the problem for me:
--- gcc-4.4-20090227/libgomp/team.c.orig 2009-05-16 22:57:05.000000000
+0300
+++ gcc-4.4-20090227/libgomp/team.c 2009-05-16 22:57:14.000000000 +0300
@@ -458,6 +458,7 @@ gomp_team_start (void (*fn) (void *), vo
void
gomp_team_end (void)
{
+ int i;
struct gomp_thread *thr = gomp_thread ();
struct gomp_team *team = thr->ts.team;
@@ -493,6 +494,9 @@ gomp_team_end (void)
}
while (ws != NULL);
}
+
+ for(i = 1; i < team->nthreads; i++)
+ gomp_sem_destroy (team->ordered_release[i]);
gomp_sem_destroy (&team->master_release);
#ifndef HAVE_SYNC_BUILTINS
gomp_mutex_destroy (&team->work_share_list_free_lock);
The problem is not observed on Linux because it looks like sem_init()
implementation for Linux does not do memory allocation in the process' virtual
space. The memory for the test program below grows on FreeBSD and does not
on Linux.
#include <semaphore.h>
int
main(int argc, char *argv[]) {
sem_t sem;
for(;;) { sem_init(&sem, 0, 0);}
return 0;
}
--
Summary: Memory leak when using '#pragma omp parallel'
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgomp
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: to dot my dot trociny at gmail dot com
GCC host triplet: i386-portbld-freebsd7.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libgomp/40174] Memory leak when using '#pragma omp parallel'
2009-05-17 7:26 [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel' to dot my dot trociny at gmail dot com
@ 2009-05-19 7:31 ` jakub at gcc dot gnu dot org
2009-05-19 10:06 ` to dot my dot trociny at gmail dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-19 7:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from jakub at gcc dot gnu dot org 2009-05-19 07:31 -------
Created an attachment (id=17891)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17891&action=view)
gcc45-pr40174.patch
thr->release is owned by thread, not team, and is initialized by the thread, so
it should be each thread that destroys it as well, not the team.
Can you please try this patch instead? It makes no difference on Linux,
because gomp_sem_destroy is empty inline, so I can't verify it easily.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jakub at gcc dot gnu dot org
|dot org |
Status|UNCONFIRMED |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libgomp/40174] Memory leak when using '#pragma omp parallel'
2009-05-17 7:26 [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel' to dot my dot trociny at gmail dot com
2009-05-19 7:31 ` [Bug libgomp/40174] " jakub at gcc dot gnu dot org
@ 2009-05-19 10:06 ` to dot my dot trociny at gmail dot com
2009-05-20 20:55 ` jakub at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: to dot my dot trociny at gmail dot com @ 2009-05-19 10:06 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from to dot my dot trociny at gmail dot com 2009-05-19 10:06 -------
The patch works for me.
Actually, calling mutex_destroy in gomp_thread_start() before return was the
first my solution and it solved my problem too. But I am not very familiar with
libgomp so I was not completely sure if it was safe to release mutex then (I
did not do deep investigations how this mutex is used). Releasing it in
gomp_team_end(), when all other structures associated with team threads are
freed, looked safer for me :-). But it looks as I shouldn't have been so
paranoid. Thank you.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libgomp/40174] Memory leak when using '#pragma omp parallel'
2009-05-17 7:26 [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel' to dot my dot trociny at gmail dot com
2009-05-19 7:31 ` [Bug libgomp/40174] " jakub at gcc dot gnu dot org
2009-05-19 10:06 ` to dot my dot trociny at gmail dot com
@ 2009-05-20 20:55 ` jakub at gcc dot gnu dot org
2009-05-20 20:56 ` jakub at gcc dot gnu dot org
2009-05-20 21:15 ` jakub at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-20 20:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jakub at gcc dot gnu dot org 2009-05-20 20:55 -------
Subject: Bug 40174
Author: jakub
Date: Wed May 20 20:54:45 2009
New Revision: 147747
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147747
Log:
PR libgomp/40174
* team.c (gomp_thread_start): Destroy thr->release semaphore.
(gomp_free_pool_helper): Likewise.
Modified:
trunk/libgomp/ChangeLog
trunk/libgomp/team.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libgomp/40174] Memory leak when using '#pragma omp parallel'
2009-05-17 7:26 [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel' to dot my dot trociny at gmail dot com
` (2 preceding siblings ...)
2009-05-20 20:55 ` jakub at gcc dot gnu dot org
@ 2009-05-20 20:56 ` jakub at gcc dot gnu dot org
2009-05-20 21:15 ` jakub at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-20 20:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from jakub at gcc dot gnu dot org 2009-05-20 20:55 -------
Subject: Bug 40174
Author: jakub
Date: Wed May 20 20:55:25 2009
New Revision: 147748
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147748
Log:
PR libgomp/40174
* team.c (gomp_thread_start): Destroy thr->release semaphore.
(gomp_free_pool_helper): Likewise.
Modified:
branches/gcc-4_4-branch/libgomp/ChangeLog
branches/gcc-4_4-branch/libgomp/team.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libgomp/40174] Memory leak when using '#pragma omp parallel'
2009-05-17 7:26 [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel' to dot my dot trociny at gmail dot com
` (3 preceding siblings ...)
2009-05-20 20:56 ` jakub at gcc dot gnu dot org
@ 2009-05-20 21:15 ` jakub at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-05-20 21:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from jakub at gcc dot gnu dot org 2009-05-20 21:15 -------
Fixed for 4.4/4.5.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-05-20 21:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-17 7:26 [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel' to dot my dot trociny at gmail dot com
2009-05-19 7:31 ` [Bug libgomp/40174] " jakub at gcc dot gnu dot org
2009-05-19 10:06 ` to dot my dot trociny at gmail dot com
2009-05-20 20:55 ` jakub at gcc dot gnu dot org
2009-05-20 20:56 ` jakub at gcc dot gnu dot org
2009-05-20 21:15 ` jakub at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).