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,AWL,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 620BC1F462; Mon, 10 Jun 2019 10:09:31 +0000 (UTC) Date: Mon, 10 Jun 2019 10:09:31 +0000 From: Eric Wong To: Konstantin Ryabitsev Cc: meta@public-inbox.org Subject: [RFC] optionally support glibc malloc_info via SIGCONT Message-ID: <20190610100931.p3hkf52zoxksmqyz@dcvr> References: <20181201194429.d5aldesjkb56il5c@dcvr> <20190606190455.GA17362@chatter.i7.local> <20190606203752.7wpdla5ynemjlshs@dcvr> <20190606214509.GA4087@chatter.i7.local> <20190606221009.y4fe2e2rervvq3z4@dcvr> <20190606221904.GB4087@chatter.i7.local> <20190606222938.y7nt3uankntkktly@dcvr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190606222938.y7nt3uankntkktly@dcvr> List-Id: Eric Wong wrote: > Konstantin Ryabitsev wrote: > > On Thu, Jun 06, 2019 at 10:10:09PM +0000, Eric Wong wrote: > > > > > All those endpoints should detect backpressure from a slow > > > > > client (varnish/nginx in your case) using the ->getline method. > > > > > > > > Wouldn't that spike up and down? The size I'm seeing stays pretty constant > > > > without any significant changes across requests. > > > > > > Nope. That's the thing with glibc malloc not wanting to trim > > > the heap for good benchmarks. glibc's malloc_info(3) function shows a bunch of info about malloc internal structures which can't be examined easily with other tools. Maybe this can help track down what glibc malloc is doing and can tell us how much free memory glibc is holding onto w/o giving back to the kernel. ------------8<------------- Subject: [RFC] optionally support glibc malloc_info via SIGCONT If run with PERL_INLINE_DIRECTORY for Inline::C support along with INBOX_DEBUG=malloc_info, we can allow users to opt-in to compiling extra code to support the glibc malloc_info(3) function. We'll also add SIGCONT handler to dump the malloc_info(3) output to stderr on our daemons. --- MANIFEST | 1 + lib/PublicInbox/Spawn.pm | 17 +++++++++++++++++ t/malloc_info.t | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 t/malloc_info.t diff --git a/MANIFEST b/MANIFEST index 5085bff..4a7f7ef 100644 --- a/MANIFEST +++ b/MANIFEST @@ -210,6 +210,7 @@ t/indexlevels-mirror.t t/init.t t/linkify.t t/main-bin/spamc +t/malloc_info.t t/mda.t t/mda_filter_rubylang.t t/mid.t diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 66b916d..9210f11 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -149,6 +149,23 @@ int pi_fork_exec(int in, int out, int err, } VFORK_SPAWN +# TODO: we may support other mallocs through this parameter +if (($ENV{INBOX_DEBUG} // '') =~ /\bmalloc_info\b/) { + $vfork_spawn .= < + +int inbox_malloc_info(int options) +{ + int rc = malloc_info(options, stderr); + + return rc == 0 ? TRUE : FALSE; +} +MALLOC_DEBUG + + # dump malloc info to stderr on SIGCONT + $SIG{CONT} = sub { inbox_malloc_info(0) }; +} + my $inline_dir = $ENV{PERL_INLINE_DIRECTORY}; $vfork_spawn = undef unless defined $inline_dir && -d $inline_dir && -w _; if (defined $vfork_spawn) { diff --git a/t/malloc_info.t b/t/malloc_info.t new file mode 100644 index 0000000..352ec5c --- /dev/null +++ b/t/malloc_info.t @@ -0,0 +1,25 @@ +# Copyright (C) 2019 all contributors +# License: AGPL-3.0+ +use strict; +use warnings; +use Test::More; +use PublicInbox::Spawn (); + +if (!PublicInbox::Spawn->can('inbox_malloc_info')) { + plan skip_all => 'inbox_malloc_info not enabled'; +} + +open my $olderr, '>&', \*STDERR or die "dup stderr: $!"; +open my $tmp, '+>', undef or die "tmpfile: $!"; +open STDERR, '>&', $tmp or die "redirect stderr to \$tmp: $!"; +my @x = map { '0' x (1024 * 1024) } (1..128); +my $cb = $SIG{CONT}; +$cb->(); +@x = ('hello'); +PublicInbox::Spawn::inbox_malloc_info(0); +open STDERR, '>&', $olderr or die "restore stderr: $!"; +sysseek($tmp, 0, 0) == 0 or die "sysseek: $!"; +my @info = <$tmp>; +like($info[0], qr/