On Thu, Jul 18, 2024 at 10:55:17PM GMT, Pasha Tatashin wrote: > On Thu, Jul 18, 2024 at 7:36 PM Shakeel Butt <shakeel.butt@xxxxxxxxx> 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. > Is this really that performance critical? > > > > > +{ > > > + 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. > The above makes me think it is better to move stack_not_used() and the new function to C file unless we can show the negative performance impact. I have another question. At the moment, the metrics are exposed conditionally through procfs based on stack size. So, based on the kernel config someone may not see kstack_16k. Why not just output all of these metrics irrespective of the config? Shakeel