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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE1B8C4332F for ; Mon, 12 Dec 2022 01:58:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 244A48E0003; Sun, 11 Dec 2022 20:58:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F5198E0002; Sun, 11 Dec 2022 20:58:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0965A8E0003; Sun, 11 Dec 2022 20:58:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EDDC58E0002 for ; Sun, 11 Dec 2022 20:58:47 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id BD3A2806AF for ; Mon, 12 Dec 2022 01:58:47 +0000 (UTC) X-FDA: 80231995494.28.9B12291 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id C5A48C0002 for ; Mon, 12 Dec 2022 01:58:45 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PGlQ0mRK; spf=pass (imf28.hostedemail.com: domain of ikent@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=ikent@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670810325; a=rsa-sha256; cv=none; b=Eo3QrO4ijDMhuiroEClnO/6NDQtzqECNq9M87y2tjA3B8r6gEmQcwME88lzEioWKDgIznZ q++WEBoZB8koyrqKtRX+n/gLfnbasO0gOKik6RLphTEfwZIjEH+mX1ZF7tSu6+yedzfW6A XDjwYQoiKjbP5mJr4Ksjm/rar+0PHOk= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PGlQ0mRK; spf=pass (imf28.hostedemail.com: domain of ikent@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=ikent@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670810325; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6g3xEHXieH9G9pXYF7oUeGJEYp7M2m+YZ1AfoAjJ2Mg=; b=O0oFwQ8Nm0sbevBqLjhznOS4e6o1emtX79O28oLomWMUZzyqlWFHLnwDRcydQiInM6UU+i V8p7OAL3Ktyc4GZ68qv4VRrixPrQj2qwgo/l58xdvVotqcq3rjSjEJh6PUxac7EZgnl9TI YSuEuhwX5aCHXPjIT1AGIOks+lC/7FM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670810325; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6g3xEHXieH9G9pXYF7oUeGJEYp7M2m+YZ1AfoAjJ2Mg=; b=PGlQ0mRK+aunD33Nb+K91U6aI/56sScfTt0DlGCZdEp7UB/QshiRsWmrxujJKOXqI6MzlG Eh5w0ILNe8Wr/ZcGG9ANHjG5dpBjEwklt/npNklT2D00HoesfY+HLXcNJG++HysAsSjBJm srBVmmN+exBzdDhPW5phwL669oylFQs= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-563-GzNZ2LQ9MR-qtX6oHGmkkA-1; Sun, 11 Dec 2022 20:58:43 -0500 X-MC-Unique: GzNZ2LQ9MR-qtX6oHGmkkA-1 Received: by mail-pl1-f199.google.com with SMTP id y6-20020a17090322c600b00189892baa53so9189076plg.6 for ; Sun, 11 Dec 2022 17:58:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6g3xEHXieH9G9pXYF7oUeGJEYp7M2m+YZ1AfoAjJ2Mg=; b=LkpKJjrOISLxVTcYbodExQfN3/8ZPnXHaaQAypHi3sMsXvsgBIbh3B/ksXDoyvcSqU aU45AAlY0qzljZAhz/PE+e52onR3f9FCKmHbeIDXBfU8htI1fTSDIO9VfX3lghFb2xCM 0zOmjOolxV4+HC6sI3kaS0o2+WKXArzoHavWAycqLGu9TlHNh4kAn40d//I1QoFIVesc S6R1DzKRcOjOr9VuHDstgNQniPk6L55oc+yE9Xadn17cGgngHQrmGkqInso8vGpQl56p NxwhL4efX9DldGqQmm9XWF7IJXZL2xkav41rzUyQihJ46t0lzcthhW4EGDhKcwCzs8s3 o3fQ== X-Gm-Message-State: ANoB5pmik29U0YeIHHl8ZngkAK9BeVmtASOjdfZMWUC+wuD1V9IPppdP ikqhpxWaVqF8vSx/F+tmCUVwDgTq9QI3Dl1OOFUCJ5XOHQqAm2uln6T2fl/Gyl1Z+BZzbNt4RDA yJdsT7kZfJIs= X-Received: by 2002:aa7:9616:0:b0:573:1d31:2b79 with SMTP id q22-20020aa79616000000b005731d312b79mr14102261pfg.28.1670810322554; Sun, 11 Dec 2022 17:58:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5kpqcD/WARrHkSIyJuhGn5/Ao4JFQbn2+IfehjkSLF7UQUmqJdeZNAvwwXgMyNj1fztp1sQg== X-Received: by 2002:aa7:9616:0:b0:573:1d31:2b79 with SMTP id q22-20020aa79616000000b005731d312b79mr14102248pfg.28.1670810322262; Sun, 11 Dec 2022 17:58:42 -0800 (PST) Received: from ?IPV6:2403:580e:4b40:0:7968:2232:4db8:a45e? (2403-580e-4b40--7968-2232-4db8-a45e.ip6.aussiebb.net. [2403:580e:4b40:0:7968:2232:4db8:a45e]) by smtp.gmail.com with ESMTPSA id 13-20020a62170d000000b00574de4a2fc7sm4527776pfx.205.2022.12.11.17.58.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Dec 2022 17:58:41 -0800 (PST) Message-ID: <4a283c76-9609-7e66-bcf8-61d6ee2e8b06@redhat.com> Date: Mon, 12 Dec 2022 09:58:36 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v3 5/5] procfs: use efficient tgid pid search on root readdir To: Brian Foster , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: onestero@redhat.com, willy@infradead.org, ebiederm@redhat.com References: <20221202171620.509140-1-bfoster@redhat.com> <20221202171620.509140-6-bfoster@redhat.com> From: Ian Kent In-Reply-To: <20221202171620.509140-6-bfoster@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C5A48C0002 X-Stat-Signature: ay64hps1x7ayycibkxszaqnrrkx49own X-HE-Tag: 1670810325-627007 X-HE-Meta: U2FsdGVkX18Z16NOXcUYAEz2DqHmnB6+bM9sth5jiweOxDcpLFB5oeTOA5Nn6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amicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/12/22 01:16, Brian Foster wrote: > find_ge_pid() walks every allocated id and checks every associated > pid in the namespace for a link to a PIDTYPE_TGID task. If the pid > namespace contains processes with large numbers of threads, this > search doesn't scale and can notably increase getdents() syscall > latency. > > For example, on a mostly idle 2.4GHz Intel Xeon running Fedora on > 5.19.0-rc2, 'strace -T xfs_io -c readdir /proc' shows the following: > > getdents64(... /* 814 entries */, 32768) = 20624 <0.000568> > > With the addition of a dummy (i.e. idle) process running that > creates an additional 100k threads, that latency increases to: > > getdents64(... /* 815 entries */, 32768) = 20656 <0.011315> > > While this may not be noticeable to users in one off /proc scans or > simple usage of ps or top, we have users that report problems caused > by this latency increase in these sort of scaled environments with > custom tooling that makes heavier use of task monitoring. > > Optimize the tgid task scanning in proc_pid_readdir() by using the > more efficient find_get_tgid_task() helper. This significantly > improves readdir() latency when the pid namespace is populated with > processes with very large thread counts. For example, the above 100k > idle task test against a patched kernel now results in the > following: > > Idle: > getdents64(... /* 861 entries */, 32768) = 21048 <0.000670> > > "" + 100k threads: > getdents64(... /* 862 entries */, 32768) = 21096 <0.000959> > > ... which is a much smaller latency hit after the high thread count > task is started. This may not sound like much but in the environment where it was reported it makes quite a difference. The thing is that the scenario above sounds totally unreal but apparently it isn't and even if it was think about many thread group leaders each with even a moderately large number of threads and the observed overhead problem becomes clear. > > Signed-off-by: Brian Foster Reviewed-by: Ian Kent Ian > --- > fs/proc/base.c | 17 +---------------- > 1 file changed, 1 insertion(+), 16 deletions(-) > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 9e479d7d202b..ac34b6bb7249 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -3475,24 +3475,9 @@ struct tgid_iter { > }; > static struct tgid_iter next_tgid(struct pid_namespace *ns, struct tgid_iter iter) > { > - struct pid *pid; > - > if (iter.task) > put_task_struct(iter.task); > - rcu_read_lock(); > -retry: > - iter.task = NULL; > - pid = find_ge_pid(iter.tgid, ns); > - if (pid) { > - iter.tgid = pid_nr_ns(pid, ns); > - iter.task = pid_task(pid, PIDTYPE_TGID); > - if (!iter.task) { > - iter.tgid += 1; > - goto retry; > - } > - get_task_struct(iter.task); > - } > - rcu_read_unlock(); > + iter.task = find_get_tgid_task(&iter.tgid, ns); > return iter; > } >