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 int cg_create(const char *cgroup); 22 extern int cg_destroy(const char *cgroup); 23 extern int cg_read(const char *cgroup, const char *control, 24 char *buf, size_t len); 25 extern int cg_read_strcmp(const char *cgroup, const char *control, 26 const char *expected); 27 extern int cg_read_strstr(const char *cgroup, const char *control, 28 const char *needle); 29 extern long cg_read_long(const char *cgroup, const char *control); 30 long cg_read_key_long(const char *cgroup, const char *control, const char *key); 31 extern int cg_write(const char *cgroup, const char *control, char *buf); 32 extern int cg_run(const char *cgroup, 33 int (*fn)(const char *cgroup, void *arg), 34 void *arg); 35 extern int cg_enter_current(const char *cgroup); 36 extern int cg_run_nowait(const char *cgroup, 37 int (*fn)(const char *cgroup, void *arg), 38 void *arg); 39 extern int get_temp_fd(void); 40 extern int alloc_pagecache(int fd, size_t size); 41 extern int alloc_anon(const char *cgroup, void *arg); 42 extern int is_swap_enabled(void); 43 extern int set_oom_adj_score(int pid, int score); 44