xref: /linux/tools/testing/selftests/mm/thp_settings.h (revision 24b10e5f8e0d2bee1a10fc67011ea5d936c1a389)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __THP_SETTINGS_H__
3 #define __THP_SETTINGS_H__
4 
5 #include <stdbool.h>
6 #include <stddef.h>
7 #include <stdint.h>
8 
9 enum thp_enabled {
10 	THP_NEVER,
11 	THP_ALWAYS,
12 	THP_INHERIT,
13 	THP_MADVISE,
14 };
15 
16 enum thp_defrag {
17 	THP_DEFRAG_ALWAYS,
18 	THP_DEFRAG_DEFER,
19 	THP_DEFRAG_DEFER_MADVISE,
20 	THP_DEFRAG_MADVISE,
21 	THP_DEFRAG_NEVER,
22 };
23 
24 enum shmem_enabled {
25 	SHMEM_ALWAYS,
26 	SHMEM_WITHIN_SIZE,
27 	SHMEM_ADVISE,
28 	SHMEM_NEVER,
29 	SHMEM_DENY,
30 	SHMEM_FORCE,
31 };
32 
33 #define NR_ORDERS 20
34 
35 struct hugepages_settings {
36 	enum thp_enabled enabled;
37 };
38 
39 struct khugepaged_settings {
40 	bool defrag;
41 	unsigned int alloc_sleep_millisecs;
42 	unsigned int scan_sleep_millisecs;
43 	unsigned int max_ptes_none;
44 	unsigned int max_ptes_swap;
45 	unsigned int max_ptes_shared;
46 	unsigned long pages_to_scan;
47 };
48 
49 struct thp_settings {
50 	enum thp_enabled thp_enabled;
51 	enum thp_defrag thp_defrag;
52 	enum shmem_enabled shmem_enabled;
53 	bool use_zero_page;
54 	struct khugepaged_settings khugepaged;
55 	unsigned long read_ahead_kb;
56 	struct hugepages_settings hugepages[NR_ORDERS];
57 };
58 
59 int read_file(const char *path, char *buf, size_t buflen);
60 int write_file(const char *path, const char *buf, size_t buflen);
61 const unsigned long read_num(const char *path);
62 void write_num(const char *path, unsigned long num);
63 
64 int thp_read_string(const char *name, const char * const strings[]);
65 void thp_write_string(const char *name, const char *val);
66 const unsigned long thp_read_num(const char *name);
67 void thp_write_num(const char *name, unsigned long num);
68 
69 void thp_write_settings(struct thp_settings *settings);
70 void thp_read_settings(struct thp_settings *settings);
71 struct thp_settings *thp_current_settings(void);
72 void thp_push_settings(struct thp_settings *settings);
73 void thp_pop_settings(void);
74 void thp_restore_settings(void);
75 void thp_save_settings(void);
76 
77 void thp_set_read_ahead_path(char *path);
78 unsigned long thp_supported_orders(void);
79 
80 #endif /* __THP_SETTINGS_H__ */
81