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 A412A1F4B9; Fri, 24 Jan 2020 19:07:12 +0000 (UTC) Date: Fri, 24 Jan 2020 19:07:12 +0000 From: Eric Wong To: meta@public-inbox.org Subject: Re: [PATCH 3/4] ds: tmpio: store offsets per-buffer Message-ID: <20200124190712.GA10143@dcvr> References: <20200124094352.19437-1-e@yhbt.net> <20200124094352.19437-4-e@yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200124094352.19437-4-e@yhbt.net> List-Id: Eric Wong wrote: > diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm > index 970061fd..a9ac7fcd 100644 > --- a/lib/PublicInbox/DS.pm > +++ b/lib/PublicInbox/DS.pm > @@ -490,12 +491,13 @@ sub drop { > # PerlIO::mmap or PerlIO::scalar if needed > sub tmpio ($$$) { > my ($self, $bref, $off) = @_; > - my $fh = tmpfile('wbuf', $self->{sock}, 1) or > + my $fh = tmpfile('wbuf', $self->{sock}, O_APPEND) or > return drop($self, "tmpfile $!"); > $fh->autoflush(1); > + binmode $fh, ':unix'; # reduce syscalls for read() >8192 bytes That binmode :unix call triggers a leak in Perl[1], going to have to squash the patch below to workaround it: diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index a9ac7fcd..c76a5038 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -494,7 +494,6 @@ sub tmpio ($$$) { my $fh = tmpfile('wbuf', $self->{sock}, O_APPEND) or return drop($self, "tmpfile $!"); $fh->autoflush(1); - binmode $fh, ':unix'; # reduce syscalls for read() >8192 bytes my $len = bytes::length($$bref) - $off; $fh->write($$bref, $len, $off) or return drop($self, "write ($len): $!"); [ $fh, 0 ] # [1] = offset, [2] = length, not set by us ... And perhaps just use sysread() instead of read(), since I'm not seeing a good reason to keep compatibility with PerlIO::scalar for buffering, after all. [1] http://nntp.perl.org/group/perl.perl5.porters/256918