From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Florian Weimer Newsgroups: gmane.comp.lib.glibc.alpha Subject: Re: [PATCH 3/3] Refactor atfork handlers Date: Tue, 20 Feb 2018 12:29:35 +0100 Message-ID: <7b71dd04-afd0-9ff0-79c3-3d47cbd77ee2@redhat.com> References: <1518008967-8310-1-git-send-email-adhemerval.zanella@linaro.org> <1518008967-8310-3-git-send-email-adhemerval.zanella@linaro.org> <88a58530-092d-4daa-1096-97a1bf8e08ff@redhat.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1519126061 10436 195.159.176.226 (20 Feb 2018 11:27:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 20 Feb 2018 11:27:41 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Cc: libc-alpha@sourceware.org To: Adhemerval Zanella Original-X-From: libc-alpha-return-90394-glibc-alpha=m.gmane.org@sourceware.org Tue Feb 20 12:27:37 2018 Return-path: Envelope-to: glibc-alpha@blaine.gmane.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=qHO8ifHnb0u9pt6J vYOYqgDv2PfqW9lXIVvH97C+s8wirN7vms3fM3VxzYtnG3PvFfnpjGGR+5V2Iwjp YPDzNA7Wir2SePSbBTszjYJLZr5NLPrQajc6Quvu6HQIN6dmMqzoF8BIE0XdvS0o tNzM4APT2/st+2Zi8uCJQvNJic0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=6WZEWD6Bt+RPnOpGt0zKNt KLl34=; b=whWTPX/fEHioD9WM+cT9SSTuweJXE0KlLc6j5lZiX9TI91pvvdnGNm GWsa5DKKrIBmkkLZkk8WPQ95GMAPyochuBoX+Ogtt/qsB9V7pzRDQSqlHSh7jQew 0Eq4X+UL94Yq+pMquDNW8cMnX+LcDDDb/FLUUv5VCyzq5FKPZlswk= Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Original-Sender: libc-alpha-owner@sourceware.org Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=H*M:79c3 X-HELO: mx1.redhat.com In-Reply-To: Xref: news.gmane.org gmane.comp.lib.glibc.alpha:82726 Archived-At: Received: from server1.sourceware.org ([209.132.180.131] helo=sourceware.org) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eo65A-0002DQ-NK for glibc-alpha@blaine.gmane.org; Tue, 20 Feb 2018 12:27:37 +0100 Received: (qmail 111569 invoked by alias); 20 Feb 2018 11:29:39 -0000 Received: (qmail 111557 invoked by uid 89); 20 Feb 2018 11:29:38 -0000 On 02/08/2018 01:50 PM, Adhemerval Zanella wrote: > +static struct fork_handler * > +fork_handler_list_find_if (struct fork_handler_list *fork_handlers, > + void *dso_handle) Should be called _find, not find_if (no callback is involved). > + struct fork_handler *first = fork_handler_list_find_if (&fork_handlers, > + dso_handle); > + /* Removing is done by shifting the elements in the way the elements > + that are not to be removed appear in the beginning in dynarray. > + This avoid the quadradic run-time if a naive strategy to remove and > + shift one element at time. */ > + if (first != NULL) > + { > + struct fork_handler *result = first; result should probably be called new_end or something like that. > + first++; > + for (; first != fork_handler_list_end (&fork_handlers); ++first) > + { > + if (first->dso_handle != dso_handle) > + { > + memcpy (result, first, sizeof (struct fork_handler)); Wouldn't a simple struct assignment work here? I think this patch is a step in the right direction, so it should go in with these changes. However, I think we should make a few improvements in follow-up fixes: Reduce RSS usage for the common case that no atfork handlers are ever registered. This will be the case once we remove the bogus __reclaim_stacks function. Make a temporary copy of the handler array during fork. This has two benefits: We can run the handlers without acquiring the handler lock (to avoid application deadlocks). We also make sure that a handler does not run in a child process which did not run in the parent process. I think the old implementation had both properties. Thanks, Florian