selftests: cgroup: add memory controller self-tests
Cgroups are used for controlling the physical resource distribution
(memory, CPU, io, etc) and often are used as basic building blocks
for large distributed computing systems. Even small differences
in the actual behavior may lead to significant incidents.
The codebase is under the active development, which will unlikely
stop at any time soon. Also it's scattered over different kernel
subsystems, which makes regressions more probable.
Given that, the lack of any tests is crying.
This patch implements some basic tests for the memory controller,
as well as a minimal required framework. It doesn't pretend for a
very good coverage, but pretends to be a starting point.
Hopefully, any following significant changes will include corresponding
tests.
Tests for CPU and io controllers, as well as cgroup core
are next in the todo list.
Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Cc: kernel-team@fb.com
Cc: linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
2018-05-12 02:03:49 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define PAGE_SIZE 4096
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
|
|
|
|
|
|
|
#define MB(x) (x << 20)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if two given values differ by less than err% of their sum.
|
|
|
|
*/
|
|
|
|
static inline int values_close(long a, long b, int err)
|
|
|
|
{
|
|
|
|
return abs(a - b) <= (a + b) / 100 * err;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int cg_find_unified_root(char *root, size_t len);
|
|
|
|
extern char *cg_name(const char *root, const char *name);
|
|
|
|
extern char *cg_name_indexed(const char *root, const char *name, int index);
|
|
|
|
extern int cg_create(const char *cgroup);
|
|
|
|
extern int cg_destroy(const char *cgroup);
|
|
|
|
extern int cg_read(const char *cgroup, const char *control,
|
|
|
|
char *buf, size_t len);
|
|
|
|
extern int cg_read_strcmp(const char *cgroup, const char *control,
|
|
|
|
const char *expected);
|
|
|
|
extern int cg_read_strstr(const char *cgroup, const char *control,
|
|
|
|
const char *needle);
|
|
|
|
extern long cg_read_long(const char *cgroup, const char *control);
|
|
|
|
long cg_read_key_long(const char *cgroup, const char *control, const char *key);
|
|
|
|
extern int cg_write(const char *cgroup, const char *control, char *buf);
|
|
|
|
extern int cg_run(const char *cgroup,
|
|
|
|
int (*fn)(const char *cgroup, void *arg),
|
|
|
|
void *arg);
|
|
|
|
extern int cg_run_nowait(const char *cgroup,
|
|
|
|
int (*fn)(const char *cgroup, void *arg),
|
|
|
|
void *arg);
|
|
|
|
extern int get_temp_fd(void);
|
|
|
|
extern int alloc_pagecache(int fd, size_t size);
|
|
|
|
extern int alloc_anon(const char *cgroup, void *arg);
|
2018-05-16 00:05:53 +08:00
|
|
|
extern int is_swap_enabled(void);
|