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
28912891 }
28922892 #endif /* CONFIG_LIVEPATCH */
28932893
2894+#ifdef CONFIG_STACKLEAK_METRICS
2895+static 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+
28942909 /*
28952910 * Thread groups
28962911 */
@@ -2992,6 +3007,9 @@ static const struct pid_entry tgid_base_stuff[] = { · 95 unmodified lines
29923007 #ifdef CONFIG_LIVEPATCH
29933008 ONE("patch_state", S_IRUSR, proc_pid_patch_state),
29943009 #endif
3010+#ifdef CONFIG_STACKLEAK_METRICS
3011+ ONE("stack_depth", S_IRUGO, proc_stack_depth),
3012+#endif
29953013 };
29963014
29973015 static 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
11941194
11951195 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
11961196 unsigned long lowest_stack;
1197+ unsigned long prev_lowest_stack;
11971198 #endif
11981199
11991200 /*
include/linux/stackleak.h+3−0
@@ -18,6 +18,9 @@ · 17 unmodified lines
1818 static inline void stackleak_task_init(struct task_struct *t)
1919 {
2020 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
2124 }
2225 #else /* !CONFIG_GCC_PLUGIN_STACKLEAK */
2326 static 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
4141 if (kstack_ptr == boundary)
4242 kstack_ptr += sizeof(unsigned long);
4343
44+#ifdef CONFIG_STACKLEAK_METRICS
45+ current->prev_lowest_stack = kstack_ptr;
46+#endif
47+
4448 /*
4549 * Now write the poison value to the kernel stack. Start from
4650 * '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
170170 a stack frame size greater than or equal to this parameter.
171171 If unsure, leave the default value 100.
172172
173+config 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+
173185 endif