unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell via Libc-alpha <libc-alpha@sourceware.org>
To: Christian Brauner <christian.brauner@ubuntu.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: libc-alpha <libc-alpha@sourceware.org>,
	Joseph Myers <joseph@codesourcery.com>
Subject: Re: [RFC PATCH glibc 3/8] nptl: Start new threads with all signals blocked [BZ #25098]
Date: Wed, 22 Apr 2020 12:38:07 -0400	[thread overview]
Message-ID: <f7a70dad-a05b-42cb-cd8c-fec4c4b7211e@redhat.com> (raw)
In-Reply-To: <20200323170503.dkaad3zmwe5owc4p@wittgenstein>

On 3/23/20 1:05 PM, Christian Brauner wrote:
> On Mon, Mar 23, 2020 at 01:02:12PM -0400, Mathieu Desnoyers via Libc-alpha wrote:
>> ----- On Mar 23, 2020, at 11:31 AM, Christian Brauner christian.brauner@ubuntu.com wrote:
>>
>>> On Mon, Mar 23, 2020 at 09:16:02AM -0400, Mathieu Desnoyers via Libc-alpha
>>> wrote:
>>>> From: Florian Weimer <fweimer@redhat.com>
>>>>
>>>> New threads inherit the signal mask from the current thread.  This
>>>> means that signal handlers can run on the newly created thread
>>>> immediately after the kernel has created the userspace thread, even
>>>> before glibc has initialized the TCB.  Consequently, new threads can
>>>> observe uninitialized ctype data, among other things.
>>>>
>>>> To address this, block all signals before starting the thread, and
>>>> pass the original signal mask to the start routine wrapper.  On the
>>>> new thread, first perform all thread initialization, and then unblock
>>>> signals.
>>>>
>>>> The cost of doing this is two rt_sigprocmask system calls on the old
>>>> thread, and one rt_sigprocmask system call on the new thread.  (If
>>>> there was a way to clone a new thread with a signals disabled, this
>>>
>>> This could be a new clone3() flag. If someone wants to send a patch I'd
>>> take it.
>>
>> I agree that it would be a nice improvement to alleviate the overhead of
>> tweaking the signal masks on thread creation. I suspect the code proposed in
>> this patch is still needed, because glibc would have to support the currently
>> existing kernels. The improvement you envision involves adding this new flag
>> into the Linux kernel clone3 system call and then wiring up glibc support.
>>
>> I don't expect this should delay rseq integration into glibc ?
> 
> Oh no, I wasn't trying to say that rseq() in glibc should be blocked on
> this, not at all. I was just saying we should probably do this since
> it's a valuable improvement.

That's up to you to decide, and it depends on the workload. I'd be hesitant
to spend a flag bit on this. To cleanup the glibc code would require you to
(a) implement this in the kernel
(b) have glibc move the minimum kernel line above the new kernel that has this
We're talking a minor cleanup that would take 10-15 years to arrive... if ever.
Moving the minimum kernel baseline has container workload impacts that are
going to become real problems soon.

Mathieu, Florian, and I talked about this very issue at GNU Tools
Cauldron 2019 (Montreal). We agreed that even if we could fix it immediately
we would still need the above implementation.

IMO you are doing something wrong if this shows up in your profiling though.
You should not be starting up and killing threads that fast. You should be
using thread pools etc. The kernel reaping of tasks is quite slow and even
in glibc we often hit EAGAIN limits on heavily loaded test boxes.

The above code is required for correctness so certain state is not observable,
but it need not be that fast. Someone correct me if I'm wrong though and I've
missed a use case.

-- 
Cheers,
Carlos.


  reply	other threads:[~2020-04-22 16:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 13:15 [RFC PATCH glibc 0/8] Restartable Sequences enablement Mathieu Desnoyers via Libc-alpha
2020-03-23 13:16 ` [RFC PATCH glibc 1/8] Introduce <elf_machine_sym_no_match.h> Mathieu Desnoyers via Libc-alpha
2020-03-23 14:51   ` H.J. Lu via Libc-alpha
2020-03-23 17:04     ` Mathieu Desnoyers via Libc-alpha
2020-03-23 13:16 ` [RFC PATCH glibc 2/8] Implement __libc_early_init Mathieu Desnoyers via Libc-alpha
2020-03-23 13:16 ` [RFC PATCH glibc 3/8] nptl: Start new threads with all signals blocked [BZ #25098] Mathieu Desnoyers via Libc-alpha
2020-03-23 15:31   ` Christian Brauner
2020-03-23 17:02     ` Mathieu Desnoyers via Libc-alpha
2020-03-23 17:05       ` Christian Brauner
2020-04-22 16:38         ` Carlos O'Donell via Libc-alpha [this message]
2020-03-23 13:16 ` [RFC PATCH glibc 4/8] glibc: Perform rseq(2) registration at C startup and thread creation (v16) Mathieu Desnoyers via Libc-alpha
2020-03-23 22:01   ` Joseph Myers
2020-03-24 13:08     ` Mathieu Desnoyers via Libc-alpha
2020-03-24 18:58       ` Joseph Myers
2020-03-24 19:44         ` Mathieu Desnoyers via Libc-alpha
2020-03-23 13:16 ` [RFC PATCH glibc 5/8] glibc: sched_getcpu(): use rseq cpu_id TLS on Linux (v7) Mathieu Desnoyers via Libc-alpha
2020-03-23 13:16 ` [RFC PATCH glibc 6/8] support record failure: allow use from constructor Mathieu Desnoyers via Libc-alpha
2020-03-23 13:16 ` [RFC PATCH glibc 7/8] support: implement xpthread key create/delete (v4) Mathieu Desnoyers via Libc-alpha
2020-03-23 13:16 ` [RFC PATCH glibc 8/8] rseq registration tests (v9) Mathieu Desnoyers via Libc-alpha
  -- strict thread matches above, loose matches on Subject: below --
2020-03-19 14:41 [RFC PATCH glibc 0/8] Restartable Sequences enablement Mathieu Desnoyers via Libc-alpha
2020-03-19 14:41 ` [RFC PATCH glibc 3/8] nptl: Start new threads with all signals blocked [BZ #25098] Mathieu Desnoyers via Libc-alpha
2020-01-08 14:58 [RFC PATCH glibc 0/8] Restartable Sequences enablement Mathieu Desnoyers
2020-01-08 14:58 ` [RFC PATCH glibc 3/8] nptl: Start new threads with all signals blocked [BZ #25098] Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f7a70dad-a05b-42cb-cd8c-fec4c4b7211e@redhat.com \
    --to=libc-alpha@sourceware.org \
    --cc=carlos@redhat.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=joseph@codesourcery.com \
    --cc=mathieu.desnoyers@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).