Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5669444ybv; Tue, 18 Feb 2020 01:40:13 -0800 (PST) X-Google-Smtp-Source: APXvYqxeZZ/9sqeIOQCVgUBfBGfvy16uXJwHY0BpLR7poTueIWBq2Tbuva0vn6gKPH5UDEjAHEzk X-Received: by 2002:aca:fd4c:: with SMTP id b73mr690546oii.33.1582018813480; Tue, 18 Feb 2020 01:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582018813; cv=none; d=google.com; s=arc-20160816; b=nMbw2xW3LG2oPpnVwfp1zbtrC9Egz6mzIZpvbnh42kKZPLCmiIgIor8ikjnqH5mOz5 zxOTPBbq68SSaUf5i/4YKnrGpWMs0T9Dv+tZw3aay+Xf6pTpjD5XLY+VuQb3QFzdCvFP rZTozofpkxzqp4vBQ2ho3Q6OLufMiy4NwLuQeQ9/PlDzirJvmX6yfQvi4aqZXOMJbWK+ vVwc3piJJ/eHDP8c26l30/Qq04DBJC55LGH3eTJX/kKK75rbKRFwT+zAxNo/zzg9ENRY niovrj9KqdPTfF+RrKfmCCl11lfc5nM7AYIpzfKa3gfWWpTYYng5+1ZpaIv+bJEuFB9U L77Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Ri50rwS+DwKS+xdiT/P+5HE1fXClWtkp9WTD/LVC98k=; b=Ddz8BJ6AifRp69Gi62/Fgmvz4ytW2BSWps0oihDRV3XcEyC/ggGe5wQhiVfWtsIHhB nGMkGcvnngu2CKm0k5aevY4QeDSjvWWv/b4fPyl5lVuKFsGkXWd8YBtF2gL1IwOHw2GL vJOdj701whksAJDo/p8IZs64gO2oSJ3TNB9rdI6jpwcAfYc5tArP4DQHXMRrhl7mr0EB ScIgHbFxPR4/1HNrvdr4ln8slnsKk+Y4oAgo0zBO1Iwxx7eICQunqLP6/Vrl4cpwQysf plwK2M1w0iGZOcXgQe+2fH1W5z8rXkyM18SL2GvOaRWXjACkMo+WPMyhP0n5msVpbCFD AyVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="KI/aHslK"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13si1395624otq.146.2020.02.18.01.40.01; Tue, 18 Feb 2020 01:40:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="KI/aHslK"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbgBRJjy (ORCPT + 99 others); Tue, 18 Feb 2020 04:39:54 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:41089 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbgBRJjx (ORCPT ); Tue, 18 Feb 2020 04:39:53 -0500 Received: by mail-ed1-f68.google.com with SMTP id c26so24046463eds.8 for ; Tue, 18 Feb 2020 01:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ri50rwS+DwKS+xdiT/P+5HE1fXClWtkp9WTD/LVC98k=; b=KI/aHslK/e7VD/qZEsqk3jaN/3BOu1yhytDSreqQtdWbJRTqjVSjc3qM6Tzuh2zz5i R0fsIro52A0NGmibGj/wVghzgz+NwLLd0gALlAjAbYQyCiuK2d7msEHAJ1X2oH8k3yVt hqbO0jgTLMFp5c0SjbWvorIk/GMYAFoFN96yxpqkblV70wtKw/JLy+beQnJAti3FCimP FQiop4PsagBP/+xGrTI7n7O87WubWDGxR0VZKa2C+jYUYXpjlq7DLCeLZiyW+ncm1Zjc 7DIEK47AM4nw4BMDt0ynD4NJjvrOnzfoe6h+gQPROuNdcbx5BSJiOlpnTx2ozKfE4Oq9 x8GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ri50rwS+DwKS+xdiT/P+5HE1fXClWtkp9WTD/LVC98k=; b=SQPgZ5DRauBf7BJ2DNx7vPZaa/RaoW+wfx5u/2+wgXmZu7Kq9kR32mgG2B2ss00hai 0tuQykZOFG0TOtn/R7zeaps1b8kZQbFUC+kP7FyOr90TbVpXKcQdW829jFQtckfDEqP4 yowMcyfz5NAP3+3VZ1FnmKyP15AGPW6BanKknRfKbkM0+DXfhkYDe/d4DsGcHB49pxB6 yHquj+GnHvuVubBGyp1uPyVFosQmOq2nDfJSa5szt/eSERQPKFChaGTLh7RXGpRuz4hJ 1oLYK2f4N3kLAQL26hzLbTfB/tWFR3REPLaPhjbp4nlPJakL7MHoISWOzGm3LC507nCt igJQ== X-Gm-Message-State: APjAAAXG9BYedrGvhaLv1nEQ7gxBPiXbaSFF3M2mGYSV75hSA+ToDJGX HS7Ie5CH3lFCIp7TKrbgAwq/xwV9Xd1EKaoZk2O45A== X-Received: by 2002:aa7:c2cb:: with SMTP id m11mr18480901edp.89.1582018791471; Tue, 18 Feb 2020 01:39:51 -0800 (PST) MIME-Version: 1.0 References: <20200218005659.91318-1-lrizzo@google.com> <20200218165529.39e761c4be828285cc060279@kernel.org> In-Reply-To: <20200218165529.39e761c4be828285cc060279@kernel.org> From: Luigi Rizzo Date: Tue, 18 Feb 2020 01:39:40 -0800 Message-ID: Subject: Re: [PATCH v3] kretprobe: percpu support To: Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, naveen.n.rao@linux.ibm.com, anil.s.keshavamurthy@intel.com, David Miller , gregkh@linuxfoundation.org, Ingo Molnar , Steven Rostedt Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 17, 2020 at 11:55 PM Masami Hiramatsu wrote: > > Hi Luigi, > > On Mon, 17 Feb 2020 16:56:59 -0800 > Luigi Rizzo wrote: > > > kretprobe uses a list protected by a single lock to allocate a > > kretprobe_instance in pre_handler_kretprobe(). This works poorly with > > concurrent calls. > > Yes, there are several potential performance issue and the recycle > instance is one of them. However, I think this spinlock is not so racy, > but noisy (especially on many core machine) right? correct, it is especially painful on 2+ sockets and many-core systems when attaching kretprobes on otherwise uncontended paths. > > Racy lock is the kretprobe_hash_lock(), I would like to replace it > with ftrace's per-task shadow stack. But that will be available > only if CONFIG_FUNCTION_GRAPH_TRACER=y (and instance has no own > payload). > > > This patch offers a simplified fix: the percpu_instance flag indicates > > that we allocate one instance per CPU, and the allocation is contention > > free, but we allow only have one pending entry per CPU (this could be > > extended to a small constant number without much trouble). > > OK, the percpu instance idea is good to me, and I think it should be > default option. Unless user specifies the number of instances, it should > choose percpu instance by default. That was my initial implementation, which would not even need the percpu_instance flag in struct kretprobe. However, I felt that changing the default would have subtle side effects (e.g., only one outstanding call per CPU) so I thought it would be better to leave the default unchanged and make the flag explicit. > Moreover, this makes things a bit complicated, can you add per-cpu > instance array? If it is there, we can remove the old recycle rp insn > code. Can you clarify what you mean by "per-cpu instance array" ? Do you mean allowing multiple outstanding entries per cpu? I will address your code comments in an updated patch. thanks luigi