about summary refs log tree commit homepage
path: root/configure.ac
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-11-13 21:47:50 +0000
committerEric Wong <e@80x24.org>2015-11-13 23:40:09 +0000
commitb45c3852dfcc153ef6ac820ec5fd54265845d296 (patch)
treeca4397afec30d0b4ce9c752c2fb9170eddf61a83 /configure.ac
parent4fb84823e327de868a14c4158cedf1dc7751d3fc (diff)
downloadcmogstored-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 'configure.ac')
-rw-r--r--configure.ac1
1 files changed, 1 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 8bd98e2..0d551c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,6 +51,7 @@ AC_CHECK_FUNCS([ioctl])
 AC_CHECK_FUNCS([sendfile])
 AC_CHECK_FUNCS([open_memstream])
 AC_CHECK_FUNCS([posix_fadvise])
+AC_CHECK_FUNCS([vfork])
 
 dnl need LIBS=-lfreebsd-glue (but not CFLAGS=-I/usr/include/freebsd)
 AC_CHECK_FUNCS([bsd_sendfile])