lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7citTUkj5z4bu0HsF73Msnks=2vOBcZU5skT77zUri_Bag@mail.gmail.com>
Date:   Wed, 18 Oct 2023 16:30:15 -0700
From:   Namhyung Kim <namhyung@...nel.org>
To:     Ian Rogers <irogers@...gle.com>
Cc:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Adrian Hunter <adrian.hunter@...el.com>,
        Nick Terrell <terrelln@...com>,
        Kan Liang <kan.liang@...ux.intel.com>,
        Song Liu <song@...nel.org>,
        Sandipan Das <sandipan.das@....com>,
        Anshuman Khandual <anshuman.khandual@....com>,
        James Clark <james.clark@....com>,
        Liam Howlett <liam.howlett@...cle.com>,
        Miguel Ojeda <ojeda@...nel.org>, Leo Yan <leo.yan@...aro.org>,
        German Gomez <german.gomez@....com>,
        Ravi Bangoria <ravi.bangoria@....com>,
        Artem Savkov <asavkov@...hat.com>,
        Athira Rajeev <atrajeev@...ux.vnet.ibm.com>,
        Andi Kleen <ak@...ux.intel.com>, linux-kernel@...r.kernel.org,
        linux-perf-users@...r.kernel.org, bpf@...r.kernel.org
Subject: Re: [PATCH v2 13/13] perf machine thread: Remove exited threads by default

On Wed, Oct 11, 2023 at 11:24 PM Ian Rogers <irogers@...gle.com> wrote:
>
> struct thread values hold onto references to mmaps, dsos, etc. When a
> thread exits it is necessary to clean all of this memory up by
> removing the thread from the machine's threads. Some tools require
> this doesn't happen, such as perf report if offcpu events exist or if
> a task list is being generated, so add a symbol_conf value to make the
> behavior optional. When an exited thread is left in the machine's
> threads, mark it as exited.
>
> This change relates to commit 40826c45eb0b ("perf thread: Remove
> notion of dead threads"). Dead threads were removed as they had a
> reference count of 0 and were difficult to reason about with the
> reference count checker. Here a thread is removed from threads when it
> exits, unless via symbol_conf the exited thread isn't remove and is
> marked as exited. Reference counting behaves as it normally does.

Maybe we can do it the other way around.  IOW tools can access
dead threads for whatever reason if they are dealing with a data
file.  And I guess the main concern is perf top to reduce memory
footprint, right?  Then we can declare to remove the dead threads
for perf top case only IMHO.

Thanks,
Namhyung

>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---
>  tools/perf/builtin-report.c   |  7 +++++++
>  tools/perf/util/machine.c     | 10 +++++++---
>  tools/perf/util/symbol_conf.h |  3 ++-
>  tools/perf/util/thread.h      | 14 ++++++++++++++
>  4 files changed, 30 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
> index dcedfe00f04d..749246817aed 100644
> --- a/tools/perf/builtin-report.c
> +++ b/tools/perf/builtin-report.c
> @@ -1411,6 +1411,13 @@ int cmd_report(int argc, const char **argv)
>         if (ret < 0)
>                 goto exit;
>
> +       /*
> +        * tasks_mode require access to exited threads to list those that are in
> +        * the data file. Off-cpu events are synthesized after other events and
> +        * reference exited threads.
> +        */
> +       symbol_conf.keep_exited_threads = true;
> +
>         annotation_options__init(&report.annotation_opts);
>
>         ret = perf_config(report__config, &report);
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 6ca7500e2cf4..5cda47eb337d 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2157,9 +2157,13 @@ int machine__process_exit_event(struct machine *machine, union perf_event *event
>         if (dump_trace)
>                 perf_event__fprintf_task(event, stdout);
>
> -       if (thread != NULL)
> -               thread__put(thread);
> -
> +       if (thread != NULL) {
> +               if (symbol_conf.keep_exited_threads)
> +                       thread__set_exited(thread, /*exited=*/true);
> +               else
> +                       machine__remove_thread(machine, thread);
> +       }
> +       thread__put(thread);
>         return 0;
>  }
>
> diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
> index 2b2fb9e224b0..6040286e07a6 100644
> --- a/tools/perf/util/symbol_conf.h
> +++ b/tools/perf/util/symbol_conf.h
> @@ -43,7 +43,8 @@ struct symbol_conf {
>                         disable_add2line_warn,
>                         buildid_mmap2,
>                         guest_code,
> -                       lazy_load_kernel_maps;
> +                       lazy_load_kernel_maps,
> +                       keep_exited_threads;
>         const char      *vmlinux_name,
>                         *kallsyms_name,
>                         *source_prefix,
> diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> index e79225a0ea46..0df775b5c110 100644
> --- a/tools/perf/util/thread.h
> +++ b/tools/perf/util/thread.h
> @@ -36,13 +36,22 @@ struct thread_rb_node {
>  };
>
>  DECLARE_RC_STRUCT(thread) {
> +       /** @maps: mmaps associated with this thread. */
>         struct maps             *maps;
>         pid_t                   pid_; /* Not all tools update this */
> +       /** @tid: thread ID number unique to a machine. */
>         pid_t                   tid;
> +       /** @ppid: parent process of the process this thread belongs to. */
>         pid_t                   ppid;
>         int                     cpu;
>         int                     guest_cpu; /* For QEMU thread */
>         refcount_t              refcnt;
> +       /**
> +        * @exited: Has the thread had an exit event. Such threads are usually
> +        * removed from the machine's threads but some events/tools require
> +        * access to dead threads.
> +        */
> +       bool                    exited;
>         bool                    comm_set;
>         int                     comm_len;
>         struct list_head        namespaces_list;
> @@ -189,6 +198,11 @@ static inline refcount_t *thread__refcnt(struct thread *thread)
>         return &RC_CHK_ACCESS(thread)->refcnt;
>  }
>
> +static inline void thread__set_exited(struct thread *thread, bool exited)
> +{
> +       RC_CHK_ACCESS(thread)->exited = exited;
> +}
> +
>  static inline bool thread__comm_set(const struct thread *thread)
>  {
>         return RC_CHK_ACCESS(thread)->comm_set;
> --
> 2.42.0.609.gbb76f46606-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ