public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Ihor Solodrai <ihor.solodrai@pm.me>
Cc: Jiri Olsa <olsajiri@gmail.com>,
	dwarves@vger.kernel.org, acme@kernel.org,
	alan.maguire@oracle.com, eddyz87@gmail.com, andrii@kernel.org,
	mykolal@fb.com, bpf@vger.kernel.org
Subject: Re: [PATCH dwarves v3 8/8] btf_encoder: clean up global encoders list
Date: Fri, 3 Jan 2025 10:27:50 +0100	[thread overview]
Message-ID: <Z3etlqj0h8rG88IR@krava> (raw)
In-Reply-To: <hG-genPmZbX2hjVJ0oU90oOYrm7AWp9v0_G4kJwRvC3TBbFcg1rPFMEfu4-zQT8YHDihSU4XbSYNru8XrS-0fcpwSos0AODh8ASitiI5szQ=@pm.me>

On Fri, Jan 03, 2025 at 12:43:42AM +0000, Ihor Solodrai wrote:
> On Wednesday, January 1st, 2025 at 8:56 AM, Jiri Olsa <olsajiri@gmail.com> wrote:
> 
> > 
> > On Sat, Dec 21, 2024 at 01:23:45AM +0000, Ihor Solodrai wrote:
> > 
> > SNIP
> > 
> > > -static int btf_encoder__add_saved_funcs(bool skip_encoding_inconsistent_proto)
> > > +static int btf_encoder__add_saved_funcs(struct btf_encoder *encoder, bool skip_encoding_inconsistent_proto)
> > > {
> > > struct btf_encoder_func_state **saved_fns, *s;
> > > - struct btf_encoder *e = NULL;
> > > - int i = 0, j, nr_saved_fns = 0;
> > > + int err = 0, i = 0, j, nr_saved_fns = 0;
> > > 
> > > - /* Retrieve function states from each encoder, combine them
> > > + /* Retrieve function states from the encoder, combine them
> > > * and sort by name, addr.
> > > */
> > > - btf_encoders__for_each_encoder(e) {
> > > - list_for_each_entry(s, &e->func_states, node)
> > > - nr_saved_fns++;
> > > + list_for_each_entry(s, &encoder->func_states, node) {
> > > + nr_saved_fns++;
> > > }
> > > 
> > > if (nr_saved_fns == 0)
> > > - return 0;
> > > + goto out;
> > > 
> > > saved_fns = calloc(nr_saved_fns, sizeof(*saved_fns));
> > > - btf_encoders__for_each_encoder(e) {
> > > - list_for_each_entry(s, &e->func_states, node)
> > > - saved_fns[i++] = s;
> > > + if (!saved_fns) {
> > > + err = -ENOMEM;
> > > + goto out;
> > > + }
> > > +
> > > + list_for_each_entry(s, &encoder->func_states, node) {
> > > + saved_fns[i++] = s;
> > > }
> > > qsort(saved_fns, nr_saved_fns, sizeof(*saved_fns), saved_functions_cmp);
> > > 
> > > @@ -1377,11 +1313,10 @@ static int btf_encoder__add_saved_funcs(bool skip_encoding_inconsistent_proto)
> > > 
> > > /* Now that we are done with function states, free them. */
> > > free(saved_fns);
> > > - btf_encoders__for_each_encoder(e) {
> > > - btf_encoder__delete_saved_funcs(e);
> > > - }
> > > + btf_encoder__delete_saved_funcs(encoder);
> > 
> > 
> > is this call necessary? there's btf_encoder__delete call right after
> > same for elf_functions_list__clear in btf_encoder__encode
> 
> At this point we know that the function information is no longer
> needed, so we can free up some memory.
> 
> I remember when I wrote a "context" patch [1] (now discarded), there
> was a significant difference in MAX RSS between freeing this right
> away and delaying until encoding is finished. Now it might not be as
> significant, but still there is no reason to keep the stuff we know is
> not used later.

ok, makes sense

jirka

> 
> [1] https://lore.kernel.org/dwarves/20241213223641.564002-8-ihor.solodrai@pm.me/
> 
> > 
> > thanks,
> > jirka
> > 
> > > - return 0;
> > > +out:
> > > + return err;
> > > }
> > 
> > 
> > SNIP
> 

      reply	other threads:[~2025-01-03  9:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-21  1:22 [PATCH dwarves v3 0/8] pahole: faster reproducible BTF encoding Ihor Solodrai
2024-12-21  1:22 ` [PATCH dwarves v3 1/8] btf_encoder: simplify function encoding Ihor Solodrai
2024-12-21  1:23 ` [PATCH dwarves v3 2/8] btf_encoder: separate elf function, saved function representations Ihor Solodrai
2025-01-01 16:56   ` Jiri Olsa
2025-01-02 19:54     ` Ihor Solodrai
2024-12-21  1:23 ` [PATCH dwarves v3 3/8] btf_encoder: introduce elf_functions struct type Ihor Solodrai
2025-01-01 16:56   ` Jiri Olsa
2025-01-02 20:06     ` Ihor Solodrai
2024-12-21  1:23 ` [PATCH dwarves v3 4/8] btf_encoder: introduce elf_functions_list Ihor Solodrai
2024-12-21  1:23 ` [PATCH dwarves v3 5/8] btf_encoder: remove skip_encoding_inconsistent_proto Ihor Solodrai
2024-12-21  1:23 ` [PATCH dwarves v3 6/8] dwarf_loader: introduce cu->id Ihor Solodrai
2024-12-21  1:23 ` [PATCH dwarves v3 7/8] dwarf_loader: multithreading with a job/worker model Ihor Solodrai
2024-12-30 16:07   ` Arnaldo Carvalho de Melo
2024-12-30 16:11     ` Arnaldo Carvalho de Melo
2024-12-30 18:37       ` Arnaldo Carvalho de Melo
2025-01-02 23:09         ` Ihor Solodrai
2025-01-01 16:56   ` Jiri Olsa
2025-01-03  0:24     ` Ihor Solodrai
2024-12-21  1:23 ` [PATCH dwarves v3 8/8] btf_encoder: clean up global encoders list Ihor Solodrai
2025-01-01 16:56   ` Jiri Olsa
2025-01-03  0:43     ` Ihor Solodrai
2025-01-03  9:27       ` Jiri Olsa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z3etlqj0h8rG88IR@krava \
    --to=olsajiri@gmail.com \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=ihor.solodrai@pm.me \
    --cc=mykolal@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox