]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
doc: tuning: note reduced fragmentation w/ jemalloc
authorEric Wong <e@80x24.org>
Mon, 11 Mar 2024 19:40:11 +0000 (19:40 +0000)
committerEric Wong <e@80x24.org>
Tue, 12 Mar 2024 06:18:18 +0000 (06:18 +0000)
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
examples/public-inbox-netd@.service

index 38810ce6d12cce0d8396ebd6e647953cb34fe8d5..732461441adb3c6bf7cd27000ba55b5d998c73d6 100644 (file)
@@ -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
index de5feea626ce2dd0e035a20565fd3ebef691cc76..2330bd5952fe6149ad5ea61ec510797b9c3eebcf 100644 (file)
@@ -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 \