From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7866 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: posix_spawn vs fork+exec test program Date: Wed, 3 Jun 2015 23:14:47 -0400 Message-ID: <20150604031447.GA25336@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="qDbXVdCdHGoSgWSk" X-Trace: ger.gmane.org 1433387713 29523 80.91.229.3 (4 Jun 2015 03:15:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 4 Jun 2015 03:15:13 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7879-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 04 05:15:13 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Z0Lca-0003Qt-8k for gllmg-musl@m.gmane.org; Thu, 04 Jun 2015 05:15:08 +0200 Original-Received: (qmail 26258 invoked by uid 550); 4 Jun 2015 03:15:04 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 26227 invoked from network); 4 Jun 2015 03:15:00 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:7866 Archived-At: --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The attached test program can be used to measure the performance of posix_spawn vs fork+exec under simulated memory conditions in the parent. The options it takes are: -n bytes memory to allocate -r fragment memory into alternating ro/rw vmas -d dirty allocated memory -f use fork+exec (instead of default posix_spawn) At -n 200000000 -r -d, I've observed a nearly 300x performance difference. As (somewhat) expected, with large -n but neither -r or -d, fork+exec performs well -- all pages are COW zero pages and easily forked. But if the pages are dirty, or if there are lots of vmas (even non-dirty ones), fork gets very slow. Rich --qDbXVdCdHGoSgWSk Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="spawntime.c" #define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include extern char **environ; static void bloat_up(size_t n, int frag, int dirty) { size_t pg = sysconf(_SC_PAGESIZE); size_t i; if (frag) { n /= pg; for (i=0; itv_sec = 0; clock_gettime(CLOCK_MONOTONIC, t0); if (!use_fork) { posix_spawn(&pid, prog, 0, 0, (char *[]){prog, 0}, environ); } else if (!(pid=fork())) { execve(prog, (char *[]){prog, 0}, environ); _exit(1); } waitpid(pid, 0, 0); return 0; } t2.tv_sec -= t1.tv_sec; if ((t2.tv_nsec -= t1.tv_nsec) < 0) { t2.tv_nsec += 1000000000; t2.tv_sec--; } printf("spawn time: %jd.%.9d\n", (intmax_t)t2.tv_sec, (int)t2.tv_nsec); return 0; } --qDbXVdCdHGoSgWSk--