[Dnsmasq-discuss] Memory usage growing over time — possibly due to logging or caching (v2.90 / OpenEmbedded kirkstone)
Geert Stappers
stappers at stappers.nl
Mon Apr 14 19:48:53 UTC 2025
On Mon, Apr 14, 2025 at 12:55:03PM -0400, Nitesh Divecha via Dnsmasq-discuss wrote:
>
> On Apr 14, 2025, at 10:48 AM, Simon Kelley wrote:
> >
> > Do you only see this memory-size growth when logging to a file? It's
> > possible that there's a memory leak elsewhere, but unlikely that
> > one that big could have been undetected until now.
> >
> > It's possible that the libc in use is memory-mapping the log
> > file. Dnsmasq uses very standard open() and write() calls, but it's
> > up to the libc how it implements that. Memory-mapping the file and
> > converting write() calls to memory writes would be a legitimate
> > thing to do. In this case some measures of the process's memory
> > usage would increase, but the actual physical RAM usage would not -
> > long untouched pages will be written out to the filesystem and the
> > RAM freed for reuse, just like swapping.
> >
> > Dnsmasq allows log-file rotation in the conventional way. The
> > simplest thing to do is to delete the log file and then send the
> > dnsmasq process SIGUSR2. That makes dnsmasq close and reopen the
> > file. The close removes the last reference to the deleted file and
> > its disk storage is freed-up. The re-open creates a new log file
> > which begins empty. Real logfile rotation renames the live file
> > instead of deleting it, and only deletes old logfiles after a few
> > days: see man logrotate for details on that.
> >
>
> Yes, when I turn on --log-facility=/var/log/dnsmasq.log, I see memory-size growing.
:-)
> # systemctl status dnsmasq
> * dnsmasq.service - DNS forwarder and DHCP server
> Active: active (running) since Sat 2025-04-12 21:27:30 UTC; 15h ago
> Memory: 16.3M
>
>
> # ls -lah /var/log/dnsmasq.log
> -rw-rw---- 1 nobody root 16M Apr 13 13:05 /var/log/dnsmasq.log
>
>
> And if I restart the service it will reset the log file and memory-size will go down.
>
> # systemctl status dnsmasq --no-pager
> ● dnsmasq.service - DNS forwarder and DHCP server
> Active: active (running) since Mon 2025-04-14 16:08:27 UTC; 43min ago
> Memory: 1.3M
>
> # ls -lah /var/log/dnsmasq.log
> -rw-rw---- 1 nobody root 1.2M Apr 14 16:52 /var/log/dnsmasq.log
>
Groeten
Geert Stappers
--
Silence is hard to parse
More information about the Dnsmasq-discuss
mailing list