2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

19 Commits

Author SHA1 Message Date
Tony Finch
4b5ec07bb7 Refactor qp-trie to use QSBR
The first working multi-threaded qp-trie was stuck with an unpleasant
trade-off:

  * Use `isc_rwlock`, which has acceptable write performance, but
    terrible read scalability because the qp-trie made all accesses
    through a single lock.

  * Use `liburcu`, which has great read scalability, but terrible
    write performance, because I was relying on `rcu_synchronize()`
    which is rather slow. And `liburcu` is LGPL.

To get the best of both worlds, we need our own scalable read side,
which we now have with `isc_qsbr`. And we need to modify the write
side so that it is not blocked by readers.

Better write performance requires an async cleanup function like
`call_rcu()`, instead of the blocking `rcu_synchronize()`. (There
is no blocking cleanup in `isc_qsbr`, because I have concluded
that it would be an attractive nuisance.)

Until now, all my multithreading qp-trie designs have been based
around two versions, read-only and mutable. This is too few to
work with asynchronous cleanup. The bare minimum (as in epoch
based reclamation) is three, but it makes more sense to support an
arbitrary number. Doing multi-version support "properly" makes
fewer assumptions about how safe memory reclamation works, and it
makes snapshots and rollbacks simpler.

To avoid making the memory management even more complicated, I
have introduced a new kind of "packed reader node" to anchor the
root of a version of the trie. This is simpler because it re-uses
the existing chunk lifetime logic - see the discussion under
"packed reader nodes" in `qp_p.h`.

I have also made the chunk lifetime logic simpler. The idea of a
"generation" is gone; instead, chunks are either mutable or
immutable. And the QSBR phase number is used to indicate when a
chunk can be reclaimed.

Instead of the `shared_base` flag (which was basically a one-bit
reference count, with a two version limit) the base array now has a
refcount, which replaces the confusing ad-hoc lifetime logic with
something more familiar and systematic.
2023-02-27 13:47:55 +00:00
Tony Finch
4b09c9a6ae qp-trie naming improvements
Adjust to typename_operation style
	s/VALID_QP/QP_VALID/g
	s/QP_VALIDMULTI/QPMULTI_VALID/g

Improved greppability
	s/\bctx\b/uctx/g

Less cluttered logging
	s/QP_TRACE/TRACE/g
	s/QP_LOG_STATS/LOG_STATS/g
2023-02-27 13:47:25 +00:00
Tony Finch
c1c679b1a9 Test infrastructure for the qp-trie
This change adds a number of support routines for the unit tests, and
for benchmarks and fuzz tests to be added later. It isn't necessary to
include the support routines in libdns, since they are not needed by
BIND's installed programs. So `libtest` seems like the best place for
them.

The tests themselves verify that dns_qpkey_fromname() behaves as
expected.
2023-02-27 13:47:25 +00:00
Evan Hunt
7975b785fd Support for relative names in unit tests
The dns_test_namefromstring() function can now generate relative
names, and all the tests that used it before it have been updated
to use FQDNs.
2023-02-27 13:47:25 +00:00
Evan Hunt
a52b17d39b
remove isc_task completely
as there is no further use of isc_task in BIND, this commit removes
it, along with isc_taskmgr, isc_event, and all other related types.

functions that accepted taskmgr as a parameter have been cleaned up.
as a result of this change, some functions can no longer fail, so
they've been changed to type void, and their callers have been
updated accordingly.

the tasks table has been removed from the statistics channel and
the stats version has been updated. dns_dyndbctx has been changed
to reference the loopmgr instead of taskmgr, and DNS_DYNDB_VERSION
has been udpated as well.
2023-02-16 18:35:32 +01:00
Tony Finch
6927a30926 Remove do-nothing header <isc/print.h>
This one really truly did nothing. No lines added!
2023-02-15 16:44:47 +00:00
Mark Andrews
cdcd605ede Increase the number of available file descriptors
notify_test and query_test run out of descriptors on some platforms.

    % ./notify_test
    [==========] Running 1 test(s).
    [ RUN      ] notify_start
    netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace
    0   libisc-9.19.9-dev.dylib             0x00000001045c5080 default_callback + 72
    1   libisc-9.19.9-dev.dylib             0x00000001045c4ffc isc_assertion_failed + 56
    2   libisc-9.19.9-dev.dylib             0x00000001045b8bcc start_tcp_child + 304
    3   libisc-9.19.9-dev.dylib             0x00000001045b8710 isc_nm_listentcp + 636
    4   libisc-9.19.9-dev.dylib             0x00000001045b3e0c isc_nm_listenstreamdns + 344
    5   libns-9.19.9-dev.dylib              0x0000000104b90630 ns_interface_listentcp + 152
    6   libns-9.19.9-dev.dylib              0x0000000104b8f65c interface_setup + 488
    7   libns-9.19.9-dev.dylib              0x0000000104b8de98 do_scan + 2028
    8   libns-9.19.9-dev.dylib              0x0000000104b8d640 ns_interfacemgr_scan + 212
    9   notify_test                         0x000000010418ddd0 scan_interfaces + 44
    10  libisc-9.19.9-dev.dylib             0x00000001045d5fd8 isc__job_cb + 116
    11  libuv.1.dylib                       0x000000010545afe4 uv__run_idle + 152
    12  libuv.1.dylib                       0x0000000105455cd0 uv_run + 204
    13  libisc-9.19.9-dev.dylib             0x00000001045e1120 loop_run + 460
    14  libisc-9.19.9-dev.dylib             0x00000001045df824 loop_thread + 44
    15  libisc-9.19.9-dev.dylib             0x00000001045df6dc isc_loopmgr_run + 456
    16  notify_test                         0x000000010418b900 run_test_notify_start + 88
    17  libcmocka.0.dylib                   0x00000001054968c0 cmocka_run_one_test_or_fixture + 448
    18  libcmocka.0.dylib                   0x0000000105494ca4 _cmocka_run_group_tests + 848
    19  notify_test                         0x000000010418be60 main + 120
    20  libdyld.dylib                       0x0000000181509430 start + 4
    Abort
    % ./query_test
    [==========] Running 4 test(s).
    [ RUN      ] ns__query_sfcache
    netmgr/tcp.c:369: REQUIRE(csock->fd >= 0) failed, back trace
    0   libisc-9.19.9-dev.dylib             0x000000010294d080 default_callback + 72
    1   libisc-9.19.9-dev.dylib             0x000000010294cffc isc_assertion_failed + 56
    2   libisc-9.19.9-dev.dylib             0x0000000102940bcc start_tcp_child + 304
    3   libisc-9.19.9-dev.dylib             0x0000000102940710 isc_nm_listentcp + 636
    4   libisc-9.19.9-dev.dylib             0x000000010293be0c isc_nm_listenstreamdns + 344
    5   libns-9.19.9-dev.dylib              0x00000001026cc630 ns_interface_listentcp + 152
    6   libns-9.19.9-dev.dylib              0x00000001026cb65c interface_setup + 488
    7   libns-9.19.9-dev.dylib              0x00000001026c9e98 do_scan + 2028
    8   libns-9.19.9-dev.dylib              0x00000001026c9640 ns_interfacemgr_scan + 212
    9   query_test                          0x00000001026a1018 scan_interfaces + 44
    10  libisc-9.19.9-dev.dylib             0x000000010295dfd8 isc__job_cb + 116
    11  libuv.1.dylib                       0x0000000103996fe4 uv__run_idle + 152
    12  libuv.1.dylib                       0x0000000103991cd0 uv_run + 204
    13  libisc-9.19.9-dev.dylib             0x0000000102969120 loop_run + 460
    14  libisc-9.19.9-dev.dylib             0x0000000102967824 loop_thread + 44
    15  libisc-9.19.9-dev.dylib             0x00000001029676dc isc_loopmgr_run + 456
    16  query_test                          0x000000010269cf34 run_test_ns__query_sfcache + 88
    17  libcmocka.0.dylib                   0x00000001028068c0 cmocka_run_one_test_or_fixture + 448
    18  libcmocka.0.dylib                   0x0000000102804ca4 _cmocka_run_group_tests + 848
    19  query_test                          0x000000010269eab8 main + 116
    20  libdyld.dylib                       0x0000000181509430 start + 4
    Abort
    %

expected_creads can exceed the number of file descriptors on some
platforms.

    % ./udp_test
    [==========] Running 18 test(s).
    [ RUN      ] mock_listenudp_uv_udp_open
    [       OK ] mock_listenudp_uv_udp_open
    [ RUN      ] mock_listenudp_uv_udp_bind
    [       OK ] mock_listenudp_uv_udp_bind
    [ RUN      ] mock_listenudp_uv_udp_recv_start
    [       OK ] mock_listenudp_uv_udp_recv_start
    [ RUN      ] mock_udpconnect_uv_udp_open
    [       OK ] mock_udpconnect_uv_udp_open
    [ RUN      ] mock_udpconnect_uv_udp_bind
    [       OK ] mock_udpconnect_uv_udp_bind
    [ RUN      ] mock_udpconnect_uv_udp_connect
    [       OK ] mock_udpconnect_uv_udp_connect
    [ RUN      ] mock_udpconnect_uv_recv_buffer_size
    [       OK ] mock_udpconnect_uv_recv_buffer_size
    [ RUN      ] mock_udpconnect_uv_send_buffer_size
    [       OK ] mock_udpconnect_uv_send_buffer_size
    [ RUN      ] udp_noop
    [       OK ] udp_noop
    [ RUN      ] udp_noresponse
    [       OK ] udp_noresponse
    [ RUN      ] udp_shutdown_connect
    [       OK ] udp_shutdown_connect
    [ RUN      ] udp_shutdown_read
    [       OK ] udp_shutdown_read
    [ RUN      ] udp_cancel_read
    [       OK ] udp_cancel_read
    [ RUN      ] udp_timeout_recovery
    [       OK ] udp_timeout_recovery
    [ RUN      ] udp_double_read
    [       OK ] udp_double_read
    [ RUN      ] udp_recv_one
    [       OK ] udp_recv_one
    [ RUN      ] udp_recv_two
    [       OK ] udp_recv_two
    [ RUN      ] udp_recv_send
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    udp__connect_cb(0x0, too many open files, 0x0)
    %
2023-01-11 10:44:07 +00:00
Evan Hunt
916ea26ead remove nonfunctional DSCP implementation
DSCP has not been fully working since the network manager was
introduced in 9.16, and has been completely broken since 9.18.
This seems to have caused very few difficulties for anyone,
so we have now marked it as obsolete and removed the
implementation.

To ensure that old config files don't fail, the code to parse
dscp key-value pairs is still present, but a warning is logged
that the feature is obsolete and should not be used. Nothing is
done with configured values, and there is no longer any
range checking.
2023-01-09 12:15:21 -08:00
Ondřej Surý
e2262c2112
Remove isc_resource API and set limits directly in named_os unit
The only function left in the isc_resource API was setting the file
limit.  Replace the whole unit with a simple getrlimit to check the
maximum value of RLIMIT_NOFILE and set the maximum back to rlimit_cur.

This is more compatible than trying to set RLIMIT_UNLIMITED on the
RLIMIT_NOFILE as it doesn't work on Linux (see man 5 proc on
/proc/sys/fs/nr_open), neither it does on Darwin kernel (see man 2
getrlimit).

The only place where the maximum value could be raised under privileged
user would be BSDs, but the `named_os_adjustnofile()` were not called
there before.  We would apply the increased limits only on Linux and Sun
platforms.
2022-12-07 19:40:00 +01:00
Evan Hunt
09ee254514 change dns_db_settask() to _setloop()
The mechanism for associating a worker task to a database now
uses loops rather than tasks.

For this reason, the parameters to dns_cache_create() have been
updated to take a loop manager rather than a task manager.
2022-11-30 11:47:35 -08:00
Ondřej Surý
fa275a59da Remove the unused cache cleaning mechanism from dns_cache API
The dns_cache API contained a cache cleaning mechanism that would be
disabled for 'rbt' based cache.  As named doesn't have any other cache
implementations, remove the cache cleaning mechanism from dns_cache API.
2022-11-29 13:48:33 -08:00
Michal Nowak
afdb41a5aa
Update sources to Clang 15 formatting 2022-11-29 08:54:34 +01:00
Ondřej Surý
6ba0a22627
Change the return type of isc_lex_create() to void
The isc_lex_create() cannot fail, so cleanup the return type from
isc_result_t to void.
2022-10-26 12:55:06 +02:00
Tony Finch
45b2d8938b
Simplify and speed up DNS name compression
All we need for compression is a very small hash set of compression
offsets, because most of the information we need (the previously added
names) can be found in the message using the compression offsets.

This change combines dns_compress_find() and dns_compress_add() into
one function dns_compress_name() that both finds any existing suffix,
and adds any new prefix to the table. The old split led to performance
problems caused by duplicate names in the compression context.

Compression contexts are now either small or large, which the caller
chooses depending on the expected size of the message. There is no
dynamic resizing.

There is a behaviour change: compression now acts on all the labels in
each name, instead of just the last few.

A small benchmark suggests this is about 2x faster.
2022-10-17 08:45:44 +02:00
Ondřej Surý
b69e783164
Update netmgr, tasks, and applications to use isc_loopmgr
Previously:

* applications were using isc_app as the base unit for running the
  application and signal handling.

* networking was handled in the netmgr layer, which would start a
  number of threads, each with a uv_loop event loop.

* task/event handling was done in the isc_task unit, which used
  netmgr event loops to run the isc_event calls.

In this refactoring:

* the network manager now uses isc_loop instead of maintaining its
  own worker threads and event loops.

* the taskmgr that manages isc_task instances now also uses isc_loopmgr,
  and every isc_task runs on a specific isc_loop bound to the specific
  thread.

* applications have been updated as necessary to use the new API.

* new ISC_LOOP_TEST macros have been added to enable unit tests to
  run isc_loop event loops. unit tests have been updated to use this
  where needed.
2022-08-26 09:09:24 +02:00
Ondřej Surý
84c90e223f
New event loop handling API
This commit introduces new APIs for applications and signal handling,
intended to replace isc_app for applications built on top of libisc.

* isc_app will be replaced with isc_loopmgr, which handles the
  starting and stopping of applications. In isc_loopmgr, the main
  thread is not blocked, but is part of the working thread set.
  The loop manager will start a number of threads, each with a
  uv_loop event loop running. Setup and teardown functions can be
  assigned which will run when the loop starts and stops, and
  jobs can be scheduled to run in the meantime. When
  isc_loopmgr_shutdown() is run from any the loops, all loops
  will shut down and the application can terminate.

* signal handling will now be handled with a separate isc_signal unit.
  isc_loopmgr only handles SIGTERM and SIGINT for application
  termination, but the application may install additional signal
  handlers, such as SIGHUP as a signal to reload configuration.

* new job running primitives, isc_job and isc_async, have been added.
  Both units schedule callbacks (specifying a callback function and
  argument) on an event loop. The difference is that isc_job unit is
  unlocked and not thread-safe, so it can be used to efficiently
  run jobs in the same thread, while isc_async is thread-safe and
  uses locking, so it can be used to pass jobs from one thread to
  another.

* isc_tid will be used to track the thread ID in isc_loop worker
  threads.

* unit tests have been added for the new APIs.
2022-08-25 12:24:29 +02:00
Ondřej Surý
714fe2f617 Don't list libtest.la headers in HEADERS variable
The libtest.la headers were installed in very weird place, in fact, we
don't need to list them in the HEADERS variable, listing them in SOURCES
is enough for autotools to figure out how to compile the convenience
library.
2022-06-01 17:08:37 +02:00
Tony Finch
e37b782c1a DNS name compression does not depend on the EDNS version
There was a proposal in the late 1990s that it might, but it turned
out to be unworkable. See RFC 6891, Extension Mechanisms for
DNS (EDNS(0)), section 5, Extended Label Types.

The remnants of the code that supported this in BIND are redundant.
2022-06-01 13:00:40 +01:00
Evan Hunt
568f65cc56 Stop the unit tests from running twice
Move the libtest code into a 'libtest' subdirectory and make it
one of the SUBDIRS in the tests Makefile. having it at the top level
required having "." as one of the subdirs, and that caused the
unit tests to be executed twice.
2022-05-28 14:53:02 -07:00