diff options
author | Eric Wong <e@80x24.org> | 2015-11-13 21:47:50 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-11-13 23:40:09 +0000 |
commit | b45c3852dfcc153ef6ac820ec5fd54265845d296 (patch) | |
tree | ca4397afec30d0b4ce9c752c2fb9170eddf61a83 /upgrade.c | |
parent | 4fb84823e327de868a14c4158cedf1dc7751d3fc (diff) | |
download | cmogstored-b45c3852dfcc153ef6ac820ec5fd54265845d296.tar.gz |
Given the prevalance of gigantic VM footprints due to current glibc malloc and our potentially large number of threads, vfork can speed up fork used for spawning iostat and SIGUSR2 upgrades. vfork only pauses the spawning thread, so it will not affect other I/O threads used in cmogstored; only the non-performance-critical master thread. Swapping 'fork()' for 'vfork()' in the following C test program should show a large speedup under Linux. Changing FILL to increase or decrease memory usage will respectively decrease or increase performance improvement gain from vfork over fork.. -----------------------------8<------------------------- /* gcc -o x x.c -Wall -O2 -lpthread && ./x */ #include <sys/types.h> #include <sys/time.h> #include <unistd.h> #include <pthread.h> #include <poll.h> #include <stdio.h> #include <sys/wait.h> #include <stdlib.h> #include <string.h> #define FILL (1024 * 1024) static void *thfunc(void *p) { void *ptr = malloc(FILL); memset(ptr, 1, FILL); poll(0, 0, -1); return 0; } int main(void) { long i; void *ptr = malloc(FILL); memset(ptr, 1, FILL); for (i = 0; i < 100; i++) { pthread_t th; pthread_create(&th, 0, thfunc, (void *)i); } poll(0, 0, 1000); for (i = 0; i < 100; i++) { /* swapping fork with vfork increases performance on Linux */ pid_t pid = fork(); if (pid < 0) { fprintf(stderr, "ERROR: forking %m\n"); return 1; } if (pid == 0) { char *argv[] = { "/bin/true", 0 }; char *env[] = { 0 }; execve(argv[0], argv, env); return 1; } else { int s; waitpid(pid, &s, 0); } } return 0; }
Diffstat (limited to 'upgrade.c')
-rw-r--r-- | upgrade.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -125,13 +125,14 @@ pid_t mog_upgrade_spawn(void) assert(dst[bytes - 1] == ',' && "not comma-terminated no listeners?"); dst[bytes - 1] = '\0'; /* kill the last comma */ + start.envp[0] = dst; - pid = fork(); + pid = mog_fork_for_exec(); if (pid == 0) { - start.envp[0] = dst; mog_svc_upgrade_prepare(); execve(execfile, start.argv, start.envp); - die_errno("execve %s", execfile); + syslog(LOG_ERR, "execve %s failed for upgrade: %m", execfile); + _exit(2); } else if (pid > 0) { mog_process_register(pid, MOG_PROC_UPGRADE); syslog(LOG_INFO, "upgrade spawned PID:%d", pid); @@ -143,6 +144,7 @@ out: /* find_in_path does not malloc if output == input */ if (execfile != start.argv[0]) mog_free(execfile); + start.envp[0] = 0; free(dst); return pid; |