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 28AA01F620 for ; Thu, 19 Mar 2020 08:32:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/6] daemon: do more immortal allocations up front Date: Thu, 19 Mar 2020 03:32:55 -0500 Message-Id: <20200319083256.15593-6-e@yhbt.net> In-Reply-To: <20200319083256.15593-1-e@yhbt.net> References: <20200319083256.15593-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Doing immortal allocations late can cause those allocations to end up in places where it fragments the heap. So do more things up front for long-lived daemons. --- lib/PublicInbox/NNTPD.pm | 4 ++++ lib/PublicInbox/WWW.pm | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm index 7a917169..451f4d41 100644 --- a/lib/PublicInbox/NNTPD.pm +++ b/lib/PublicInbox/NNTPD.pm @@ -45,6 +45,10 @@ sub refresh_groups () { # Only valid if msgmap and search works $new->{$ngname} = $ng; push @list, $ng; + + # preload to avoid fragmentation: + $ng->description; + $ng->base_url; } }); @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 534ee028..2434f2f5 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -132,7 +132,9 @@ sub call { } } -# for CoW-friendliness, MOOOOO! +# for CoW-friendliness, MOOOOO! Even for single-process setups, +# we want to get all immortal allocations done early to avoid heap +# fragmentation since common allocators favor a large contiguous heap. sub preload { my ($self) = @_; require PublicInbox::ExtMsg; @@ -148,18 +150,29 @@ sub preload { require PublicInbox::Search; PublicInbox::Search::load_xapian(); }; - foreach (qw(PublicInbox::SearchView - PublicInbox::MboxGz - PublicInbox::NewsWWW)) { + foreach (qw(PublicInbox::SearchView PublicInbox::MboxGz)) { eval "require $_;"; } if (ref($self)) { + my $pi_config = $self->{pi_config}; + if (defined($pi_config->{'publicinbox.cgitrc'})) { + $pi_config->limiter('-cgit'); + } $self->cgit; $self->stylesheets_prepare($_) for ('', '../', '../../'); $self->www_listing; + $self->news_www; + $pi_config->each_inbox(\&preload_inbox); } } +sub preload_inbox { + my $ibx = shift; + $ibx->cloneurl; + $ibx->description; + $ibx->base_url; +} + # private functions below sub r404 {