]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
syscall: common $F_SETPIPE_SZ definition
authorEric Wong <e@80x24.org>
Tue, 17 Oct 2023 23:38:02 +0000 (23:38 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Oct 2023 20:50:32 +0000 (20:50 +0000)
We use this in various places to minimize or maximize pipe
size on Linux.  So keep it all in one place.

lib/PublicInbox/CidxLogP.pm
lib/PublicInbox/EOFpipe.pm
lib/PublicInbox/LeiXSearch.pm
lib/PublicInbox/SearchIdxShard.pm
lib/PublicInbox/Syscall.pm
t/gcf2.t
t/lei-sigpipe.t

index 7877d5acfb9d3b0b4307b71a6c07c25016ad1d32..34f7201d68076b0b8e7b06b4685bdf392a3c9bec 100644 (file)
 package PublicInbox::CidxLogP;
 use v5.12;
 use parent qw(PublicInbox::DS);
-use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
+use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT $F_SETPIPE_SZ);
 
 sub new {
        my ($cls, $rd, $cidx, $git, $roots) = @_;
        my $self = bless { cidx => $cidx, git => $git, roots => $roots }, $cls;
-       fcntl($rd, 1031, 1048576) if $^O eq 'linux'; # fatter pipes
+       fcntl($rd, $F_SETPIPE_SZ, 1048576) if $F_SETPIPE_SZ;
        $self->SUPER::new($rd, EPOLLIN|EPOLLONESHOT);
 }
 
index 628e9366fe61dea68b56aa5c380368626071c8ed..3474874f7b418ee4b26dcc90f7165ddbf0535e9a 100644 (file)
@@ -4,13 +4,13 @@
 package PublicInbox::EOFpipe;
 use v5.12;
 use parent qw(PublicInbox::DS);
-use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
+use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT $F_SETPIPE_SZ);
 
 sub new {
        my (undef, $rd, $cb) = @_;
        my $self = bless { cb => $cb }, __PACKAGE__;
-       # 1031: F_SETPIPE_SZ, 4096: page size
-       fcntl($rd, 1031, 4096) if $^O eq 'linux';
+       # 4096: page size
+       fcntl($rd, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
        $self->SUPER::new($rd, EPOLLIN|EPOLLONESHOT);
 }
 
index d83a403c94723860c524d1bacd4347b9af890822..25b66b3b0cc05332b39ae347a8882cc971bf5ee6 100644 (file)
@@ -21,6 +21,7 @@ use Fcntl qw(SEEK_SET F_SETFL O_APPEND O_RDWR);
 use PublicInbox::ContentHash qw(git_sha);
 use POSIX qw(strftime);
 use autodie qw(open read seek truncate);
+use PublicInbox::Syscall qw($F_SETPIPE_SZ);
 
 sub new {
        my ($class) = @_;
@@ -536,7 +537,6 @@ sub do_query {
                if ($lei->{opt}->{augment} && delete $lei->{early_mua}) {
                        $lei->start_mua;
                }
-               my $F_SETPIPE_SZ = $^O eq 'linux' ? 1031 : undef;
                if ($l2m->{-wq_nr_workers} > 1 &&
                                $l2m->{base_type} =~ /\A(?:maildir|mbox)\z/) {
                        # setup two barriers to coordinate ->has_entries
index 21bd56c2794517f20c704361312abb06c3ad7df3..1630eb4aa2deba6b7a1908addc5d7707e0e91afa 100644 (file)
@@ -7,6 +7,7 @@ package PublicInbox::SearchIdxShard;
 use v5.12;
 use parent qw(PublicInbox::SearchIdx PublicInbox::IPC);
 use PublicInbox::OnDestroy;
+use PublicInbox::Syscall qw($F_SETPIPE_SZ);
 
 sub new {
        my ($class, $v2w, $shard) = @_; # v2w may be ExtSearchIdx
@@ -20,13 +21,12 @@ sub new {
        if ($v2w->{parallel}) {
                local $self->{-v2w_afc} = $v2w;
                $self->ipc_worker_spawn("shard[$shard]");
-               # F_SETPIPE_SZ = 1031 on Linux; increasing the pipe size for
-               # inputs speeds V2Writable batch imports across 8 cores by
-               # nearly 20%.  Since any of our responses are small, make
-               # the response pipe as small as possible
-               if ($^O eq 'linux') {
-                       fcntl($self->{-ipc_req}, 1031, 1048576);
-                       fcntl($self->{-ipc_res}, 1031, 4096);
+               # Increasing the pipe size for requests speeds V2 batch imports
+               # across 8 cores by nearly 20%.  Since many of our responses
+               # are small, make the response pipe as small as possible
+               if ($F_SETPIPE_SZ) {
+                       fcntl($self->{-ipc_req}, $F_SETPIPE_SZ, 1048576);
+                       fcntl($self->{-ipc_res}, $F_SETPIPE_SZ, 4096);
                }
        }
        $self;
index e83beb6a80858b2be8fe895eccf41a923cea2d9f..78181bb6a6224d865b700588c0f53331de6d8e26 100644 (file)
@@ -28,7 +28,7 @@ our @EXPORT_OK = qw(epoll_ctl epoll_create epoll_wait
                   EPOLLIN EPOLLOUT EPOLLET
                   EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
                   EPOLLONESHOT EPOLLEXCLUSIVE
-                  signalfd rename_noreplace %SIGNUM);
+                  signalfd rename_noreplace %SIGNUM $F_SETPIPE_SZ);
 use constant {
        EPOLLIN => 1,
        EPOLLOUT => 4,
@@ -55,13 +55,12 @@ use constant {
 
 my @BYTES_4_hole = BYTES_4_hole ? (0) : ();
 
-our (
-     $SYS_epoll_create,
-     $SYS_epoll_ctl,
-     $SYS_epoll_wait,
-     $SYS_signalfd4,
-     $SYS_renameat2,
-     );
+our ($SYS_epoll_create,
+       $SYS_epoll_ctl,
+       $SYS_epoll_wait,
+       $SYS_signalfd4,
+       $SYS_renameat2,
+       $F_SETPIPE_SZ);
 
 my ($SYS_sendmsg, $SYS_recvmsg);
 my $SYS_fstatfs; # don't need fstatfs64, just statfs.f_type
@@ -70,6 +69,7 @@ my $SFD_CLOEXEC = 02000000; # Perl does not expose O_CLOEXEC
 our $no_deprecated = 0;
 
 if ($^O eq "linux") {
+       $F_SETPIPE_SZ = 1031;
     my (undef, undef, $release, undef, $machine) = POSIX::uname();
     my ($maj, $min) = ($release =~ /\A([0-9]+)\.([0-9]+)/);
     $SYS_renameat2 = 0 if "$maj.$min" < 3.15;
index d12a4420b5c01099bbb0b8bbd0ef8d94460afb8a..33f3bbca52ea543c031f37ebe7bff56d74e2a1f8 100644 (file)
--- a/t/gcf2.t
+++ b/t/gcf2.t
@@ -10,6 +10,7 @@ use POSIX qw(_exit);
 use Cwd qw(abs_path);
 require_mods('PublicInbox::Gcf2');
 use_ok 'PublicInbox::Gcf2';
+use PublicInbox::Syscall qw($F_SETPIPE_SZ);
 use PublicInbox::Import;
 my ($tmpdir, $for_destroy) = tmpdir();
 
@@ -109,7 +110,7 @@ SKIP: {
        for my $blk (1, 0) {
                my ($r, $w);
                pipe($r, $w) or BAIL_OUT $!;
-               fcntl($w, 1031, 4096) or
+               fcntl($w, $F_SETPIPE_SZ, 4096) or
                        skip('Linux too old for F_SETPIPE_SZ', 14);
                $w->blocking($blk);
                seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
@@ -129,7 +130,7 @@ SKIP: {
                $ck_copying->("pipe blocking($blk)");
 
                pipe($r, $w) or BAIL_OUT $!;
-               fcntl($w, 1031, 4096) or BAIL_OUT $!;
+               fcntl($w, $F_SETPIPE_SZ, 4096) or BAIL_OUT $!;
                $w->blocking($blk);
                close $r;
                local $SIG{PIPE} = 'IGNORE';
index 55c208e2740c039327f26855964c94e12bcb5c5e..622598a40d2e4a0094e8f5eb3e6c3437c4ecedfa 100644 (file)
@@ -6,6 +6,7 @@ use v5.10.1;
 use PublicInbox::TestCommon;
 use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
 use PublicInbox::OnDestroy;
+use PublicInbox::Syscall qw($F_SETPIPE_SZ);
 
 # undo systemd (and similar) ignoring SIGPIPE, since lei expects to be run
 # from an interactive terminal:
@@ -21,10 +22,8 @@ test_lei(sub {
        my $imported;
        for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
                pipe(my ($r, $w)) or BAIL_OUT $!;
-               my $size = 65536;
-               if ($^O eq 'linux' && fcntl($w, 1031, 4096)) {
-                       $size = 4096;
-               }
+               my $size = $F_SETPIPE_SZ && fcntl($w, $F_SETPIPE_SZ, 4096) ?
+                       4096 : 65536;
                unless (-f $f) {
                        open my $fh, '>', $f or xbail "open $f: $!";
                        print $fh <<'EOM' or xbail;