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
3234#define MAX_BACKOFF (10000)
3335
3436static 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)
5861static 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-
147159err_close_fds2 :
148160 (void )close (fds [2 ]);
149161err_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
235249static 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
0 commit comments