From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0401C433E0 for ; Fri, 12 Mar 2021 21:26:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABDE964F8D for ; Fri, 12 Mar 2021 21:26:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235250AbhCLVZ5 (ORCPT ); Fri, 12 Mar 2021 16:25:57 -0500 Received: from out03.mta.xmission.com ([166.70.13.233]:51258 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235201AbhCLVZx (ORCPT ); Fri, 12 Mar 2021 16:25:53 -0500 Received: from in01.mta.xmission.com ([166.70.13.51]) by out03.mta.xmission.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lKpI7-008z6D-Qb; Fri, 12 Mar 2021 14:25:51 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=fess.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1lKpI6-0006pZ-U7; Fri, 12 Mar 2021 14:25:51 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Jim Newsome Cc: Andrew Morton , Oleg Nesterov , Christian Brauner , linux-kernel@vger.kernel.org References: <20210312173855.24843-1-jnewsome@torproject.org> Date: Fri, 12 Mar 2021 15:25:56 -0600 In-Reply-To: (Jim Newsome's message of "Fri, 12 Mar 2021 15:05:16 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1lKpI6-0006pZ-U7;;;mid=;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18u2BA0eeUG39rmxl9H+zFfEItifezblC8= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH v5] do_wait: make PIDTYPE_PID case O(1) instead of O(n) X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jim Newsome writes: > On 3/12/21 14:29, Eric W. Biederman wrote: >> When I looked at this a second time it became apparent that using >> pid_task twice should actually be faster as it removes a dependent load >> caused by thread_group_leader, and replaces it by accessing two adjacent >> pointers in the same cache line. >> >> I know the algorithmic improvement is the main advantage, but removing >> 60ns or so for a dependent load can't hurt. >> >> Plus I think using the two pid types really makes it clear that one >> is always a process and the other is always potentially a thread. >> >> /* >> * Optimization for waiting on PIDTYPE_PID. No need to iterate through child >> * and tracee lists to find the target task. >> */ >> static int do_wait_pid(struct wait_opts *wo) >> { >> bool ptrace; >> struct task_struct *target; >> int retval; >> >> ptrace = false; >> target = pid_task(wo->wo_pid, PIDTYPE_TGID); >> if (target && is_effectively_child(wo, ptrace, target)) { >> retval = wait_consider_task(wo, ptrace, target); >> if (retval) >> return retval; >> } >> >> ptrace = true; >> target = pid_task(wo->wo_pid, PIDTYPE_PID); >> if (target && target->ptrace && >> is_effectively_child(wo, ptrace, target)) { >> retval = wait_consider_task(wo, ptrace, target); >> if (retval) >> return retval; >> } >> >> return 0; >> } > > I'm fine with either way. > > Part of what made my earlier version with the double-lookup a bit > awkward was only doing the second lookup if the first lookup failed. I'm > happy to take your word though that making the second lookup conditional > is unnecessary or even detrimental :). Oh absolutely. The two lookups are independent. > It did cross my mind that it > might not be a very consistent branch for a branch-predictor, but I also > figured pid_task's synchronization might outweigh that. pid_task has a lot of verbiage but it is only reading a pointer, verifying the pointer is not NULL and calling container_of on the result of the pointer read. Eric