From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111569 invoked by alias); 20 Feb 2018 11:29:39 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 111557 invoked by uid 89); 20 Feb 2018 11:29:38 -0000 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 Subject: Re: [PATCH 3/3] Refactor atfork handlers To: Adhemerval Zanella Cc: libc-alpha@sourceware.org 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> From: Florian Weimer Message-ID: <7b71dd04-afd0-9ff0-79c3-3d47cbd77ee2@redhat.com> Date: Tue, 20 Feb 2018 12:57:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2018-02/txt/msg00540.txt.bz2 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