1 #ifndef _MEM_H
2 #define _MEM_H
3 #include "config.h"
4 #include "test.h"
5
6 #if defined(__powerpc__) || defined(__powerpc64__)
7 #define MAXNODES 256
8 #else
9 #define MAXNODES 512
10 #endif
11 #define MB (1UL<<20)
12 #define KB (1UL<<10)
13 #define PATH_SYS_SYSTEM "/sys/devices/system"
14 #define PATH_SYSVM "/proc/sys/vm/"
15 #define PATH_MEMINFO "/proc/meminfo"
16 #define BITS_PER_LONG (8 * sizeof(long))
17
set_node(unsigned long * array,unsigned int node)18 static inline void set_node(unsigned long *array, unsigned int node)
19 {
20 array[node / BITS_PER_LONG] |= 1UL << (node % BITS_PER_LONG);
21 }
22
clean_node(unsigned long * array)23 static inline void clean_node(unsigned long *array)
24 {
25 unsigned int i;
26
27 for (i = 0; i < MAXNODES / BITS_PER_LONG; i++)
28 array[i] &= 0UL;
29 }
30
31 /* OOM */
32
33 #define LENGTH (3UL<<30)
34 #define TESTMEM (1UL<<30)
35 #define NORMAL 1
36 #define MLOCK 2
37 #define KSM 3
38
39 long overcommit;
40 void oom(int testcase, int lite, int retcode, int allow_sigkill);
41 void testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
42
43 /* KSM */
44
45 #define PATH_KSM "/sys/kernel/mm/ksm/"
46
47 void save_max_page_sharing(void);
48 void restore_max_page_sharing(void);
49 void test_ksm_merge_across_nodes(unsigned long nr_pages);
50
51 /* THP */
52
53 #define PATH_THP "/sys/kernel/mm/transparent_hugepage/"
54 #define PATH_KHPD PATH_THP "khugepaged/"
55
56 /* HUGETLB */
57
58 #define PATH_SHMMAX "/proc/sys/kernel/shmmax"
59
60 void write_memcg(void);
61 void create_same_memory(int size, int num, int unit);
62 int opt_num, opt_size, opt_unit;
63 char *opt_numstr, *opt_sizestr, *opt_unitstr;
64 void check_ksm_options(int *size, int *num, int *unit);
65 void ksm_usage(void);
66
67 /* cpuset/memcg */
68
69 #define CPATH "/dev/cpuset"
70 #define CPATH_NEW CPATH "/1"
71 #define MEMCG_PATH "/dev/cgroup"
72 #define MEMCG_PATH_NEW MEMCG_PATH "/1"
73 #define MEMCG_LIMIT MEMCG_PATH_NEW "/memory.limit_in_bytes"
74 #define MEMCG_SW_LIMIT MEMCG_PATH_NEW "/memory.memsw.limit_in_bytes"
75 #if HAVE_SYS_EVENTFD_H
76 #define PATH_OOMCTRL MEMCG_PATH_NEW "/memory.oom_control"
77 #define PATH_EVTCTRL MEMCG_PATH_NEW "/cgroup.event_control"
78 #endif
79
80 void read_cpuset_files(char *prefix, char *filename, char *retbuf);
81 void write_cpuset_files(char *prefix, char *filename, char *buf);
82 void write_cpusets(long nd);
83 void mount_mem(char *name, char *fs, char *options, char *path, char *path_new);
84 void umount_mem(char *path, char *path_new);
85
86 /* shared */
87 unsigned int get_a_numa_node(void (*cleanup_fn)(void));
88 int path_exist(const char *path, ...);
89 long read_meminfo(char *item);
90 void set_sys_tune(char *sys_file, long tune, int check);
91 long get_sys_tune(char *sys_file);
92 void cleanup(void);
93 void setup(void);
94
95 void update_shm_size(size_t *shm_size);
96
97 /* MMAP */
98 int range_is_mapped(void (*cleanup_fn) (void), unsigned long low, unsigned long high);
99 #endif
100