Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2779837rda; Wed, 25 Oct 2023 12:03:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVvFL7Tcfa1bGViH8Ff2mSHxpEzBtHVKhAgOQIf6tcR7eCzjbGsNM1fhe5TRfdYPvfa3Nx X-Received: by 2002:a25:6a04:0:b0:d9a:401d:f5da with SMTP id f4-20020a256a04000000b00d9a401df5damr13760317ybc.51.1698260587166; Wed, 25 Oct 2023 12:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698260587; cv=none; d=google.com; s=arc-20160816; b=NrQZJ7KUYV1EzrBp1gS++MoFSQ/ch5Kzvs4J5PyUpaQTDTXUUaD0S2B2GCM6X1Q7Bp 9hDg0TI38lYxzfZB+0U+zzH0UnQsOplXcw7P1af1PqJwoIg23V/CGUfsSD3LXmFLPvEH MKvfFPcwbGfka4UalaLIcaOxG2y+iMiwYmytiqqLdRvT4YM48hVvq8cTji5uoZ4LXqR2 M4GK+uBCOYPJtTtGTkAYsOos6iJYFVEIAkdMNIYrVgwsKbJaR/w3wyJoffZDjV47+kFu 2AMBYiXGaO40FkaOClos7+yWLI1pfbWx29P5Lej+F9i3+wkVjBec58+qnnXkRpTDtjlD 78cA== 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; bh=KCbAkEHOZoDqanvNOhqgZkEFe38eLZHjazWmviWMY0E=; fh=t/Kse57aOOnSQi2pqQmQ7BlGapmbZVBij7CKWwkqPEE=; b=zNfY9hQHBW3pfZaTGTRbk3tkedhg8iiMvivHvCcqdWnH/t+eI0lHiuxICSD7VnSGfZ maT8+cpdYbbD1QUIs/4pKaJKN/RYexeVHz5RsXyDeXko2xEBMwvM3Trr44a2FOnFG3t7 C8VzktzkeaKIYvxro11PGozQzTUB6TzKLVN+p1gtryzVAPTFtJx7A4x7pUn4TlH8ljLL OspOWaMtsya+nRcG+d1IXon9ZVJahkvbepsSLgme1wlWS7juDIYTROwcMF8qNzF46kSW lqeIOPO48GiSD7WbLEXvEidoxPN6XPAn23BMgAhdmlAmt7vIBm/ceMQi+NFaix4IDeyx hf1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b136-20020a25348e000000b00d747f98fea8si11672038yba.510.2023.10.25.12.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 12:03:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id A08A38070665; Wed, 25 Oct 2023 12:01:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbjJYTBL convert rfc822-to-8bit (ORCPT + 99 others); Wed, 25 Oct 2023 15:01:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjJYTBJ (ORCPT ); Wed, 25 Oct 2023 15:01:09 -0400 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ECC810E; Wed, 25 Oct 2023 12:01:08 -0700 (PDT) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-565e54cb93aso99560a12.3; Wed, 25 Oct 2023 12:01:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698260467; x=1698865267; 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=hFFp1teDPTWctvGkI7bKcJj5VRaVw2/baBUihjKuLl8=; b=YOsPyctpJ841e2DNiD87/TjFzFrBqL5IYKn1+0iG4LmAZGo03FhqIujqkmLBfR4Pbr dSS/3GRo6rZjIjwXvyD/kkQeaE0t1Wqzlmtf8N8ONYd4EQUpExDdr9E+XoGXAM/4HN3H GXpoYqOvXt2DF57MlbVaD4c7/cQGnMDvQisNmaCLnt+OzgSrQ17IhiR96R8xZyAfaGo6 nw5C/4HoHUUzJnBbiruZIX8pZi5BsS2vWqwlfeqwmLfG7jigVgd20prYvkx8tZbRAWGE rh3zk9X2Qk8+1IDblpooSpCSnXj0RVz0H43yDDqn2a1pXnZePuI9pVRQdQ1qkH4I2ACs zc4A== X-Gm-Message-State: AOJu0YzTptOYgmIUZSSciTbsEpHcQRdqgaKA6skVDz7pYuy/rJm28RVq oJJY0pPExCqxIfNZbzvGolioWcpHiIrb+Poy3TpwJ8afy9Q= X-Received: by 2002:a17:90b:608:b0:27d:44ce:cf7a with SMTP id gb8-20020a17090b060800b0027d44cecf7amr14544657pjb.5.1698260467237; Wed, 25 Oct 2023 12:01:07 -0700 (PDT) MIME-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> <20231024222353.3024098-21-irogers@google.com> In-Reply-To: <20231024222353.3024098-21-irogers@google.com> From: Namhyung Kim Date: Wed, 25 Oct 2023 12:00:56 -0700 Message-ID: Subject: Re: [PATCH v3 20/50] perf record: Be lazier in allocating lost samples buffer To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 25 Oct 2023 12:01:13 -0700 (PDT) On Tue, Oct 24, 2023 at 3:25 PM Ian Rogers wrote: > > 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); Sorry for naively choosing the max size. :-p It could be sizeof(*lost) + machine->id_hdr_size. Thanks, Namhyung > - if (lost == NULL) { > - pr_debug("Memory allocation failed\n"); > - return; > - } > - > - 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.758.gaed0368e0e-goog >