Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3163603pxb; Mon, 1 Mar 2021 03:19:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJytW4ezgeIYwfXOVfmuHzI1TPGx7ro5TFOhgtFMVSeqG7vXs61Y6rjqbr01jyGWm/3V6Qol X-Received: by 2002:aa7:cf16:: with SMTP id a22mr15487595edy.288.1614597557584; Mon, 01 Mar 2021 03:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614597557; cv=none; d=google.com; s=arc-20160816; b=ei1WDwRRfLVMTYkl4TQIDWtr+p0fgTRoFe4E+/bwSiOWMhdTw09jwGkEo5QnK2jhyY 6cTvsrBErWQxSyyLS6nygVyLUnJFVIye2bI52blNUJTkB0B72cqHV08hDuPLYKhjcK7o WA6qK9rwGVPfWXFbLkdbo+eDPLjfGVJ7SMyXz2vVwvEl64SsYwX4beIFX2o0geiHo3S8 FBSFlffgft4ScV6/lt7D5+bvSgtGC5TjuihDv3AvtC7cWxeGB/lFkijpv1AOAlbBzL/c YAaMvXWFgO0FoReFl/Ag0ustkncCNf2Fy+GXj72gJm9AMKzASKTVTFU1FLZQIVRpwoFM 3/eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:cc:to :organization:references:subject:from:ironport-sdr:ironport-sdr; bh=ouTHapopqy03QjSpAgqlrcYKZTDqiUyqLsZSVWHARhQ=; b=hU5A/MaOxyqdANpNJr7kBlZr9/XbVjtYpIs7fXf+M2lOX8ds4x1Hn2tHVLzitTFYlu EKdbRPb5PWk8B26N1JaEB1TlTytiRKxQ5Rqaee7BchBKDZh1shGNmpBCj2bL9zQ5kvnX lEqn25AwEK0yPpPRproReXYBODHcAk0m/BaqgablmQq1CbCMNk2+DdSYhbTQqVnk3fQ6 YI75UNV/qA3i77jwtOgBCPhDDxl93TfXU28qURIBZ3PqQpw87rv4OooXyQ0a7+MniHuk pJtVlIVz/dRdYC4IdjMEcw/IrUjQP+z7zY75FZYoy5C52JEJyIrv9HoPAa7SFnvOIsJu 1VYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s20si11365571eji.387.2021.03.01.03.18.52; Mon, 01 Mar 2021 03:19:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbhCALR4 (ORCPT + 99 others); Mon, 1 Mar 2021 06:17:56 -0500 Received: from mga01.intel.com ([192.55.52.88]:25326 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232033AbhCALR4 (ORCPT ); Mon, 1 Mar 2021 06:17:56 -0500 IronPort-SDR: zZIFKygTmlWuI2h6OpIkQSAKH4SzqQkKNGe+pOscLGWnPZ4npVQFjMo1TnTVgDV+amPYjrRZVX NId7IOu18uTQ== X-IronPort-AV: E=McAfee;i="6000,8403,9909"; a="206035612" X-IronPort-AV: E=Sophos;i="5.81,215,1610438400"; d="scan'208";a="206035612" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 03:16:10 -0800 IronPort-SDR: 8kpapafSxW/FY0BkiQkWd6121dmlKLANMD+R/FV1oDkMtDB5q0QXboLWM8G24sUUOuZJTb930R llG83deb8Eaw== X-IronPort-AV: E=Sophos;i="5.81,215,1610438400"; d="scan'208";a="406180903" Received: from abaydur-mobl1.ccr.corp.intel.com (HELO [10.249.226.70]) ([10.249.226.70]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 03:16:07 -0800 From: "Bayduraev, Alexey V" Subject: Re: [PATCH v3 07/12] perf record: init data file at mmap buffer object References: <7d197a2d-56e2-896d-bf96-6de0a4db1fb8@linux.intel.com> <20201120104942.GF94830@google.com> Organization: Intel Corporation To: Namhyung Kim , Alexei Budankov Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov Message-ID: <64b0859f-aad3-43fa-4e4c-81614d0c75e4@linux.intel.com> Date: Mon, 1 Mar 2021 14:16:04 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20201120104942.GF94830@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 20.11.2020 13:49, Namhyung Kim wrote: > On Mon, Nov 16, 2020 at 03:19:41PM +0300, Alexey Budankov wrote: >> >> @@ -1400,8 +1417,12 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist, >> /* >> * Mark the round finished in case we wrote >> * at least one event. >> + * >> + * No need for round events in directory mode, >> + * because per-cpu maps and files have data >> + * sorted by kernel. > > But it's not just for single cpu since task can migrate so we need to > look at other cpu's data too. Thus we use the ordered events queue > and round events help to determine when to flush the data. Without > the round events, it'd consume huge amount of memory during report. > > If we separate tracking records and process them first, we should be > able to process samples immediately without sorting them in the > ordered event queue. This will save both cpu cycles and memory > footprint significantly IMHO. > > Thanks, > Namhyung > As far as I understand, to split tracing records (FORK/MMAP/COMM) into a separate file, we need to implement a runtime trace decoder on the perf-record side to recognize such tracing records coming from the kernel. Is that what you mean? IMHO this can be tricky to implement and adds some overhead that can lead to possible data loss. Do you have any other ideas how to optimize memory consumption on perf-report side without a runtime trace decoder? Maybe "round events" would somehow help in directory mode? BTW In our tool we use another approach: two-pass trace file loading. The first loads tracing records, the second loads samples. Thanks, Alexey > >> */ >> - if (bytes_written != rec->bytes_written) >> + if (!record__threads_enabled(rec) && bytes_written != rec->bytes_written) >> rc = record__write(rec, NULL, &finished_round_event, sizeof(finished_round_event)); >> >> if (overwrite) >> @@ -1514,7 +1535,9 @@ static void record__init_features(struct record *rec) >> if (!rec->opts.use_clockid) >> perf_header__clear_feat(&session->header, HEADER_CLOCK_DATA); >> >> - perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT); >> + if (!record__threads_enabled(rec)) >> + perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT); >> + >> if (!record__comp_enabled(rec)) >> perf_header__clear_feat(&session->header, HEADER_COMPRESSED); >> >> @@ -1525,15 +1548,21 @@ static void >> record__finish_output(struct record *rec) >> { >> struct perf_data *data = &rec->data; >> - int fd = perf_data__fd(data); >> + int i, fd = perf_data__fd(data); >> >> if (data->is_pipe) >> return; >> >> rec->session->header.data_size += rec->bytes_written; >> data->file.size = lseek(perf_data__fd(data), 0, SEEK_CUR); >> + if (record__threads_enabled(rec)) { >> + for (i = 0; i < data->dir.nr; i++) >> + data->dir.files[i].size = lseek(data->dir.files[i].fd, 0, SEEK_CUR); >> + } >> >> if (!rec->no_buildid) { >> + /* this will be recalculated during process_buildids() */ >> + rec->samples = 0; >> process_buildids(rec); >> >> if (rec->buildid_all) >> @@ -2438,8 +2467,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) >> status = err; >> >> record__synthesize(rec, true); >> - /* this will be recalculated during process_buildids() */ >> - rec->samples = 0; >> >> if (!err) { >> if (!rec->timestamp_filename) { >> @@ -3179,7 +3206,7 @@ int cmd_record(int argc, const char **argv) >> >> } >> >> - if (rec->opts.kcore) >> + if (rec->opts.kcore || record__threads_enabled(rec)) >> rec->data.is_dir = true; >> >> if (rec->opts.comp_level != 0) { >> diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h >> index 266760ac9143..9c13a39cc58f 100644 >> --- a/tools/perf/util/record.h >> +++ b/tools/perf/util/record.h >> @@ -74,6 +74,7 @@ struct record_opts { >> int ctl_fd; >> int ctl_fd_ack; >> bool ctl_fd_close; >> + int threads_spec; >> }; >> >> extern const char * const *record_usage; >> -- >> 2.24.1 >>