worker: remove freelists for iohandle and iorequest

A quick profiling showed no change in performance,
and in particular no change in time spent in malloc/free.
Some of the types in the union differed in size by a multiple.

If their performance won't be satisfying, replacements should be
considered first (e.g. jemalloc) before rolling our own stuff.
parent c4608cce
......@@ -34,8 +34,6 @@
} \
} while (0)
void io_release(uv_handle_t *handle);
static void check_bufsize(uv_handle_t* handle)
{
/* We want to buffer at least N waves in advance.
......@@ -235,11 +233,10 @@ static void _tcp_accept(uv_stream_t *master, int status, bool tls)
}
struct worker_ctx *worker = (struct worker_ctx *)master->loop->data;
uv_stream_t *client = worker_iohandle_borrow(worker);
uv_stream_t *client = malloc(sizeof(uv_tcp_t));
if (!client) {
return;
}
memset(client, 0, sizeof(*client));
int res = io_create(master->loop, (uv_handle_t *)client, SOCK_STREAM, AF_UNSPEC);
if (res) {
if (res == UV_EMFILE) {
......@@ -249,7 +246,7 @@ static void _tcp_accept(uv_stream_t *master, int status, bool tls)
/* Since res isn't OK struct session wasn't allocated \ borrowed.
* We must release client handle only.
*/
worker_iohandle_release(worker, client);
free(client);
return;
}
......@@ -448,17 +445,6 @@ void io_free(uv_handle_t *handle)
free(handle);
}
void io_release(uv_handle_t *handle)
{
if (!handle) {
return;
}
uv_loop_t *loop = handle->loop;
struct worker_ctx *worker = loop->data;
io_deinit(handle);
worker_iohandle_release(worker, handle);
}
int io_start_read(uv_handle_t *handle)
{
switch (handle->type) {
......
......@@ -35,12 +35,9 @@ struct session {
static void on_session_close(uv_handle_t *handle)
{
uv_loop_t *loop = handle->loop;
struct worker_ctx *worker = loop->data;
struct session *session = handle->data;
assert(session->handle == handle);
io_deinit(handle);
worker_iohandle_release(worker, handle);
io_free(handle);
}
static void on_session_timer_close(uv_handle_t *timer)
......
This diff is collapsed.
......@@ -74,10 +74,6 @@ struct session *worker_session_borrow(struct worker_ctx *worker);
void worker_session_release(struct worker_ctx *worker, uv_handle_t *handle);
void *worker_iohandle_borrow(struct worker_ctx *worker);
void worker_iohandle_release(struct worker_ctx *worker, void *h);
int worker_task_step(struct qr_task *task, const struct sockaddr *packet_source,
knot_pkt_t *packet);
......@@ -163,35 +159,9 @@ struct worker_ctx {
/** Subrequest leaders (struct qr_task*), indexed by qname+qtype+qclass. */
trie_t *subreq_out;
mp_freelist_t pool_mp;
mp_freelist_t pool_ioreqs;
mp_freelist_t pool_sessions;
mp_freelist_t pool_iohandles;
knot_mm_t pkt_pool;
};
/* @internal Union of some libuv handles for freelist.
* These have session as their `handle->data` and own it.
* Subset of uv_any_handle. */
union uv_handles {
uv_handle_t handle;
uv_stream_t stream;
uv_udp_t udp;
uv_tcp_t tcp;
uv_timer_t timer;
};
typedef union uv_any_handle uv_handles_t;
/* @internal Union of derivatives from uv_req_t libuv request handles for freelist.
* These have only a reference to the task they're operating on.
* Subset of uv_any_req. */
union uv_reqs {
uv_req_t req;
uv_shutdown_t sdown;
uv_write_t write;
uv_connect_t connect;
uv_udp_send_t send;
};
typedef union uv_reqs uv_reqs_t;
/** @endcond */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment