Merge branch '4038-resize-send-buffers-to-avoid-excessive-memory-allocation' into 'main'

Use appropriately sized send buffers for DNS messages over TCP

Closes #4038

See merge request isc-projects/bind9!8004
This commit is contained in:
Ondřej Surý
2023-06-06 11:41:44 +00:00
4 changed files with 24 additions and 6 deletions

View File

@@ -1,3 +1,7 @@
6188. [performance] Reduce memory consumption by allocating properly
sized send buffers for stream-based transports.
[GL #4038]
6187. [bug] Address view shutdown INSIST when accessing the
zonetable. [GL #4093]

View File

@@ -64,6 +64,10 @@ Bug Fixes
a delegation from cache was returned to the client. This has now been fixed.
:gl:`#3950`
- BIND could allocate too big buffers when sending data via
stream-based DNS transports, leading to increased memory usage.
This has been fixed. :gl:`#4038`
Known Issues
~~~~~~~~~~~~

View File

@@ -331,6 +331,7 @@ client_allocsendbuf(ns_client_t *client, isc_buffer_t *buffer,
INSIST(client->tcpbuf == NULL);
client->tcpbuf = isc_mem_get(client->manager->mctx,
NS_CLIENT_TCP_BUFFER_SIZE);
client->tcpbuf_size = NS_CLIENT_TCP_BUFFER_SIZE;
data = client->tcpbuf;
isc_buffer_init(buffer, data, NS_CLIENT_TCP_BUFFER_SIZE);
} else {
@@ -363,7 +364,17 @@ client_sendpkg(ns_client_t *client, isc_buffer_t *buffer) {
REQUIRE(client->sendhandle == NULL);
isc_buffer_usedregion(buffer, &r);
if (isc_buffer_base(buffer) == client->tcpbuf) {
size_t used = isc_buffer_usedlength(buffer);
client->tcpbuf = isc_mem_reget(client->manager->mctx,
client->tcpbuf,
client->tcpbuf_size, used);
client->tcpbuf_size = used;
r.base = client->tcpbuf;
r.length = used;
} else {
isc_buffer_usedregion(buffer, &r);
}
isc_nmhandle_attach(client->handle, &client->sendhandle);
if (isc_nm_is_http_handle(client->handle)) {
@@ -434,8 +445,7 @@ ns_client_sendraw(ns_client_t *client, dns_message_t *message) {
done:
if (client->tcpbuf != NULL) {
isc_mem_put(client->manager->mctx, client->tcpbuf,
NS_CLIENT_TCP_BUFFER_SIZE);
client->tcpbuf = NULL;
client->tcpbuf_size);
}
ns_client_drop(client, result);
@@ -719,8 +729,7 @@ renderend:
cleanup:
if (client->tcpbuf != NULL) {
isc_mem_put(client->manager->mctx, client->tcpbuf,
NS_CLIENT_TCP_BUFFER_SIZE);
client->tcpbuf = NULL;
client->tcpbuf_size);
}
if (cleanup_cctx) {
@@ -1609,7 +1618,7 @@ ns__client_reset_cb(void *client0) {
ns_client_endrequest(client);
if (client->tcpbuf != NULL) {
isc_mem_put(client->manager->mctx, client->tcpbuf,
NS_CLIENT_TCP_BUFFER_SIZE);
client->tcpbuf_size);
}
if (client->keytag != NULL) {

View File

@@ -171,6 +171,7 @@ struct ns_client {
(query, update, notify) */
isc_nmhandle_t *updatehandle; /* Waiting for update callback */
unsigned char *tcpbuf;
size_t tcpbuf_size;
dns_message_t *message;
unsigned char *sendbuf;
dns_rdataset_t *opt;