1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) Linux Test Project, 2011-2021
4f08c3bdfSopenharmony_ci */
5f08c3bdfSopenharmony_ci#ifndef _MEM_H
6f08c3bdfSopenharmony_ci#define _MEM_H
7f08c3bdfSopenharmony_ci#include "config.h"
8f08c3bdfSopenharmony_ci#include "tst_test.h"
9f08c3bdfSopenharmony_ci#include "ksm_helper.h"
10f08c3bdfSopenharmony_ci#include "tst_memutils.h"
11f08c3bdfSopenharmony_ci
12f08c3bdfSopenharmony_ci#if defined(__powerpc__) || defined(__powerpc64__)
13f08c3bdfSopenharmony_ci#define MAXNODES		256
14f08c3bdfSopenharmony_ci#else
15f08c3bdfSopenharmony_ci#define MAXNODES		512
16f08c3bdfSopenharmony_ci#endif
17f08c3bdfSopenharmony_ci#define MB			(1UL<<20)
18f08c3bdfSopenharmony_ci#define KB			(1UL<<10)
19f08c3bdfSopenharmony_ci#define PATH_SYS_SYSTEM		"/sys/devices/system"
20f08c3bdfSopenharmony_ci#define PATH_SYSVM		"/proc/sys/vm/"
21f08c3bdfSopenharmony_ci#define PATH_MEMINFO		"/proc/meminfo"
22f08c3bdfSopenharmony_ci#define BITS_PER_LONG           (8 * sizeof(long))
23f08c3bdfSopenharmony_ci
24f08c3bdfSopenharmony_cistatic inline void set_node(unsigned long *array, unsigned int node)
25f08c3bdfSopenharmony_ci{
26f08c3bdfSopenharmony_ci	array[node / BITS_PER_LONG] |= 1UL << (node % BITS_PER_LONG);
27f08c3bdfSopenharmony_ci}
28f08c3bdfSopenharmony_ci
29f08c3bdfSopenharmony_cistatic inline void clean_node(unsigned long *array)
30f08c3bdfSopenharmony_ci{
31f08c3bdfSopenharmony_ci	unsigned int i;
32f08c3bdfSopenharmony_ci
33f08c3bdfSopenharmony_ci	for (i = 0; i < MAXNODES / BITS_PER_LONG; i++)
34f08c3bdfSopenharmony_ci		array[i] &= 0UL;
35f08c3bdfSopenharmony_ci}
36f08c3bdfSopenharmony_ci
37f08c3bdfSopenharmony_ci/* OOM */
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_ci#define LENGTH			(3UL<<30)
40f08c3bdfSopenharmony_ci#define TESTMEM			(1UL<<30)
41f08c3bdfSopenharmony_ci#define NORMAL			1
42f08c3bdfSopenharmony_ci#define MLOCK			2
43f08c3bdfSopenharmony_ci#define KSM			3
44f08c3bdfSopenharmony_ci
45f08c3bdfSopenharmony_civoid oom(int testcase, int lite, int retcode, int allow_sigkill);
46f08c3bdfSopenharmony_civoid testoom(int mempolicy, int lite, int retcode, int allow_sigkill);
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci/* KSM */
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_civoid create_same_memory(int size, int num, int unit);
51f08c3bdfSopenharmony_civoid test_ksm_merge_across_nodes(unsigned long nr_pages);
52f08c3bdfSopenharmony_civoid ksm_group_check(int run, int pg_shared, int pg_sharing, int pg_volatile,
53f08c3bdfSopenharmony_ci                     int pg_unshared, int sleep_msecs, int pages_to_scan);
54f08c3bdfSopenharmony_ci
55f08c3bdfSopenharmony_ci/* THP */
56f08c3bdfSopenharmony_ci
57f08c3bdfSopenharmony_ci#define PATH_THP		"/sys/kernel/mm/transparent_hugepage/"
58f08c3bdfSopenharmony_ci#define PATH_KHPD		PATH_THP "khugepaged/"
59f08c3bdfSopenharmony_ci
60f08c3bdfSopenharmony_ci/* HUGETLB */
61f08c3bdfSopenharmony_ci
62f08c3bdfSopenharmony_ci#define PATH_HUGEPAGES		"/sys/kernel/mm/hugepages/"
63f08c3bdfSopenharmony_ci#define PATH_SHMMAX		"/proc/sys/kernel/shmmax"
64f08c3bdfSopenharmony_ci
65f08c3bdfSopenharmony_civoid check_hugepage(void);
66f08c3bdfSopenharmony_civoid write_memcg(void);
67f08c3bdfSopenharmony_ci
68f08c3bdfSopenharmony_ci/* cpuset/memcg - include/tst_cgroup.h */
69f08c3bdfSopenharmony_civoid write_cpusets(const struct tst_cg_group *cg, long nd);
70f08c3bdfSopenharmony_ci
71f08c3bdfSopenharmony_ci/* shared */
72f08c3bdfSopenharmony_ciunsigned int get_a_numa_node(void);
73f08c3bdfSopenharmony_ciint  path_exist(const char *path, ...);
74f08c3bdfSopenharmony_civoid set_sys_tune(char *sys_file, long tune, int check);
75f08c3bdfSopenharmony_cilong get_sys_tune(char *sys_file);
76f08c3bdfSopenharmony_ci
77f08c3bdfSopenharmony_civoid update_shm_size(size_t *shm_size);
78f08c3bdfSopenharmony_ci
79f08c3bdfSopenharmony_ci/* MMAP */
80f08c3bdfSopenharmony_ciint range_is_mapped(unsigned long low, unsigned long high);
81f08c3bdfSopenharmony_ci#endif
82