Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1586588pxf; Fri, 12 Mar 2021 13:27:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzS4AD5I/5pYVoIHPNoklR+IpWrsFGiRITXEvuBe2HI9Hp4n03DpOQv6r8ezmFSOfnyHatx X-Received: by 2002:a17:906:68c5:: with SMTP id y5mr10879450ejr.371.1615584436575; Fri, 12 Mar 2021 13:27:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615584436; cv=none; d=google.com; s=arc-20160816; b=VPsnOmvtROsWYyQDl/i8ycdIK9ui8i3Z7uzgOebp4WFYiL+FKVnd92LQaUROTbjaW1 OXBM8p4qvjvSTgVXR6YZjoJSIMaZjP0ZVSDDAnN0epmUX4D3Azg7JDqTU7WzdHQGU2xo zD8jlGGHSNtuZMBHGReRRJJ93hD5TXRG9k6uJ+cJOGzyYYcBt7PN0N5N/PU8mqTkQ8eV EQ6x6oyYKokY82eEltQh0ytOTxhkLXk6kCDCQOinBHI/fOTqcixEoa7qoQ7nAZoBwFpU aKSBNqRh+/LPXBuJfGOgeS3mjgfkJ5PVv/Xz+9WfTZQnMXkw/9UlV5HIQyQeTWToO9VR 0hyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=aaKFaZuo1uU8Xg5q0wHwqUFiMuMsGRaDJC/+jxI6Tt8=; b=eI+QtAONMepfJMI9CYLKiFXt86dPTtX7XjDXNTSllqaSZGqHi2UTW2RA5lWelx/hAg AbdwTjUJnypE5L7pO7/+NvU/b2P22alb31cHyM2YA3rf5N1z+1pgjNRWIF7pejbzUX6R g8SDTj+MgHg2UC05tZZUagWjC8iLHWRWGaCO89sSfiePAmyn48FFZ8TKl9yl3wL+bGe2 fbkL0+yKRQvr4oA1SaG//mV1DSykDTq3QXeopTEsg/b3N8vQvZc9q27/WN2OptfZ7FiN e70WEF4sIOqN6FtK058HL15rtdp2btt+kEdjQ/y7Mdm1H7JYqYLaMmK8A2zJc8NDD0Ks BcXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c1si4903722edt.469.2021.03.12.13.26.53; Fri, 12 Mar 2021 13:27:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235237AbhCLVZ4 (ORCPT + 99 others); Fri, 12 Mar 2021 16:25:56 -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 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa02.xmission.com X-Spam-Level: ** X-Spam-Status: No, score=2.0 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,TR_Symld_Words,T_TM2_M_HEADER_IN_MSG, T_TooManySym_01,T_TooManySym_02,XMSubLong autolearn=disabled version=3.4.2 X-Spam-Virus: No X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4983] * 1.5 TR_Symld_Words too many words that have symbols inside * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Jim Newsome X-Spam-Relay-Country: X-Spam-Timing: total 387 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 3.5 (0.9%), b_tie_ro: 2.4 (0.6%), parse: 0.72 (0.2%), extract_message_metadata: 8 (2.1%), get_uri_detail_list: 1.08 (0.3%), tests_pri_-1000: 11 (2.9%), tests_pri_-950: 1.01 (0.3%), tests_pri_-900: 0.80 (0.2%), tests_pri_-90: 132 (34.2%), check_bayes: 128 (33.2%), b_tokenize: 4.8 (1.2%), b_tok_get_all: 8 (2.0%), b_comp_prob: 1.59 (0.4%), b_tok_touch_all: 112 (28.9%), b_finish: 0.63 (0.2%), tests_pri_0: 219 (56.7%), check_dkim_signature: 0.38 (0.1%), check_dkim_adsp: 2.2 (0.6%), poll_dns_idle: 0.78 (0.2%), tests_pri_10: 1.76 (0.5%), tests_pri_500: 6 (1.5%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v5] do_wait: make PIDTYPE_PID case O(1) instead of O(n) X-Spam-Flag: No 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