user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [RFC] optionally support glibc malloc_info via SIGCONT
  @ 2019-06-10 10:09 14%             ` Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2019-06-10 10:09 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: meta

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

^ permalink raw reply related	[relevance 14%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
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 14%             ` [RFC] optionally support glibc malloc_info via SIGCONT Eric Wong

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