Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2278757rda; Tue, 24 Oct 2023 19:39:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVkd3xqKwl55ustLMEMXj3kiz4T9kY10QRhqSP07+0zjOO1d8+uLHgAHjwwqvl9vc1WOMy X-Received: by 2002:a05:620a:2949:b0:772:63d9:5264 with SMTP id n9-20020a05620a294900b0077263d95264mr17402039qkp.59.1698201547859; Tue, 24 Oct 2023 19:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698201547; cv=none; d=google.com; s=arc-20160816; b=L8uF36fw4UPrcw8mcrmYxkE2Y7q8xbSDUox5dsbqK6bJrLRO34AQUudnLadSwb9+md 6/r44ivK6pbhXeXh6WPhTJKOVWAxno6guAqfihc8XRsbbHuBKl+1dzMcZcYxmzyaaKZn zFP7IflS0LgrRWgfAuH6BLLtaPOhlQsQRlXtsL0pTT1OzDAKmv5CkZittAG2pTG9Wo6U Nb8Ycu36OQW+Han33uw63tLE669VfLZ2v8oYQZzLwe7EZR9CK8uunSY3vmyTFV7wZb3h CJ+VVq8odYQXl6JqHgBcM9obRRrmmJwY0SYWDN8r4ySXH6wR/XIhY2ON1yYtmgy0NXNS LyFA== 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:from:cc :references:to:subject; bh=+aDIAdCIuTTdjaa84B0Yk5DPdsU/eCHaCFJgxgLjLq0=; fh=av5YlIHd8cJ0z8wQWhpJUrKGVYkamMBHufu2MbKWk8A=; b=ncWEnNstoQ0o2kXNL5k9quuoHxT58XIhDmiZ3j7C5WMH6sUW0DE1Ud8rS4sT6oNzkm B31NzwZa3pacOmHWznKQbVp9Wv+LbXM2ohjbDVcU4YcBKhkSg20ikEVwy+GPNFGwNj9G MiUj4EqmBGn+FJ7Tihs4bIzbf9oIevLuDoz1/iKZsw7xjv4uUgajgU4KRtD7l/NRs3Oi ydCp9j/pZz8orzk0MppRcGRtrtKMDtLNNSi00bycovgAsRpThqCbGCF/DgTxR77BEVSL X82ci4nN5mOIDe9JpHXmy3IoIHR2IIewu4jjrjfiDWZ8T7rEBGq8UWcAfrmXSfSFlTn7 Yo1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id j11-20020a25550b000000b00da03805ba41si3122743ybb.547.2023.10.24.19.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 19:39:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8A45B802170C; Tue, 24 Oct 2023 19:39:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231732AbjJYCi7 (ORCPT + 99 others); Tue, 24 Oct 2023 22:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbjJYCi6 (ORCPT ); Tue, 24 Oct 2023 22:38:58 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 203C010E; Tue, 24 Oct 2023 19:38:56 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SFY2S5kzWzrTcT; Wed, 25 Oct 2023 10:36:00 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm000003.china.huawei.com (7.193.23.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 25 Oct 2023 10:38:52 +0800 Subject: Re: [PATCH v3 13/50] libperf: Lazily allocate mmap event copy To: Ian Rogers References: <20231024222353.3024098-1-irogers@google.com> <20231024222353.3024098-14-irogers@google.com> CC: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , , From: Yang Jihong Message-ID: <4d275fcd-a102-662f-d9f7-3acd3586acf2@huawei.com> Date: Wed, 25 Oct 2023 10:38:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20231024222353.3024098-14-irogers@google.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm000003.china.huawei.com (7.193.23.66) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 19:39:05 -0700 (PDT) Hello, On 2023/10/25 6:23, Ian Rogers wrote: > The event copy in the mmap is used to have storage to a read > event. Not all users of mmaps read the events, such as perf record, so > switch the allocation to being on first read rather than being > embedded within the perf_mmap. > > Signed-off-by: Ian Rogers > --- > tools/lib/perf/include/internal/mmap.h | 2 +- > tools/lib/perf/mmap.c | 9 +++++++++ > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/tools/lib/perf/include/internal/mmap.h b/tools/lib/perf/include/internal/mmap.h > index 5a062af8e9d8..b11aaf5ed645 100644 > --- a/tools/lib/perf/include/internal/mmap.h > +++ b/tools/lib/perf/include/internal/mmap.h > @@ -33,7 +33,7 @@ struct perf_mmap { > bool overwrite; > u64 flush; > libperf_unmap_cb_t unmap_cb; > - char event_copy[PERF_SAMPLE_MAX_SIZE] __aligned(8); > + void *event_copy; > struct perf_mmap *next; > }; > > diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c > index 2184814b37dd..91ae46aac378 100644 > --- a/tools/lib/perf/mmap.c > +++ b/tools/lib/perf/mmap.c > @@ -51,6 +51,8 @@ int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, > > void perf_mmap__munmap(struct perf_mmap *map) > { > + free(map->event_copy); > + map->event_copy = NULL; > if (map && map->base != NULL) { > munmap(map->base, perf_mmap__mmap_len(map)); > map->base = NULL; > @@ -226,6 +228,13 @@ static union perf_event *perf_mmap__read(struct perf_mmap *map, > unsigned int len = min(sizeof(*event), size), cpy; > void *dst = map->event_copy; > > + if (!dst) { > + dst = malloc(PERF_SAMPLE_MAX_SIZE); `event` is used as the return parameter of libperf API perf_mmap__read_event(). Is `zalloc` better to avoid dirty data? Thanks, Yang