1*d166453eSJames Houghton /* SPDX-License-Identifier: GPL-2.0-only */ 2*d166453eSJames Houghton /* 3*d166453eSJames Houghton * Tools for integrating with lru_gen, like parsing the lru_gen debugfs output. 4*d166453eSJames Houghton * 5*d166453eSJames Houghton * Copyright (C) 2025, Google LLC. 6*d166453eSJames Houghton */ 7*d166453eSJames Houghton #ifndef SELFTEST_KVM_LRU_GEN_UTIL_H 8*d166453eSJames Houghton #define SELFTEST_KVM_LRU_GEN_UTIL_H 9*d166453eSJames Houghton 10*d166453eSJames Houghton #include <inttypes.h> 11*d166453eSJames Houghton #include <limits.h> 12*d166453eSJames Houghton #include <stdlib.h> 13*d166453eSJames Houghton 14*d166453eSJames Houghton #include "test_util.h" 15*d166453eSJames Houghton 16*d166453eSJames Houghton #define MAX_NR_GENS 16 /* MAX_NR_GENS in include/linux/mmzone.h */ 17*d166453eSJames Houghton #define MAX_NR_NODES 4 /* Maximum number of nodes supported by the test */ 18*d166453eSJames Houghton 19*d166453eSJames Houghton #define LRU_GEN_DEBUGFS "/sys/kernel/debug/lru_gen" 20*d166453eSJames Houghton #define LRU_GEN_ENABLED_PATH "/sys/kernel/mm/lru_gen/enabled" 21*d166453eSJames Houghton #define LRU_GEN_ENABLED 1 22*d166453eSJames Houghton #define LRU_GEN_MM_WALK 2 23*d166453eSJames Houghton 24*d166453eSJames Houghton struct generation_stats { 25*d166453eSJames Houghton int gen; 26*d166453eSJames Houghton long age_ms; 27*d166453eSJames Houghton long nr_anon; 28*d166453eSJames Houghton long nr_file; 29*d166453eSJames Houghton }; 30*d166453eSJames Houghton 31*d166453eSJames Houghton struct node_stats { 32*d166453eSJames Houghton int node; 33*d166453eSJames Houghton int nr_gens; /* Number of populated gens entries. */ 34*d166453eSJames Houghton struct generation_stats gens[MAX_NR_GENS]; 35*d166453eSJames Houghton }; 36*d166453eSJames Houghton 37*d166453eSJames Houghton struct memcg_stats { 38*d166453eSJames Houghton unsigned long memcg_id; 39*d166453eSJames Houghton int nr_nodes; /* Number of populated nodes entries. */ 40*d166453eSJames Houghton struct node_stats nodes[MAX_NR_NODES]; 41*d166453eSJames Houghton }; 42*d166453eSJames Houghton 43*d166453eSJames Houghton void lru_gen_read_memcg_stats(struct memcg_stats *stats, const char *memcg); 44*d166453eSJames Houghton long lru_gen_sum_memcg_stats(const struct memcg_stats *stats); 45*d166453eSJames Houghton long lru_gen_sum_memcg_stats_for_gen(int gen, const struct memcg_stats *stats); 46*d166453eSJames Houghton void lru_gen_do_aging(struct memcg_stats *stats, const char *memcg); 47*d166453eSJames Houghton int lru_gen_find_generation(const struct memcg_stats *stats, 48*d166453eSJames Houghton unsigned long total_pages); 49*d166453eSJames Houghton bool lru_gen_usable(void); 50*d166453eSJames Houghton 51*d166453eSJames Houghton #endif /* SELFTEST_KVM_LRU_GEN_UTIL_H */ 52