xref: /aosp_15_r20/external/ltp/testcases/kernel/mem/include/mem.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Linux Test Project, 2011-2021
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker #ifndef _MEM_H
6*49cdfc7eSAndroid Build Coastguard Worker #define _MEM_H
7*49cdfc7eSAndroid Build Coastguard Worker #include "config.h"
8*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
9*49cdfc7eSAndroid Build Coastguard Worker #include "ksm_helper.h"
10*49cdfc7eSAndroid Build Coastguard Worker #include "tst_memutils.h"
11*49cdfc7eSAndroid Build Coastguard Worker 
12*49cdfc7eSAndroid Build Coastguard Worker #if defined(__powerpc__) || defined(__powerpc64__)
13*49cdfc7eSAndroid Build Coastguard Worker #define MAXNODES		256
14*49cdfc7eSAndroid Build Coastguard Worker #else
15*49cdfc7eSAndroid Build Coastguard Worker #define MAXNODES		512
16*49cdfc7eSAndroid Build Coastguard Worker #endif
17*49cdfc7eSAndroid Build Coastguard Worker #define MB			(1UL<<20)
18*49cdfc7eSAndroid Build Coastguard Worker #define KB			(1UL<<10)
19*49cdfc7eSAndroid Build Coastguard Worker #define PATH_SYS_SYSTEM		"/sys/devices/system"
20*49cdfc7eSAndroid Build Coastguard Worker #define PATH_SYSVM		"/proc/sys/vm/"
21*49cdfc7eSAndroid Build Coastguard Worker #define PATH_MEMINFO		"/proc/meminfo"
22*49cdfc7eSAndroid Build Coastguard Worker #define BITS_PER_LONG           (8 * sizeof(long))
23*49cdfc7eSAndroid Build Coastguard Worker 
set_node(unsigned long * array,unsigned int node)24*49cdfc7eSAndroid Build Coastguard Worker static inline void set_node(unsigned long *array, unsigned int node)
25*49cdfc7eSAndroid Build Coastguard Worker {
26*49cdfc7eSAndroid Build Coastguard Worker 	array[node / BITS_PER_LONG] |= 1UL << (node % BITS_PER_LONG);
27*49cdfc7eSAndroid Build Coastguard Worker }
28*49cdfc7eSAndroid Build Coastguard Worker 
clean_node(unsigned long * array)29*49cdfc7eSAndroid Build Coastguard Worker static inline void clean_node(unsigned long *array)
30*49cdfc7eSAndroid Build Coastguard Worker {
31*49cdfc7eSAndroid Build Coastguard Worker 	unsigned int i;
32*49cdfc7eSAndroid Build Coastguard Worker 
33*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < MAXNODES / BITS_PER_LONG; i++)
34*49cdfc7eSAndroid Build Coastguard Worker 		array[i] &= 0UL;
35*49cdfc7eSAndroid Build Coastguard Worker }
36*49cdfc7eSAndroid Build Coastguard Worker 
37*49cdfc7eSAndroid Build Coastguard Worker /* OOM */
38*49cdfc7eSAndroid Build Coastguard Worker 
39*49cdfc7eSAndroid Build Coastguard Worker #define LENGTH			(3UL<<30)
40*49cdfc7eSAndroid Build Coastguard Worker #define TESTMEM			(1UL<<30)
41*49cdfc7eSAndroid Build Coastguard Worker #define NORMAL			1
42*49cdfc7eSAndroid Build Coastguard Worker #define MLOCK			2
43*49cdfc7eSAndroid Build Coastguard Worker #define KSM			3
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker void oom(int testcase, int lite, int retcode, int allow_sigkill);
46*49cdfc7eSAndroid Build Coastguard Worker void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
47*49cdfc7eSAndroid Build Coastguard Worker 
48*49cdfc7eSAndroid Build Coastguard Worker /* KSM */
49*49cdfc7eSAndroid Build Coastguard Worker 
50*49cdfc7eSAndroid Build Coastguard Worker void create_same_memory(int size, int num, int unit);
51*49cdfc7eSAndroid Build Coastguard Worker void test_ksm_merge_across_nodes(unsigned long nr_pages);
52*49cdfc7eSAndroid Build Coastguard Worker void ksm_group_check(int run, int pg_shared, int pg_sharing, int pg_volatile,
53*49cdfc7eSAndroid Build Coastguard Worker                      int pg_unshared, int sleep_msecs, int pages_to_scan);
54*49cdfc7eSAndroid Build Coastguard Worker 
55*49cdfc7eSAndroid Build Coastguard Worker /* THP */
56*49cdfc7eSAndroid Build Coastguard Worker 
57*49cdfc7eSAndroid Build Coastguard Worker #define PATH_THP		"/sys/kernel/mm/transparent_hugepage/"
58*49cdfc7eSAndroid Build Coastguard Worker #define PATH_KHPD		PATH_THP "khugepaged/"
59*49cdfc7eSAndroid Build Coastguard Worker 
60*49cdfc7eSAndroid Build Coastguard Worker /* HUGETLB */
61*49cdfc7eSAndroid Build Coastguard Worker 
62*49cdfc7eSAndroid Build Coastguard Worker #define PATH_HUGEPAGES		"/sys/kernel/mm/hugepages/"
63*49cdfc7eSAndroid Build Coastguard Worker #define PATH_SHMMAX		"/proc/sys/kernel/shmmax"
64*49cdfc7eSAndroid Build Coastguard Worker 
65*49cdfc7eSAndroid Build Coastguard Worker void check_hugepage(void);
66*49cdfc7eSAndroid Build Coastguard Worker void write_memcg(void);
67*49cdfc7eSAndroid Build Coastguard Worker 
68*49cdfc7eSAndroid Build Coastguard Worker /* cpuset/memcg - include/tst_cgroup.h */
69*49cdfc7eSAndroid Build Coastguard Worker void write_cpusets(const struct tst_cg_group *cg, long nd);
70*49cdfc7eSAndroid Build Coastguard Worker 
71*49cdfc7eSAndroid Build Coastguard Worker /* shared */
72*49cdfc7eSAndroid Build Coastguard Worker unsigned int get_a_numa_node(void);
73*49cdfc7eSAndroid Build Coastguard Worker int  path_exist(const char *path, ...);
74*49cdfc7eSAndroid Build Coastguard Worker void set_sys_tune(char *sys_file, long tune, int check);
75*49cdfc7eSAndroid Build Coastguard Worker long get_sys_tune(char *sys_file);
76*49cdfc7eSAndroid Build Coastguard Worker 
77*49cdfc7eSAndroid Build Coastguard Worker void update_shm_size(size_t *shm_size);
78*49cdfc7eSAndroid Build Coastguard Worker 
79*49cdfc7eSAndroid Build Coastguard Worker /* MMAP */
80*49cdfc7eSAndroid Build Coastguard Worker int range_is_mapped(unsigned long low, unsigned long high);
81*49cdfc7eSAndroid Build Coastguard Worker #endif
82