user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/4] doc: tuning: note reduced fragmentation w/ jemalloc
Date: Mon, 11 Mar 2024 19:40:11 +0000	[thread overview]
Message-ID: <20240311194012.1266143-4-e@80x24.org> (raw)
In-Reply-To: <20240311194012.1266143-1-e@80x24.org>

I may be mistaken, but I suspect the reason jemalloc handles
long-lived processes better than glibc is due to granularity
reduction being scaled to larger size classes.  This can waste
20% of an individual allocation, but increases the likelyhood
of reuse (without splitting/consolidating into other sizes).

In other words, glibc seems to try too hard to make the best fit
for initial allocations.  This ends up being suboptimal over
time as those allocations are freed and similar (but not
identical) allocations come in.  jemalloc sacrifices the best
initial fit for better fits over a long process lifetime.
---
 Documentation/public-inbox-tuning.pod | 5 +++++
 examples/public-inbox-netd@.service   | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/Documentation/public-inbox-tuning.pod b/Documentation/public-inbox-tuning.pod
index 38810ce6..73246144 100644
--- a/Documentation/public-inbox-tuning.pod
+++ b/Documentation/public-inbox-tuning.pod
@@ -163,6 +163,11 @@ Transport Layer Security (IMAPS, NNTPS, or via STARTTLS) significantly
 increases memory use of client sockets, be sure to account for that in
 capacity planning.
 
+Bursts of small object allocations late in process life contribute to
+fragmentation of the heap due to arenas (slabs) used internally by Perl.
+jemalloc (tested as an LD_PRELOAD on GNU/Linux) appears to reduce
+overall fragmentation compared to glibc malloc in long-lived processes.
+
 =head2 Other OS tuning knobs
 
 Linux users: the C<sys.vm.max_map_count> sysctl may need to be increased if
diff --git a/examples/public-inbox-netd@.service b/examples/public-inbox-netd@.service
index de5feea6..2330bd59 100644
--- a/examples/public-inbox-netd@.service
+++ b/examples/public-inbox-netd@.service
@@ -12,6 +12,8 @@ Wants = public-inbox-netd.socket
 After = public-inbox-netd.socket
 
 [Service]
+# An LD_PRELOAD for libjemalloc can be added here.  It currently seems
+# more resistant to fragmentation to glibc in long-lived daemons.
 Environment = PI_CONFIG=/home/pi/.public-inbox/config \
 PATH=/usr/local/bin:/usr/bin:/bin \
 TZ=UTC \

  parent reply	other threads:[~2024-03-11 19:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 19:40 [PATCH 0/4] memory reductions for WWW + solver Eric Wong
2024-03-11 19:40 ` [PATCH 1/4] www: use a dedicated limiter for blob solver Eric Wong
2024-03-11 19:40 ` [PATCH 2/4] codesearch: deduplicate {ibx_score} name pairs Eric Wong
2024-03-11 19:40 ` Eric Wong [this message]
2024-03-11 19:40 ` [PATCH 4/4] codesearch: deduplicate $git->{nick} field 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: https://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=20240311194012.1266143-4-e@80x24.org \
    --to=e@80x24.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).