1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <stdlib.h>
3 
4 #define PAGE_SIZE 4096
5 
6 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
7 
8 #define MB(x) (x << 20)
9 
10 /*
11  * Checks if two given values differ by less than err% of their sum.
12  */
13 static inline int values_close(long a, long b, int err)
14 {
15 	return abs(a - b) <= (a + b) / 100 * err;
16 }
17 
18 extern int cg_find_unified_root(char *root, size_t len);
19 extern char *cg_name(const char *root, const char *name);
20 extern char *cg_name_indexed(const char *root, const char *name, int index);
21 extern char *cg_control(const char *cgroup, const char *control);
22 extern int cg_create(const char *cgroup);
23 extern int cg_destroy(const char *cgroup);
24 extern int cg_read(const char *cgroup, const char *control,
25 		   char *buf, size_t len);
26 extern int cg_read_strcmp(const char *cgroup, const char *control,
27 			  const char *expected);
28 extern int cg_read_strstr(const char *cgroup, const char *control,
29 			  const char *needle);
30 extern long cg_read_long(const char *cgroup, const char *control);
31 long cg_read_key_long(const char *cgroup, const char *control, const char *key);
32 extern int cg_write(const char *cgroup, const char *control, char *buf);
33 extern int cg_run(const char *cgroup,
34 		  int (*fn)(const char *cgroup, void *arg),
35 		  void *arg);
36 extern int cg_enter(const char *cgroup, int pid);
37 extern int cg_enter_current(const char *cgroup);
38 extern int cg_run_nowait(const char *cgroup,
39 			 int (*fn)(const char *cgroup, void *arg),
40 			 void *arg);
41 extern int get_temp_fd(void);
42 extern int alloc_pagecache(int fd, size_t size);
43 extern int alloc_anon(const char *cgroup, void *arg);
44 extern int is_swap_enabled(void);
45 extern int set_oom_adj_score(int pid, int score);
46 extern int cg_wait_for_proc_count(const char *cgroup, int count);
47 extern int cg_killall(const char *cgroup);
48 extern char proc_read_text(int pid, const char *item, char *buf, size_t size);
49