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