mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
Optimise TLS stream for small write size (>= 512 bytes)
This commit changes TLS stream behaviour in such a way, that it is now optimised for small writes. In the case there is a need to write less or equal to 512 bytes, we could avoid calling the memory allocator at the expense of possibly slight increase in memory usage. In case of larger writes, the behviour remains unchanged.
This commit is contained in:
@@ -754,6 +754,7 @@ typedef struct isc_nmsocket_tls_send_req {
|
||||
void *cbarg;
|
||||
isc_nmhandle_t *handle;
|
||||
bool finish;
|
||||
uint8_t smallbuf[512];
|
||||
} isc_nmsocket_tls_send_req_t;
|
||||
|
||||
typedef enum isc_http_request_type {
|
||||
|
@@ -123,8 +123,15 @@ tls_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||
}
|
||||
}
|
||||
|
||||
/* We are tying to avoid a memory allocation for small write
|
||||
* requests. See the mirroring code in the tls_send_outgoing()
|
||||
* function. */
|
||||
if (ISC_UNLIKELY(send_req->data.length > sizeof(send_req->smallbuf))) {
|
||||
isc_mem_put(handle->sock->mgr->mctx, send_req->data.base,
|
||||
send_req->data.length);
|
||||
} else {
|
||||
INSIST(&send_req->smallbuf[0] == send_req->data.base);
|
||||
}
|
||||
isc_mem_put(handle->sock->mgr->mctx, send_req, sizeof(*send_req));
|
||||
tlssock->tlsstream.nsending--;
|
||||
|
||||
@@ -236,11 +243,15 @@ tls_send_outgoing(isc_nmsocket_t *sock, bool finish, isc_nmhandle_t *tlshandle,
|
||||
}
|
||||
|
||||
send_req = isc_mem_get(sock->mgr->mctx, sizeof(*send_req));
|
||||
*send_req = (isc_nmsocket_tls_send_req_t){
|
||||
.finish = finish,
|
||||
.data.base = isc_mem_get(sock->mgr->mctx, pending),
|
||||
.data.length = pending
|
||||
};
|
||||
*send_req = (isc_nmsocket_tls_send_req_t){ .finish = finish,
|
||||
.data.length = pending };
|
||||
|
||||
/* Let's try to avoid a memory allocation for small write requests */
|
||||
if (ISC_UNLIKELY((size_t)pending > sizeof(send_req->smallbuf))) {
|
||||
send_req->data.base = isc_mem_get(sock->mgr->mctx, pending);
|
||||
} else {
|
||||
send_req->data.base = &send_req->smallbuf[0];
|
||||
}
|
||||
|
||||
isc__nmsocket_attach(sock, &send_req->tlssock);
|
||||
if (cb != NULL) {
|
||||
|
Reference in New Issue
Block a user