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: Thu, 8 Feb 2018 09:32:10 +0100 Message-ID: <88a58530-092d-4daa-1096-97a1bf8e08ff@redhat.com> References: <1518008967-8310-1-git-send-email-adhemerval.zanella@linaro.org> <1518008967-8310-3-git-send-email-adhemerval.zanella@linaro.org> 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 1518078635 5439 195.159.176.226 (8 Feb 2018 08:30:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 8 Feb 2018 08:30:35 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 Cc: libc-alpha@sourceware.org To: Adhemerval Zanella Original-X-From: libc-alpha-return-90136-glibc-alpha=m.gmane.org@sourceware.org Thu Feb 08 09:30:31 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=T1GDKRDctsWqAy47 mW85FFyPeDVO0rzWTQSdHjwDNq9LWR4JdlxFpd9F7X72jdMuRa1d9vaF8A5+rVEq /b1gotp35DBxVCLAWI2XnA7DziKyflOqhR1Uiv8U7u7gJdZODgFBn2rr5CwAYYVM 7w7sMwxAFybuc7YRNdDEgJHqG48= 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=6FO7OvJLUoQ/ANYsPD/BlM euzjU=; b=cosfHtKArS8Dwo3TTn9rl067/AJovde6NMeqSEvgOATU5SgrGMDGfd SgTupbawUftpSlwA/Rx2FfehevuGe9aXD0XWGWZrEzwTdbgT439N3+lEG5smq2Ed wo6TK1gzbOjQvMHcby37xM5XXHLWVTBbA4h8CVkxDBUxTKphA4ZY0= 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=-7.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_1,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com In-Reply-To: Xref: news.gmane.org gmane.comp.lib.glibc.alpha:82484 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 1ejhaz-0000GI-Gn for glibc-alpha@blaine.gmane.org; Thu, 08 Feb 2018 09:30:17 +0100 Received: (qmail 18177 invoked by alias); 8 Feb 2018 08:32:19 -0000 Received: (qmail 17605 invoked by uid 89); 8 Feb 2018 08:32:18 -0000 On 02/07/2018 06:16 PM, Adhemerval Zanella wrote: > + for (size_t i = 0; i < fork_handler_list_size (&fork_handlers);) > + { > + /* dynarray remove maintains element order, so update index iff there is > + no removal. */ > + if (fork_handler_list_at (&fork_handlers, i)->dso_handle == dso_handle) > + fork_handler_list_remove (&fork_handlers, i); > + else > + i++; > + } I thought a bit more about this. Doesn't this lead to cubic run-time as DSOs are unloaded (quadratic run-time locally here, multiplied by the outer loop for unloading the DSOs)? I think fork_handler_list_remove is the wrong abstraction here. Something like std::remove_if would be better, which moves each array element at most once even if multiple elements are removed during the scan. Writing this generically in C is probably not worth the effort, so perhaps open-code that here? Thanks, Florian