Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5779908ybv; Tue, 18 Feb 2020 03:51:52 -0800 (PST) X-Google-Smtp-Source: APXvYqxrWzOIECh8uSkqwWHBcrMOFRDxM8IXhXvTdYWX6B+a1GDsO6fmkE+CWWnEU6x2ZfX/aO9Y X-Received: by 2002:a9d:7:: with SMTP id 7mr14816949ota.26.1582026712491; Tue, 18 Feb 2020 03:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582026712; cv=none; d=google.com; s=arc-20160816; b=Z3YWDY9B8xVptgxDq31X9Ou3xHBubnv4BczQw0UzkRc5P9cl/pEe/CV8VbS9FfkK0J Tg5LPhh439KMaP2lwikQJkqDooVd+45GvN3nHyHMMBhzdjQ6HHdOAhu9NQU+gJD0WdSk zXmEBR+8yq8sZGuqPGQSa/me6EXUCUGmj8K7gEiPDiniYWMROlt0DRxFF222HI9iR350 N6CQSzhJb0VbdyEYEu6ZVd46W9a7xmfklZH+d3jbaLG9E3mx5l++4xr70ovAGils/ftP PINyxyxCUmR++XtvZ2grwqfMAEqgPmE3lv9yViMhQKnAXX+FeXImF+Oo1sr87XS1TD2L fadA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=RnT21az9bXxWsaJUFWvvsDpaT6BqnlWCcqakUgFNKII=; b=1FxgPeq7sPWm9THOLwEj7UHrFESNphpX/HuXSZTQJt8IbrcvBJClaF8+cUpOwBGn0o tw6hki50DF86T1zX+LrYnpKLhUqWoA1IDZbvof83UMNiePSoGBmqsFReuzE5Py2ZkDcL bjarqRJFVcR/kFgNu6wovvMkntdPk+wNzv17JZQZZv9yBX0d5GrjWe60x39PdIdoEwf+ 8mXFHhcC+5J+NUm55Ne17VyIbEP4Qi3eoBDQbnuB/EY2tSwQ61I+YjC5gs+rUp2oWKSp luaJ1cYYWwiVTvkOn9VqC4eHqssm5XerYLkzMOkU/UBoeS5WiOFvUcUHwPFgt5znGioA FpWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="F/Qi0Pw9"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w16si8177428oih.154.2020.02.18.03.51.38; Tue, 18 Feb 2020 03:51:52 -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=@kernel.org header.s=default header.b="F/Qi0Pw9"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbgBRLub (ORCPT + 99 others); Tue, 18 Feb 2020 06:50:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:46376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgBRLub (ORCPT ); Tue, 18 Feb 2020 06:50:31 -0500 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F2BFC207FD; Tue, 18 Feb 2020 11:50:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582026629; bh=MSQMEr8/X8jyl/lO4pX5AF1skDj7s9X7KlOL2Iv7x+E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=F/Qi0Pw9wch5TLlaX1Psb0ymv+ZQd/8s5aF1+GyFvfoTwHYhyLxRaSQPPuZrn3V5x d5UZ2bhsvZi+HuQpemRRtQf4Ni25f+1ixBDH3lyzLNqmdHPWTKXXYocISh6cmlnQaq XYNYSbCCO5V+y0PEHrlIfuzFnlO3vVM5AY9fKXXU= Date: Tue, 18 Feb 2020 20:50:25 +0900 From: Masami Hiramatsu To: Luigi Rizzo 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 Subject: Re: [PATCH v3] kretprobe: percpu support Message-Id: <20200218205025.4047cf0506f56b18f9a989c4@kernel.org> In-Reply-To: References: <20200218005659.91318-1-lrizzo@google.com> <20200218165529.39e761c4be828285cc060279@kernel.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Feb 2020 01:39:40 -0800 Luigi Rizzo wrote: > 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? Yes, either allocating it on percpu area or allocating arraies on percpu pointer is OK. e.g. instance_size = sizeof(*rp->pcpu) + rp->data_size; rp->pcpu = __alloc_percpu(instance_size * array_size, __alignof__(*rp->pcpu)); And we will search free ri on the percpu array by checking ri->rp == NULL. Thank you, > > I will address your code comments in an updated patch. > > thanks > luigi -- Masami Hiramatsu