unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Alyssa Ross <hi@alyssa.is>
To: meta@public-inbox.org
Subject: [PATCH 2/2] treewide: lose F_SETPIPE_SZ page size assumptions
Date: Tue,  7 Jan 2025 18:46:25 +0100	[thread overview]
Message-ID: <20250107174624.1504268-3-hi@alyssa.is> (raw)
In-Reply-To: <20250107174624.1504268-1-hi@alyssa.is>

fcntl(2) is documented as rounding up sizes to an integer multiple of
the page size.  When a pipe buffer as small as possible is desired,
it's cleaner to pass 0 and let the kernel set the pipe buffer to
exactly one page than it is to assume that pages are 4096 bytes.

Currently, Linux doesn't support pages smaller than 4096 bytes, so this 
is a purely stylistic change, but I think it will help avoid future 
bugs caused by assuming page sizes are 4096 bytes.

 lib/PublicInbox/EOFpipe.pm        | 4 ++--
 lib/PublicInbox/LeiXSearch.pm     | 6 +++---
 lib/PublicInbox/SearchIdxShard.pm | 2 +-
 t/gcf2.t                          | 4 ++--
 t/lei-sigpipe.t                   | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/EOFpipe.pm b/lib/PublicInbox/EOFpipe.pm
index 3eaa0e4e..9fe9f67d 100644
--- a/lib/PublicInbox/EOFpipe.pm
+++ b/lib/PublicInbox/EOFpipe.pm
@@ -10,8 +10,8 @@ use Errno qw(EAGAIN);
 sub new {
 	my (undef, $rd, @cb_args) = @_;
 	my $self = bless { cb_args => \@cb_args }, __PACKAGE__;
-	# 4096: page size
-	fcntl($rd, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
+	# 0: one page
+	fcntl($rd, $F_SETPIPE_SZ, 0) if $F_SETPIPE_SZ;
 	$rd->blocking(0); # avoid EINTR
 	$self->SUPER::new($rd, EPOLLIN); # level trigger for spurious wakeup
 }
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index e20b13c6..909e16ed 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -545,16 +545,16 @@ sub do_query {
 			# setup two barriers to coordinate ->has_entries
 			# between l2m workers
 			pipe(my ($a_r, $a_w)) or die "pipe: $!";
-			fcntl($a_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
+			fcntl($a_r, $F_SETPIPE_SZ, 0) if $F_SETPIPE_SZ;
 			pipe(my ($b_r, $b_w)) or die "pipe: $!";
-			fcntl($b_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
+			fcntl($b_r, $F_SETPIPE_SZ, 0) if $F_SETPIPE_SZ;
 			$l2m->{au_peers} = [ $a_r, $a_w, $b_r, $b_w ];
 		}
 		$l2m->wq_workers_start('lei2mail', undef,
 					$lei->oldset, { lei => $lei },
 					\&xsearch_done_wait, $lei);
 		pipe($lei->{startq}, $lei->{au_done}) or die "pipe: $!";
-		fcntl($lei->{startq}, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
+		fcntl($lei->{startq}, $F_SETPIPE_SZ, 0) if $F_SETPIPE_SZ;
 		delete $l2m->{au_peers};
 		close(delete $l2m->{-wq_s2}); # share wq_s1 with lei_xsearch
 	}
diff --git a/lib/PublicInbox/SearchIdxShard.pm b/lib/PublicInbox/SearchIdxShard.pm
index 7ee8a121..c12aef9e 100644
--- a/lib/PublicInbox/SearchIdxShard.pm
+++ b/lib/PublicInbox/SearchIdxShard.pm
@@ -26,7 +26,7 @@ sub new {
 		# 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);
+			fcntl($self->{-ipc_res}, $F_SETPIPE_SZ, 0);
 		}
 	}
 	$self;
diff --git a/t/gcf2.t b/t/gcf2.t
index 33f3bbca..28c69a01 100644
--- a/t/gcf2.t
+++ b/t/gcf2.t
@@ -110,7 +110,7 @@ SKIP: {
 	for my $blk (1, 0) {
 		my ($r, $w);
 		pipe($r, $w) or BAIL_OUT $!;
-		fcntl($w, $F_SETPIPE_SZ, 4096) or
+		fcntl($w, $F_SETPIPE_SZ, 0) or
 			skip('Linux too old for F_SETPIPE_SZ', 14);
 		$w->blocking($blk);
 		seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
@@ -130,7 +130,7 @@ SKIP: {
 		$ck_copying->("pipe blocking($blk)");
 
 		pipe($r, $w) or BAIL_OUT $!;
-		fcntl($w, $F_SETPIPE_SZ, 4096) or BAIL_OUT $!;
+		fcntl($w, $F_SETPIPE_SZ, 0) or BAIL_OUT $!;
 		$w->blocking($blk);
 		close $r;
 		local $SIG{PIPE} = 'IGNORE';
diff --git a/t/lei-sigpipe.t b/t/lei-sigpipe.t
index c01d9f83..f093dc5c 100644
--- a/t/lei-sigpipe.t
+++ b/t/lei-sigpipe.t
@@ -33,7 +33,7 @@ test_lei(sub {
 	my $imported;
 	for my $out ([], [qw(-f mboxcl2)], [qw(-f text)]) {
 		pipe(my $r, my $w);
-		my $size = ($F_SETPIPE_SZ && fcntl($w, $F_SETPIPE_SZ, 4096)) ||
+		my $size = ($F_SETPIPE_SZ && fcntl($w, $F_SETPIPE_SZ, 0)) ||
 		    65536;
 		unless (-f $f) {
 			my $fh = write_file '>', $f, <<'EOM';
-- 
2.47.0


  reply	other threads:[~2025-01-07 17:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 17:46 [PATCH 1/2] t/lei-sigpipe.t: use correct pipe size Alyssa Ross
2025-01-07 17:46 ` Alyssa Ross [this message]
2025-01-07 22:26   ` [PATCH 2/2] treewide: lose F_SETPIPE_SZ page size assumptions Eric Wong
2025-01-08  4:51     ` Eric Wong
2025-01-07 22:22 ` [PATCH 1/2] t/lei-sigpipe.t: use correct pipe size Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250107174624.1504268-3-hi@alyssa.is \
    --to=hi@alyssa.is \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).