mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2025-12-05 04:50:07 +00:00
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.com Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Kent Overstreet <kent.overstreet@linux.dev> Acked-by: Shakeel 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: Andrew Morton <akpm@linux-foundation.org>
193 lines
4.2 KiB
C
193 lines
4.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef VM_EVENT_ITEM_H_INCLUDED
|
|
#define VM_EVENT_ITEM_H_INCLUDED
|
|
|
|
#ifdef CONFIG_ZONE_DMA
|
|
#define DMA_ZONE(xx) xx##_DMA,
|
|
#else
|
|
#define DMA_ZONE(xx)
|
|
#endif
|
|
|
|
#ifdef CONFIG_ZONE_DMA32
|
|
#define DMA32_ZONE(xx) xx##_DMA32,
|
|
#else
|
|
#define DMA32_ZONE(xx)
|
|
#endif
|
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
#define HIGHMEM_ZONE(xx) xx##_HIGH,
|
|
#else
|
|
#define HIGHMEM_ZONE(xx)
|
|
#endif
|
|
|
|
#ifdef CONFIG_ZONE_DEVICE
|
|
#define DEVICE_ZONE(xx) xx##_DEVICE,
|
|
#else
|
|
#define DEVICE_ZONE(xx)
|
|
#endif
|
|
|
|
#define FOR_ALL_ZONES(xx) DMA_ZONE(xx) DMA32_ZONE(xx) xx##_NORMAL, \
|
|
HIGHMEM_ZONE(xx) xx##_MOVABLE, DEVICE_ZONE(xx)
|
|
|
|
enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
|
|
FOR_ALL_ZONES(PGALLOC)
|
|
FOR_ALL_ZONES(ALLOCSTALL)
|
|
FOR_ALL_ZONES(PGSCAN_SKIP)
|
|
PGFREE, PGACTIVATE, PGDEACTIVATE, PGLAZYFREE,
|
|
PGFAULT, PGMAJFAULT,
|
|
PGLAZYFREED,
|
|
PGREFILL,
|
|
PGREUSE,
|
|
PGSTEAL_KSWAPD,
|
|
PGSTEAL_DIRECT,
|
|
PGSTEAL_KHUGEPAGED,
|
|
PGSCAN_KSWAPD,
|
|
PGSCAN_DIRECT,
|
|
PGSCAN_KHUGEPAGED,
|
|
PGSCAN_DIRECT_THROTTLE,
|
|
PGSCAN_ANON,
|
|
PGSCAN_FILE,
|
|
PGSTEAL_ANON,
|
|
PGSTEAL_FILE,
|
|
#ifdef CONFIG_NUMA
|
|
PGSCAN_ZONE_RECLAIM_SUCCESS,
|
|
PGSCAN_ZONE_RECLAIM_FAILED,
|
|
#endif
|
|
PGINODESTEAL, SLABS_SCANNED, KSWAPD_INODESTEAL,
|
|
KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY,
|
|
PAGEOUTRUN, PGROTATED,
|
|
DROP_PAGECACHE, DROP_SLAB,
|
|
OOM_KILL,
|
|
#ifdef CONFIG_NUMA_BALANCING
|
|
NUMA_PTE_UPDATES,
|
|
NUMA_HUGE_PTE_UPDATES,
|
|
NUMA_HINT_FAULTS,
|
|
NUMA_HINT_FAULTS_LOCAL,
|
|
NUMA_PAGE_MIGRATE,
|
|
#endif
|
|
#ifdef CONFIG_MIGRATION
|
|
PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,
|
|
THP_MIGRATION_SUCCESS,
|
|
THP_MIGRATION_FAIL,
|
|
THP_MIGRATION_SPLIT,
|
|
#endif
|
|
#ifdef CONFIG_COMPACTION
|
|
COMPACTMIGRATE_SCANNED, COMPACTFREE_SCANNED,
|
|
COMPACTISOLATED,
|
|
COMPACTSTALL, COMPACTFAIL, COMPACTSUCCESS,
|
|
KCOMPACTD_WAKE,
|
|
KCOMPACTD_MIGRATE_SCANNED, KCOMPACTD_FREE_SCANNED,
|
|
#endif
|
|
#ifdef CONFIG_HUGETLB_PAGE
|
|
HTLB_BUDDY_PGALLOC, HTLB_BUDDY_PGALLOC_FAIL,
|
|
#endif
|
|
#ifdef CONFIG_CMA
|
|
CMA_ALLOC_SUCCESS,
|
|
CMA_ALLOC_FAIL,
|
|
#endif
|
|
UNEVICTABLE_PGCULLED, /* culled to noreclaim list */
|
|
UNEVICTABLE_PGSCANNED, /* scanned for reclaimability */
|
|
UNEVICTABLE_PGRESCUED, /* rescued from noreclaim list */
|
|
UNEVICTABLE_PGMLOCKED,
|
|
UNEVICTABLE_PGMUNLOCKED,
|
|
UNEVICTABLE_PGCLEARED, /* on COW, page truncate */
|
|
UNEVICTABLE_PGSTRANDED, /* unable to isolate on unlock */
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
|
THP_FAULT_ALLOC,
|
|
THP_FAULT_FALLBACK,
|
|
THP_FAULT_FALLBACK_CHARGE,
|
|
THP_COLLAPSE_ALLOC,
|
|
THP_COLLAPSE_ALLOC_FAILED,
|
|
THP_FILE_ALLOC,
|
|
THP_FILE_FALLBACK,
|
|
THP_FILE_FALLBACK_CHARGE,
|
|
THP_FILE_MAPPED,
|
|
THP_SPLIT_PAGE,
|
|
THP_SPLIT_PAGE_FAILED,
|
|
THP_DEFERRED_SPLIT_PAGE,
|
|
THP_SPLIT_PMD,
|
|
THP_SCAN_EXCEED_NONE_PTE,
|
|
THP_SCAN_EXCEED_SWAP_PTE,
|
|
THP_SCAN_EXCEED_SHARED_PTE,
|
|
#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
|
|
THP_SPLIT_PUD,
|
|
#endif
|
|
THP_ZERO_PAGE_ALLOC,
|
|
THP_ZERO_PAGE_ALLOC_FAILED,
|
|
THP_SWPOUT,
|
|
THP_SWPOUT_FALLBACK,
|
|
#endif
|
|
#ifdef CONFIG_MEMORY_BALLOON
|
|
BALLOON_INFLATE,
|
|
BALLOON_DEFLATE,
|
|
#ifdef CONFIG_BALLOON_COMPACTION
|
|
BALLOON_MIGRATE,
|
|
#endif
|
|
#endif
|
|
#ifdef CONFIG_DEBUG_TLBFLUSH
|
|
NR_TLB_REMOTE_FLUSH, /* cpu tried to flush others' tlbs */
|
|
NR_TLB_REMOTE_FLUSH_RECEIVED,/* cpu received ipi for flush */
|
|
NR_TLB_LOCAL_FLUSH_ALL,
|
|
NR_TLB_LOCAL_FLUSH_ONE,
|
|
#endif /* CONFIG_DEBUG_TLBFLUSH */
|
|
#ifdef CONFIG_SWAP
|
|
SWAP_RA,
|
|
SWAP_RA_HIT,
|
|
#ifdef CONFIG_KSM
|
|
KSM_SWPIN_COPY,
|
|
#endif
|
|
#endif
|
|
#ifdef CONFIG_KSM
|
|
COW_KSM,
|
|
#endif
|
|
#ifdef CONFIG_ZSWAP
|
|
ZSWPIN,
|
|
ZSWPOUT,
|
|
ZSWPWB,
|
|
#endif
|
|
#ifdef CONFIG_X86
|
|
DIRECT_MAP_LEVEL2_SPLIT,
|
|
DIRECT_MAP_LEVEL3_SPLIT,
|
|
#endif
|
|
#ifdef CONFIG_PER_VMA_LOCK_STATS
|
|
VMA_LOCK_SUCCESS,
|
|
VMA_LOCK_ABORT,
|
|
VMA_LOCK_RETRY,
|
|
VMA_LOCK_MISS,
|
|
#endif
|
|
#ifdef CONFIG_DEBUG_STACK_USAGE
|
|
KSTACK_1K,
|
|
#if THREAD_SIZE > 1024
|
|
KSTACK_2K,
|
|
#endif
|
|
#if THREAD_SIZE > 2048
|
|
KSTACK_4K,
|
|
#endif
|
|
#if THREAD_SIZE > 4096
|
|
KSTACK_8K,
|
|
#endif
|
|
#if THREAD_SIZE > 8192
|
|
KSTACK_16K,
|
|
#endif
|
|
#if THREAD_SIZE > 16384
|
|
KSTACK_32K,
|
|
#endif
|
|
#if THREAD_SIZE > 32768
|
|
KSTACK_64K,
|
|
#endif
|
|
#if THREAD_SIZE > 65536
|
|
KSTACK_REST,
|
|
#endif
|
|
#endif /* CONFIG_DEBUG_STACK_USAGE */
|
|
NR_VM_EVENT_ITEMS
|
|
};
|
|
|
|
#ifndef CONFIG_TRANSPARENT_HUGEPAGE
|
|
#define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })
|
|
#define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })
|
|
#define THP_FILE_FALLBACK_CHARGE ({ BUILD_BUG(); 0; })
|
|
#define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })
|
|
#endif
|
|
|
|
#endif /* VM_EVENT_ITEM_H_INCLUDED */
|