History

fs/proc: Show STACKLEAK metrics in the /proc file system

Introduce CONFIG_STACKLEAK_METRICS providing STACKLEAK information about tasks via the /proc file system. In particular, /proc/<pid>/stack_depth shows the maximum kernel stack consumption for the current and previous syscalls. Although this information is not precise, it can be useful for estimating the STACKLEAK performance impact for your workloads.

Alexander Popov committed 8 years ago

Commit c8d12621 parent f90d1e05 files · +38 −0Browse files

Unified · Split

5 files
  1. fs/proc/base.c +18 −0
  2. include/linux/sched.h +1 −0
  3. include/linux/stackleak.h +3 −0
  4. kernel/stackleak.c +4 −0
  5. scripts/gcc-plugins/Kconfig +12 −0
fs/proc/base.c+18−0
@@ -2891,6 +2891,21 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, · 2890 unmodified lines
2891}2891}
2892#endif /* CONFIG_LIVEPATCH */2892#endif /* CONFIG_LIVEPATCH */
2893 2893
2894#ifdef CONFIG_STACKLEAK_METRICS
2895static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
2896 struct pid *pid, struct task_struct *task)
2897{
2898 unsigned long prev_depth = THREAD_SIZE -
2899 (task->prev_lowest_stack & (THREAD_SIZE - 1));
2900 unsigned long depth = THREAD_SIZE -
2901 (task->lowest_stack & (THREAD_SIZE - 1));
2902
2903 seq_printf(m, "previous stack depth: %lu\nstack depth: %lu\n",
2904 prev_depth, depth);
2905 return 0;
2906}
2907#endif /* CONFIG_STACKLEAK_METRICS */
2908
2894/*2909/*
2895 * Thread groups2910 * Thread groups
2896 */2911 */
@@ -2992,6 +3007,9 @@ static const struct pid_entry tgid_base_stuff[] = { · 95 unmodified lines
2992#ifdef CONFIG_LIVEPATCH3007#ifdef CONFIG_LIVEPATCH
2993 ONE("patch_state", S_IRUSR, proc_pid_patch_state),3008 ONE("patch_state", S_IRUSR, proc_pid_patch_state),
2994#endif3009#endif
3010#ifdef CONFIG_STACKLEAK_METRICS
3011 ONE("stack_depth", S_IRUGO, proc_stack_depth),
3012#endif
2995};3013};
2996 3014
2997static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)3015static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
include/linux/sched.h+1−0
@@ -1194,6 +1194,7 @@ struct task_struct { · 1193 unmodified lines
1194 1194
1195#ifdef CONFIG_GCC_PLUGIN_STACKLEAK1195#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
1196 unsigned long lowest_stack;1196 unsigned long lowest_stack;
1197 unsigned long prev_lowest_stack;
1197#endif1198#endif
1198 1199
1199 /*1200 /*
include/linux/stackleak.h+3−0
@@ -18,6 +18,9 @@ · 17 unmodified lines
18static inline void stackleak_task_init(struct task_struct *t)18static inline void stackleak_task_init(struct task_struct *t)
19{19{
20 t->lowest_stack = (unsigned long)end_of_stack(t) + sizeof(unsigned long);20 t->lowest_stack = (unsigned long)end_of_stack(t) + sizeof(unsigned long);
21# ifdef CONFIG_STACKLEAK_METRICS
22 t->prev_lowest_stack = t->lowest_stack;
23# endif
21}24}
22#else /* !CONFIG_GCC_PLUGIN_STACKLEAK */25#else /* !CONFIG_GCC_PLUGIN_STACKLEAK */
23static inline void stackleak_task_init(struct task_struct *t) { }26static inline void stackleak_task_init(struct task_struct *t) { }
kernel/stackleak.c+4−0
@@ -41,6 +41,10 @@ asmlinkage void stackleak_erase(void) · 40 unmodified lines
41 if (kstack_ptr == boundary)41 if (kstack_ptr == boundary)
42 kstack_ptr += sizeof(unsigned long);42 kstack_ptr += sizeof(unsigned long);
43 43
44#ifdef CONFIG_STACKLEAK_METRICS
45 current->prev_lowest_stack = kstack_ptr;
46#endif
47
44 /*48 /*
45 * Now write the poison value to the kernel stack. Start from49 * Now write the poison value to the kernel stack. Start from
46 * 'kstack_ptr' and move up till the new 'boundary'. We assume that50 * 'kstack_ptr' and move up till the new 'boundary'. We assume that
scripts/gcc-plugins/Kconfig+12−0
@@ -170,4 +170,16 @@ config STACKLEAK_TRACK_MIN_SIZE · 169 unmodified lines
170 a stack frame size greater than or equal to this parameter.170 a stack frame size greater than or equal to this parameter.
171 If unsure, leave the default value 100.171 If unsure, leave the default value 100.
172 172
173config STACKLEAK_METRICS
174 bool "Show STACKLEAK metrics in the /proc file system"
175 depends on GCC_PLUGIN_STACKLEAK
176 depends on PROC_FS
177 help
178 If this is set, STACKLEAK metrics for every task are available in
179 the /proc file system. In particular, /proc/<pid>/stack_depth
180 shows the maximum kernel stack consumption for the current and
181 previous syscalls. Although this information is not precise, it
182 can be useful for estimating the STACKLEAK performance impact for
183 your workloads.
184
173endif185endif