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