Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1539695pxf; Fri, 12 Mar 2021 12:03:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyh0Ublza5a70Qt0u83w5x/WgpmlJf68gpVoEfSev12CuKHNGWv61szD6GRHOXDwancf0IY X-Received: by 2002:a05:6402:278b:: with SMTP id b11mr16271696ede.380.1615579409050; Fri, 12 Mar 2021 12:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615579409; cv=none; d=google.com; s=arc-20160816; b=zivtmKiiNqGD+1/XoaIt+0kcb+idrvFHvOwMAfUY0EfB4z0v0s16mRqkXdAoG7yDx/ GhXzAFfr4/UusxVy1nIPkyvdIikQClqBfpgchwcJRq9FMXLdX0nAM3Ykw7F/l3+ZWozG nod1veI0lcLpbFYFFx0Dc/ynOq+DgK3iQ8+qnjX8dc78GaKs0dZpZk6ysU0RMAqP75IO 9umoDMLh12fuYN8fTkn89POG6eH8sOpxLR9z1kwGKXQWWplIFvAd6RQe6WxIwEHflXrn x9FBHJu0MC5XMlRJ5XC490mAFN3CQsULfjNPk4aWZCnzhLNIjo4Wb4az3HMGI0kymSWz 8ATg== 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:references:cc :to:from:subject; bh=AD66UF6fKyB8ySil9L3xZuTsPNrlPWHyoviTLgfEjKA=; b=fO5bUYj/MVYWFcNbRdY77YD9VZqxPzixEpTl4sSZWQ8pqVvcnFoatEoJsjr6FON3YV bVODKzS9bKtNgKaTqDCAjNX9Vhhs7YNyuB+l3OVgaavVaQMbLAylnwYmCiqltTPNwEem s4xo12jpmwVe9cy947FI8lLWYlDxwVfr34hUoI2ni8naSztLacDytRGbbLSZtI7U3w/q 7acULvfew3PaoKaP2h3+xtLaIy17gCcCjnL9i+i2wJQfUpEU6oJaeqdx7w1o/en5BWsA VUjD9/4conVvsNRTDgwQPLiiuUW/iamMK5bzTmS44fuuB3O1hcGfPrSsCPUMqKRjJ3Ez XZfw== 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 z22si4627725edc.427.2021.03.12.12.03.04; Fri, 12 Mar 2021 12:03:29 -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 S234512AbhCLUCE (ORCPT + 99 others); Fri, 12 Mar 2021 15:02:04 -0500 Received: from mx1.riseup.net ([198.252.153.129]:47278 "EHLO mx1.riseup.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbhCLUBm (ORCPT ); Fri, 12 Mar 2021 15:01:42 -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 4DxxXk4bSjzDqCH; Fri, 12 Mar 2021 12:01:42 -0800 (PST) X-Riseup-User-ID: 48AD520682A172C0D2723F83ED3442DB99E29EB8E46036614C1E5308AF18023B Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4DxxXj6L1hz5wGG; Fri, 12 Mar 2021 12:01:41 -0800 (PST) Subject: Re: [PATCH v5] do_wait: make PIDTYPE_PID case O(1) instead of O(n) From: Jim Newsome To: Andrew Morton Cc: Oleg Nesterov , "Eric W . Biederman" , Christian Brauner , linux-kernel@vger.kernel.org References: <20210312173855.24843-1-jnewsome@torproject.org> <20210312102207.a347e38db375226a78cc37bf@linux-foundation.org> Organization: The Tor Project Message-ID: Date: Fri, 12 Mar 2021 14:01:41 -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 (Re-sent without html part, which the list rejected) On 3/12/21 12:47, Andrew Morton wrote: > IOW, please spend a bit of time selling the patch! What is the case > for including it in Linux? What benefit does it provide our users? Ah yes - I'd included some context when I first reached out to Oleg, but that never made it to the list :). I'm helping develop a new ptrace-based version of Shadow [1] - a tool for simulating a (potentially large) network. Shadow runs the network user-space applications in an emulated environment, and routes network traffic through a model of the network accounting for latency, bandwidth, etc. The Tor Project plans to make increasing use of Shadow both for focused evaluation of specific proposed software and parameter changes, attacks, and defenses, and as a regular automated performance evaluation prior to deployment of new versions. Today Shadow is already actively used in the research community for applications including tor and bitcoin. We're interested in running simulations including at least tens of thousands of processes, with a stretch goal of being able to handle 1M processes. Since each process is being ptraced, calling an O(n) waitpid has a huge performance penalty at this scale, and results in simulation performance growing ~quadratically with the size of the simulation. We do have a workaround where we use a "fork proxy" thread to actually fork all the processes, and we stop and detach inactive processes. (The number of "active" processes is roughly fixed to the number of worker threads, which is generally the # of CPUs available). i.e. this keeps the number of children and tracees small and fixed, allowing us to scale linearly. However, having to detach and reattach tracees adds a significant linear overhead factor. This kernel patch would allow us to get rid of the complexity and extra overhead of this workaround, and benefit other applications that haven't implemented such a workaround. We have some details and analysis of this issue in GitHub [2]. I haven't added results with the patch yet, but plan to do so. This should also help other applications that have a large number of children or tracees. Ptrace-based emulation tools are probably the most likely to benefit. e.g. I suspect it'll help User Mode Linux [3], which IIUC uses a single tracer thread to ptrace every process running on its kernel. Likewise it could help DetTrace [4], which uses ptrace for deterministic software builds. [1]: https://shadow.github.io/ [2]: https://github.com/shadow/shadow/issues/1134 [3]: https://en.wikipedia.org/wiki/User-mode_Linux [4]: https://github.com/dettrace/dettrace