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-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 E2F561FB05 for ; Wed, 27 Jan 2021 09:42:31 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 8/9] v2writable: nproc: use sysconf() on Linux and FreeBSD Date: Wed, 27 Jan 2021 03:42:29 -0600 Message-Id: <20210127094230.31174-9-e@80x24.org> In-Reply-To: <20210127094230.31174-1-e@80x24.org> References: <20210127094230.31174-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No need to fork a process on platforms I use daily, at least. --- lib/PublicInbox/V2Writable.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 7f9342b0..35b7fe30 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -21,6 +21,7 @@ use PublicInbox::Search; use PublicInbox::SearchIdx qw(log2stack is_ancestor check_size is_bad_blob); use IO::Handle; # ->autoflush use File::Temp (); +use POSIX (); my $OID = qr/[a-f0-9]{40,}/; # an estimate of the post-packed size to the raw uncompressed size @@ -35,6 +36,11 @@ our $PACKING_FACTOR = 0.4; our $NPROC_MAX_DEFAULT = 4; sub detect_nproc () { + # _SC_NPROCESSORS_ONLN = 84 on both Linux glibc and musl + return POSIX::sysconf(84) if $^O eq 'linux'; + return POSIX::sysconf(58) if $^O eq 'freebsd'; + # TODO: more OSes + # getconf(1) is POSIX, but *NPROCESSORS* vars are not for (qw(_NPROCESSORS_ONLN NPROCESSORS_ONLN)) { `getconf $_ 2>/dev/null` =~ /^(\d+)$/ and return $1;