• Pasha Tatashin's avatar
    vmstat: kernel stack usage histogram · c4a6fce8
    Pasha Tatashin authored
    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
    
    Link: https://lkml.kernel.org/r/20240730150158.832783-3-pasha.tatashin@soleen.com
    Link: https://lkml.kernel.org/r/20240724203322.2765486-3-pasha.tatashin@soleen.comSigned-off-by: default avatarPasha Tatashin <pasha.tatashin@soleen.com>
    Reviewed-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
    Acked-by: default avatarShakeel Butt <shakeel.butt@linux.dev>
    Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
    Cc: Li Zhijian <lizhijian@fujitsu.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Nhat Pham <nphamcs@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Zi Yan <ziy@nvidia.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    c4a6fce8
vm_event_item.h 4.23 KB