Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp514520rdb; Thu, 30 Nov 2023 10:29:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9BkPzGIw/mwqTiWjyhI8eaT9noGUiKCXdB46Q0ppGZicqwNWI/ehBjCOHhK7O9T01FYE3 X-Received: by 2002:a17:90b:4d0f:b0:27d:1ea0:bc84 with SMTP id mw15-20020a17090b4d0f00b0027d1ea0bc84mr21948573pjb.34.1701368995021; Thu, 30 Nov 2023 10:29:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701368995; cv=none; d=google.com; s=arc-20160816; b=owo8Rsokx1ZEXihv7aV13yOrtlWmeWznhU5gEWJwlfDRrHH+yHHXx1dLB2W5x1CPdU uukxN15G9Nj0cI+PHraivLHfprfHRBlA+/5pBRPpbQrGX3o0+XuMJVye4l+c+HSOXWRl tNBiDgKnS9m5etmtfF0my4y6rfcf3uHh4csd6VE2+33BzF34kJbnIxK54COCHsC/9iOL 24HNavjYGr9vWgCg/GhgTYJ2uUysHwaBtj8Pn8iops7yJGjFfd2AH3tl4sXq+Qz2AV+f DJiieahAYcny/151g0/6i5P+vCnuJL1d1jRh8b1KBvfF2VgXyDs6O1MHEIwwwY2gUUu3 hCkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=FBKQZd68edVxF6ECkF2oX9KfXPiYc6EetlvZAUBR47c=; fh=zt+aMtm74o2VDnWd+fyn50LeDgsHvuUMqskurVhx6uc=; b=vt2s8gozn4TZ019yCAHklpdhLYuh7sSP1yrSzPsXF+fjGXb/yqaBAl+RGpPkYgycHM JrCOo5k7P+ge42yZDNUoDq6vcMgXPayqVZ/lKTRViWWLsSmMNii0eGx/3kEihHyjBc+m aGyu59tIHs3be3LMHLqpn3jthPzdKRKiKo6tidcYcZhCe7W29o0vfsoaTvl0oWs6oqAv QgtEcWWG2EJDuf2nshxFOsEO9kzGd8V6gd8OgRClEW5sCnT/z4kJ0388Va5ieuC7CGx7 SwXPlYtrt9dVvS4ACfLKb/vzpE4ts6QzBRYcBL+Ou3Cb+sKz/C5n5VVZaTaeC4KJmJwx a7fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ouETubjN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id pi13-20020a17090b1e4d00b00285aaf2d6aesi4333197pjb.116.2023.11.30.10.29.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 10:29:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ouETubjN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 51329808AB8D; Thu, 30 Nov 2023 10:29:52 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231959AbjK3S3j (ORCPT + 99 others); Thu, 30 Nov 2023 13:29:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjK3S3h (ORCPT ); Thu, 30 Nov 2023 13:29:37 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C67E10D0 for ; Thu, 30 Nov 2023 10:29:43 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40b51e26a7aso14365e9.1 for ; Thu, 30 Nov 2023 10:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701368982; x=1701973782; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FBKQZd68edVxF6ECkF2oX9KfXPiYc6EetlvZAUBR47c=; b=ouETubjN1Hdfwdi3lj5ciw9BryOW7yvcfzKQ8Y6c9yMy99sUrEZjdtvK4hgBXQcrHw QOKA/wmdEMYw8XZhz70GYM/rzYolQYCaA/htcob/jmnpV9u06qUnjK/rlDjXJalwiolJ UyBsk8YT8+T8NWijedkchFVYnMhjTsmaZi5AfrsNxxq71qnVGwJccjjm4xWh+/JrxXtn gxBp4vE83nlRW5PewqnFvmVSjDvi6STPDLTpS/2PE/+sJfusmXGrMAyyn8aJ9nq7PZ69 B2Gcq76iRn1gs0o3w1id+LxjamdEHE19sbD8RJdXLPJSguWAMHMJLPIIG8QTp4jISYC9 +JxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701368982; x=1701973782; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FBKQZd68edVxF6ECkF2oX9KfXPiYc6EetlvZAUBR47c=; b=w6m4eqYXjzkr5sFPnoy/tYHbIpss4u9omigWe6kVW34YZyvc4R/QNLj89QZGkvEQVu EbjIV5z2pyQCVw4o4S9BToMCyRB1m2zFbq+HqQIb9WM6W6l7Z9Gcn0Wu50Qi3pPltSIV mxBlw87ynql1XEvTToYyZFnbwaPfwnD90KHSK8lPH171TL/sFDr3V8EZbU2SSf/MPDvr 2NXgqaYZ3+TaRFK20TWJrIK6n45y7snMA5u4BULxnRnWvamXmVtfPDhe1RbW9av8d8v1 k/OGptFhdA2yLAr7/HxDX4mU3RR3ARf4JisRrFFT7NAq/8atK5If2XhIvOO1DCzpmP4J wy0g== X-Gm-Message-State: AOJu0YyMP3CR099BvlofR7cawTf70NUns72ZAN9pfyvtQG4upKvGHNxH M5GQZ+uBQPoTbKhBo/hcgVaQ0Ru8YHVSj2O5VcXWnQ== X-Received: by 2002:a05:600c:1c04:b0:40b:43f4:df9e with SMTP id j4-20020a05600c1c0400b0040b43f4df9emr211199wms.2.1701368981847; Thu, 30 Nov 2023 10:29:41 -0800 (PST) MIME-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> <20231127220902.1315692-9-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Thu, 30 Nov 2023 10:29:30 -0800 Message-ID: Subject: Re: [PATCH v5 08/50] perf record: Be lazier in allocating lost samples buffer To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 30 Nov 2023 10:29:52 -0800 (PST) On Wed, Nov 29, 2023 at 6:09=E2=80=AFPM Namhyung Kim = wrote: > > On Mon, Nov 27, 2023 at 2:09=E2=80=AFPM Ian Rogers w= rote: > > > > Wait until a lost sample occurs to allocate the lost samples buffer, > > often the buffer isn't necessary. This saves a 64kb allocation and > > 5.3kb of peak memory consumption. > > > > Signed-off-by: Ian Rogers > > --- > > tools/perf/builtin-record.c | 29 +++++++++++++++++++---------- > > 1 file changed, 19 insertions(+), 10 deletions(-) > > > > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c > > index 9b4f3805ca92..b6c8c1371b39 100644 > > --- a/tools/perf/builtin-record.c > > +++ b/tools/perf/builtin-record.c > > @@ -1924,21 +1924,13 @@ static void __record__save_lost_samples(struct = record *rec, struct evsel *evsel, > > static void record__read_lost_samples(struct record *rec) > > { > > struct perf_session *session =3D rec->session; > > - struct perf_record_lost_samples *lost; > > + struct perf_record_lost_samples *lost =3D NULL; > > struct evsel *evsel; > > > > /* there was an error during record__open */ > > if (session->evlist =3D=3D NULL) > > return; > > > > - lost =3D zalloc(PERF_SAMPLE_MAX_SIZE); > > To minimize the allocation size, this can be > sizeof(*lost) + session->machines.host.id_hdr_size > instead of PERF_SAMPLE_MAX_SIZE. Sounds good, should probably be a follow up. The current size is PERF_SAMPLE_MAX_SIZE. Thanks, Ian > Thanks, > Namhyung > > > > - if (lost =3D=3D NULL) { > > - pr_debug("Memory allocation failed\n"); > > - return; > > - } > > - > > - lost->header.type =3D PERF_RECORD_LOST_SAMPLES; > > - > > evlist__for_each_entry(session->evlist, evsel) { > > struct xyarray *xy =3D evsel->core.sample_id; > > u64 lost_count; > > @@ -1961,6 +1953,14 @@ static void record__read_lost_samples(struct rec= ord *rec) > > } > > > > if (count.lost) { > > + if (!lost) { > > + lost =3D zalloc(PERF_SA= MPLE_MAX_SIZE); > > + if (!lost) { > > + pr_debug("Memor= y allocation failed\n"); > > + return; > > + } > > + lost->header.type =3D P= ERF_RECORD_LOST_SAMPLES; > > + } > > __record__save_lost_samples(rec= , evsel, lost, > > x, = y, count.lost, 0); > > } > > @@ -1968,9 +1968,18 @@ static void record__read_lost_samples(struct rec= ord *rec) > > } > > > > lost_count =3D perf_bpf_filter__lost_count(evsel); > > - if (lost_count) > > + if (lost_count) { > > + if (!lost) { > > + lost =3D zalloc(PERF_SAMPLE_MAX_SIZE); > > + if (!lost) { > > + pr_debug("Memory allocation fai= led\n"); > > + return; > > + } > > + lost->header.type =3D PERF_RECORD_LOST_= SAMPLES; > > + } > > __record__save_lost_samples(rec, evsel, lost, 0= , 0, lost_count, > > PERF_RECORD_MISC_LO= ST_SAMPLES_BPF); > > + } > > } > > out: > > free(lost); > > -- > > 2.43.0.rc1.413.gea7ed67945-goog > >