Optimise readng large number --server options at start up.

When re-reading upstream servers from /etc/resolv.conf or other
sources that can change dnsmasq tries to avoid memory fragmentation by
re-using existing records that are being re-read unchanged. This
involves seaching all the server records for each new one installed.
During startup this search is pointless, and can cause long start
times with thousands of --server options because the work needed is
O(n^2). Handle this case more intelligently.  Thanks to Ye Zhou for
spotting the problem and an initial patch.
This commit is contained in:
Simon Kelley
2022-11-21 16:40:53 +00:00
parent d6d7527c95
commit 881eaa4dbc
3 changed files with 49 additions and 21 deletions

View File

@@ -5753,7 +5753,10 @@ void read_opts(int argc, char **argv, char *compile_opts)
#endif
add_txt("servers.bind", NULL, TXT_STAT_SERVERS);
#endif
/* See comment above make_servers(). Optimises server-read code. */
mark_servers(0);
while (1)
{
#ifdef HAVE_GETOPT_LONG