From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80B863587CD for ; Wed, 22 Oct 2025 16:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761149389; cv=none; b=XlGP5kN7TTDhlNZ9Ir/JKWxqeY9GfOEFkZ309L3Z/agBxA73ag7eiw3+m+UB3L/c0F6GxSKISkO/R9yW+ZcA3nDCp+EgJ3DoAuvULheFcIZqry+KGXXqg0kZGdQh7M1i7c/83Zs6aGFsMbhWWK9qClVJx8wHAZV1ks3MEJnBXxA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761149389; c=relaxed/simple; bh=kCv5GZq3aXFKjf+qpb+MVrtS6nZnSsKamPeJnxcujeI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aDoyiPme32NCnd4D02R6kr3DcVlsfjRDRqgUSyHLhORT5A19jATVU/pGrm5vJaFg4aOWXjpU6ha1aeNkkhUOXw3F8lRT4TjQGGwu4H03tH+mbSURdmikdj5WjZ/G7QLH6LBvoIK5Kpd1uCc6xAVZc2Qx4KLltM+ROjFD6Cy0xX8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tUminb+T; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tUminb+T" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1761149375; 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=h+0kkqV8nNznZBElyk26pXakcabrm8PG0JX9d48AtfQ=; b=tUminb+TWDKYU6LcCoz+iY2hUJVKaArB5uQrLkFnzOV1rSKYF4nFzcobQJ1tV9sJgp6M5J zd3wjncFIrF6ctmnrzNOoL85fSSKUGDjjJbzALthdTP2aCnvFUFGkH50JZjFVaKoYaSHxL 5pLa08nwYoq8MUhb3s4iv3LwdZ+v7GU= Date: Thu, 23 Oct 2025 00:08:32 +0800 Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v4 2/2] bpf: Use per-cpu BPF callchain entry to save callchain To: Alexei Starovoitov Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Song Liu , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , "linux-perf-use." , LKML , bpf References: <20251021160633.3046301-1-chen.dylane@linux.dev> <20251021160633.3046301-3-chen.dylane@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Chen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2025/10/22 01:28, Alexei Starovoitov 写道: > On Tue, Oct 21, 2025 at 9:07 AM Tao Chen wrote: >> >> As Alexei noted, get_perf_callchain() return values may be reused >> if a task is preempted after the BPF program enters migrate disable >> mode. Drawing on the per-cpu design of bpf_bprintf_buffers, >> per-cpu BPF callchain entry is used here. >> >> Signed-off-by: Tao Chen >> --- >> kernel/bpf/stackmap.c | 98 ++++++++++++++++++++++++++++++++----------- >> 1 file changed, 73 insertions(+), 25 deletions(-) >> >> diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c >> index 94e46b7f340..97028d39df1 100644 >> --- a/kernel/bpf/stackmap.c >> +++ b/kernel/bpf/stackmap.c >> @@ -31,6 +31,52 @@ struct bpf_stack_map { >> struct stack_map_bucket *buckets[] __counted_by(n_buckets); >> }; >> >> +struct bpf_perf_callchain_entry { >> + u64 nr; >> + u64 ip[PERF_MAX_STACK_DEPTH]; >> +}; >> + >> +#define MAX_PERF_CALLCHAIN_PREEMPT 3 >> +static DEFINE_PER_CPU(struct bpf_perf_callchain_entry[MAX_PERF_CALLCHAIN_PREEMPT], >> + bpf_perf_callchain_entries); >> +static DEFINE_PER_CPU(int, bpf_perf_callchain_preempt_cnt); > > This is too much extra memory. Above adds 1k * 3 * num_cpus. > Let's reuse perf callchains. > Especially since they're controlled by perf_event_max_stack sysctl. > See Peter's suggestion in v3. > And for the future don't respin so quickly. Ok, let's base our discussion on v3, sorry for the overly rapid version iterations impacted the maintainers' review process, i will respin slowly, thanks. -- Best Regards Tao Chen