public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug malloc/22111] malloc: per thread cache is not returned when thread exits
       [not found] <bug-22111-131@http.sourceware.org/bugzilla/>
@ 2020-10-10  7:23 ` jeffy.chen@rock-chips.com
  2021-06-30  7:54 ` fweimer at redhat dot com
  1 sibling, 0 replies; 2+ messages in thread
From: jeffy.chen@rock-chips.com @ 2020-10-10  7:23 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=22111

JeffyChen <jeffy.chen@rock-chips.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jeffy.chen@rock-chips.com

--- Comment #12 from JeffyChen <jeffy.chen@rock-chips.com> ---
Hi guys,

It seems this this issue is still exist in some cases, for example i can repro
it with this test in glibc 2.29:

#include <pthread.h>
void *noop() { pthread_detach(pthread_self()); return NULL; }
void main() {
        pthread_t id;
        while(1) pthread_create(&id, NULL, noop, 0);
}

There's also another report at:
https://sourceware.org/ml/glibc-bugs/2018-01/msg00171.html

So it looks like the tcache_shutting_down is still not early enough, when we
detach a thread with no tcache allocated(like the above test), the
tcache_shutting_down would still be false:
static void
tcache_thread_shutdown (void)
{
  int i;
  tcache_perthread_struct *tcache_tmp = tcache;

  if (!tcache)
    return; <--- returned here

  /* Disable the tcache and prevent it from being reinitialized.  */
  tcache = NULL;
  tcache_shutting_down = true; <--- unreachable


And the tcache might be reinitialized later(breakpoint at later
MAYBE_INIT_TCACHE):
Thread 2 (Thread 0x7f993c61e0 (LWP 8920)):
#0  0x0000007f9d444f7c in free () from /lib/libc.so.6
#1  0x0000007f9d57a3e4 in _dl_deallocate_tls () from /lib/ld-linux-aarch64.so.1
#2  0x0000007f9d541490 in free_stacks () from /lib/libpthread.so.0
#3  0x0000007f9d541a4c in __deallocate_stack () from /lib/libpthread.so.0
#4  0x0000007f9d542984 in start_thread () from /lib/libpthread.so.0
#5  0x0000007f9d49b1fc in thread_start () from /lib/libc.so.6



This works:
+++ b/malloc/malloc.c
@@ -2958,13 +2958,14 @@ tcache_thread_shutdown (void)
 {
   int i;
   tcache_perthread_struct *tcache_tmp = tcache;

+  tcache_shutting_down = true;

   if (!tcache)
     return;

   /* Disable the tcache and prevent it from being reinitialized.  */
   tcache = NULL;
-  tcache_shutting_down = true;

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug malloc/22111] malloc: per thread cache is not returned when thread exits
       [not found] <bug-22111-131@http.sourceware.org/bugzilla/>
  2020-10-10  7:23 ` [Bug malloc/22111] malloc: per thread cache is not returned when thread exits jeffy.chen@rock-chips.com
@ 2021-06-30  7:54 ` fweimer at redhat dot com
  1 sibling, 0 replies; 2+ messages in thread
From: fweimer at redhat dot com @ 2021-06-30  7:54 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=22111

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://sourceware.org/bugz
                   |                            |illa/show_bug.cgi?id=28028

--- Comment #13 from Florian Weimer <fweimer at redhat dot com> ---
(In reply to JeffyChen from comment #12)
> Hi guys,
> 
> It seems this this issue is still exist in some cases, for example i can
> repro it with this test in glibc 2.29:

Thanks for the report, this is now bug 28028.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-30  7:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-22111-131@http.sourceware.org/bugzilla/>
2020-10-10  7:23 ` [Bug malloc/22111] malloc: per thread cache is not returned when thread exits jeffy.chen@rock-chips.com
2021-06-30  7:54 ` fweimer at redhat dot com

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).