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