Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1575367pxf; Fri, 12 Mar 2021 13:07:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRvxlY7qYXNzv0/fc6Tz5Yac/C34e2ORIs5fsv3uQlrL2Ukjyj39OQXsU3iy0eHg5bApaQ X-Received: by 2002:a17:906:cd05:: with SMTP id oz5mr10878884ejb.345.1615583231229; Fri, 12 Mar 2021 13:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615583231; cv=none; d=google.com; s=arc-20160816; b=ZFbyhG1SYWho6xpzBt5iXlHoGWjscPSzKQUb4ijyr3chHYPCYs71XEjtf2A6BL2obm FmWsTqTCMmaE3pUI6DOp7FHQSHGNKi7QuO9Pk+OdqSJKQXZnura9cxbLyke/wBVS4QDL nNynN4/6KRTolLfEwLSX/KWqZ6QsNtTvtsbtbKwmu/oiOVM7BK59R/bQ+DOKXEmEXQf+ 9wiR+sfppvYc7jQJsyDoOIJ7ir1TeU0SxNDwC8V1xg3ZOMhkr/PXfDwChOfWI2pk3RPQ jqyPfj7VJ7zsjF7O5zQdRgN7PAXKA8NWNaHRs1LKJLC569KCUprFx1u5uUN47cjN155+ wmCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:date:message-id:organization:from :references:cc:to:subject; bh=kWAelqLjMGrs5sObrV4KatQjM7S8z7geqIVrtpbGvIY=; b=fb3ui4YPSBqA6FrHVPfMViSXWZ6/pTNcpCL5DOmeeClnywum19pE+b9XMcFKllbM/v 9ecppArCB2rtWoyqw3nFyhQgkTSSjJMDgHtCrYzm0iZucZg9gJxuT+HHicD4x77VGla1 BsakWAGlSQuHj+P7W5ci9KurIki1PSlF6NIiA1nc0CjhG4PbdmAZxwQK2E18/5cw1WmY XGxGbgi4uTFYkKpVQjdkXRytldyxS/TKn63raPDRfmwEJU3KFhhEAbjvEC0elCWq2IVn x0qwqst/3pUmk3fa3KACZdIkWDX/8HoN2A8KD6V0vx+G3rhXtQw/Rke1jb7im4SCJNJP FsBg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si4974956edw.509.2021.03.12.13.06.48; Fri, 12 Mar 2021 13:07:11 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235116AbhCLVFf (ORCPT + 99 others); Fri, 12 Mar 2021 16:05:35 -0500 Received: from mx1.riseup.net ([198.252.153.129]:53714 "EHLO mx1.riseup.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234964AbhCLVFS (ORCPT ); Fri, 12 Mar 2021 16:05:18 -0500 Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4Dxyy607lPzDs7k; Fri, 12 Mar 2021 13:05:17 -0800 (PST) X-Riseup-User-ID: A2BFFF25D9BFEAD604F30614484E4852CBFFA42F7BAFECCE6B0CB8AA2237842D Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4Dxyy516Z8z5wGj; Fri, 12 Mar 2021 13:05:17 -0800 (PST) Subject: Re: [PATCH v5] do_wait: make PIDTYPE_PID case O(1) instead of O(n) To: "Eric W. Biederman" Cc: Andrew Morton , Oleg Nesterov , Christian Brauner , linux-kernel@vger.kernel.org References: <20210312173855.24843-1-jnewsome@torproject.org> From: Jim Newsome Organization: The Tor Project Message-ID: Date: Fri, 12 Mar 2021 15:05:16 -0600 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 :). 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.