Re: [PATCH v5 08/50] perf record: Be lazier in allocating lost samples buffer

From: Namhyung Kim
Date: Sat Dec 02 2023 - 18:57:04 EST


On Thu, Nov 30, 2023 at 10:29 AM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> On Wed, Nov 29, 2023 at 6:09 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > On Mon, Nov 27, 2023 at 2:09 PM Ian Rogers <irogers@xxxxxxxxxx> 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 <irogers@xxxxxxxxxx>
> > > ---
> > > 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);
> >
> > 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.

Yep, I'm ok with having it as a follow-up.

Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx>

Thanks,
Namhyung