diff options
author | Fengguang Wu <fengguang.wu@intel.com> | 2018-12-17 20:15:22 +0800 |
---|---|---|
committer | Fengguang Wu <fengguang.wu@intel.com> | 2018-12-18 19:03:07 +0800 |
commit | f9bbfa8ea722559f2fac4c2b14057c6a58658d70 (patch) | |
tree | 39731c1382673816f6618e78f9fe7d6ab096f338 | |
parent | c8ec30c34feced387bc4a889af36d6ed51571773 (diff) | |
download | vm-scalability-f9bbfa8ea722559f2fac4c2b14057c6a58658d70.tar.gz |
usemem: exactly detach before sleeping
This fixes blocked parent usemem when child is OOM killed.
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
-rw-r--r-- | usemem.c | 69 |
1 files changed, 2 insertions, 67 deletions
@@ -93,7 +93,6 @@ int opt_sync_rw = 0; int opt_sync_free = 0; int opt_bind_interval = 0; unsigned long opt_delay = 0; -int sem_id = -1; int nr_task; int nr_thread; int nr_cpu; @@ -113,7 +112,6 @@ int start_wake_fds[2]; int free_ready_fds[2]; int free_wake_fds[2]; - void usage(int ok) { fprintf(stderr, @@ -284,29 +282,6 @@ static inline long os_random_long(unsigned long max, struct drand48_data *rs) return (unsigned long)((double)max * val / (RAND_MAX + 1.0)); } -/* - * semaphore get/put wrapper - */ -int down(int sem_id) -{ - struct sembuf buf = { - .sem_num = 0, - .sem_op = -1, - .sem_flg = SEM_UNDO, - }; - return semop(sem_id, &buf, 1); -} - -int up(int sem_id) -{ - struct sembuf buf = { - .sem_num = 0, - .sem_op = 1, - .sem_flg = SEM_UNDO, - }; - return semop(sem_id, &buf, 1); -} - void update_pid_file(pid_t pid) { FILE *file; @@ -324,31 +299,10 @@ void update_pid_file(pid_t pid) fclose(file); } - -void sighandler(int sig, siginfo_t *si, void *arg) -{ - up(sem_id); - - printf("usemem: exit on signal %d\n", sig); - exit(0); -} - void detach(void) { pid_t pid; - sem_id = semget(IPC_PRIVATE, 1, 0666|IPC_CREAT|IPC_EXCL); - if (sem_id == -1) { - perror("semget"); - exit(1); - } - if (semctl(sem_id, 0, SETVAL, 0) == -1) { - perror("semctl"); - if (semctl(sem_id, 0, IPC_RMID) == -1) - perror("sem_id IPC_RMID"); - exit(1); - } - pid = fork(); if (pid < 0) { perror("fork"); @@ -357,24 +311,8 @@ void detach(void) if (pid) { /* parent */ update_pid_file(pid); - if (down(sem_id)) - perror("down"); - semctl(sem_id, 0, IPC_RMID); exit(0); } - - if (pid == 0) { /* child */ - struct sigaction sa = { - .sa_sigaction = sighandler, - .sa_flags = SA_SIGINFO, - }; - - /* - * XXX: SIGKILL cannot be caught. - * The parent will wait for ever if child is OOM killed. - */ - sigaction(SIGINT, &sa, NULL); - } } unsigned long * allocate(unsigned long bytes) @@ -728,9 +666,6 @@ long do_units(void) void *ptrs[MAX_POINTERS]; unsigned int nptr = 0; - if (opt_detach) - detach(); - /* Base the random seed on the thread ID for multithreaded tests */ if (opt_randomise) os_random_seed(time(0) ^ syscall(SYS_gettid), &rand_data); @@ -770,8 +705,8 @@ long do_units(void) } } - if (opt_detach && up(sem_id)) - perror("up"); + if (opt_detach) + detach(); if (sleep_secs) sleep(sleep_secs); |