On Wed, Jul 24, 2024 at 08:33:21PM GMT, Pasha Tatashin wrote: > As part of the dynamic kernel stack project, we need to know the amount > of data that can be saved by reducing the default kernel stack size [1]. > > Provide a kernel stack usage histogram to aid in optimizing kernel stack > sizes and minimizing memory waste in large-scale environments. The > histogram divides stack usage into power-of-two buckets and reports the > results in /proc/vmstat. This information is especially valuable in > environments with millions of machines, where even small optimizations > can have a significant impact. > > The histogram data is presented in /proc/vmstat with entries like > "kstack_1k", "kstack_2k", and so on, indicating the number of threads > that exited with stack usage falling within each respective bucket. > > Example outputs: > Intel: > $ grep kstack /proc/vmstat > kstack_1k 3 > kstack_2k 188 > kstack_4k 11391 > kstack_8k 243 > kstack_16k 0 > > ARM with 64K page_size: > $ grep kstack /proc/vmstat > kstack_1k 1 > kstack_2k 340 > kstack_4k 25212 > kstack_8k 1659 > kstack_16k 0 > kstack_32k 0 > kstack_64k 0 > > Note: once the dynamic kernel stack is implemented it will depend on the > implementation the usability of this feature: On hardware that supports > faults on kernel stacks, we will have other metrics that show the total > number of pages allocated for stacks. On hardware where faults are not > supported, we will most likely have some optimization where only some > threads are extended, and for those, these metrics will still be very > useful. > > [1] https://lwn.net/Articles/974367 > > Signed-off-by: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx> > Reviewed-by: Kent Overstreet <kent.overstreet@xxxxxxxxx> Acked-by: Shakeel Butt <shakeel.butt@xxxxxxxxx>