]> git.ipfire.org Git - thirdparty/knot-resolver.git/commit
daemon/session2: optimize allocations
authorOto Šťáva <oto.stava@nic.cz>
Wed, 22 May 2024 13:18:30 +0000 (15:18 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Tue, 4 Jun 2024 11:05:00 +0000 (13:05 +0200)
commit9f6042c38851ebd3494810e2227ea4ffa0534648
tree15c844111a027673ddfbf7d1e09bbd814cc69b65
parentb475d004170fd4abe8b967b9f08f5c9472dbdbbb
daemon/session2: optimize allocations

A) Context-specific allocations
-------------------------------

There were two problems:

1) Some payloads are short-lived (e.g. allocated on stack) and we need
   to make a copy of them if the iteration over protocol layers becomes
   asynchronous.
2) The `pl_dns_stream_wrap` function used a mempool belonging to its
   session-wide context. Some sessions may live for a long time, which
   could potentially lead to needlessly long-lived memory allocations.

Both of these problems are solved in this commit by using a new
`knot_mm_t pool` field in `struct protolayer_iter_ctx`, which lives only
for a single submit (and survives asynchronicity). The whole pool is
then freed all at once when the `struct protolayer_iter_ctx` is
finalized.

B) Merging `struct protolayer_manager` into `struct session2`
-------------------------------------------------------------

It actually made no real sense to have the two separated. It only
introduced an extra layer of indirection and many layers actually needed
to access both anyway. This should simplify things considerably.
daemon/http.c
daemon/io.c
daemon/proxyv2.c
daemon/session2.c
daemon/session2.h
daemon/tls.c
daemon/worker.c