user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: meta@public-inbox.org
Subject: [RFC] optionally support glibc malloc_info via SIGCONT
Date: Mon, 10 Jun 2019 10:09:31 +0000	[thread overview]
Message-ID: <20190610100931.p3hkf52zoxksmqyz@dcvr> (raw)
In-Reply-To: <20190606222938.y7nt3uankntkktly@dcvr>

Eric Wong <e@80x24.org> wrote:
> Konstantin Ryabitsev <konstantin@linuxfoundation.org> 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 .= <<MALLOC_DEBUG;
+#include <malloc.h>
+
+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 <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+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/</, 'output looks like XML');
+
+done_testing;
-- 
EW

  reply	other threads:[~2019-06-10 10:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-01 19:44 how's memory usage on public-inbox-httpd? Eric Wong
2019-06-06 19:04 ` Konstantin Ryabitsev
2019-06-06 20:37   ` Eric Wong
2019-06-06 21:45     ` Konstantin Ryabitsev
2019-06-06 22:10       ` Eric Wong
2019-06-06 22:19         ` Konstantin Ryabitsev
2019-06-06 22:29           ` Eric Wong
2019-06-10 10:09             ` Eric Wong [this message]
2019-06-09  8:39         ` Eric Wong
2019-06-12 17:08           ` Eric Wong
2019-06-06 20:54   ` Eric Wong
2019-10-16 22:10   ` Eric Wong
2019-10-18 19:23     ` Konstantin Ryabitsev
2019-10-19  0:11       ` Eric Wong
2019-10-22 17:28         ` Konstantin Ryabitsev
2019-10-22 19:11           ` Eric Wong
2019-10-28 23:24         ` 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: http://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=20190610100931.p3hkf52zoxksmqyz@dcvr \
    --to=e@80x24.org \
    --cc=konstantin@linuxfoundation.org \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).