diff options
-rw-r--r-- | src/nxt_conn.h | 1 | ||||
-rw-r--r-- | src/nxt_conn_accept.c | 4 | ||||
-rw-r--r-- | src/nxt_event_engine.c | 9 | ||||
-rw-r--r-- | src/nxt_event_engine.h | 4 | ||||
-rw-r--r-- | src/nxt_router.c | 8 | ||||
-rw-r--r-- | src/nxt_sockaddr.c | 20 | ||||
-rw-r--r-- | src/nxt_sockaddr.h | 12 |
7 files changed, 27 insertions, 31 deletions
diff --git a/src/nxt_conn.h b/src/nxt_conn.h index c4cabd05..32cad432 100644 --- a/src/nxt_conn.h +++ b/src/nxt_conn.h @@ -103,7 +103,6 @@ typedef struct { uint32_t ready; uint32_t batch; - uint32_t mem_cache; /* 8 bits */ /* An accept() interface is cached to minimize memory accesses. */ nxt_work_handler_t accept; diff --git a/src/nxt_conn_accept.c b/src/nxt_conn_accept.c index 53bbe83e..fbafc553 100644 --- a/src/nxt_conn_accept.c +++ b/src/nxt_conn_accept.c @@ -46,8 +46,6 @@ nxt_listen_event(nxt_task_t *task, nxt_listen_socket_t *ls) engine = task->thread->engine; lev->batch = engine->batch; - lev->mem_cache = (uint32_t) -1; - lev->socket.read_work_queue = &engine->accept_work_queue; lev->socket.read_handler = nxt_conn_listen_handler; lev->socket.error_handler = nxt_conn_listen_event_error; @@ -105,7 +103,7 @@ nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev) c->socket.write_ready = 1; c->listen = lev; - c->remote = nxt_sockaddr_cache_alloc(engine, lev); + c->remote = nxt_sockaddr_cache_alloc(engine, lev->listen); if (nxt_fast_path(c->remote != NULL)) { return c; } diff --git a/src/nxt_event_engine.c b/src/nxt_event_engine.c index e275571c..0b40d552 100644 --- a/src/nxt_event_engine.c +++ b/src/nxt_event_engine.c @@ -556,10 +556,10 @@ nxt_event_engine_start(nxt_event_engine_t *engine) void * -nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint32_t *slot, +nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint8_t *slot, size_t size) { - uint32_t n; + uint8_t n; nxt_uint_t items; nxt_array_t *mem_cache; nxt_mem_cache_t *cache; @@ -568,7 +568,7 @@ nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint32_t *slot, mem_cache = engine->mem_cache; n = *slot; - if (n == (uint32_t) -1) { + if (n == (uint8_t) -1) { if (mem_cache == NULL) { /* IPv4 nxt_sockaddr_t and HTTP/1 and HTTP/2 buffers. */ @@ -618,7 +618,6 @@ nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint32_t *slot, if (block != NULL) { cache->free = block->next; cache->count--; - return block; } @@ -627,7 +626,7 @@ nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint32_t *slot, void -nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint32_t *slot, void *p) +nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint8_t *slot, void *p) { nxt_mem_cache_t *cache; nxt_mem_cache_block_t *block; diff --git a/src/nxt_event_engine.h b/src/nxt_event_engine.h index 329a5a64..7a7149e6 100644 --- a/src/nxt_event_engine.h +++ b/src/nxt_event_engine.h @@ -512,9 +512,9 @@ NXT_EXPORT void nxt_event_engine_post(nxt_event_engine_t *engine, NXT_EXPORT void nxt_event_engine_signal(nxt_event_engine_t *engine, nxt_uint_t signo); -void *nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint32_t *slot, +void *nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint8_t *slot, size_t size); -void nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint32_t *slot, +void nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint8_t *slot, void *p); diff --git a/src/nxt_router.c b/src/nxt_router.c index 32a3b9d3..a7842350 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -1301,6 +1301,7 @@ static void nxt_router_listen_socket_rpc_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf) { + size_t size; uint32_t stream; nxt_buf_t *b; nxt_port_t *main_port, *router_port; @@ -1315,13 +1316,14 @@ nxt_router_listen_socket_rpc_create(nxt_task_t *task, rpc->socket_conf = skcf; rpc->temp_conf = tmcf; - b = nxt_buf_mem_alloc(tmcf->mem_pool, skcf->sockaddr->sockaddr_size, 0); + size = nxt_sockaddr_size(skcf->sockaddr); + + b = nxt_buf_mem_alloc(tmcf->mem_pool, size, 0); if (b == NULL) { goto fail; } - b->mem.free = nxt_cpymem(b->mem.free, skcf->sockaddr, - skcf->sockaddr->sockaddr_size); + b->mem.free = nxt_cpymem(b->mem.free, skcf->sockaddr, size); rt = task->thread->runtime; main_port = rt->port_by_type[NXT_PROCESS_MAIN]; diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c index 38e2189e..af2b8674 100644 --- a/src/nxt_sockaddr.c +++ b/src/nxt_sockaddr.c @@ -21,23 +21,22 @@ static nxt_int_t nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs); nxt_sockaddr_t * -nxt_sockaddr_cache_alloc(nxt_event_engine_t *engine, nxt_listen_event_t *lev) +nxt_sockaddr_cache_alloc(nxt_event_engine_t *engine, nxt_listen_socket_t *ls) { - size_t size; - nxt_sockaddr_t *sa; - nxt_listen_socket_t *ls; - - ls = lev->listen; + uint8_t hint; + size_t size; + nxt_sockaddr_t *sa; + hint = (uint8_t) -1; size = offsetof(nxt_sockaddr_t, u) + ls->socklen + ls->address_length; - sa = nxt_event_engine_mem_alloc(engine, &lev->mem_cache, size); + sa = nxt_event_engine_mem_alloc(engine, &hint, size); if (nxt_fast_path(sa != NULL)) { /* Zero only beginning of structure up to sockaddr_un.sun_path[1]. */ nxt_memzero(sa, offsetof(nxt_sockaddr_t, u.sockaddr.sa_data[1])); - sa->sockaddr_size = size; + sa->cache_hint = hint; sa->socklen = ls->socklen; sa->length = ls->address_length; @@ -57,7 +56,7 @@ nxt_sockaddr_cache_alloc(nxt_event_engine_t *engine, nxt_listen_event_t *lev) void nxt_sockaddr_cache_free(nxt_event_engine_t *engine, nxt_conn_t *c) { - nxt_event_engine_mem_free(engine, &c->listen->mem_cache, c->remote); + nxt_event_engine_mem_free(engine, &c->remote->cache_hint, c->remote); } @@ -82,7 +81,6 @@ nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen, size_t address_length) if (nxt_fast_path(sa != NULL)) { sa->socklen = socklen; sa->length = address_length; - sa->sockaddr_size = size; } return sa; @@ -239,7 +237,7 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa) sa->port_start = offset; start = nxt_pointer_to(sa, offset); - end = nxt_pointer_to(sa, sa->sockaddr_size); + end = start + sa->length; switch (sa->u.sockaddr.sa_family) { diff --git a/src/nxt_sockaddr.h b/src/nxt_sockaddr.h index 6f2c4a77..ca5d8054 100644 --- a/src/nxt_sockaddr.h +++ b/src/nxt_sockaddr.h @@ -41,11 +41,9 @@ struct nxt_sockaddr_s { * Port length is (start + length) - port_start. */ uint8_t port_start; - /* - * Size of the whole structure: struct sockaddr union and maximal textual - * representation, used to place sockaddr into appropriate free list. - */ - uint8_t sockaddr_size; + + /* A cache hist used to place sockaddr into appropriate free list. */ + uint8_t cache_hint; union { struct sockaddr sockaddr; @@ -70,7 +68,7 @@ typedef struct { nxt_sockaddr_t *nxt_sockaddr_cache_alloc(nxt_event_engine_t *engine, - nxt_listen_event_t *lev); + nxt_listen_socket_t *ls); void nxt_sockaddr_cache_free(nxt_event_engine_t *engine, nxt_conn_t *c); NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen, @@ -107,6 +105,8 @@ NXT_EXPORT nxt_int_t nxt_inet6_addr(struct in6_addr *in6_addr, u_char *buf, (sizeof("[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]:65535") - 1) +#define nxt_sockaddr_size(sa) \ + (offsetof(nxt_sockaddr_t, u) + sa->socklen + sa->length) #define nxt_sockaddr_start(sa) nxt_pointer_to(sa, (sa)->start) #define nxt_sockaddr_address(sa) nxt_pointer_to(sa, (sa)->address_start) #define nxt_sockaddr_port(sa) nxt_pointer_to(sa, (sa)->port_start) |