Skip to content

Commit 1ef70be

Browse files
committed
stress-daemon: add --daemon-bloat option to simulte memory usage
This new option adds memory bloat to a daemon process by mmap'ping a user specified amount of memory (with MAP_POPULATE where possible). This simulates memory bloated daemon processes. Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent 16067e9 commit 1ef70be

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

core-opts.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ const struct option stress_long_options[] = {
245245
{ "cyclic-sleep", 1, NULL, OPT_cyclic_sleep },
246246

247247
{ "daemon", 1, NULL, OPT_daemon },
248+
{ "daemon-bloat", 1, NULL, OPT_daemon_bloat },
248249
{ "daemon-ops", 1, NULL, OPT_daemon_ops },
249250
{ "daemon-wait", 0, NULL, OPT_daemon_wait },
250251

core-opts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ typedef enum {
372372
OPT_cyclic_sleep,
373373

374374
OPT_daemon,
375+
OPT_daemon_bloat,
375376
OPT_daemon_ops,
376377
OPT_daemon_wait,
377378

stress-daemon.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "stress-ng.h"
2121
#include "core-capabilities.h"
2222
#include "core-signal.h"
23+
#include "core-mmap.h"
24+
#include "core-put.h"
2325

2426
#if defined(NSIG)
2527
#define MAX_SIGNUM NSIG
@@ -32,10 +34,11 @@
3234
#define MAX_BACKOFF (10000)
3335

3436
static const stress_help_t help[] = {
35-
{ NULL, "daemon N", "start N workers creating multiple daemons" },
36-
{ NULL, "daemon-ops N", "stop when N daemons have been created" },
37-
{ NULL, "daemon-wait", "stressor wait for daemon to exit and not init" },
38-
{ NULL, NULL, NULL }
37+
{ NULL, "daemon N", "start N workers creating multiple daemons" },
38+
{ NULL, "daemon-bloat N", "specify N bytes of daemon child process memory bloat" },
39+
{ NULL, "daemon-ops N", "stop when N daemons have been created" },
40+
{ NULL, "daemon-wait", "stressor wait for daemon to exit and not init" },
41+
{ NULL, NULL, NULL }
3942
};
4043

4144
/*
@@ -58,6 +61,7 @@ static void daemon_wait_pid(const pid_t pid, const bool daemon_wait)
5861
static int stress_make_daemon(
5962
stress_args_t *args,
6063
const int fd,
64+
const size_t daemon_bloat,
6165
const bool daemon_wait)
6266
{
6367
int fds[3];
@@ -134,6 +138,15 @@ static int stress_make_daemon(
134138
VOID_RET(int, stress_capabilities_drop(args->name));
135139
stress_proc_state_set(args->name, STRESS_STATE_RUN);
136140

141+
if (daemon_bloat) {
142+
void *ptr;
143+
144+
ptr = stress_mmap_populate(NULL, daemon_bloat,
145+
PROT_READ | PROT_WRITE,
146+
MAP_PRIVATE | MAP_ANONYMOUS,
147+
-1, 0);
148+
stress_put_void_ptr(ptr);
149+
}
137150
sz = write(fd, &rc, sizeof(rc));
138151
if (sz != sizeof(rc))
139152
goto err_close_fds2;
@@ -143,7 +156,6 @@ static int stress_make_daemon(
143156
break;
144157
}
145158
}
146-
147159
err_close_fds2:
148160
(void)close(fds[2]);
149161
err_close_fds1:
@@ -166,7 +178,9 @@ static int stress_daemon(stress_args_t *args)
166178
int rc = EXIT_SUCCESS;
167179
pid_t pid;
168180
bool daemon_wait = false;
181+
size_t daemon_bloat = 0;
169182

183+
(void)stress_setting_get("daemon-bloat", &daemon_bloat);
170184
(void)stress_setting_get("daemon-wait", &daemon_wait);
171185

172186
if (stress_signal_stop_stressing(args->name, SIGALRM) < 0)
@@ -198,7 +212,7 @@ static int stress_daemon(stress_args_t *args)
198212
/* Children */
199213
stress_make_it_fail_set();
200214
(void)close(fds[0]);
201-
rc = stress_make_daemon(args, fds[1], daemon_wait);
215+
rc = stress_make_daemon(args, fds[1], daemon_bloat, daemon_wait);
202216
shim_exit_group(rc);
203217
} else {
204218
/* Parent */
@@ -233,7 +247,8 @@ static int stress_daemon(stress_args_t *args)
233247
}
234248

235249
static const stress_opt_t opts[] = {
236-
{ OPT_daemon_wait, "daemon-wait", TYPE_ID_BOOL, 0, 1, NULL },
250+
{ OPT_daemon_bloat, "daemon-bloat", TYPE_ID_SIZE_T_BYTES, 4096, 64 * MB, NULL },
251+
{ OPT_daemon_wait, "daemon-wait", TYPE_ID_BOOL, 0, 1, NULL },
237252
END_OPT,
238253
};
239254

stress-ng.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,6 +2795,10 @@ This puts pressure on init to do rapid child reaping. The daemon processes
27952795
perform the usual mix of calls to turn into typical UNIX daemons, so this
27962796
artificially mimics very heavy daemon system stress.
27972797
.TP
2798+
.B \-\-daemon\-bloat N
2799+
specify daemon's memory mapping bloat size in bytes. This simulates memory usage
2800+
by a deameon process, default is zero (no memory mapping), range 4K to 64MB.
2801+
.TP
27982802
.B \-\-daemon\-ops N
27992803
stop daemon workers after N daemons have been created.
28002804
.TP

0 commit comments

Comments
 (0)