linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: akpm@linux-foundation.org, jpoimboe@kernel.org,
	kent.overstreet@linux.dev,  peterz@infradead.org,
	nphamcs@gmail.com, cerasuolodomenico@gmail.com,
	 surenb@google.com, lizhijian@fujitsu.com, willy@infradead.org,
	vbabka@suse.cz,  ziy@nvidia.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v4] vmstat: Kernel stack usage histogram
Date: Thu, 18 Jul 2024 22:55:17 -0400	[thread overview]
Message-ID: <CA+CK2bB4RELLHExbkL444ArTtUnqiYVYKJ1rLQGarLyenY6WxQ@mail.gmail.com> (raw)
In-Reply-To: <2fbbxcsjs7vtzpb6a5wudbppcr2wgc2xwdw3cgs6ejzx6rioze@z2sct6rbulng>

On Thu, Jul 18, 2024 at 7:36 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
>
> On Thu, Jul 18, 2024 at 08:26:11PM GMT, Pasha Tatashin wrote:
> [...]
> > diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h
> > index ccd72b978e1f..65e8c9fb7f9b 100644
> > --- a/include/linux/sched/task_stack.h
> > +++ b/include/linux/sched/task_stack.h
> > @@ -95,9 +95,51 @@ static inline int object_is_on_stack(const void *obj)
> >  extern void thread_stack_cache_init(void);
> >
> >  #ifdef CONFIG_DEBUG_STACK_USAGE
> > +#ifdef CONFIG_VM_EVENT_COUNTERS
> > +#include <linux/vm_event_item.h>
> > +
> > +/* Count the maximum pages reached in kernel stacks */
> > +static inline void kstack_histogram(unsigned long used_stack)
>
> Any specific reason to add this function in header?

For performance reasons to keep it inlined into stack_not_used() which
is also defined as inline function in this header.

>
> > +{
> > +     if (used_stack <= 1024)
> > +             this_cpu_inc(vm_event_states.event[KSTACK_1K]);
>
> Why not count_vm_event(KSTACK_1K)? Avoiding header include recursion?

I could not include "linux/vmstat.h" into "linux/sched/task_stack.h"
because it introduces some dependencies such linux/mm.h and
linux/fs.h, uapi/linux/stat.h, and when all of those are added it
still fails to compile on some architectures, so it was just simpler
to stop resolving the conflicts and use this_cpu_inc() directly.

>
> > +#if THREAD_SIZE > 1024
> > +     else if (used_stack <= 2048)
> > +             this_cpu_inc(vm_event_states.event[KSTACK_2K]);
> > +#endif
> > +#if THREAD_SIZE > 2048
> > +     else if (used_stack <= 4096)
> > +             this_cpu_inc(vm_event_states.event[KSTACK_4K]);
> > +#endif
> > +#if THREAD_SIZE > 4096
> > +     else if (used_stack <= 8192)
> > +             this_cpu_inc(vm_event_states.event[KSTACK_8K]);
> > +#endif
> > +#if THREAD_SIZE > 8192
> > +     else if (used_stack <= 16384)
> > +             this_cpu_inc(vm_event_states.event[KSTACK_16K]);
> > +#endif
> > +#if THREAD_SIZE > 16384
> > +     else if (used_stack <= 32768)
> > +             this_cpu_inc(vm_event_states.event[KSTACK_32K]);
> > +#endif
> > +#if THREAD_SIZE > 32768
> > +     else if (used_stack <= 65536)
> > +             this_cpu_inc(vm_event_states.event[KSTACK_64K]);
> > +#endif
> > +#if THREAD_SIZE > 65536
> > +     else
> > +             this_cpu_inc(vm_event_states.event[KSTACK_REST]);
> > +#endif
> > +}
> > +#else /* !CONFIG_VM_EVENT_COUNTERS */
> > +static inline void kstack_histogram(unsigned long used_stack) {}
> > +#endif /* CONFIG_VM_EVENT_COUNTERS */
> > +
> >  static inline unsigned long stack_not_used(struct task_struct *p)
> >  {
> >       unsigned long *n = end_of_stack(p);
> > +     unsigned long unused_stack;
> >
> >       do {    /* Skip over canary */
> >  # ifdef CONFIG_STACK_GROWSUP
> > @@ -108,10 +150,13 @@ static inline unsigned long stack_not_used(struct task_struct *p)
> >       } while (!*n);
> >
> >  # ifdef CONFIG_STACK_GROWSUP
> > -     return (unsigned long)end_of_stack(p) - (unsigned long)n;
> > +     unused_stack = (unsigned long)end_of_stack(p) - (unsigned long)n;
> >  # else
> > -     return (unsigned long)n - (unsigned long)end_of_stack(p);
> > +     unused_stack = (unsigned long)n - (unsigned long)end_of_stack(p);
> >  # endif
> > +     kstack_histogram(THREAD_SIZE - unused_stack);
> > +
> > +     return unused_stack;
> >  }
> >  #endif
> >  extern void set_task_stack_end_magic(struct task_struct *tsk);
>


  reply	other threads:[~2024-07-19  2:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-18 20:26 Pasha Tatashin
2024-07-18 21:44 ` Kent Overstreet
2024-07-18 23:36 ` Shakeel Butt
2024-07-19  2:55   ` Pasha Tatashin [this message]
2024-07-19 22:04     ` Shakeel Butt
2024-07-24  0:09       ` Andrew Morton
2024-07-24  0:10     ` Andrew Morton
2024-07-24  6:46 ` Andrew Morton
2024-07-24 14:43   ` Pasha Tatashin
2024-07-24 16:59     ` Shakeel Butt

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=CA+CK2bB4RELLHExbkL444ArTtUnqiYVYKJ1rLQGarLyenY6WxQ@mail.gmail.com \
    --to=pasha.tatashin@soleen.com \
    --cc=akpm@linux-foundation.org \
    --cc=cerasuolodomenico@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizhijian@fujitsu.com \
    --cc=nphamcs@gmail.com \
    --cc=peterz@infradead.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.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