<div dir="ltr"><p>Hi Simon,</p><ul><li style="margin-left:15px"><p> OpenWrt defaults to musl and this cannot be changed. It’s the standard environment for millions of these devices.</p></li><li style="margin-left:15px"><p>The script is an "accelerator", Sub-second SIGHUPs aren't as rare as my case, Each time an IPv6 address expires, when OpenWrt maintains the mapping between local domain names and IP addresses, it triggers SIGHUP multiple times within one second. I have previously posted the actual logs about this on GitHub. —in my case, the exhaustion takes weeks to show up, which is why this bug has haunted me for years. The script is just to speed up the observation.</p></li><li style="margin-left:15px"><p>Even at 100 SIGHUPs per second, the memory rises slowly—it’s just a matter of duration. However, using a larger config file will significantly speed up this process.<br>Here is a much more slow script with at most 100 SIGHUPs per second to expose this behavior<br><span style="color:rgb(227,227,227);font-family:"Google Sans Flex","Google Sans","Helvetica Neue",sans-serif;font-size:16px;font-variant-ligatures:none;background-color:rgb(30,31,32)">while :;do top -bn1 | grep [d]nsmasq  |grep -v ujail | awk '{print $3 "| Memory is about: " $5*1024 " B"}';sleep 1;done <br><br>while :;do PID=$(pidof dnsmasq);for i in $(seq 1 100); do kill -SIGHUP $PID;sleep 1; done;done</span></p></li><li style="margin-left:15px"><p>If you throttle the VM's RAM and CPU, the trend becomes obvious much sooner. You don't need half a million HUPs to see it if the system resources are constrained.<br>I have an x86_64 VM image ready with the latest OpenWrt snapshot if you want to test it in a this environment.<br><br></p></li></ul><div>Regards.<br><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Simon Kelley <<a href="mailto:simon@thekelleys.org.uk">simon@thekelleys.org.uk</a>> 于2026年1月31日周六 00:53写道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I just sent SIGHUP twice in succession to the dnsmasq process in my <br>
OpenWRT router, with the new malloc-logging feature enabled.<br>
<br>
HUP frees a load of configuration and the re-reads it and I correlated <br>
all the memory freed by the second HUP with what was allocated in the <br>
first HUP.<br>
<br>
It's perfect. Every block is freed.<br>
<br>
<br>
This is a fairly old installation, so old libraries, etc, but the very <br>
latest dnsmasq code.<br>
<br>
The configuration it's re-reading is pretty small.<br>
<br>
I then tried your technique of hitting dnsmasq hard with many HUPs.<br>
<br>
I had to go up to half a million to see much effect, but I guess most of <br>
those were dropped since they will have arrived before the previous one <br>
was cleared.<br>
<br>
In any case I could see a reproducible rise of a few percent in the VSZ <br>
of the process each time.<br>
<br>
What's clear is that the configuration is stored in a _lot_ of small <br>
allocations, so re-reading a substantial configuration  will free a lot <br>
of small blocks and then malloc a lot of small blocks.<br>
<br>
A quick Google produces some complaints about the fragmentation <br>
performance of musl, which may be significant.<br>
<br>
Is your installation using musl as the C library, and is it possible to <br>
build dnsmasq against, say glibc to test?<br>
<br>
Nearly all of the memory management on dnsmasq that gets hit by <br>
answering DNS or DHCP requests avoid hammering the malloc system by <br>
building pools of free data structures that get re-cycled as needed. <br>
Once the pools have grown to equilibrium size, even a very busy server <br>
hardly uses the heap. I guess the configuration code to use the same <br>
policy, but it's a big re-write, and re-reading configuration on a <br>
sub-second timescale is an unlikely use-case.<br>
<br>
<br>
<br>
<br>
Cheers,<br>
<br>
Simon.<br>
<br>
<br>
<br>
<br>
<br>
On 30.01.2026 01:59, Y.Y. wrote:<br>
> *Hi Simon,*<br>
> <br>
> I think Your suspicion about the configuration re-reading logic is spot <br>
> on. I have documented the reproduction and some analysis here: https:// <br>
> <a href="http://github.com/openwrt/openwrt/issues/21729#issuecomment-3815442601" rel="noreferrer" target="_blank">github.com/openwrt/openwrt/issues/21729#issuecomment-3815442601</a> <br>
> <<a href="https://github.com/openwrt/openwrt/issues/21729#issuecomment-3815442601" rel="noreferrer" target="_blank">https://github.com/openwrt/openwrt/issues/21729#issuecomment-3815442601</a>><br>
> <br>
> To assist with the debugging, I can provide an OpenWrt *Linux x86_64 VM <br>
> image* that consistently reproduces this memory leak. Please let me know <br>
> if this would be helpful for your investigation.<br>
> <br>
> <br>
> _______________________________________________<br>
> Dnsmasq-discuss mailing list<br>
> <a href="mailto:Dnsmasq-discuss@lists.thekelleys.org.uk" target="_blank">Dnsmasq-discuss@lists.thekelleys.org.uk</a><br>
> <a href="https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss" rel="noreferrer" target="_blank">https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss</a><br>
<br>
<br>
_______________________________________________<br>
Dnsmasq-discuss mailing list<br>
<a href="mailto:Dnsmasq-discuss@lists.thekelleys.org.uk" target="_blank">Dnsmasq-discuss@lists.thekelleys.org.uk</a><br>
<a href="https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss" rel="noreferrer" target="_blank">https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss</a><br>
</blockquote></div>