Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3423189rdh; Mon, 27 Nov 2023 14:03:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzrRb2mx7Rpidn0UJt5IHcGDltaepj5TVQQ0HsU8+vFw4KRoNtOF60UGF9ZDhj8kJqvCho X-Received: by 2002:a05:6820:1ca7:b0:581:ff09:62e4 with SMTP id ct39-20020a0568201ca700b00581ff0962e4mr15916439oob.2.1701122630599; Mon, 27 Nov 2023 14:03:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701122630; cv=none; d=google.com; s=arc-20160816; b=vk8xyhTIvKBoSppY3osYN/LkRi/WPsKeHUN9tMlNh84hPXlokZqF6qjJOtMydmwSD5 32DzpYG9d95euvkx+BQ2NTkL43mApJVICs+KjVa/Rre+uZSVOJXjWsEoiN3UxSLCbWeJ 598InQBneHP6XefaLdPmK1+rXKJeU00OkBwmdidl7yQbI93t+p7qs26v3zju3iaqNyvw zTAjdFISF1YQyftJf64dEPa1QGfFJbWS3KPLwOl3aymS5tk5QhYPjgOjHRnGZVXhKAwh +2vAJn0cwyr8uMtipv+aMBprgOm30ByY+1qdhaq+GFmzYCRt6VoYOgzNvbsti2vhs12z i5iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=HIjpk8JwjH80FkUq6OwfSD7z5TIycp4f0GTRotfkr1U=; fh=+v6iOBhBPepiTm5jfh5hb/DbZOKRJ3o62f2r0DhfAo4=; b=YCcelREPiecjyp2N/96AWMc7BF/vj0swlVs/yryR3anyDIKsKMKEpuUmuQHv0Javne J+F+GnsX6itEprWEk3NPQiGNEIZ10YTPe5jRJu3HGnZBNNIePNUIdwj2SAq77XSUeE4H TYNqnizVez63YJuMcfTkW5AZj56IR5Gv3t13hjNhpRMCzo3TiTfFgZFx+ApNJBstk2fw 4Lof8jaUk6mLCmq+ELVNHj4Sr9rcx0PRLKw6IOyBJodaX/hoQE/ukGvow5eBfoND7XWr GZ305qMal8K4PRj40hRJRNls/evvrFXGwmfJh/kLqdUm0zXfVfWydT1CawCGjsVmc4ja wZdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q+a5RdsP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x12-20020a4a868c000000b0058d91900e99si884602ooh.94.2023.11.27.14.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:03:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q+a5RdsP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 9188D809B71B; Mon, 27 Nov 2023 14:03:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233348AbjK0WDb (ORCPT + 99 others); Mon, 27 Nov 2023 17:03:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbjK0WDa (ORCPT ); Mon, 27 Nov 2023 17:03:30 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD5891AE for ; Mon, 27 Nov 2023 14:03:36 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E386C433C7; Mon, 27 Nov 2023 22:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701122616; bh=sgOJ6U7HZ+AC7XaG2fCShwuNmSNdLJ8YQTkNUpN7nZg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=q+a5RdsPeiaQ54NWiK+EKzu7bs8ByxbFAfEqornh3xkrEW1HwUB5TmXEccV/B9y0j uRzqKrEVkO3tif+P3BGK5r6o9Shp1bznyFfc5mzQQOO7oPLwfee7XzW8kqTlUDtMKk opeVtzHxo0dP0WHtPgXd84285qsrKKtdyy5dDdgTajhgduZUbiYgRzGCB///T/zVY0 RMa0JupNUOs30FbsdfQd2fmVkcCj3vQTsJJZ5/OPG4HIca9ZvgGxOfKZhpIt75O+pR h3ur5N9/n0Kc4x1J8ySnaBcxEzYm4DavvWmssohucTyp/YxNZmPKjvSimtF3eYOiad jdIVXf5ciUY/A== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id AB4FA40094; Mon, 27 Nov 2023 19:03:32 -0300 (-03) Date: Mon, 27 Nov 2023 19:03:32 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , 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 Subject: Re: [PATCH v4 10/53] perf record: Be lazier in allocating lost samples buffer Message-ID: References: <20231102175735.2272696-1-irogers@google.com> <20231102175735.2272696-11-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231102175735.2272696-11-irogers@google.com> X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 27 Nov 2023 14:03:44 -0800 (PST) Em Thu, Nov 02, 2023 at 10:56:52AM -0700, Ian Rogers escreveu: > 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 = rec->session; > - struct perf_record_lost_samples *lost; > + struct perf_record_lost_samples *lost = NULL; > struct evsel *evsel; > > /* there was an error during record__open */ > if (session->evlist == NULL) > return; > > - lost = zalloc(PERF_SAMPLE_MAX_SIZE); > - if (lost == NULL) { > - pr_debug("Memory allocation failed\n"); > - return; > - } Shouldn't we take the time here and instead improve this error message and then propagate the error? For instance, we may want to still get some perf.data file without these records but inform the user at this point how many records were lost (count.lost)? - Arnaldo > - > - lost->header.type = PERF_RECORD_LOST_SAMPLES; > - > evlist__for_each_entry(session->evlist, evsel) { > struct xyarray *xy = evsel->core.sample_id; > u64 lost_count; > @@ -1961,6 +1953,14 @@ static void record__read_lost_samples(struct record *rec) > } > > if (count.lost) { > + if (!lost) { > + lost = zalloc(PERF_SAMPLE_MAX_SIZE); > + if (!lost) { > + pr_debug("Memory allocation failed\n"); > + return; > + } > + lost->header.type = PERF_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 record *rec) > } > > lost_count = perf_bpf_filter__lost_count(evsel); > - if (lost_count) > + if (lost_count) { > + if (!lost) { > + lost = zalloc(PERF_SAMPLE_MAX_SIZE); > + if (!lost) { > + pr_debug("Memory allocation failed\n"); > + return; > + } > + lost->header.type = PERF_RECORD_LOST_SAMPLES; > + } > __record__save_lost_samples(rec, evsel, lost, 0, 0, lost_count, > PERF_RECORD_MISC_LOST_SAMPLES_BPF); > + } > } > out: > free(lost); > -- > 2.42.0.869.gea05f2083d-goog > -- - Arnaldo