Skip to content

Commit a52c7da

Browse files
committed
adaptivemmd port to adaptived: Adding adaptivemmd_causes.c & adaptivemmd_effects.c & adaptivemmd_utils.c
Signed-off-by: George Kennedy <[email protected]>
1 parent 9aba4f8 commit a52c7da

File tree

10 files changed

+3037
-4
lines changed

10 files changed

+3037
-4
lines changed

adaptived/src/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SOURCES = \
1313
causes/periodic.c \
1414
causes/pressure.c \
1515
causes/pressure_rate.c \
16+
causes/adaptivemmd_causes.c \
1617
causes/slabinfo.c \
1718
causes/time_of_day.c \
1819
causes/top.c \
@@ -31,6 +32,7 @@ SOURCES = \
3132
effects/sd_bus_setting.c \
3233
effects/snooze.c \
3334
effects/validate.c \
35+
effects/adaptivemmd_effects.c \
3436
effect.c \
3537
effect.h \
3638
log.c \
@@ -45,7 +47,9 @@ SOURCES = \
4547
utils/mem_utils.c \
4648
utils/path_utils.c \
4749
utils/pressure_utils.c \
48-
utils/sched_utils.c
50+
utils/sched_utils.c \
51+
utils/adaptivemmd_utils.c \
52+
adaptivemmd.h
4953

5054
adaptived_SOURCES = ${SOURCES}
5155
adaptived_CFLAGS = ${AM_CFLAGS} ${CFLAGS} ${CODE_COVERAGE_CFLAGS} -Wall

adaptived/src/adaptived-internal.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,24 @@ int _sort_pid_list(const void *p1, const void *p2);
148148
struct adaptived_rule *rule_init(const char * const name);
149149
void rule_destroy(struct adaptived_rule ** rule);
150150

151+
int common_logger_init(void *logger_opts, struct json_object *args_obj);
152+
int common_logger_main(void *logger_opts);
153+
void common_logger_exit(void *logger_opts);
154+
151155
/*
152156
* mem_utils defines
153157
*/
154158

155-
#define PROC_MEMINFO "/proc/meminfo"
156-
#define PROC_SLABINFO "/proc/slabinfo"
157-
#define PROC_STAT "/proc/stat"
159+
#define PROC_BUDDYINFO "/proc/buddyinfo"
160+
#define PROC_ZONEINFO "/proc/zoneinfo"
161+
#define PROC_VMSTAT "/proc/vmstat"
162+
#define PROC_MEMINFO "/proc/meminfo"
163+
#define PROC_KPAGECOUNT "/proc/kpagecount"
164+
#define PROC_KPAGEFLAGS "/proc/kpageflags"
165+
#define PROC_SLABINFO "/proc/slabinfo"
166+
#define PROC_STAT "/proc/stat"
167+
#define PROC_MODULES "/proc/modules"
168+
#define MM_HUGEPAGESINFO "/sys/kernel/mm/hugepages"
158169

159170
/*
160171
* mem_utils slabinfo defines

adaptived/src/adaptivemmd.h

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
/*
2+
* * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
* *
5+
* * This code is free software; you can redistribute it and/or modify it
6+
* * under the terms of the GNU General Public License version 2 only, as
7+
* * published by the Free Software Foundation.
8+
* *
9+
* * This code is distributed in the hope that it will be useful, but WITHOUT
10+
* * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* * version 2 for more details (a copy is included in the LICENSE file that
13+
* * accompanied this code).
14+
* *
15+
* * You should have received a copy of the GNU General Public License version
16+
* * 2 along with this work; if not, write to the Free Software Foundation,
17+
* * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
* *
19+
* * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* * or visit www.oracle.com if you need additional information or have any
21+
* * questions.
22+
* */
23+
#ifndef PREDICT_H
24+
#define PREDICT_H
25+
26+
#include <stdio.h>
27+
#include <stdlib.h>
28+
#include <unistd.h>
29+
#include <stdarg.h>
30+
#include <string.h>
31+
#include <syslog.h>
32+
33+
#ifdef __cplusplus
34+
extern "C" {
35+
#endif
36+
37+
/* Size of sliding window for computing trend line */
38+
#define LSQ_LOOKBACK 8
39+
40+
/* How often should data be sampled and trend analyzed*/
41+
#define LOW_PERIODICITY 60
42+
#define NORM_PERIODICITY 30
43+
#define HIGH_PERIODICITY 15
44+
45+
#define MAX_ORDER 11
46+
#define MEMPREDICT_RECLAIM 0x01
47+
#define MEMPREDICT_COMPACT 0x02
48+
#define MEMPREDICT_LOWER_WMARKS 0x04
49+
50+
struct lsq_struct {
51+
int next;
52+
int ready;
53+
long long y[LSQ_LOOKBACK];
54+
long long x[LSQ_LOOKBACK];
55+
};
56+
57+
enum output_type {
58+
OUTPUT_OBSERVATIONS,
59+
OUTPUT_PREDICTIONS,
60+
MAX_OUTPUT
61+
};
62+
63+
struct frag_info {
64+
long long free_pages;
65+
long long msecs;
66+
};
67+
68+
#define BATCHSIZE 8192
69+
70+
#define EOF_RET -1
71+
72+
#define MAX_VERBOSE 5
73+
#define MAX_NEGDENTRY 100
74+
#define MAX_NEGDENTRY_DEFAULT 15 /* default is 1.5% */
75+
76+
#define MAX_NUMANODES 1024
77+
78+
/*
79+
* Number of consecutive samples showing growth in unaccounted memory
80+
* that will trigger memory leak warning
81+
*/
82+
#define UNACCT_MEM_GRTH_MAX 10
83+
84+
/* Minimum % change in meminfo numbers to trigger warnings */
85+
#define MEM_TRIGGER_DELTA 10
86+
87+
#define FLDLEN 20
88+
89+
/*
90+
* System files to control reclamation and compaction
91+
*/
92+
#define COMPACT_PATH_FORMAT "/sys/devices/system/node/node%d/compact"
93+
#define RESCALE_WMARK "/proc/sys/vm/watermark_scale_factor"
94+
95+
/*
96+
* System files to control negative dentries
97+
*/
98+
#define NEG_DENTRY_LIMIT "/proc/sys/fs/negative-dentry-limit"
99+
100+
enum memdata_items {
101+
MEMAVAIL,
102+
BUFFERS,
103+
CACHED,
104+
SWPCACHED,
105+
UNEVICTABLE,
106+
MLOCKED,
107+
ANONPAGES,
108+
MAPPED,
109+
SHMEM,
110+
KRECLAIMABLE,
111+
SLAB,
112+
SUNRECLAIM,
113+
KSTACK,
114+
PGTABLE,
115+
SECPGTABLE,
116+
VMALLOCUSED,
117+
CMA,
118+
NR_MEMDATA_ITEMS
119+
};
120+
121+
enum trigger_type {
122+
NO_TRIGGER,
123+
MEMORY_PRESSURE_TRIGGER,
124+
SUDDEN_MEMORY_LEAK_TRIGGER,
125+
BACKGROUND_MEMORY_LEAK_TRIGGER,
126+
SLOW_MEMORY_LEAK_TRIGGER
127+
};
128+
129+
struct curr_mem_info {
130+
unsigned long pr_memdata[NR_MEMDATA_ITEMS];
131+
unsigned long freemem;
132+
unsigned long prv_free;
133+
unsigned long mem_remain;
134+
unsigned long unacct_mem;
135+
long unmapped_pages;
136+
};
137+
138+
struct adaptivemmd_opts {
139+
int unacct_mem_grth_max;
140+
int mem_trigger_delta;
141+
int aggressiveness;
142+
unsigned int maxwsf; /* Highest value to set watermark_scale_factor to. */
143+
unsigned int mywsf;
144+
int max_compaction_order; /* Highest order pages to look at for fragmentation. */
145+
int compaction_requested[MAX_NUMANODES];
146+
unsigned long last_bigpages[MAX_NUMANODES];
147+
unsigned long last_reclaimed;
148+
unsigned long total_free_pages;
149+
unsigned long total_cache_pages;
150+
unsigned long total_hugepages;
151+
unsigned long base_psize;
152+
long compaction_rate;
153+
long reclaim_rate;
154+
struct lsq_struct page_lsq[MAX_NUMANODES][MAX_ORDER];
155+
FILE *ifile;
156+
struct timespec spec_before;
157+
int periodicity;
158+
int dry_run;
159+
160+
bool memleak_check_enabled;
161+
bool memory_pressure_check_enabled; /* aka ENABLE_FREE_PAGE_MGMT */
162+
int maxgap; /* Maximum gap between low and high watermarks (in GB) */
163+
bool neg_dentry_check_enabled; /* aka ENABLE_NEG_DENTRY_MGMT */
164+
int neg_dentry_pct; /* aka NEG_DENTRY_CAP negative dentry memory usage cap is expressed as
165+
* a percentage of total memory on the system. */
166+
unsigned long base_mem;
167+
unsigned long mem_remain;
168+
unsigned long gr_count;
169+
unsigned long prv_free;
170+
unsigned long memdata[NR_MEMDATA_ITEMS];
171+
unsigned long pr_memdata[NR_MEMDATA_ITEMS];
172+
unsigned long min_wmark[MAX_NUMANODES];
173+
unsigned long low_wmark[MAX_NUMANODES];
174+
unsigned long high_wmark[MAX_NUMANODES];
175+
unsigned long managed_pages[MAX_NUMANODES];
176+
int skip_dmazone;
177+
int debug_mode;
178+
int verbose;
179+
180+
long unmapped_pages;
181+
unsigned long unacct_mem;
182+
183+
struct curr_mem_info curr_mem_info;
184+
185+
unsigned long final_result;
186+
187+
enum trigger_type mem_pressure_trigger;
188+
enum trigger_type mem_leak_trigger;
189+
190+
char *capture_data_dir; /* directory to capture data to - must already exist */
191+
int max_triggers; /* used during capture data to limit amount of captured data */
192+
int trigger_count;
193+
char *log_file; /* capture messages for testing */
194+
int iteration;
195+
};
196+
197+
struct adaptivemmd_effects_opts {
198+
const struct adaptived_cause *cse;
199+
};
200+
201+
int run_adaptivemm_init(struct adaptivemmd_opts * const opts, int interval);
202+
203+
int run_adaptivemm(struct adaptivemmd_opts * const opts);
204+
205+
int run_adaptivemm_effects(struct adaptivemmd_opts * const opts);
206+
207+
208+
#define log_err(...) log_msg(LOG_ERR, __VA_ARGS__)
209+
#define log_warn(...) log_msg(LOG_WARNING, __VA_ARGS__)
210+
#define log_dbg(...) if (debug_mode) \
211+
log_msg(LOG_DEBUG, __VA_ARGS__)
212+
#define log_info(verb_level, ...) if (verbose >= verb_level) \
213+
log_msg(LOG_INFO, __VA_ARGS__)
214+
215+
/* Use pr_info to log info irrespective of verbosity level */
216+
#define pr_info(...) log_msg(LOG_INFO, __VA_ARGS__)
217+
218+
extern void log_msg(int level, char *fmt, ...);
219+
220+
#ifdef __cplusplus
221+
}
222+
#endif
223+
224+
#endif /* PREDICT_H */

adaptived/src/cause.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const char * const cause_names[] = {
5555
"memory.stat",
5656
"top",
5757
"cgroup_memory_setting",
58+
"adaptivemmd_causes",
5859
};
5960
static_assert(ARRAY_SIZE(cause_names) == CAUSE_CNT,
6061
"cause_names[] must be same length as CAUSE_CNT");
@@ -81,6 +82,7 @@ const struct adaptived_cause_functions cause_fns[] = {
8182
{memorystat_init, memorystat_main, memorystat_exit},
8283
{top_init, top_main, top_exit},
8384
{cgset_memory_init, cgset_memory_main, cgset_exit},
85+
{adaptivemmd_causes_init, adaptivemmd_causes_main, adaptivemmd_causes_exit},
8486
};
8587
static_assert(ARRAY_SIZE(cause_fns) == CAUSE_CNT,
8688
"cause_fns[] must be same length as CAUSE_CNT");

adaptived/src/cause.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum cause_enum {
6363
MEMORYSTAT,
6464
TOP,
6565
CGROUP_MEMORY_SETTING,
66+
ADAPTIVEMMD_CAUSES,
6667

6768
CAUSE_CNT
6869
};
@@ -138,4 +139,8 @@ int top_init(struct adaptived_cause * const cse, struct json_object *args_obj, i
138139
int top_main(struct adaptived_cause * const cse, int time_since_last_run);
139140
void top_exit(struct adaptived_cause * const cse);
140141

142+
int adaptivemmd_causes_init(struct adaptived_cause * const cse, struct json_object *args_obj, int interval);
143+
int adaptivemmd_causes_main(struct adaptived_cause * const cse, int time_since_last_run);
144+
void adaptivemmd_causes_exit(struct adaptived_cause * const cse);
145+
141146
#endif /* __ADAPTIVED_CAUSE_H */

0 commit comments

Comments
 (0)