]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
doc: strongly recommend MALLOC_MMAP_THRESHOLD_=131072 for glibc
authorEric Wong <e@80x24.org>
Thu, 18 Apr 2024 19:46:16 +0000 (19:46 +0000)
committerEric Wong <e@80x24.org>
Mon, 22 Apr 2024 09:55:00 +0000 (09:55 +0000)
The 131072 byte lower bound was the old default before the
sliding mmap window was introduced in modern glibc malloc.
While the sliding mmap window was intended to be faster by
reducing syscalls, zeroing and kernel overhead, it is also prone
to fragmentation from allocation patterns seen in evented Perl
servers.

Individual allocations over 128K are rare in our codebase since
there aren't many messages this large, making any performance
impact tiny.  Furthermore, the reduction in fragmentation and
memory use will be a speedup for memory-constrained systems
since they can avoid swap and have more leftover for the page
cache.

Documentation/RelNotes/v2.0.0.wip
Documentation/public-inbox-tuning.pod
examples/public-inbox-httpd@.service
examples/public-inbox-imapd@.service
examples/public-inbox-netd@.service
examples/public-inbox-nntpd@.service

index 4d872fd721db759b0577d536f7bf8e5719f1def5..794d79565abbdd0e69590414bdc070a244908440 100644 (file)
@@ -54,8 +54,9 @@ treewide
 
   * SHA-256 coderepos are fully supported (but not inboxes, yet)
 
-  * jemalloc (tested as an LD_PRELOAD) is recommended to reduce fragmentation
-    in long-running daemon processes serving unpredictable traffic
+  * for daemons serving public traffic, MALLOC_MMAP_THRESHOLD_=131072 is
+    recommended to reduce fragmentation in glibc malloc, while jemalloc
+    (tested as an LD_PRELOAD) is another option.
 
 PublicInbox::WWW
 
index 7d0690b42ad523fac3b428ac4b50a4de0b364a15..892ee0f22d458ce3de086cdaccba3911ee5d8f57 100644 (file)
@@ -165,11 +165,10 @@ 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) reduces
-overall fragmentation compared to glibc malloc in long-lived processes.
-glibc malloc users may try setting C<MALLOC_MMAP_THRESHOLD_> to a lower
-value (e.g. 131072) but that may require increasing the
-C<sys.vm.max_map_count> sysctl.
+glibc malloc users should use C<MALLOC_MMAP_THRESHOLD_=131072> to reduce
+fragmentation from the sliding mmap window.  jemalloc (tested as an
+LD_PRELOAD on GNU/Linux) also reduces fragmentation compared to an
+unconfigured glibc malloc in long-lived processes.
 
 =head2 Other OS tuning knobs
 
index 11859198e49497d106b7eccfc4969cd5c4e65408..ca68fc7ef6809d31a5643414dd74bc8a7dce9752 100644 (file)
@@ -19,6 +19,7 @@ After = public-inbox-httpd.socket
 Environment = PI_CONFIG=/home/pi/.public-inbox/config \
 PATH=/usr/local/bin:/usr/bin:/bin \
 TZ=UTC \
+MALLOC_MMAP_THRESHOLD_=131072 \
 PERL_INLINE_DIRECTORY=/tmp/.pub-inline
 
 LimitNOFILE = 30000
index 801046056ca3ff38f2f5384ba6ce719795e1a131..1aede65dd847aa3f4eb0fce7c9ce80bf407b1474 100644 (file)
@@ -16,6 +16,8 @@ After = public-inbox-imapd.socket
 [Service]
 Environment = PI_CONFIG=/home/pi/.public-inbox/config \
 PATH=/usr/local/bin:/usr/bin:/bin \
+TZ=UTC \
+MALLOC_MMAP_THRESHOLD_=131072 \
 PERL_INLINE_DIRECTORY=/tmp/.pub-inline
 
 LimitNOFILE = 30000
index 7437f086730a136e7877d9b6083861e656de06e8..51f58fbb21aa87366beca7158630389dbe2818db 100644 (file)
@@ -12,14 +12,15 @@ Wants = public-inbox-netd.socket
 After = public-inbox-netd.socket
 
 [Service]
-# An LD_PRELOAD for libjemalloc can be added here.  It is
-# more resistant to fragmentation in long-lived daemons than glibc.
-# If you're unable to use jemalloc, setting MALLOC_MMAP_THRESHOLD_
-# to a lower value (e.g. 131072) but that may also require increasing
-# the sys.vm.max_map_count sysctl.
+
+# Setting MALLOC_MMAP_THRESHOLD_=131072 reduces fragmentation by
+# disabling the sliding mmap window in glibc malloc.  An LD_PRELOAD for
+# libjemalloc may be added here, instead.  jemalloc is more resistant to
+# fragmentation in long-lived daemons than unconfigured glibc malloc.
 Environment = PI_CONFIG=/home/pi/.public-inbox/config \
 PATH=/usr/local/bin:/usr/bin:/bin \
 TZ=UTC \
+MALLOC_MMAP_THRESHOLD_=131072 \
 PERL_INLINE_DIRECTORY=/tmp/.netd-inline
 
 LimitNOFILE = 30000
index 24f9ca730ed7060e7bee3f5f6fd163beb1dca521..556cb76fcb262dc045e4b6146c207c8b8be0b186 100644 (file)
@@ -16,6 +16,8 @@ After = public-inbox-nntpd.socket
 [Service]
 Environment = PI_CONFIG=/home/pi/.public-inbox/config \
 PATH=/usr/local/bin:/usr/bin:/bin \
+TZ=UTC \
+MALLOC_MMAP_THRESHOLD_=131072 \
 PERL_INLINE_DIRECTORY=/tmp/.pub-inline
 
 LimitNOFILE = 30000