File: lru_gen_util.h

package info (click to toggle)
linux 6.18.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,742,212 kB
  • sloc: ansic: 26,783,651; asm: 272,129; sh: 148,799; python: 79,242; makefile: 57,742; perl: 36,527; xml: 19,542; cpp: 5,911; yacc: 4,939; lex: 2,950; awk: 1,607; sed: 30; ruby: 25
file content (51 lines) | stat: -rw-r--r-- 1,456 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Tools for integrating with lru_gen, like parsing the lru_gen debugfs output.
 *
 * Copyright (C) 2025, Google LLC.
 */
#ifndef SELFTEST_KVM_LRU_GEN_UTIL_H
#define SELFTEST_KVM_LRU_GEN_UTIL_H

#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>

#include "test_util.h"

#define MAX_NR_GENS 16 /* MAX_NR_GENS in include/linux/mmzone.h */
#define MAX_NR_NODES 4 /* Maximum number of nodes supported by the test */

#define LRU_GEN_DEBUGFS "/sys/kernel/debug/lru_gen"
#define LRU_GEN_ENABLED_PATH "/sys/kernel/mm/lru_gen/enabled"
#define LRU_GEN_ENABLED 1
#define LRU_GEN_MM_WALK 2

struct generation_stats {
	int gen;
	long age_ms;
	long nr_anon;
	long nr_file;
};

struct node_stats {
	int node;
	int nr_gens; /* Number of populated gens entries. */
	struct generation_stats gens[MAX_NR_GENS];
};

struct memcg_stats {
	unsigned long memcg_id;
	int nr_nodes; /* Number of populated nodes entries. */
	struct node_stats nodes[MAX_NR_NODES];
};

void lru_gen_read_memcg_stats(struct memcg_stats *stats, const char *memcg);
long lru_gen_sum_memcg_stats(const struct memcg_stats *stats);
long lru_gen_sum_memcg_stats_for_gen(int gen, const struct memcg_stats *stats);
void lru_gen_do_aging(struct memcg_stats *stats, const char *memcg);
int lru_gen_find_generation(const struct memcg_stats *stats,
			    unsigned long total_pages);
bool lru_gen_usable(void);

#endif /* SELFTEST_KVM_LRU_GEN_UTIL_H */