From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6ABA11F55B; Mon, 11 May 2020 04:27:38 +0000 (UTC) Date: Mon, 11 May 2020 04:27:36 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH v2] spawn: use ~/.cache/public-inbox/inline-c if writable Message-ID: <20200511042736.GA96942@dcvr> References: <20200510223715.19254-1-e@yhbt.net> <20200510223715.19254-6-e@yhbt.net> <20200511002927.GA13730@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200511002927.GA13730@dcvr> List-Id: Despite several memory reductions and pure Perl performance improvements, Inline::C spawn() still gives us a noticeable performance boost. More user-oriented command-line programs are likely coming, setting PERL_INLINE_DIRECTORY is annoying to users, and so is is poor performance. So allow users to opt-in to using our Inline::C code once by creating a `~/.cache/public-inbox/inline-c' directory. XDG_CACHE_HOME is respected to override the location of ~/.cache independent of HOME, according to https://specifications.freedesktop.org/basedir-spec/0.6/ar01s03.html v2: use "/nonexistent" if HOME is undefined, since that's the home of the "nobody" user on both FreeBSD and Debian. --- lib/PublicInbox/Spawn.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index ad6be187..785ea865 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -2,7 +2,8 @@ # License: AGPL-3.0+ # # This allows vfork to be used for spawning subprocesses if -# PERL_INLINE_DIRECTORY is explicitly defined in the environment. +# ~/.cache/public-inbox/inline-c is writable or if PERL_INLINE_DIRECTORY +# is explicitly defined in the environment (and writable). # Under Linux, vfork can make a big difference in spawning performance # as process size increases (fork still needs to mark pages for CoW use). # Currently, we only use this for code intended for long running @@ -140,8 +141,12 @@ int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref, } VFORK_SPAWN -my $inline_dir = $ENV{PERL_INLINE_DIRECTORY}; -$vfork_spawn = undef unless defined $inline_dir && -d $inline_dir && -w _; +my $inline_dir = $ENV{PERL_INLINE_DIRECTORY} // ( + $ENV{XDG_CACHE_HOME} // + ( ($ENV{HOME} // '/nonexistent').'/.cache' ) + ).'/public-inbox/inline-c'; + +$vfork_spawn = undef unless -d $inline_dir && -w _; if (defined $vfork_spawn) { # Inline 0.64 or later has locking in multi-process env, # but we support 0.5 on Debian wheezy @@ -150,7 +155,7 @@ if (defined $vfork_spawn) { my $f = "$inline_dir/.public-inbox.lock"; open my $fh, '>', $f or die "failed to open $f: $!\n"; flock($fh, LOCK_EX) or die "LOCK_EX failed on $f: $!\n"; - eval 'use Inline C => $vfork_spawn'; #, BUILD_NOISY => 1'; + eval 'use Inline C => $vfork_spawn, directory => $inline_dir'; my $err = $@; flock($fh, LOCK_UN) or die "LOCK_UN failed on $f: $!\n"; die $err if $err;