Using new memory pool implementation.
This commit is contained in:
@@ -30,8 +30,6 @@ NXT_LIB_DEPS=" \
|
||||
src/nxt_utf8.h \
|
||||
src/nxt_unicode_lowcase.h \
|
||||
src/nxt_parse.h \
|
||||
src/nxt_mem_pool.h \
|
||||
src/nxt_mem_pool_cleanup.h \
|
||||
src/nxt_mp.h \
|
||||
src/nxt_mem_zone.h \
|
||||
src/nxt_sprintf.h \
|
||||
@@ -94,8 +92,6 @@ NXT_LIB_SRCS=" \
|
||||
src/nxt_random.c \
|
||||
src/nxt_queue.c \
|
||||
src/nxt_rbtree.c \
|
||||
src/nxt_mem_pool.c \
|
||||
src/nxt_mem_pool_cleanup.c \
|
||||
src/nxt_mp.c \
|
||||
src/nxt_mem_zone.c \
|
||||
src/nxt_string.c \
|
||||
@@ -107,7 +103,6 @@ NXT_LIB_SRCS=" \
|
||||
src/nxt_djb_hash.c \
|
||||
src/nxt_murmur_hash.c \
|
||||
src/nxt_lvlhsh.c \
|
||||
src/nxt_lvlhsh_pool.c \
|
||||
src/nxt_array.c \
|
||||
src/nxt_vector.c \
|
||||
src/nxt_list.c \
|
||||
@@ -158,6 +153,9 @@ NXT_LIB_SRC0=" \
|
||||
src/nxt_http_chunk_parse.c \
|
||||
src/nxt_fastcgi_source.c \
|
||||
src/nxt_fastcgi_record_parse.c \
|
||||
\
|
||||
src/nxt_mem_pool_cleanup.h \
|
||||
src/nxt_mem_pool_cleanup.c \
|
||||
"
|
||||
|
||||
NXT_LIB_THREAD_DEPS=" \
|
||||
|
||||
@@ -71,7 +71,7 @@ static nxt_buf_t *nxt_app_buf_free;
|
||||
static nxt_buf_t *nxt_app_buf_done;
|
||||
|
||||
static nxt_event_engine_t *nxt_app_engine;
|
||||
static nxt_mem_pool_t *nxt_app_mem_pool;
|
||||
static nxt_mp_t *nxt_app_mem_pool;
|
||||
|
||||
static nxt_uint_t nxt_app_buf_current_number;
|
||||
static nxt_uint_t nxt_app_buf_max_number = 16;
|
||||
@@ -167,7 +167,7 @@ nxt_app_thread(void *ctx)
|
||||
link = nxt_queue_first(&rt->engines);
|
||||
nxt_app_engine = nxt_queue_link_data(link, nxt_event_engine_t, link);
|
||||
|
||||
nxt_app_mem_pool = nxt_mem_pool_create(512);
|
||||
nxt_app_mem_pool = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(nxt_app_mem_pool == NULL)) {
|
||||
return;
|
||||
}
|
||||
@@ -225,13 +225,13 @@ nxt_app_thread(void *ctx)
|
||||
|
||||
if (nxt_app_http_parse_request(r, buf, n) != NXT_OK) {
|
||||
nxt_log_debug(thr->log, "nxt_app_http_parse_request() failed");
|
||||
nxt_mem_pool_destroy(r->mem_pool);
|
||||
nxt_mp_destroy(r->mem_pool);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (nxt_app_http_process_headers(r) != NXT_OK) {
|
||||
nxt_log_debug(thr->log, "nxt_app_http_process_headers() failed");
|
||||
nxt_mem_pool_destroy(r->mem_pool);
|
||||
nxt_mp_destroy(r->mem_pool);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -256,21 +256,21 @@ nxt_app_thread(void *ctx)
|
||||
static nxt_app_request_t *
|
||||
nxt_app_request_create(nxt_socket_t s, nxt_log_t *log)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_conn_t *c;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_app_request_t *r;
|
||||
|
||||
mp = nxt_mem_pool_create(1024);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
r = nxt_mem_zalloc(mp, sizeof(nxt_app_request_t));
|
||||
r = nxt_mp_zalloc(mp, sizeof(nxt_app_request_t));
|
||||
if (nxt_slow_path(r == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
c = nxt_mem_zalloc(mp, sizeof(nxt_conn_t));
|
||||
c = nxt_mp_zalloc(mp, sizeof(nxt_conn_t));
|
||||
if (nxt_slow_path(c == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -785,9 +785,9 @@ nxt_app_buf_send(nxt_conn_t *c, nxt_buf_t *out)
|
||||
static void
|
||||
nxt_app_delivery_handler(nxt_task_t *task, void *obj, void *data)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_buf_t *b;
|
||||
nxt_conn_t *c;
|
||||
nxt_mem_pool_t *mp;
|
||||
|
||||
c = obj;
|
||||
b = data;
|
||||
@@ -800,7 +800,7 @@ nxt_app_delivery_handler(nxt_task_t *task, void *obj, void *data)
|
||||
}
|
||||
|
||||
if (c->mem_pool == NULL) {
|
||||
mp = nxt_mem_pool_create(256);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
close(c->socket.fd);
|
||||
return;
|
||||
@@ -990,6 +990,6 @@ nxt_app_close_request(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
r = c->socket.data;
|
||||
|
||||
nxt_mem_pool_destroy(c->mem_pool);
|
||||
nxt_mem_pool_destroy(r->mem_pool);
|
||||
nxt_mp_destroy(c->mem_pool);
|
||||
nxt_mp_destroy(r->mem_pool);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
nxt_event_engine_t *engine;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
nxt_conn_t *event_conn;
|
||||
nxt_log_t *log;
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
|
||||
nxt_array_t *
|
||||
nxt_array_create(nxt_mem_pool_t *mp, nxt_uint_t n, size_t size)
|
||||
nxt_array_create(nxt_mp_t *mp, nxt_uint_t n, size_t size)
|
||||
{
|
||||
nxt_array_t *array;
|
||||
|
||||
array = nxt_mem_alloc(mp, sizeof(nxt_array_t) + n * size);
|
||||
array = nxt_mp_alloc(mp, sizeof(nxt_array_t) + n * size);
|
||||
|
||||
if (nxt_slow_path(array == NULL)) {
|
||||
return NULL;
|
||||
@@ -47,7 +47,7 @@ nxt_array_add(nxt_array_t *array)
|
||||
new_alloc = nalloc + nalloc / 2;
|
||||
}
|
||||
|
||||
p = nxt_mem_alloc(array->mem_pool, array->size * new_alloc);
|
||||
p = nxt_mp_alloc(array->mem_pool, array->size * new_alloc);
|
||||
|
||||
if (nxt_slow_path(p == NULL)) {
|
||||
return NULL;
|
||||
@@ -55,6 +55,8 @@ nxt_array_add(nxt_array_t *array)
|
||||
|
||||
nxt_memcpy(p, array->elts, array->size * nalloc);
|
||||
|
||||
nxt_mp_free(array->mem_pool, array->elts);
|
||||
|
||||
array->elts = p;
|
||||
array->nalloc = new_alloc;
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ typedef struct {
|
||||
uint32_t nelts;
|
||||
uint16_t size;
|
||||
uint16_t nalloc;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
} nxt_array_t;
|
||||
|
||||
|
||||
NXT_EXPORT nxt_array_t *nxt_array_create(nxt_mem_pool_t *mp, nxt_uint_t n,
|
||||
NXT_EXPORT nxt_array_t *nxt_array_create(nxt_mp_t *mp, nxt_uint_t n,
|
||||
size_t size);
|
||||
NXT_EXPORT void *nxt_array_add(nxt_array_t *array);
|
||||
NXT_EXPORT void *nxt_array_zero_add(nxt_array_t *array);
|
||||
|
||||
@@ -23,11 +23,11 @@ nxt_buf_mem_init(nxt_buf_t *b, void *start, size_t size)
|
||||
|
||||
|
||||
nxt_buf_t *
|
||||
nxt_buf_mem_alloc(nxt_mem_pool_t *mp, size_t size, nxt_uint_t flags)
|
||||
nxt_buf_mem_alloc(nxt_mp_t *mp, size_t size, nxt_uint_t flags)
|
||||
{
|
||||
nxt_buf_t *b;
|
||||
|
||||
b = nxt_mem_cache_zalloc0(mp, NXT_BUF_MEM_SIZE);
|
||||
b = nxt_mp_zalloc(mp, NXT_BUF_MEM_SIZE);
|
||||
if (nxt_slow_path(b == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ nxt_buf_mem_alloc(nxt_mem_pool_t *mp, size_t size, nxt_uint_t flags)
|
||||
b->size = NXT_BUF_MEM_SIZE;
|
||||
|
||||
if (size != 0) {
|
||||
b->mem.start = nxt_mem_buf(mp, &size, flags);
|
||||
b->mem.start = nxt_mp_alloc(mp, size);
|
||||
if (nxt_slow_path(b->mem.start == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -52,11 +52,11 @@ nxt_buf_mem_alloc(nxt_mem_pool_t *mp, size_t size, nxt_uint_t flags)
|
||||
|
||||
|
||||
nxt_buf_t *
|
||||
nxt_buf_file_alloc(nxt_mem_pool_t *mp, size_t size, nxt_uint_t flags)
|
||||
nxt_buf_file_alloc(nxt_mp_t *mp, size_t size, nxt_uint_t flags)
|
||||
{
|
||||
nxt_buf_t *b;
|
||||
|
||||
b = nxt_mem_cache_zalloc0(mp, NXT_BUF_FILE_SIZE);
|
||||
b = nxt_mp_zalloc(mp, NXT_BUF_FILE_SIZE);
|
||||
if (nxt_slow_path(b == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ nxt_buf_file_alloc(nxt_mem_pool_t *mp, size_t size, nxt_uint_t flags)
|
||||
nxt_buf_set_file(b);
|
||||
|
||||
if (size != 0) {
|
||||
b->mem.start = nxt_mem_buf(mp, &size, flags);
|
||||
b->mem.start = nxt_mp_alloc(mp, size);
|
||||
if (nxt_slow_path(b->mem.start == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -82,11 +82,11 @@ nxt_buf_file_alloc(nxt_mem_pool_t *mp, size_t size, nxt_uint_t flags)
|
||||
|
||||
|
||||
nxt_buf_t *
|
||||
nxt_buf_mmap_alloc(nxt_mem_pool_t *mp, size_t size)
|
||||
nxt_buf_mmap_alloc(nxt_mp_t *mp, size_t size)
|
||||
{
|
||||
nxt_buf_t *b;
|
||||
|
||||
b = nxt_mem_cache_zalloc0(mp, NXT_BUF_MMAP_SIZE);
|
||||
b = nxt_mp_zalloc(mp, NXT_BUF_MMAP_SIZE);
|
||||
|
||||
if (nxt_fast_path(b != NULL)) {
|
||||
b->data = mp;
|
||||
@@ -103,11 +103,11 @@ nxt_buf_mmap_alloc(nxt_mem_pool_t *mp, size_t size)
|
||||
|
||||
|
||||
nxt_buf_t *
|
||||
nxt_buf_sync_alloc(nxt_mem_pool_t *mp, nxt_uint_t flags)
|
||||
nxt_buf_sync_alloc(nxt_mp_t *mp, nxt_uint_t flags)
|
||||
{
|
||||
nxt_buf_t *b;
|
||||
|
||||
b = nxt_mem_cache_zalloc0(mp, NXT_BUF_SYNC_SIZE);
|
||||
b = nxt_mp_zalloc(mp, NXT_BUF_SYNC_SIZE);
|
||||
|
||||
if (nxt_fast_path(b != NULL)) {
|
||||
b->data = mp;
|
||||
@@ -158,8 +158,8 @@ nxt_buf_chain_length(nxt_buf_t *b)
|
||||
static void
|
||||
nxt_buf_completion(nxt_task_t *task, void *obj, void *data)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_buf_t *b, *parent;
|
||||
nxt_mem_pool_t *mp;
|
||||
|
||||
b = obj;
|
||||
parent = data;
|
||||
|
||||
@@ -243,17 +243,17 @@ nxt_buf_used_size(b) \
|
||||
|
||||
|
||||
NXT_EXPORT void nxt_buf_mem_init(nxt_buf_t *b, void *start, size_t size);
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_mem_alloc(nxt_mem_pool_t *mp, size_t size,
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_mem_alloc(nxt_mp_t *mp, size_t size,
|
||||
nxt_uint_t flags);
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_file_alloc(nxt_mem_pool_t *mp, size_t size,
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_file_alloc(nxt_mp_t *mp, size_t size,
|
||||
nxt_uint_t flags);
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_mmap_alloc(nxt_mem_pool_t *mp, size_t size);
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_sync_alloc(nxt_mem_pool_t *mp, nxt_uint_t flags);
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_mmap_alloc(nxt_mp_t *mp, size_t size);
|
||||
NXT_EXPORT nxt_buf_t *nxt_buf_sync_alloc(nxt_mp_t *mp, nxt_uint_t flags);
|
||||
|
||||
|
||||
#define \
|
||||
nxt_buf_free(mp, b) \
|
||||
nxt_mem_cache_free0((mp), (b), (b)->size)
|
||||
nxt_mp_free((mp), (b))
|
||||
|
||||
|
||||
NXT_EXPORT void nxt_buf_chain_add(nxt_buf_t **head, nxt_buf_t *in);
|
||||
|
||||
@@ -415,7 +415,7 @@ nxt_buf_filter_buf_completion(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
fb = ctx->buf;
|
||||
|
||||
nxt_mem_cache_free0(f->mem_pool, ctx, sizeof(nxt_buf_filter_ctx_t));
|
||||
nxt_mp_free(f->mem_pool, ctx);
|
||||
nxt_buf_pool_free(&f->filter_file->buffers, b);
|
||||
|
||||
if (fb->file_pos < fb->file_end) {
|
||||
|
||||
@@ -94,7 +94,7 @@ struct nxt_buf_filter_s {
|
||||
nxt_work_queue_t *work_queue;
|
||||
nxt_buf_filter_file_t *filter_file;
|
||||
void *data;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
|
||||
const nxt_buf_filter_ops_t *run;
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ nxt_buf_pool_free(nxt_buf_pool_t *bp, nxt_buf_t *b)
|
||||
}
|
||||
|
||||
if (!bp->mmap) {
|
||||
nxt_mem_free(bp->mem_pool, b->mem.start);
|
||||
nxt_mp_free(bp->mem_pool, b->mem.start);
|
||||
}
|
||||
|
||||
nxt_buf_free(bp->mem_pool, b);
|
||||
@@ -184,7 +184,7 @@ nxt_buf_pool_destroy(nxt_buf_pool_t *bp)
|
||||
for (b = bp->free; b != NULL; b = b->next) {
|
||||
p = b->mem.start;
|
||||
nxt_buf_free(bp->mem_pool, b);
|
||||
nxt_mem_free(bp->mem_pool, p);
|
||||
nxt_mp_free(bp->mem_pool, p);
|
||||
}
|
||||
|
||||
bp->free = b; /* NULL */
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
typedef struct {
|
||||
nxt_buf_t *current;
|
||||
nxt_buf_t *free;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
|
||||
uint16_t num;
|
||||
uint16_t max;
|
||||
|
||||
@@ -26,12 +26,12 @@ nxt_conf_json_value_t *nxt_conf_json_object_get_member(
|
||||
|
||||
nxt_int_t nxt_conf_json_op_compile(nxt_conf_json_value_t *object,
|
||||
nxt_conf_json_value_t *value, nxt_conf_json_op_t **ops, nxt_str_t *path,
|
||||
nxt_mem_pool_t *pool);
|
||||
nxt_mp_t *pool);
|
||||
nxt_conf_json_value_t *nxt_conf_json_clone_value(nxt_conf_json_value_t *value,
|
||||
nxt_conf_json_op_t *op, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_op_t *op, nxt_mp_t *pool);
|
||||
|
||||
nxt_conf_json_value_t *nxt_conf_json_parse(u_char *pos, size_t length,
|
||||
nxt_mem_pool_t *pool);
|
||||
nxt_mp_t *pool);
|
||||
|
||||
uintptr_t nxt_conf_json_print_value(u_char *pos, nxt_conf_json_value_t *value,
|
||||
nxt_conf_json_pretty_t *pretty);
|
||||
|
||||
@@ -83,24 +83,26 @@ struct nxt_conf_json_op_s {
|
||||
|
||||
static u_char *nxt_conf_json_skip_space(u_char *pos, u_char *end);
|
||||
static u_char *nxt_conf_json_parse_value(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool);
|
||||
static u_char *nxt_conf_json_parse_object(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool);
|
||||
static nxt_int_t nxt_conf_json_object_hash_add(nxt_lvlhsh_t *lvlhsh,
|
||||
nxt_conf_json_obj_member_t *member, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_obj_member_t *member, nxt_mp_t *pool);
|
||||
static nxt_int_t nxt_conf_json_object_hash_test(nxt_lvlhsh_query_t *lhq,
|
||||
void *data);
|
||||
static void *nxt_conf_json_object_hash_alloc(void *data, size_t size);
|
||||
static void nxt_conf_json_object_hash_free(void *data, void *p);
|
||||
static u_char *nxt_conf_json_parse_array(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool);
|
||||
static u_char *nxt_conf_json_parse_string(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool);
|
||||
static u_char *nxt_conf_json_parse_number(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool);
|
||||
|
||||
static nxt_int_t nxt_conf_json_copy_value(nxt_conf_json_value_t *dst,
|
||||
nxt_conf_json_value_t *src, nxt_conf_json_op_t *op, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_value_t *src, nxt_conf_json_op_t *op, nxt_mp_t *pool);
|
||||
static nxt_int_t nxt_conf_json_copy_object(nxt_conf_json_value_t *dst,
|
||||
nxt_conf_json_value_t *src, nxt_conf_json_op_t *op, nxt_mem_pool_t *pool);
|
||||
nxt_conf_json_value_t *src, nxt_conf_json_op_t *op, nxt_mp_t *pool);
|
||||
|
||||
static uintptr_t nxt_conf_json_print_integer(u_char *pos,
|
||||
nxt_conf_json_value_t *value);
|
||||
@@ -239,7 +241,7 @@ nxt_conf_json_object_get_member(nxt_conf_json_value_t *value, nxt_str_t *name,
|
||||
nxt_int_t
|
||||
nxt_conf_json_op_compile(nxt_conf_json_value_t *object,
|
||||
nxt_conf_json_value_t *value, nxt_conf_json_op_t **ops, nxt_str_t *path,
|
||||
nxt_mem_pool_t *pool)
|
||||
nxt_mp_t *pool)
|
||||
{
|
||||
nxt_str_t token;
|
||||
nxt_conf_json_op_t *op, **parent;
|
||||
@@ -253,7 +255,7 @@ nxt_conf_json_op_compile(nxt_conf_json_value_t *object,
|
||||
parent = ops;
|
||||
|
||||
for ( ;; ) {
|
||||
op = nxt_mem_zalloc(pool, sizeof(nxt_conf_json_op_t));
|
||||
op = nxt_mp_zget(pool, sizeof(nxt_conf_json_op_t));
|
||||
if (nxt_slow_path(op == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -289,14 +291,14 @@ nxt_conf_json_op_compile(nxt_conf_json_value_t *object,
|
||||
|
||||
if (object == NULL) {
|
||||
|
||||
member = nxt_mem_zalloc(pool, sizeof(nxt_conf_json_obj_member_t));
|
||||
member = nxt_mp_zget(pool, sizeof(nxt_conf_json_obj_member_t));
|
||||
if (nxt_slow_path(member == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
if (token.length > NXT_CONF_JSON_STR_SIZE) {
|
||||
|
||||
member->name.u.string = nxt_mem_alloc(pool, sizeof(nxt_str_t));
|
||||
member->name.u.string = nxt_mp_get(pool, sizeof(nxt_str_t));
|
||||
if (nxt_slow_path(member->name.u.string == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -327,11 +329,11 @@ nxt_conf_json_op_compile(nxt_conf_json_value_t *object,
|
||||
|
||||
nxt_conf_json_value_t *
|
||||
nxt_conf_json_clone_value(nxt_conf_json_value_t *value, nxt_conf_json_op_t *op,
|
||||
nxt_mem_pool_t *pool)
|
||||
nxt_mp_t *pool)
|
||||
{
|
||||
nxt_conf_json_value_t *copy;
|
||||
|
||||
copy = nxt_mem_alloc(pool, sizeof(nxt_conf_json_value_t));
|
||||
copy = nxt_mp_get(pool, sizeof(nxt_conf_json_value_t));
|
||||
if (nxt_slow_path(copy == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -348,7 +350,7 @@ nxt_conf_json_clone_value(nxt_conf_json_value_t *value, nxt_conf_json_op_t *op,
|
||||
|
||||
static nxt_int_t
|
||||
nxt_conf_json_copy_value(nxt_conf_json_value_t *dst, nxt_conf_json_value_t *src,
|
||||
nxt_conf_json_op_t *op, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_op_t *op, nxt_mp_t *pool)
|
||||
{
|
||||
size_t size;
|
||||
nxt_int_t rc;
|
||||
@@ -377,7 +379,7 @@ nxt_conf_json_copy_value(nxt_conf_json_value_t *dst, nxt_conf_json_value_t *src,
|
||||
size = sizeof(nxt_conf_json_array_t)
|
||||
+ src->u.array->count * sizeof(nxt_conf_json_value_t);
|
||||
|
||||
dst->u.array = nxt_mem_alloc(pool, size);
|
||||
dst->u.array = nxt_mp_get(pool, size);
|
||||
if (nxt_slow_path(dst->u.array == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -409,7 +411,7 @@ nxt_conf_json_copy_value(nxt_conf_json_value_t *dst, nxt_conf_json_value_t *src,
|
||||
|
||||
static nxt_int_t
|
||||
nxt_conf_json_copy_object(nxt_conf_json_value_t *dst,
|
||||
nxt_conf_json_value_t *src, nxt_conf_json_op_t *op, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_value_t *src, nxt_conf_json_op_t *op, nxt_mp_t *pool)
|
||||
{
|
||||
size_t size;
|
||||
nxt_int_t rc;
|
||||
@@ -432,7 +434,7 @@ nxt_conf_json_copy_object(nxt_conf_json_value_t *dst,
|
||||
size = sizeof(nxt_conf_json_object_t)
|
||||
+ count * sizeof(nxt_conf_json_obj_member_t);
|
||||
|
||||
dst->u.object = nxt_mem_alloc(pool, size);
|
||||
dst->u.object = nxt_mp_get(pool, size);
|
||||
if (nxt_slow_path(dst->u.object == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -532,12 +534,12 @@ nxt_conf_json_copy_object(nxt_conf_json_value_t *dst,
|
||||
|
||||
|
||||
nxt_conf_json_value_t *
|
||||
nxt_conf_json_parse(u_char *pos, size_t length, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_parse(u_char *pos, size_t length, nxt_mp_t *pool)
|
||||
{
|
||||
u_char *end;
|
||||
nxt_conf_json_value_t *value;
|
||||
|
||||
value = nxt_mem_alloc(pool, sizeof(nxt_conf_json_value_t));
|
||||
value = nxt_mp_get(pool, sizeof(nxt_conf_json_value_t));
|
||||
if (nxt_slow_path(value == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -588,7 +590,7 @@ nxt_conf_json_skip_space(u_char *pos, u_char *end)
|
||||
|
||||
static u_char *
|
||||
nxt_conf_json_parse_value(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool)
|
||||
{
|
||||
u_char ch;
|
||||
|
||||
@@ -651,21 +653,20 @@ static const nxt_lvlhsh_proto_t nxt_conf_json_object_hash_proto
|
||||
nxt_aligned(64) =
|
||||
{
|
||||
NXT_LVLHSH_DEFAULT,
|
||||
0,
|
||||
nxt_conf_json_object_hash_test,
|
||||
nxt_lvlhsh_pool_alloc,
|
||||
nxt_lvlhsh_pool_free,
|
||||
nxt_conf_json_object_hash_alloc,
|
||||
nxt_conf_json_object_hash_free,
|
||||
};
|
||||
|
||||
|
||||
static u_char *
|
||||
nxt_conf_json_parse_object(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool)
|
||||
{
|
||||
nxt_mp_t *temp_pool;
|
||||
nxt_int_t rc;
|
||||
nxt_uint_t count;
|
||||
nxt_lvlhsh_t hash;
|
||||
nxt_mem_pool_t *temp_pool;
|
||||
nxt_lvlhsh_each_t lhe;
|
||||
nxt_conf_json_object_t *object;
|
||||
nxt_conf_json_obj_member_t *member, *element;
|
||||
@@ -676,7 +677,7 @@ nxt_conf_json_parse_object(u_char *pos, u_char *end,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
temp_pool = nxt_mem_pool_create(256);
|
||||
temp_pool = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(temp_pool == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -694,8 +695,7 @@ nxt_conf_json_parse_object(u_char *pos, u_char *end,
|
||||
goto error;
|
||||
}
|
||||
|
||||
member = nxt_mem_alloc(temp_pool,
|
||||
sizeof(nxt_conf_json_obj_member_t));
|
||||
member = nxt_mp_get(temp_pool, sizeof(nxt_conf_json_obj_member_t));
|
||||
if (nxt_slow_path(member == NULL)) {
|
||||
goto error;
|
||||
}
|
||||
@@ -752,7 +752,7 @@ nxt_conf_json_parse_object(u_char *pos, u_char *end,
|
||||
}
|
||||
}
|
||||
|
||||
object = nxt_mem_alloc(pool, sizeof(nxt_conf_json_object_t)
|
||||
object = nxt_mp_get(pool, sizeof(nxt_conf_json_object_t)
|
||||
+ count * sizeof(nxt_conf_json_obj_member_t));
|
||||
if (nxt_slow_path(object == NULL)) {
|
||||
goto error;
|
||||
@@ -777,20 +777,20 @@ nxt_conf_json_parse_object(u_char *pos, u_char *end,
|
||||
*member++ = *element;
|
||||
}
|
||||
|
||||
nxt_mem_pool_destroy(temp_pool);
|
||||
nxt_mp_destroy(temp_pool);
|
||||
|
||||
return pos + 1;
|
||||
|
||||
error:
|
||||
|
||||
nxt_mem_pool_destroy(temp_pool);
|
||||
nxt_mp_destroy(temp_pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_conf_json_object_hash_add(nxt_lvlhsh_t *lvlhsh,
|
||||
nxt_conf_json_obj_member_t *member, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_obj_member_t *member, nxt_mp_t *pool)
|
||||
{
|
||||
nxt_lvlhsh_query_t lhq;
|
||||
nxt_conf_json_value_t *name;
|
||||
@@ -839,13 +839,27 @@ nxt_conf_json_object_hash_test(nxt_lvlhsh_query_t *lhq, void *data)
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
nxt_conf_json_object_hash_alloc(void *data, size_t size)
|
||||
{
|
||||
return nxt_mp_align(data, size, size);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nxt_conf_json_object_hash_free(void *data, void *p)
|
||||
{
|
||||
return nxt_mp_free(data, p);
|
||||
}
|
||||
|
||||
|
||||
static u_char *
|
||||
nxt_conf_json_parse_array(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool)
|
||||
{
|
||||
nxt_mp_t *temp_pool;
|
||||
nxt_uint_t count;
|
||||
nxt_list_t *list;
|
||||
nxt_mem_pool_t *temp_pool;
|
||||
nxt_conf_json_array_t *array;
|
||||
nxt_conf_json_value_t *element;
|
||||
|
||||
@@ -855,7 +869,7 @@ nxt_conf_json_parse_array(u_char *pos, u_char *end,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
temp_pool = nxt_mem_pool_create(256);
|
||||
temp_pool = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(temp_pool == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -905,7 +919,7 @@ nxt_conf_json_parse_array(u_char *pos, u_char *end,
|
||||
}
|
||||
}
|
||||
|
||||
array = nxt_mem_alloc(pool, sizeof(nxt_conf_json_array_t)
|
||||
array = nxt_mp_get(pool, sizeof(nxt_conf_json_array_t)
|
||||
+ count * sizeof(nxt_conf_json_value_t));
|
||||
if (nxt_slow_path(array == NULL)) {
|
||||
goto error;
|
||||
@@ -921,20 +935,20 @@ nxt_conf_json_parse_array(u_char *pos, u_char *end,
|
||||
*element++ = *value;
|
||||
} nxt_list_loop;
|
||||
|
||||
nxt_mem_pool_destroy(temp_pool);
|
||||
nxt_mp_destroy(temp_pool);
|
||||
|
||||
return pos + 1;
|
||||
|
||||
error:
|
||||
|
||||
nxt_mem_pool_destroy(temp_pool);
|
||||
nxt_mp_destroy(temp_pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static u_char *
|
||||
nxt_conf_json_parse_string(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool)
|
||||
{
|
||||
u_char ch, *last, *s;
|
||||
size_t size, surplus;
|
||||
@@ -1146,7 +1160,7 @@ nxt_conf_json_parse_string(u_char *pos, u_char *end,
|
||||
|
||||
static u_char *
|
||||
nxt_conf_json_parse_number(u_char *pos, u_char *end,
|
||||
nxt_conf_json_value_t *value, nxt_mem_pool_t *pool)
|
||||
nxt_conf_json_value_t *value, nxt_mp_t *pool)
|
||||
{
|
||||
u_char ch, *p;
|
||||
uint64_t integer;
|
||||
|
||||
@@ -42,12 +42,12 @@ nxt_conn_io_t nxt_unix_conn_io = {
|
||||
|
||||
|
||||
nxt_conn_t *
|
||||
nxt_conn_create(nxt_mem_pool_t *mp, nxt_task_t *task)
|
||||
nxt_conn_create(nxt_mp_t *mp, nxt_task_t *task)
|
||||
{
|
||||
nxt_conn_t *c;
|
||||
nxt_thread_t *thr;
|
||||
|
||||
c = nxt_mem_zalloc(mp, sizeof(nxt_conn_t));
|
||||
c = nxt_mp_zget(mp, sizeof(nxt_conn_t));
|
||||
if (nxt_slow_path(c == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ struct nxt_conn_s {
|
||||
|
||||
#endif
|
||||
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
|
||||
nxt_task_t task;
|
||||
nxt_log_t log;
|
||||
@@ -226,7 +226,7 @@ struct nxt_conn_s {
|
||||
#endif
|
||||
|
||||
|
||||
NXT_EXPORT nxt_conn_t *nxt_conn_create(nxt_mem_pool_t *mp, nxt_task_t *task);
|
||||
NXT_EXPORT nxt_conn_t *nxt_conn_create(nxt_mp_t *mp, nxt_task_t *task);
|
||||
void nxt_conn_io_shutdown(nxt_task_t *task, void *obj, void *data);
|
||||
NXT_EXPORT void nxt_conn_close(nxt_event_engine_t *engine, nxt_conn_t *c);
|
||||
|
||||
|
||||
@@ -82,9 +82,9 @@ nxt_listen_event(nxt_task_t *task, nxt_listen_socket_t *ls)
|
||||
static nxt_conn_t *
|
||||
nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_conn_t *c;
|
||||
nxt_sockaddr_t *sa, *remote;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_event_engine_t *engine;
|
||||
nxt_listen_socket_t *ls;
|
||||
|
||||
@@ -92,11 +92,13 @@ nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev)
|
||||
|
||||
if (engine->connections < engine->max_connections) {
|
||||
|
||||
mp = nxt_mem_pool_create(lev->listen->mem_pool_size);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
|
||||
if (nxt_fast_path(mp != NULL)) {
|
||||
/* This allocation cannot fail. */
|
||||
c = nxt_conn_create(mp, lev->socket.task);
|
||||
if (nxt_slow_path(c == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
lev->next = c;
|
||||
c->socket.read_work_queue = lev->socket.read_work_queue;
|
||||
@@ -104,8 +106,12 @@ nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev)
|
||||
c->listen = lev;
|
||||
|
||||
ls = lev->listen;
|
||||
/* This allocation cannot fail. */
|
||||
|
||||
remote = nxt_sockaddr_alloc(mp, ls->socklen, ls->address_length);
|
||||
if (nxt_slow_path(remote == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
c->remote = remote;
|
||||
|
||||
sa = ls->sockaddr;
|
||||
@@ -118,6 +124,10 @@ nxt_conn_accept_alloc(nxt_task_t *task, nxt_listen_event_t *lev)
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
fail:
|
||||
|
||||
nxt_mp_destroy(mp);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -63,7 +63,7 @@ nxt_conn_proxy_create(nxt_conn_t *client)
|
||||
nxt_thread_t *thr;
|
||||
nxt_conn_proxy_t *p;
|
||||
|
||||
p = nxt_mem_zalloc(client->mem_pool, sizeof(nxt_conn_proxy_t));
|
||||
p = nxt_mp_zget(client->mem_pool, sizeof(nxt_conn_proxy_t));
|
||||
if (nxt_slow_path(p == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -152,9 +152,7 @@ nxt_conn_proxy_client_buffer_alloc(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
nxt_debug(task, "conn proxy client first read fd:%d", client->socket.fd);
|
||||
|
||||
b = nxt_buf_mem_alloc(client->mem_pool, p->client_buffer_size,
|
||||
NXT_MEM_BUF_CUTBACK | NXT_MEM_BUF_USABLE);
|
||||
|
||||
b = nxt_buf_mem_alloc(client->mem_pool, p->client_buffer_size, 0);
|
||||
if (nxt_slow_path(b == NULL)) {
|
||||
/* An error completion. */
|
||||
nxt_conn_proxy_complete(task, p);
|
||||
@@ -303,9 +301,7 @@ nxt_conn_proxy_peer_read(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
nxt_debug(task, "conn proxy peer read fd:%d", peer->socket.fd);
|
||||
|
||||
b = nxt_buf_mem_alloc(peer->mem_pool, p->peer_buffer_size,
|
||||
NXT_MEM_BUF_CUTBACK | NXT_MEM_BUF_USABLE);
|
||||
|
||||
b = nxt_buf_mem_alloc(peer->mem_pool, p->peer_buffer_size, 0);
|
||||
if (nxt_slow_path(b == NULL)) {
|
||||
/* An error completion. */
|
||||
nxt_conn_proxy_complete(task, p);
|
||||
@@ -894,7 +890,7 @@ nxt_conn_proxy_shutdown(nxt_task_t *task, nxt_conn_proxy_t *p,
|
||||
|
||||
/* Free the direction's buffer. */
|
||||
b = (source == p->client) ? p->client_buffer : p->peer_buffer;
|
||||
nxt_mem_free(source->mem_pool, b);
|
||||
nxt_mp_free(source->mem_pool, b);
|
||||
}
|
||||
|
||||
|
||||
@@ -990,8 +986,8 @@ nxt_conn_proxy_completion(nxt_task_t *task, void *obj, void *data)
|
||||
p->retain--;
|
||||
|
||||
if (p->retain == 0) {
|
||||
nxt_mem_free(p->client->mem_pool, p->client_buffer);
|
||||
nxt_mem_free(p->client->mem_pool, p->peer_buffer);
|
||||
nxt_mp_free(p->client->mem_pool, p->client_buffer);
|
||||
nxt_mp_free(p->client->mem_pool, p->peer_buffer);
|
||||
|
||||
p->completion_handler(task, p, NULL);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
typedef struct {
|
||||
nxt_conf_json_value_t *root;
|
||||
nxt_mem_pool_t *pool;
|
||||
nxt_mp_t *pool;
|
||||
} nxt_controller_conf_t;
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ static void nxt_controller_process_request(nxt_task_t *task,
|
||||
static nxt_int_t nxt_controller_response(nxt_task_t *task, nxt_conn_t *c,
|
||||
nxt_controller_response_t *resp);
|
||||
static nxt_buf_t *nxt_controller_response_body(nxt_controller_response_t *resp,
|
||||
nxt_mem_pool_t *pool);
|
||||
nxt_mp_t *pool);
|
||||
|
||||
|
||||
static nxt_http_fields_hash_entry_t nxt_controller_request_fields[] = {
|
||||
@@ -83,7 +83,7 @@ static const nxt_event_conn_state_t nxt_controller_conn_close_state;
|
||||
nxt_int_t
|
||||
nxt_controller_start(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
{
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_mp_t *mp;
|
||||
nxt_conf_json_value_t *conf;
|
||||
nxt_http_fields_hash_t *hash;
|
||||
|
||||
@@ -102,7 +102,7 @@ nxt_controller_start(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
mp = nxt_mem_pool_create(256);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
return NXT_ERROR;
|
||||
@@ -145,7 +145,7 @@ nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
rt->controller_listen = sa;
|
||||
}
|
||||
|
||||
ls = nxt_mem_alloc(rt->mem_pool, sizeof(nxt_listen_socket_t));
|
||||
ls = nxt_mp_alloc(rt->mem_pool, sizeof(nxt_listen_socket_t));
|
||||
if (ls == NULL) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -167,7 +167,7 @@ nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
|
||||
#if 0
|
||||
/* STUB */
|
||||
wq = nxt_mem_zalloc(cf->mem_pool, sizeof(nxt_work_queue_t));
|
||||
wq = nxt_mp_zget(cf->mem_pool, sizeof(nxt_work_queue_t));
|
||||
if (wq == NULL) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -178,15 +178,6 @@ nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
#endif
|
||||
ls->handler = nxt_controller_conn_init;
|
||||
|
||||
/*
|
||||
* Connection memory pool chunk size is tunned to
|
||||
* allocate the most data in one mem_pool chunk.
|
||||
*/
|
||||
ls->mem_pool_size = nxt_listen_socket_pool_min_size(ls)
|
||||
+ sizeof(nxt_event_conn_proxy_t)
|
||||
+ sizeof(nxt_conn_t)
|
||||
+ 4 * sizeof(nxt_buf_t);
|
||||
|
||||
if (nxt_listen_socket_create(task, ls, 0) != NXT_OK) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -209,7 +200,7 @@ nxt_controller_conn_init(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
nxt_debug(task, "controller conn init fd:%d", c->socket.fd);
|
||||
|
||||
r = nxt_mem_zalloc(c->mem_pool, sizeof(nxt_controller_request_t));
|
||||
r = nxt_mp_zget(c->mem_pool, sizeof(nxt_controller_request_t));
|
||||
if (nxt_slow_path(r == NULL)) {
|
||||
nxt_controller_conn_free(task, c, NULL);
|
||||
return;
|
||||
@@ -513,7 +504,7 @@ nxt_controller_conn_free(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
nxt_debug(task, "controller conn free");
|
||||
|
||||
nxt_mem_pool_destroy(c->mem_pool);
|
||||
nxt_mp_destroy(c->mem_pool);
|
||||
|
||||
//nxt_free(c);
|
||||
}
|
||||
@@ -547,11 +538,11 @@ static void
|
||||
nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
|
||||
nxt_controller_request_t *req)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t rc;
|
||||
nxt_str_t path;
|
||||
nxt_uint_t status;
|
||||
nxt_buf_mem_t *mbuf;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_conf_json_op_t *ops;
|
||||
nxt_conf_json_value_t *value;
|
||||
nxt_controller_response_t resp;
|
||||
@@ -590,7 +581,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
|
||||
|
||||
if (nxt_str_eq(&req->parser.method, "PUT", 3)) {
|
||||
|
||||
mp = nxt_mem_pool_create(512);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
status = 500;
|
||||
@@ -602,7 +593,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
|
||||
value = nxt_conf_json_parse(mbuf->pos, mbuf->free - mbuf->pos, mp);
|
||||
|
||||
if (value == NULL) {
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
status = 400;
|
||||
goto done;
|
||||
}
|
||||
@@ -625,13 +616,13 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
|
||||
ops, mp);
|
||||
|
||||
if (nxt_slow_path(value == NULL)) {
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
status = 500;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
nxt_mem_pool_destroy(nxt_controller_conf.pool);
|
||||
nxt_mp_destroy(nxt_controller_conf.pool);
|
||||
|
||||
nxt_controller_conf.root = value;
|
||||
nxt_controller_conf.pool = mp;
|
||||
@@ -645,7 +636,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
|
||||
if (nxt_str_eq(&req->parser.method, "DELETE", 6)) {
|
||||
|
||||
if (path.length == 1) {
|
||||
mp = nxt_mem_pool_create(128);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
status = 500;
|
||||
@@ -668,7 +659,7 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
|
||||
goto done;
|
||||
}
|
||||
|
||||
mp = nxt_mem_pool_create(512);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
status = 500;
|
||||
@@ -680,12 +671,12 @@ nxt_controller_process_request(nxt_task_t *task, nxt_conn_t *c,
|
||||
}
|
||||
|
||||
if (nxt_slow_path(value == NULL)) {
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
status = 500;
|
||||
goto done;
|
||||
}
|
||||
|
||||
nxt_mem_pool_destroy(nxt_controller_conf.pool);
|
||||
nxt_mp_destroy(nxt_controller_conf.pool);
|
||||
|
||||
nxt_controller_conf.root = value;
|
||||
nxt_controller_conf.pool = mp;
|
||||
@@ -772,8 +763,7 @@ nxt_controller_response(nxt_task_t *task, nxt_conn_t *c,
|
||||
|
||||
|
||||
static nxt_buf_t *
|
||||
nxt_controller_response_body(nxt_controller_response_t *resp,
|
||||
nxt_mem_pool_t *pool)
|
||||
nxt_controller_response_body(nxt_controller_response_t *resp, nxt_mp_t *pool)
|
||||
{
|
||||
size_t size;
|
||||
nxt_buf_t *b;
|
||||
|
||||
@@ -182,7 +182,7 @@ nxt_cyassl_conn_init(nxt_thread_t *thr, nxt_ssltls_conf_t *conf,
|
||||
|
||||
nxt_log_debug(c->socket.log, "cyassl conn init");
|
||||
|
||||
ssltls = nxt_mem_zalloc(c->mem_pool, sizeof(nxt_cyassl_conn_t));
|
||||
ssltls = nxt_mp_zget(c->mem_pool, sizeof(nxt_cyassl_conn_t));
|
||||
if (ssltls == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ nxt_fastcgi_source_handler(nxt_task_t *task, nxt_upstream_source_t *us,
|
||||
nxt_stream_source_t *stream;
|
||||
nxt_fastcgi_source_t *fs;
|
||||
|
||||
fs = nxt_mem_zalloc(us->buffers.mem_pool, sizeof(nxt_fastcgi_source_t));
|
||||
fs = nxt_mp_zget(us->buffers.mem_pool, sizeof(nxt_fastcgi_source_t));
|
||||
if (nxt_slow_path(fs == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -145,8 +145,7 @@ nxt_fastcgi_source_handler(nxt_task_t *task, nxt_upstream_source_t *us,
|
||||
stream = us->stream;
|
||||
|
||||
if (stream == NULL) {
|
||||
stream = nxt_mem_zalloc(us->buffers.mem_pool,
|
||||
sizeof(nxt_stream_source_t));
|
||||
stream = nxt_mp_zget(us->buffers.mem_pool, sizeof(nxt_stream_source_t));
|
||||
if (nxt_slow_path(stream == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -605,7 +604,7 @@ static const nxt_upstream_name_value_t nxt_fastcgi_source_headers[]
|
||||
|
||||
|
||||
nxt_int_t
|
||||
nxt_fastcgi_source_hash_create(nxt_mem_pool_t *mp, nxt_lvlhsh_t *lh)
|
||||
nxt_fastcgi_source_hash_create(nxt_mp_t *mp, nxt_lvlhsh_t *lh)
|
||||
{
|
||||
return nxt_upstream_header_hash_add(mp, lh, nxt_fastcgi_source_headers,
|
||||
nxt_nitems(nxt_fastcgi_source_headers));
|
||||
|
||||
@@ -37,7 +37,7 @@ struct nxt_fastcgi_parse_s {
|
||||
|
||||
nxt_buf_t *(*last_buf)(nxt_fastcgi_parse_t *fp);
|
||||
void *data;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
};
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ struct nxt_fastcgi_source_s {
|
||||
NXT_EXPORT void nxt_fastcgi_source_handler(nxt_task_t *task,
|
||||
nxt_upstream_source_t *us,
|
||||
nxt_fastcgi_source_request_create_t request_create);
|
||||
NXT_EXPORT nxt_int_t nxt_fastcgi_source_hash_create(nxt_mem_pool_t *mp,
|
||||
NXT_EXPORT nxt_int_t nxt_fastcgi_source_hash_create(nxt_mp_t *mp,
|
||||
nxt_lvlhsh_t *lh);
|
||||
void nxt_fastcgi_record_parse(nxt_task_t *task, nxt_fastcgi_parse_t *fp,
|
||||
nxt_buf_t *in);
|
||||
|
||||
@@ -14,7 +14,6 @@ static void nxt_fd_event_hash_error(nxt_task_t *task, nxt_fd_t fd);
|
||||
static const nxt_lvlhsh_proto_t nxt_event_set_fd_hash_proto nxt_aligned(64) =
|
||||
{
|
||||
NXT_LVLHSH_LARGE_MEMALIGN,
|
||||
0,
|
||||
nxt_fd_event_hash_test,
|
||||
nxt_lvlhsh_alloc,
|
||||
nxt_lvlhsh_free,
|
||||
|
||||
@@ -34,7 +34,7 @@ nxt_file_name_str_set(file_name, mem_pool, name) \
|
||||
|
||||
#define \
|
||||
nxt_file_name_alloc(mem_pool, len) \
|
||||
nxt_mem_nalloc(mem_pool, len)
|
||||
nxt_mp_nget(mem_pool, len)
|
||||
|
||||
|
||||
#define \
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
nxt_int_t
|
||||
nxt_file_name_create(nxt_mem_pool_t *mp, nxt_file_name_str_t *file_name,
|
||||
nxt_file_name_create(nxt_mp_t *mp, nxt_file_name_str_t *file_name,
|
||||
const char *format, ...)
|
||||
{
|
||||
u_char ch, *p;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define _NXT_FILE_NAME_H_INCLUDED_
|
||||
|
||||
|
||||
NXT_EXPORT nxt_int_t nxt_file_name_create(nxt_mem_pool_t *mp,
|
||||
NXT_EXPORT nxt_int_t nxt_file_name_create(nxt_mp_t *mp,
|
||||
nxt_file_name_str_t *fn, const char *format, ...);
|
||||
|
||||
|
||||
|
||||
@@ -262,7 +262,7 @@ nxt_gnutls_conn_init(nxt_thread_t *thr, nxt_ssltls_conf_t *conf,
|
||||
|
||||
nxt_log_debug(c->socket.log, "gnutls conn init");
|
||||
|
||||
ssltls = nxt_mem_zalloc(c->mem_pool, sizeof(nxt_gnutls_conn_t));
|
||||
ssltls = nxt_mp_zget(c->mem_pool, sizeof(nxt_gnutls_conn_t));
|
||||
if (ssltls == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -658,7 +658,7 @@ nxt_http_parse_field_end(nxt_http_request_parse_t *rp, u_char **pos,
|
||||
|
||||
nxt_http_fields_hash_t *
|
||||
nxt_http_fields_hash_create(nxt_http_fields_hash_entry_t *entries,
|
||||
nxt_mem_pool_t *mp)
|
||||
nxt_mp_t *mp)
|
||||
{
|
||||
size_t min_length, max_length, length, size;
|
||||
nxt_uint_t i, j, n;
|
||||
@@ -687,7 +687,7 @@ nxt_http_fields_hash_create(nxt_http_fields_hash_entry_t *entries,
|
||||
* sizeof(nxt_http_fields_hash_elt_t *);
|
||||
}
|
||||
|
||||
hash = nxt_mem_zalloc(mp, size);
|
||||
hash = nxt_mp_zget(mp, size);
|
||||
if (nxt_slow_path(hash == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -713,8 +713,7 @@ nxt_http_fields_hash_create(nxt_http_fields_hash_entry_t *entries,
|
||||
|
||||
size = sizeof(nxt_http_fields_hash_elt_t) + nxt_align_size(length, 8);
|
||||
|
||||
elt = nxt_mem_zalloc(mp, n * size
|
||||
+ sizeof(nxt_http_fields_hash_elt_t));
|
||||
elt = nxt_mp_zget(mp, n * size + sizeof(nxt_http_fields_hash_elt_t));
|
||||
|
||||
if (nxt_slow_path(elt == NULL)) {
|
||||
return NULL;
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef struct {
|
||||
|
||||
|
||||
nxt_inline nxt_int_t
|
||||
nxt_http_parse_request_init(nxt_http_request_parse_t *rp, nxt_mem_pool_t *mp)
|
||||
nxt_http_parse_request_init(nxt_http_request_parse_t *rp, nxt_mp_t *mp)
|
||||
{
|
||||
rp->fields = nxt_list_create(mp, 8, sizeof(nxt_http_field_t));
|
||||
if (nxt_slow_path(rp->fields == NULL)){
|
||||
@@ -86,7 +86,7 @@ nxt_int_t nxt_http_parse_request(nxt_http_request_parse_t *rp,
|
||||
nxt_buf_mem_t *b);
|
||||
|
||||
nxt_http_fields_hash_t *nxt_http_fields_hash_create(
|
||||
nxt_http_fields_hash_entry_t *entries, nxt_mem_pool_t *mp);
|
||||
nxt_http_fields_hash_entry_t *entries, nxt_mp_t *mp);
|
||||
nxt_http_fields_hash_entry_t *nxt_http_fields_hash_lookup(
|
||||
nxt_http_fields_hash_t *hash, nxt_http_field_t *field);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ nxt_http_source_handler(nxt_task_t *task, nxt_upstream_source_t *us,
|
||||
nxt_http_source_t *hs;
|
||||
nxt_stream_source_t *stream;
|
||||
|
||||
hs = nxt_mem_zalloc(us->buffers.mem_pool, sizeof(nxt_http_source_t));
|
||||
hs = nxt_mp_zget(us->buffers.mem_pool, sizeof(nxt_http_source_t));
|
||||
if (nxt_slow_path(hs == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -70,8 +70,7 @@ nxt_http_source_handler(nxt_task_t *task, nxt_upstream_source_t *us,
|
||||
stream = us->stream;
|
||||
|
||||
if (stream == NULL) {
|
||||
stream = nxt_mem_zalloc(us->buffers.mem_pool,
|
||||
sizeof(nxt_stream_source_t));
|
||||
stream = nxt_mp_zget(us->buffers.mem_pool, sizeof(nxt_stream_source_t));
|
||||
if (nxt_slow_path(stream == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -382,7 +381,7 @@ static const nxt_upstream_name_value_t nxt_http_source_headers[]
|
||||
|
||||
|
||||
nxt_int_t
|
||||
nxt_http_source_hash_create(nxt_mem_pool_t *mp, nxt_lvlhsh_t *lh)
|
||||
nxt_http_source_hash_create(nxt_mp_t *mp, nxt_lvlhsh_t *lh)
|
||||
{
|
||||
return nxt_upstream_header_hash_add(mp, lh, nxt_http_source_headers,
|
||||
nxt_nitems(nxt_http_source_headers));
|
||||
@@ -444,7 +443,7 @@ nxt_http_source_header_ready(nxt_task_t *task, nxt_http_source_t *hs,
|
||||
if (nxt_fast_path(nxt_buf_pool_available(&us->buffers))) {
|
||||
|
||||
if (hs->chunked) {
|
||||
hsc = nxt_mem_zalloc(hs->upstream->buffers.mem_pool,
|
||||
hsc = nxt_mp_zalloc(hs->upstream->buffers.mem_pool,
|
||||
sizeof(nxt_http_source_chunk_t));
|
||||
if (nxt_slow_path(hsc == NULL)) {
|
||||
goto fail;
|
||||
|
||||
@@ -40,7 +40,7 @@ struct nxt_http_source_s {
|
||||
|
||||
NXT_EXPORT void nxt_http_source_handler(nxt_task_t *task,
|
||||
nxt_upstream_source_t *us, nxt_http_source_request_create_t request_create);
|
||||
NXT_EXPORT nxt_int_t nxt_http_source_hash_create(nxt_mem_pool_t *mp,
|
||||
NXT_EXPORT nxt_int_t nxt_http_source_hash_create(nxt_mp_t *mp,
|
||||
nxt_lvlhsh_t *lh);
|
||||
|
||||
|
||||
|
||||
@@ -15,23 +15,22 @@ static void nxt_job_thread_return_handler(nxt_task_t *task, void *obj,
|
||||
|
||||
|
||||
void *
|
||||
nxt_job_create(nxt_mem_pool_t *mp, size_t size)
|
||||
nxt_job_create(nxt_mp_t *mp, size_t size)
|
||||
{
|
||||
size_t cache_size;
|
||||
nxt_job_t *job;
|
||||
|
||||
if (mp == NULL) {
|
||||
mp = nxt_mem_pool_create(256);
|
||||
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
job = nxt_mem_zalloc(mp, size);
|
||||
job = nxt_mp_zget(mp, size);
|
||||
cache_size = 0;
|
||||
|
||||
} else {
|
||||
job = nxt_mem_cache_zalloc0(mp, size);
|
||||
job = nxt_mp_zalloc(mp, size);
|
||||
cache_size = size;
|
||||
}
|
||||
|
||||
@@ -71,17 +70,19 @@ nxt_job_destroy(nxt_task_t *task, void *data)
|
||||
if (job->cache_size == 0) {
|
||||
|
||||
if (job->mem_pool != NULL) {
|
||||
nxt_mem_pool_destroy(job->mem_pool);
|
||||
nxt_mp_destroy(job->mem_pool);
|
||||
}
|
||||
|
||||
} else {
|
||||
nxt_mem_cache_free0(job->mem_pool, job, job->cache_size);
|
||||
nxt_mp_free(job->mem_pool, job);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
nxt_int_t
|
||||
nxt_job_cleanup_add(nxt_mem_pool_t *mp, nxt_job_t *job)
|
||||
nxt_job_cleanup_add(nxt_mp_t *mp, nxt_job_t *job)
|
||||
{
|
||||
nxt_mem_pool_cleanup_t *mpcl;
|
||||
|
||||
@@ -96,6 +97,8 @@ nxt_job_cleanup_add(nxt_mem_pool_t *mp, nxt_job_t *job)
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* The (void *) casts in nxt_thread_pool_post() and nxt_event_engine_post()
|
||||
|
||||
@@ -40,7 +40,7 @@ typedef struct {
|
||||
uint16_t cache_size;
|
||||
uint8_t cancel; /* 1 bit */
|
||||
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
nxt_queue_link_t link;
|
||||
|
||||
#if (NXT_THREADS)
|
||||
@@ -58,10 +58,10 @@ typedef struct {
|
||||
} nxt_job_t;
|
||||
|
||||
|
||||
NXT_EXPORT void *nxt_job_create(nxt_mem_pool_t *mp, size_t size);
|
||||
NXT_EXPORT void *nxt_job_create(nxt_mp_t *mp, size_t size);
|
||||
NXT_EXPORT void nxt_job_init(nxt_job_t *job, size_t size);
|
||||
NXT_EXPORT void nxt_job_destroy(nxt_task_t *task, void *data);
|
||||
NXT_EXPORT nxt_int_t nxt_job_cleanup_add(nxt_mem_pool_t *mp, nxt_job_t *job);
|
||||
NXT_EXPORT nxt_int_t nxt_job_cleanup_add(nxt_mp_t *mp, nxt_job_t *job);
|
||||
|
||||
NXT_EXPORT void nxt_job_start(nxt_task_t *task, nxt_job_t *job,
|
||||
nxt_work_handler_t handler);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
nxt_job_cache_file_t *
|
||||
nxt_job_cache_file_create(nxt_mem_pool_t *mp)
|
||||
nxt_job_cache_file_create(nxt_mp_t *mp)
|
||||
{
|
||||
nxt_job_cache_file_t *jbc;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ static nxt_int_t nxt_job_file_read_required(nxt_job_file_t *jbf);
|
||||
|
||||
|
||||
nxt_job_file_t *
|
||||
nxt_job_file_create(nxt_mem_pool_t *mp)
|
||||
nxt_job_file_create(nxt_mp_t *mp)
|
||||
{
|
||||
nxt_job_file_t *jbf;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ struct nxt_job_file_s {
|
||||
};
|
||||
|
||||
|
||||
NXT_EXPORT nxt_job_file_t *nxt_job_file_create(nxt_mem_pool_t *mp);
|
||||
NXT_EXPORT nxt_job_file_t *nxt_job_file_create(nxt_mp_t *mp);
|
||||
NXT_EXPORT void nxt_job_file_init(nxt_job_file_t *jbf);
|
||||
NXT_EXPORT void nxt_job_file_read(nxt_task_t *task, nxt_job_t *job);
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ nxt_job_resolve(nxt_job_resolve_t *jbr)
|
||||
int err;
|
||||
u_char *host;
|
||||
size_t length;
|
||||
nxt_mp_t *mp;
|
||||
nxt_uint_t n;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_sockaddr_t *sa;
|
||||
struct addrinfo hint, *res, *r;
|
||||
nxt_work_handler_t handler;
|
||||
@@ -31,7 +31,7 @@ nxt_job_resolve(nxt_job_resolve_t *jbr)
|
||||
host = buf;
|
||||
|
||||
} else {
|
||||
host = nxt_mem_alloc(jbr->job.mem_pool, length);
|
||||
host = nxt_mp_alloc(jbr->job.mem_pool, length);
|
||||
if (nxt_slow_path(host == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ nxt_job_resolve(nxt_job_resolve_t *jbr)
|
||||
jbr->count = n;
|
||||
mp = jbr->job.mem_pool;
|
||||
|
||||
jbr->sockaddrs = nxt_mem_alloc(mp, n * sizeof(nxt_sockaddr_t *));
|
||||
jbr->sockaddrs = nxt_mp_alloc(mp, n * sizeof(nxt_sockaddr_t *));
|
||||
if (nxt_slow_path(jbr->sockaddrs == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -124,5 +124,9 @@ fail:
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
|
||||
if (host != buf) {
|
||||
nxt_mp_free(jbr->job.mem_pool, host);
|
||||
}
|
||||
|
||||
nxt_job_return(jbr->job.task, &jbr->job, handler);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
|
||||
nxt_list_t *
|
||||
nxt_list_create(nxt_mem_pool_t *mp, nxt_uint_t n, size_t size)
|
||||
nxt_list_create(nxt_mp_t *mp, nxt_uint_t n, size_t size)
|
||||
{
|
||||
nxt_list_t *list;
|
||||
|
||||
list = nxt_mem_alloc(mp, sizeof(nxt_list_t) + n * size);
|
||||
list = nxt_mp_get(mp, sizeof(nxt_list_t) + n * size);
|
||||
|
||||
if (nxt_fast_path(list != NULL)) {
|
||||
list->last = &list->part;
|
||||
@@ -39,7 +39,7 @@ nxt_list_add(nxt_list_t *list)
|
||||
|
||||
/* The last list part is filled up, allocating a new list part. */
|
||||
|
||||
last = nxt_mem_alloc(list->mem_pool,
|
||||
last = nxt_mp_get(list->mem_pool,
|
||||
sizeof(nxt_list_part_t) + list->nalloc * list->size);
|
||||
|
||||
if (nxt_slow_path(last == NULL)) {
|
||||
|
||||
@@ -25,7 +25,7 @@ typedef struct {
|
||||
uint16_t size;
|
||||
uint16_t nalloc;
|
||||
#endif
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
nxt_list_part_t part;
|
||||
} nxt_list_t;
|
||||
|
||||
@@ -94,8 +94,7 @@ nxt_list_elt(nxt_list_t *list, nxt_uint_t n)
|
||||
} while (0)
|
||||
|
||||
|
||||
NXT_EXPORT nxt_list_t *nxt_list_create(nxt_mem_pool_t *mp, nxt_uint_t n,
|
||||
size_t size);
|
||||
NXT_EXPORT nxt_list_t *nxt_list_create(nxt_mp_t *mp, nxt_uint_t n, size_t size);
|
||||
NXT_EXPORT void *nxt_list_add(nxt_list_t *list);
|
||||
NXT_EXPORT void *nxt_list_zero_add(nxt_list_t *list);
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ nxt_listen_socket_pool_min_size(nxt_listen_socket_t *ls)
|
||||
|
||||
#endif
|
||||
|
||||
return size + sizeof(nxt_mem_pool_t)
|
||||
return size // + sizeof(nxt_mem_pool_t)
|
||||
+ sizeof(nxt_conn_t)
|
||||
+ sizeof(nxt_log_t);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ typedef struct {
|
||||
uint8_t address_length;
|
||||
|
||||
uint32_t count;
|
||||
uint32_t mem_pool_size;
|
||||
} nxt_listen_socket_t;
|
||||
|
||||
|
||||
|
||||
@@ -302,8 +302,7 @@ nxt_lvlhsh_new_bucket(nxt_lvlhsh_query_t *lhq, void **slot)
|
||||
{
|
||||
uint32_t *bucket;
|
||||
|
||||
bucket = lhq->proto->alloc(lhq->pool, nxt_lvlhsh_bucket_size(lhq->proto),
|
||||
lhq->proto->nalloc);
|
||||
bucket = lhq->proto->alloc(lhq->pool, nxt_lvlhsh_bucket_size(lhq->proto));
|
||||
|
||||
if (nxt_fast_path(bucket != NULL)) {
|
||||
|
||||
@@ -476,7 +475,7 @@ nxt_lvlhsh_convert_bucket_to_level(nxt_lvlhsh_query_t *lhq, void **slot,
|
||||
proto = lhq->proto;
|
||||
size = nxt_lvlhsh_level_size(proto, nlvl);
|
||||
|
||||
lvl = proto->alloc(lhq->pool, size * (sizeof(void *)), proto->nalloc);
|
||||
lvl = proto->alloc(lhq->pool, size * (sizeof(void *)));
|
||||
|
||||
if (nxt_slow_path(lvl == NULL)) {
|
||||
return NXT_ERROR;
|
||||
@@ -516,7 +515,7 @@ nxt_lvlhsh_convert_bucket_to_level(nxt_lvlhsh_query_t *lhq, void **slot,
|
||||
|
||||
*slot = lvl;
|
||||
|
||||
proto->free(lhq->pool, bucket, nxt_lvlhsh_bucket_size(proto));
|
||||
proto->free(lhq->pool, bucket);
|
||||
|
||||
return NXT_OK;
|
||||
}
|
||||
@@ -615,12 +614,10 @@ nxt_lvlhsh_bucket_convertion_insert(nxt_lvlhsh_query_t *lhq, void **slot,
|
||||
static nxt_int_t
|
||||
nxt_lvlhsh_free_level(nxt_lvlhsh_query_t *lhq, void **level, nxt_uint_t size)
|
||||
{
|
||||
size_t bsize;
|
||||
nxt_uint_t i;
|
||||
const nxt_lvlhsh_proto_t *proto;
|
||||
|
||||
proto = lhq->proto;
|
||||
bsize = nxt_lvlhsh_bucket_size(proto);
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
|
||||
@@ -630,11 +627,11 @@ nxt_lvlhsh_free_level(nxt_lvlhsh_query_t *lhq, void **level, nxt_uint_t size)
|
||||
* in the worst case one bucket cannot be converted
|
||||
* in two chained buckets but remains the same bucket.
|
||||
*/
|
||||
proto->free(lhq->pool, nxt_lvlhsh_bucket(proto, level[i]), bsize);
|
||||
proto->free(lhq->pool, nxt_lvlhsh_bucket(proto, level[i]));
|
||||
}
|
||||
}
|
||||
|
||||
proto->free(lhq->pool, level, size * (sizeof(void *)));
|
||||
proto->free(lhq->pool, level);
|
||||
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -660,7 +657,6 @@ static nxt_int_t
|
||||
nxt_lvlhsh_level_delete(nxt_lvlhsh_query_t *lhq, void **parent, uint32_t key,
|
||||
nxt_uint_t nlvl)
|
||||
{
|
||||
size_t size;
|
||||
void **slot, **lvl;
|
||||
uintptr_t mask;
|
||||
nxt_int_t ret;
|
||||
@@ -687,8 +683,7 @@ nxt_lvlhsh_level_delete(nxt_lvlhsh_query_t *lhq, void **parent, uint32_t key,
|
||||
|
||||
if (nxt_lvlhsh_level_entries(*parent, mask) == 0) {
|
||||
*parent = NULL;
|
||||
size = nxt_lvlhsh_level_size(lhq->proto, nlvl);
|
||||
lhq->proto->free(lhq->pool, lvl, size * sizeof(void *));
|
||||
lhq->proto->free(lhq->pool, lvl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -703,7 +698,6 @@ static nxt_int_t
|
||||
nxt_lvlhsh_bucket_delete(nxt_lvlhsh_query_t *lhq, void **bkt)
|
||||
{
|
||||
void *value;
|
||||
size_t size;
|
||||
uint32_t *bucket, *e;
|
||||
uintptr_t n;
|
||||
const nxt_lvlhsh_proto_t *proto;
|
||||
@@ -726,8 +720,7 @@ nxt_lvlhsh_bucket_delete(nxt_lvlhsh_query_t *lhq, void **bkt)
|
||||
|
||||
if (nxt_lvlhsh_bucket_entries(proto, *bkt) == 1) {
|
||||
*bkt = *nxt_lvlhsh_next_bucket(proto, bucket);
|
||||
size = nxt_lvlhsh_bucket_size(proto);
|
||||
proto->free(lhq->pool, bucket, size);
|
||||
proto->free(lhq->pool, bucket);
|
||||
|
||||
} else {
|
||||
nxt_lvlhsh_count_dec(*bkt);
|
||||
@@ -877,14 +870,14 @@ nxt_lvlhsh_bucket_each(nxt_lvlhsh_each_t *lhe)
|
||||
|
||||
|
||||
void *
|
||||
nxt_lvlhsh_alloc(void *data, size_t size, nxt_uint_t nalloc)
|
||||
nxt_lvlhsh_alloc(void *data, size_t size)
|
||||
{
|
||||
return nxt_memalign(size, size);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nxt_lvlhsh_free(void *data, void *p, size_t size)
|
||||
nxt_lvlhsh_free(void *data, void *p)
|
||||
{
|
||||
nxt_free(p);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
typedef struct nxt_lvlhsh_query_s nxt_lvlhsh_query_t;
|
||||
|
||||
typedef nxt_int_t (*nxt_lvlhsh_test_t)(nxt_lvlhsh_query_t *lhq, void *data);
|
||||
typedef void *(*nxt_lvlhsh_alloc_t)(void *ctx, size_t size, nxt_uint_t nalloc);
|
||||
typedef void (*nxt_lvlhsh_free_t)(void *ctx, void *p, size_t size);
|
||||
typedef void *(*nxt_lvlhsh_alloc_t)(void *ctx, size_t size);
|
||||
typedef void (*nxt_lvlhsh_free_t)(void *ctx, void *p);
|
||||
|
||||
|
||||
#if (NXT_64BIT)
|
||||
@@ -73,7 +73,6 @@ typedef struct {
|
||||
uint32_t bucket_size;
|
||||
uint32_t bucket_mask;
|
||||
uint8_t shift[8];
|
||||
uint32_t nalloc;
|
||||
|
||||
nxt_lvlhsh_test_t test;
|
||||
nxt_lvlhsh_alloc_t alloc;
|
||||
@@ -166,12 +165,8 @@ typedef struct {
|
||||
NXT_EXPORT void *nxt_lvlhsh_each(nxt_lvlhsh_t *lh, nxt_lvlhsh_each_t *le);
|
||||
|
||||
|
||||
NXT_EXPORT void *nxt_lvlhsh_alloc(void *data, size_t size, nxt_uint_t nalloc);
|
||||
NXT_EXPORT void nxt_lvlhsh_free(void *data, void *p, size_t size);
|
||||
|
||||
NXT_EXPORT void *nxt_lvlhsh_pool_alloc(void *ctx, size_t size,
|
||||
nxt_uint_t nalloc);
|
||||
NXT_EXPORT void nxt_lvlhsh_pool_free(void *ctx, void *p, size_t size);
|
||||
NXT_EXPORT void *nxt_lvlhsh_alloc(void *data, size_t size);
|
||||
NXT_EXPORT void nxt_lvlhsh_free(void *data, void *p);
|
||||
|
||||
|
||||
#endif /* _NXT_LEVEL_HASH_H_INCLUDED_ */
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) Igor Sysoev
|
||||
* Copyright (C) NGINX, Inc.
|
||||
*/
|
||||
|
||||
#include <nxt_main.h>
|
||||
|
||||
|
||||
typedef struct nxt_lvlhsh_pool_cache_s nxt_lvlhsh_pool_cache_t;
|
||||
|
||||
struct nxt_lvlhsh_pool_cache_s {
|
||||
uint32_t size;
|
||||
uint32_t nalloc;
|
||||
void *free;
|
||||
nxt_lvlhsh_pool_cache_t *next;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
void *free;
|
||||
nxt_lvlhsh_pool_cache_t *next;
|
||||
} nxt_lvlhsh_pool_t;
|
||||
|
||||
|
||||
/*
|
||||
* lvlhsh requires allocations aligned to a size of the allocations.
|
||||
* This is not issue for slab-like allocators, but glibc allocator may
|
||||
* waste memory on such aligned allocations. So nxt_lvlhsh_pool_alloc()
|
||||
* allocates memory in chunks specified by the "nalloc" parameter
|
||||
* except the first allocation. The first lvlhsh allocation is a bucket
|
||||
* allocation and it is enough for a small hash or for early stage of
|
||||
* a large hash. By default lvlhsh uses 128-bytes or 64-bytes buckets
|
||||
* and levels on 64-bit and 32-bit platforms respectively.
|
||||
* This allows to search up to 10 entries in one memory access and
|
||||
* up to 160 entries in two memory accesses on 64-bit platform.
|
||||
* And on 32-bit platform up to 7 entries and up to 112 entries
|
||||
* respectively.
|
||||
*
|
||||
* After the bucket has been filled up with 10 64-bit entries
|
||||
* or 7 32-bit entries, lvlhsh expands it to a level and spreads
|
||||
* content of the first bucket to the level's new buckets.
|
||||
* Number of the new allocations may be up to 11 on 64-bit or
|
||||
* 8 on 32-bit platforms. It's better to allocate them together
|
||||
* to eliminate wasting memory and CPU time.
|
||||
*
|
||||
* The "nalloc" should be 16.
|
||||
*/
|
||||
|
||||
|
||||
static void *nxt_lvlhsh_pool_alloc_chunk(nxt_mem_pool_cache_t *cache,
|
||||
size_t size, nxt_uint_t nalloc);
|
||||
|
||||
|
||||
/* Allocation of lvlhsh level or bucket with specified size. */
|
||||
|
||||
void *
|
||||
nxt_lvlhsh_pool_alloc(void *ctx, size_t size, nxt_uint_t nalloc)
|
||||
{
|
||||
void *p, **pp;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_mem_pool_cache_t *cache;
|
||||
|
||||
mp = ctx;
|
||||
|
||||
for (cache = mp->cache; cache != NULL; cache = cache->next) {
|
||||
|
||||
if (cache->size == size && cache->nalloc != 0) {
|
||||
|
||||
if (cache->free != NULL) {
|
||||
pp = cache->free;
|
||||
cache->free = *pp;
|
||||
return pp;
|
||||
}
|
||||
|
||||
return nxt_lvlhsh_pool_alloc_chunk(cache, size, nalloc);
|
||||
}
|
||||
}
|
||||
|
||||
cache = nxt_mem_alloc(mp, sizeof(nxt_mem_pool_cache_t));
|
||||
|
||||
if (nxt_fast_path(cache != NULL)) {
|
||||
|
||||
p = nxt_memalign(size, size);
|
||||
|
||||
if (nxt_fast_path(p != NULL)) {
|
||||
cache->size = size;
|
||||
cache->nalloc = nalloc;
|
||||
cache->free = NULL;
|
||||
cache->next = mp->cache;
|
||||
mp->cache = cache;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
nxt_lvlhsh_pool_alloc_chunk(nxt_mem_pool_cache_t *cache, size_t size,
|
||||
nxt_uint_t nalloc)
|
||||
{
|
||||
char *m, *p, *end;
|
||||
void **pp;
|
||||
size_t n;
|
||||
|
||||
n = (nalloc == 0) ? 1 : nalloc;
|
||||
n *= size;
|
||||
|
||||
m = nxt_memalign(size, n);
|
||||
|
||||
if (nxt_fast_path(m != NULL)) {
|
||||
|
||||
pp = &cache->free;
|
||||
end = m + n;
|
||||
|
||||
for (p = m + size; p < end; p = p + size) {
|
||||
*pp = p;
|
||||
pp = (void **) p;
|
||||
}
|
||||
|
||||
*pp = NULL;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Deallocation of lvlhsh level or bucket with specified size. */
|
||||
|
||||
void
|
||||
nxt_lvlhsh_pool_free(void *ctx, void *p, size_t size)
|
||||
{
|
||||
void **pp;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_mem_pool_cache_t *cache;
|
||||
|
||||
mp = ctx;
|
||||
|
||||
pp = p;
|
||||
|
||||
for (cache = mp->cache; cache != NULL; cache = cache->next) {
|
||||
|
||||
if (cache->size == size && cache->nalloc != 0) {
|
||||
*pp = cache->free;
|
||||
cache->free = p;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,7 @@
|
||||
#include <nxt_clang.h>
|
||||
#include <nxt_types.h>
|
||||
#include <nxt_time.h>
|
||||
|
||||
typedef struct nxt_mem_pool_s nxt_mem_pool_t;
|
||||
#include <nxt_mp.h>
|
||||
#include <nxt_array.h>
|
||||
|
||||
typedef struct nxt_port_s nxt_port_t;
|
||||
@@ -32,8 +31,6 @@ typedef uint16_t nxt_port_id_t;
|
||||
typedef struct nxt_thread_s nxt_thread_t;
|
||||
#include <nxt_thread_id.h>
|
||||
|
||||
#include <nxt_mem_pool.h>
|
||||
|
||||
#include <nxt_errno.h>
|
||||
#include <nxt_file.h>
|
||||
|
||||
@@ -76,9 +73,7 @@ typedef struct {
|
||||
} nxt_mem_proto_t;
|
||||
|
||||
|
||||
#include <nxt_mp.h>
|
||||
#include <nxt_mem_zone.h>
|
||||
#include <nxt_mem_pool_cleanup.h>
|
||||
#include <nxt_thread_time.h>
|
||||
|
||||
typedef struct nxt_event_engine_s nxt_event_engine_t;
|
||||
|
||||
@@ -137,7 +137,7 @@ nxt_master_start_controller_process(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
{
|
||||
nxt_process_init_t *init;
|
||||
|
||||
init = nxt_mem_alloc(rt->mem_pool, sizeof(nxt_process_init_t));
|
||||
init = nxt_mp_get(rt->mem_pool, sizeof(nxt_process_init_t));
|
||||
if (nxt_slow_path(init == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ nxt_master_start_router_process(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
{
|
||||
nxt_process_init_t *init;
|
||||
|
||||
init = nxt_mem_alloc(rt->mem_pool, sizeof(nxt_process_init_t));
|
||||
init = nxt_mp_get(rt->mem_pool, sizeof(nxt_process_init_t));
|
||||
if (nxt_slow_path(init == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ nxt_master_start_worker_processes(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
nxt_uint_t n;
|
||||
nxt_process_init_t *init;
|
||||
|
||||
init = nxt_mem_alloc(rt->mem_pool, sizeof(nxt_process_init_t));
|
||||
init = nxt_mp_get(rt->mem_pool, sizeof(nxt_process_init_t));
|
||||
if (nxt_slow_path(init == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -331,17 +331,17 @@ nxt_master_process_sigquit_handler(nxt_task_t *task, void *obj, void *data)
|
||||
static void
|
||||
nxt_master_process_sigusr1_handler(nxt_task_t *task, void *obj, void *data)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t ret;
|
||||
nxt_uint_t n;
|
||||
nxt_file_t *file, *new_file;
|
||||
nxt_runtime_t *rt;
|
||||
nxt_array_t *new_files;
|
||||
nxt_mem_pool_t *mp;
|
||||
|
||||
nxt_log(task, NXT_LOG_NOTICE, "signal %d (%s) recevied, %s",
|
||||
(int) (uintptr_t) obj, data, "log files rotation");
|
||||
|
||||
mp = nxt_mem_pool_create(1024);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (mp == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -352,7 +352,7 @@ nxt_master_process_sigusr1_handler(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
new_files = nxt_array_create(mp, n, sizeof(nxt_file_t));
|
||||
if (new_files == NULL) {
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ nxt_master_process_sigusr1_handler(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
} nxt_list_loop;
|
||||
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ fail:
|
||||
n--;
|
||||
}
|
||||
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,644 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) Igor Sysoev
|
||||
* Copyright (C) NGINX, Inc.
|
||||
*/
|
||||
|
||||
#include <nxt_main.h>
|
||||
|
||||
|
||||
/*
|
||||
* The pool allocator provides cheap allocation of small objects.
|
||||
* The objects are allocated from larger preallocated chunks.
|
||||
*
|
||||
* aligned and non-aligned allocations,
|
||||
* cache of reusable objects, lvlhsh-specific cache
|
||||
* eliminating align padding
|
||||
* data locality
|
||||
* freeing on pool destruction
|
||||
* freeing large allocations
|
||||
*/
|
||||
|
||||
|
||||
static void *nxt_mem_pool_align(nxt_mem_pool_t *mp, size_t alignment,
|
||||
size_t size);
|
||||
static void *nxt_mem_pool_ext(nxt_mem_pool_t *mp, size_t size);
|
||||
static nxt_mem_pool_chunk_t *nxt_mem_pool_next_chunk(nxt_mem_pool_t *mp,
|
||||
nxt_mem_pool_chunk_t *chunk);
|
||||
static nxt_mem_pool_chunk_t *nxt_mem_pool_chunk(nxt_mem_pool_t *mp);
|
||||
static void *nxt_mem_lvlhsh_alloc_chunk(nxt_mem_pool_cache_t *cache,
|
||||
size_t size, nxt_uint_t nalloc);
|
||||
|
||||
|
||||
#if (NXT_DEBUG)
|
||||
|
||||
static nxt_bool_t
|
||||
nxt_mem_pool_thread_is_invalid(nxt_mem_pool_t *mp)
|
||||
{
|
||||
nxt_tid_t tid;
|
||||
nxt_thread_t *thr;
|
||||
|
||||
thr = nxt_thread();
|
||||
tid = nxt_thread_tid(thr);
|
||||
|
||||
if (nxt_slow_path(mp->tid != tid)) {
|
||||
|
||||
if (mp->pid == nxt_pid) {
|
||||
nxt_log_alert(thr->log, "mem_pool locked by thread %PT", mp->tid);
|
||||
nxt_abort();
|
||||
return 1;
|
||||
}
|
||||
|
||||
mp->pid = nxt_pid;
|
||||
mp->tid = tid;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* SunC does not support C99 variadic macro with empty __VA_ARGS__. */
|
||||
|
||||
#define \
|
||||
nxt_mem_pool_thread_assert(mp) \
|
||||
if (nxt_mem_pool_thread_is_invalid(mp)) \
|
||||
return
|
||||
|
||||
|
||||
#define \
|
||||
nxt_mem_pool_thread_assert_return(mp, ret) \
|
||||
if (nxt_mem_pool_thread_is_invalid(mp)) \
|
||||
return ret
|
||||
|
||||
|
||||
#else /* !(NXT_DEBUG) */
|
||||
|
||||
#define \
|
||||
nxt_mem_pool_thread_assert(mp)
|
||||
|
||||
#define \
|
||||
nxt_mem_pool_thread_assert_return(mp, ret)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
nxt_mem_pool_t *
|
||||
nxt_mem_pool_create(size_t size)
|
||||
{
|
||||
u_char *p;
|
||||
size_t min_ext_size;
|
||||
nxt_mem_pool_t *mp;
|
||||
|
||||
mp = nxt_malloc(size);
|
||||
|
||||
if (nxt_fast_path(mp != NULL)) {
|
||||
|
||||
mp->chunk_size = (uint32_t) size;
|
||||
|
||||
min_ext_size = size - sizeof(nxt_mem_pool_t) + 1;
|
||||
mp->min_ext_size = (uint32_t) nxt_min(min_ext_size,
|
||||
NXT_MEM_POOL_MIN_EXT_SIZE);
|
||||
|
||||
nxt_malloc_usable_size(mp, size);
|
||||
|
||||
p = (u_char *) mp;
|
||||
|
||||
mp->chunk.free = p + sizeof(nxt_mem_pool_t);
|
||||
mp->chunk.end = p + size;
|
||||
mp->chunk.next = NULL;
|
||||
mp->chunk.fails = 0;
|
||||
|
||||
mp->current = &mp->chunk;
|
||||
mp->ext = NULL;
|
||||
mp->cleanup = NULL;
|
||||
mp->cache = NULL;
|
||||
|
||||
nxt_thread_log_debug("mem pool chunk size:%uz avail:%uz",
|
||||
size, mp->chunk.end - mp->chunk.free);
|
||||
|
||||
nxt_mem_pool_debug_lock(mp, nxt_thread_tid(NULL));
|
||||
}
|
||||
|
||||
return mp;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nxt_mem_pool_destroy(nxt_mem_pool_t *mp)
|
||||
{
|
||||
nxt_task_t *task;
|
||||
nxt_mem_pool_ext_t *ext;
|
||||
nxt_mem_pool_chunk_t *chunk, *next;
|
||||
nxt_mem_pool_cleanup_t *mpcl;
|
||||
|
||||
task = NULL;
|
||||
|
||||
nxt_mem_pool_thread_assert(mp);
|
||||
|
||||
for (mpcl = mp->cleanup; mpcl != NULL; mpcl = mpcl->next) {
|
||||
if (mpcl->handler != NULL) {
|
||||
nxt_thread_log_debug("mem pool cleanup: %p", mpcl);
|
||||
mpcl->handler(task, mpcl->data);
|
||||
}
|
||||
}
|
||||
|
||||
for (ext = mp->ext; ext != NULL; ext = ext->next) {
|
||||
if (ext->data != NULL) {
|
||||
nxt_free(ext->data);
|
||||
}
|
||||
}
|
||||
|
||||
chunk = &mp->chunk;
|
||||
|
||||
do {
|
||||
nxt_thread_log_debug("mem pool chunk fails:%uD unused:%uz",
|
||||
chunk->fails, chunk->end - chunk->free);
|
||||
next = chunk->next;
|
||||
nxt_free(chunk);
|
||||
chunk = next;
|
||||
|
||||
} while (chunk != NULL);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
nxt_mem_align(nxt_mem_pool_t *mp, size_t alignment, size_t size)
|
||||
{
|
||||
nxt_mem_pool_thread_assert_return(mp, NULL);
|
||||
|
||||
if (nxt_fast_path(size < mp->min_ext_size)) {
|
||||
return nxt_mem_pool_align(mp, alignment, size);
|
||||
}
|
||||
|
||||
return nxt_mem_pool_ext(mp, size);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
nxt_mem_zalign(nxt_mem_pool_t *mp, size_t alignment, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = nxt_mem_align(mp, alignment, size);
|
||||
|
||||
if (nxt_fast_path(p != NULL)) {
|
||||
nxt_memzero(p, size);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Zero-filled aligned allocation, suitable for struct
|
||||
* allocation without long double and SIMD values.
|
||||
*/
|
||||
|
||||
void *
|
||||
nxt_mem_zalloc(nxt_mem_pool_t *mp, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = nxt_mem_alloc(mp, size);
|
||||
|
||||
if (nxt_fast_path(p != NULL)) {
|
||||
nxt_memzero(p, size);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
nxt_mem_buf(nxt_mem_pool_t *mp, size_t *sizep, nxt_uint_t flags)
|
||||
{
|
||||
u_char *p;
|
||||
size_t size;
|
||||
|
||||
nxt_mem_pool_thread_assert_return(mp, NULL);
|
||||
|
||||
size = *sizep;
|
||||
|
||||
if (nxt_fast_path(size >= mp->min_ext_size)) {
|
||||
|
||||
nxt_malloc_cutback(flags & NXT_MEM_BUF_CUTBACK, size);
|
||||
|
||||
/* Windows only: try to minimize number of allocated pages. */
|
||||
p = nxt_mem_pool_ext(mp, size);
|
||||
if (p != NULL) {
|
||||
|
||||
if (flags & NXT_MEM_BUF_USABLE) {
|
||||
nxt_malloc_usable_size(p, size);
|
||||
}
|
||||
|
||||
*sizep = size;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
return nxt_mem_pool_align(mp, NXT_ALIGNMENT, size);
|
||||
}
|
||||
|
||||
|
||||
/* Non-aligned allocation, suitable for string allocation. */
|
||||
|
||||
void *
|
||||
nxt_mem_nalloc(nxt_mem_pool_t *mp, size_t size)
|
||||
{
|
||||
u_char *p;
|
||||
nxt_mem_pool_chunk_t *chunk;
|
||||
|
||||
nxt_mem_pool_thread_assert_return(mp, NULL);
|
||||
|
||||
if (nxt_slow_path(size >= mp->min_ext_size)) {
|
||||
return nxt_mem_pool_ext(mp, size);
|
||||
}
|
||||
|
||||
chunk = mp->current;
|
||||
|
||||
for ( ;; ) {
|
||||
p = chunk->end - size;
|
||||
|
||||
if (nxt_fast_path(p >= chunk->free)) {
|
||||
chunk->end = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
chunk = nxt_mem_pool_next_chunk(mp, chunk);
|
||||
|
||||
if (nxt_slow_path(chunk == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* An attempt to deallocate a large allocation outside pool. */
|
||||
|
||||
nxt_int_t
|
||||
nxt_mem_free(nxt_mem_pool_t *mp, void *p)
|
||||
{
|
||||
nxt_mem_pool_ext_t *ext;
|
||||
|
||||
nxt_mem_pool_thread_assert_return(mp, NXT_DECLINED);
|
||||
|
||||
for (ext = mp->ext; ext != NULL; ext = ext->next) {
|
||||
|
||||
if (p == ext->data) {
|
||||
nxt_free(ext->data);
|
||||
ext->data = NULL;
|
||||
|
||||
return NXT_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NXT_DECLINED;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
nxt_mem_pool_ext(nxt_mem_pool_t *mp, size_t size)
|
||||
{
|
||||
void *p;
|
||||
nxt_mem_pool_ext_t *ext;
|
||||
|
||||
ext = nxt_mem_pool_align(mp, sizeof(void *), sizeof(nxt_mem_pool_ext_t));
|
||||
|
||||
if (nxt_fast_path(ext != NULL)) {
|
||||
p = nxt_malloc(size);
|
||||
|
||||
if (nxt_fast_path(p != NULL)) {
|
||||
ext->data = p;
|
||||
ext->next = mp->ext;
|
||||
mp->ext = ext;
|
||||
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
nxt_mem_pool_align(nxt_mem_pool_t *mp, size_t alignment, size_t size)
|
||||
{
|
||||
u_char *p, *f;
|
||||
nxt_mem_pool_chunk_t *chunk;
|
||||
|
||||
chunk = mp->current;
|
||||
|
||||
for ( ;; ) {
|
||||
|
||||
p = nxt_align_ptr(chunk->free, alignment);
|
||||
f = p + size;
|
||||
|
||||
if (nxt_fast_path(f <= chunk->end)) {
|
||||
chunk->free = f;
|
||||
return p;
|
||||
}
|
||||
|
||||
chunk = nxt_mem_pool_next_chunk(mp, chunk);
|
||||
|
||||
if (nxt_slow_path(chunk == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static nxt_mem_pool_chunk_t *
|
||||
nxt_mem_pool_next_chunk(nxt_mem_pool_t *mp, nxt_mem_pool_chunk_t *chunk)
|
||||
{
|
||||
nxt_bool_t full;
|
||||
|
||||
full = (chunk->free == chunk->end || chunk->fails++ > 10);
|
||||
|
||||
chunk = chunk->next;
|
||||
|
||||
if (chunk == NULL) {
|
||||
chunk = nxt_mem_pool_chunk(mp);
|
||||
|
||||
if (nxt_slow_path(chunk == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (full) {
|
||||
mp->current = chunk;
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
static nxt_mem_pool_chunk_t *
|
||||
nxt_mem_pool_chunk(nxt_mem_pool_t *mp)
|
||||
{
|
||||
u_char *p;
|
||||
size_t size;
|
||||
nxt_mem_pool_chunk_t *ch, *chunk;
|
||||
|
||||
size = mp->chunk_size;
|
||||
|
||||
chunk = nxt_malloc(size);
|
||||
|
||||
if (nxt_fast_path(chunk != NULL)) {
|
||||
|
||||
nxt_malloc_usable_size(chunk, size);
|
||||
|
||||
p = (u_char *) chunk;
|
||||
|
||||
chunk->free = p + sizeof(nxt_mem_pool_chunk_t);
|
||||
chunk->end = p + size;
|
||||
chunk->next = NULL;
|
||||
chunk->fails = 0;
|
||||
|
||||
for (ch = mp->current; ch->next; ch = ch->next) { /* void */ }
|
||||
|
||||
ch->next = chunk;
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
nxt_mem_pool_cleanup_t *
|
||||
nxt_mem_pool_cleanup(nxt_mem_pool_t *mp, size_t size)
|
||||
{
|
||||
nxt_mem_pool_cleanup_t *mpcl;
|
||||
|
||||
nxt_mem_pool_thread_assert_return(mp, NULL);
|
||||
|
||||
mpcl = nxt_mem_pool_align(mp, sizeof(void *),
|
||||
sizeof(nxt_mem_pool_cleanup_t));
|
||||
if (nxt_fast_path(mpcl != NULL)) {
|
||||
|
||||
mpcl->handler = NULL;
|
||||
mpcl->data = NULL;
|
||||
|
||||
if (size != 0) {
|
||||
mpcl->data = nxt_mem_alloc(mp, size);
|
||||
if (nxt_slow_path(mpcl->data == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mpcl->next = mp->cleanup;
|
||||
mp->cleanup = mpcl;
|
||||
|
||||
nxt_thread_log_debug("mem pool cleanup add: %p", mpcl);
|
||||
}
|
||||
|
||||
return mpcl;
|
||||
}
|
||||
|
||||
|
||||
/* Allocation of reusable object with specified size. */
|
||||
|
||||
void *
|
||||
nxt_mem_cache_alloc0(nxt_mem_pool_t *mp, size_t size)
|
||||
{
|
||||
void **pp;
|
||||
nxt_mem_pool_cache_t *cache;
|
||||
|
||||
nxt_mem_pool_thread_assert_return(mp, NULL);
|
||||
|
||||
for (cache = mp->cache; cache != NULL; cache = cache->next) {
|
||||
|
||||
if (cache->size == size && cache->nalloc == 0) {
|
||||
|
||||
if (cache->free != NULL) {
|
||||
pp = cache->free;
|
||||
cache->free = *pp;
|
||||
return pp;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return nxt_mem_alloc(mp, size);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
nxt_mem_cache_zalloc0(nxt_mem_pool_t *mp, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = nxt_mem_cache_alloc0(mp, size);
|
||||
|
||||
if (nxt_fast_path(p != NULL)) {
|
||||
nxt_memzero(p, size);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/* Deallocation of reusable object with specified size. */
|
||||
|
||||
void
|
||||
nxt_mem_cache_free0(nxt_mem_pool_t *mp, void *p, size_t size)
|
||||
{
|
||||
void **pp;
|
||||
nxt_mem_pool_cache_t *cache, **pcache;
|
||||
|
||||
nxt_mem_pool_thread_assert(mp);
|
||||
|
||||
pp = p;
|
||||
|
||||
pcache = &mp->cache;
|
||||
for (cache = mp->cache; cache != NULL; cache = cache->next) {
|
||||
|
||||
if (cache->size == size && cache->nalloc == 0) {
|
||||
*pp = cache->free;
|
||||
cache->free = p;
|
||||
return;
|
||||
}
|
||||
|
||||
pcache = &cache->next;
|
||||
}
|
||||
|
||||
/* Non-lvlhash caches are created only on return. */
|
||||
|
||||
cache = nxt_mem_pool_align(mp, sizeof(void *),
|
||||
sizeof(nxt_mem_pool_cache_t));
|
||||
if (nxt_fast_path(cache != NULL)) {
|
||||
*pp = NULL;
|
||||
cache->size = (uint32_t) size;
|
||||
cache->nalloc = 0;
|
||||
cache->free = p;
|
||||
cache->next = NULL;
|
||||
*pcache = cache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* lvlhsh requires allocations aligned to a size of the allocations.
|
||||
* This is not issue for slab-like allocators, but glibc allocator may
|
||||
* waste memory on such aligned allocations. So nxt_mem_lvlhsh_alloc()
|
||||
* allocates memory in chunks specified by the "nalloc" parameter
|
||||
* except the first allocation. The first lvlhsh allocation is a bucket
|
||||
* allocation and it is enough for small hashes and for early stage
|
||||
* of a hash. By default lvlhsh uses 128-bytes buckets and levels.
|
||||
* This allows to search up to 10 entries in one memory access and
|
||||
* up to 160 entries in two memory accesses on 64-bit platform.
|
||||
* And on 32-bit platform up to 15 entries and up to 480 entries
|
||||
* respectively.
|
||||
*
|
||||
* After the bucket will be filled up with 10 64-bit entries or 15
|
||||
* 32-bit entries, lvlhsh will expand it to a level and content
|
||||
* of the first bucket will spread to the level's new buckets.
|
||||
* Number of the new buckets may be up to 11 on 64-bit or 16 on 32-bit
|
||||
* platforms. It's better to allocate them together to eliminate
|
||||
* wasting memory and CPU time.
|
||||
*
|
||||
* The "nalloc" should be 16 if bucket size is 128 bytes.
|
||||
*/
|
||||
|
||||
|
||||
/* Allocation of lvlhsh level or bucket with specified size. */
|
||||
|
||||
void *
|
||||
nxt_mem_lvlhsh_alloc(void *ctx, size_t size, nxt_uint_t nalloc)
|
||||
{
|
||||
void *p, **pp;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_mem_pool_cache_t *cache;
|
||||
|
||||
mp = ctx;
|
||||
|
||||
nxt_mem_pool_thread_assert_return(mp, NULL);
|
||||
|
||||
for (cache = mp->cache; cache != NULL; cache = cache->next) {
|
||||
|
||||
if (cache->size == size && cache->nalloc != 0) {
|
||||
|
||||
if (cache->free != NULL) {
|
||||
pp = cache->free;
|
||||
cache->free = *pp;
|
||||
return pp;
|
||||
}
|
||||
|
||||
return nxt_mem_lvlhsh_alloc_chunk(cache, size, nalloc);
|
||||
}
|
||||
}
|
||||
|
||||
cache = nxt_mem_pool_align(mp, sizeof(void *),
|
||||
sizeof(nxt_mem_pool_cache_t));
|
||||
if (nxt_fast_path(cache != NULL)) {
|
||||
|
||||
p = nxt_memalign(size, size);
|
||||
|
||||
if (nxt_fast_path(p != NULL)) {
|
||||
cache->size = (uint32_t) size;
|
||||
cache->nalloc = nalloc;
|
||||
cache->free = NULL;
|
||||
cache->next = mp->cache;
|
||||
mp->cache = cache;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
nxt_mem_lvlhsh_alloc_chunk(nxt_mem_pool_cache_t *cache, size_t size,
|
||||
nxt_uint_t nalloc)
|
||||
{
|
||||
char *m, *p, *end;
|
||||
void **pp;
|
||||
size_t n;
|
||||
|
||||
n = (nalloc == 0) ? 1 : nalloc;
|
||||
n *= size;
|
||||
|
||||
m = nxt_memalign(size, n);
|
||||
|
||||
if (nxt_fast_path(m != NULL)) {
|
||||
|
||||
pp = &cache->free;
|
||||
end = m + n;
|
||||
|
||||
for (p = m + size; p < end; p = p + size) {
|
||||
*pp = p;
|
||||
pp = (void **) p;
|
||||
}
|
||||
|
||||
*pp = NULL;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/* Deallocation of lvlhsh level or bucket with specified size. */
|
||||
|
||||
void
|
||||
nxt_mem_lvlhsh_free(void *ctx, void *p, size_t size)
|
||||
{
|
||||
void **pp;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_mem_pool_cache_t *cache;
|
||||
|
||||
mp = ctx;
|
||||
|
||||
nxt_mem_pool_thread_assert(mp);
|
||||
|
||||
pp = p;
|
||||
|
||||
for (cache = mp->cache; cache != NULL; cache = cache->next) {
|
||||
|
||||
if (cache->size == size && cache->nalloc != 0) {
|
||||
*pp = cache->free;
|
||||
cache->free = p;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) Igor Sysoev
|
||||
* Copyright (C) NGINX, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _NXT_MEM_POOL_H_INCLUDED_
|
||||
#define _NXT_MEM_POOL_H_INCLUDED_
|
||||
|
||||
|
||||
#define NXT_MEM_POOL_MIN_EXT_SIZE nxt_pagesize
|
||||
|
||||
|
||||
typedef void (*nxt_mem_pool_cleanup_handler_t)(nxt_task_t *task, void *data);
|
||||
typedef struct nxt_mem_pool_cleanup_s nxt_mem_pool_cleanup_t;
|
||||
typedef struct nxt_mem_pool_cache_s nxt_mem_pool_cache_t;
|
||||
typedef struct nxt_mem_pool_chunk_s nxt_mem_pool_chunk_t;
|
||||
typedef struct nxt_mem_pool_ext_s nxt_mem_pool_ext_t;
|
||||
|
||||
|
||||
struct nxt_mem_pool_cleanup_s {
|
||||
nxt_mem_pool_cleanup_handler_t handler;
|
||||
void *data;
|
||||
nxt_mem_pool_cleanup_t *next;
|
||||
};
|
||||
|
||||
|
||||
struct nxt_mem_pool_ext_s {
|
||||
void *data;
|
||||
nxt_mem_pool_ext_t *next;
|
||||
};
|
||||
|
||||
|
||||
struct nxt_mem_pool_chunk_s {
|
||||
u_char *free;
|
||||
u_char *end;
|
||||
nxt_mem_pool_chunk_t *next;
|
||||
uint32_t fails; /* 8 bits */
|
||||
};
|
||||
|
||||
|
||||
struct nxt_mem_pool_cache_s {
|
||||
uint32_t size;
|
||||
uint32_t nalloc;
|
||||
void *free;
|
||||
nxt_mem_pool_cache_t *next;
|
||||
};
|
||||
|
||||
|
||||
struct nxt_mem_pool_s {
|
||||
nxt_mem_pool_chunk_t chunk;
|
||||
uint32_t min_ext_size;
|
||||
uint32_t chunk_size;
|
||||
nxt_mem_pool_chunk_t *current;
|
||||
nxt_mem_pool_ext_t *ext;
|
||||
nxt_mem_pool_cache_t *cache;
|
||||
nxt_mem_pool_cleanup_t *cleanup;
|
||||
|
||||
#if (NXT_DEBUG)
|
||||
nxt_pid_t pid;
|
||||
nxt_tid_t tid;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
NXT_EXPORT nxt_mem_pool_t *nxt_mem_pool_create(size_t size)
|
||||
NXT_MALLOC_LIKE;
|
||||
NXT_EXPORT void nxt_mem_pool_destroy(nxt_mem_pool_t *mp);
|
||||
|
||||
|
||||
/*
|
||||
* Generic aligned allocation, suitable for struct allocations
|
||||
* without "long double" and SIMD values.
|
||||
*/
|
||||
#define \
|
||||
nxt_mem_alloc(mp, size) \
|
||||
nxt_mem_align((mp), NXT_ALIGNMENT, (size))
|
||||
|
||||
|
||||
NXT_EXPORT void *nxt_mem_align(nxt_mem_pool_t *mp, size_t alignment,
|
||||
size_t size)
|
||||
NXT_MALLOC_LIKE;
|
||||
|
||||
NXT_EXPORT void *nxt_mem_zalign(nxt_mem_pool_t *mp, size_t alignment,
|
||||
size_t size)
|
||||
NXT_MALLOC_LIKE;
|
||||
|
||||
NXT_EXPORT void *nxt_mem_nalloc(nxt_mem_pool_t *mp, size_t size)
|
||||
NXT_MALLOC_LIKE;
|
||||
|
||||
NXT_EXPORT void *nxt_mem_zalloc(nxt_mem_pool_t *mp, size_t size)
|
||||
NXT_MALLOC_LIKE;
|
||||
|
||||
|
||||
/*
|
||||
* nxt_mem_buf() is intended to allocate I/O buffers.
|
||||
* Unix network buffers usually have no size restrictions, so
|
||||
* NXT_MEM_BUF_CUTBACK and NXT_MEM_BUF_USABLE options allow to
|
||||
* utilize better allocated memory (details in unix/nxt_malloc.h).
|
||||
* Windows locks buffers in kernel memory on page basis for both
|
||||
* network and file operations, so nxt_mem_buf() should minimize
|
||||
* number of allocated pages. However, these allocations are not
|
||||
* necessary page-aligned.
|
||||
*/
|
||||
#define NXT_MEM_BUF_CUTBACK 1
|
||||
#define NXT_MEM_BUF_USABLE 2
|
||||
|
||||
NXT_EXPORT void *nxt_mem_buf(nxt_mem_pool_t *mp, size_t *sizep,
|
||||
nxt_uint_t flags);
|
||||
|
||||
|
||||
/*
|
||||
* Aligned allocation, suitable for generic allocations compatible
|
||||
* with malloc() alignment.
|
||||
*/
|
||||
#define \
|
||||
nxt_mem_malloc(mp, size) \
|
||||
nxt_mem_align((mp), NXT_MAX_ALIGNMENT, (size))
|
||||
|
||||
|
||||
NXT_EXPORT nxt_int_t nxt_mem_free(nxt_mem_pool_t *mp, void *p);
|
||||
NXT_EXPORT nxt_mem_pool_cleanup_t *nxt_mem_pool_cleanup(nxt_mem_pool_t *mp,
|
||||
size_t size);
|
||||
|
||||
NXT_EXPORT void *nxt_mem_cache_alloc0(nxt_mem_pool_t *mp, size_t size)
|
||||
NXT_MALLOC_LIKE;
|
||||
NXT_EXPORT void *nxt_mem_cache_zalloc0(nxt_mem_pool_t *mp, size_t size)
|
||||
NXT_MALLOC_LIKE;
|
||||
NXT_EXPORT void nxt_mem_cache_free0(nxt_mem_pool_t *mp, void *p, size_t size);
|
||||
|
||||
NXT_EXPORT void *nxt_mem_lvlhsh_alloc(void *ctx, size_t size,
|
||||
nxt_uint_t nalloc);
|
||||
NXT_EXPORT void nxt_mem_lvlhsh_free(void *ctx, void *p, size_t size);
|
||||
|
||||
|
||||
#if (NXT_DEBUG)
|
||||
|
||||
#define \
|
||||
nxt_mem_pool_debug_lock(_mp, _tid) \
|
||||
(_mp->tid) = _tid
|
||||
|
||||
#else
|
||||
|
||||
#define \
|
||||
nxt_mem_pool_debug_lock(_mp, _tid)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _NXT_MEM_POOL_H_INCLUDED_ */
|
||||
@@ -256,7 +256,7 @@ nxt_openssl_conn_init(nxt_task_t *task, nxt_ssltls_conf_t *conf, nxt_conn_t *c)
|
||||
|
||||
nxt_log_debug(c->socket.log, "openssl conn init");
|
||||
|
||||
ssltls = nxt_mem_zalloc(c->mem_pool, sizeof(nxt_openssl_conn_t));
|
||||
ssltls = nxt_mp_zget(c->mem_pool, sizeof(nxt_openssl_conn_t));
|
||||
if (ssltls == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ nxt_php_request_init(nxt_app_request_t *r)
|
||||
{
|
||||
nxt_php_ctx_t *ctx;
|
||||
|
||||
ctx = nxt_mem_zalloc(r->mem_pool, sizeof(nxt_php_ctx_t));
|
||||
ctx = nxt_mp_zget(r->mem_pool, sizeof(nxt_php_ctx_t));
|
||||
if (nxt_slow_path(ctx == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -261,7 +261,7 @@ nxt_php_handler(nxt_app_request_t *r)
|
||||
|
||||
#if !ABS_MODE
|
||||
ctx->script.len = sizeof(root) - 1 + ctx->script_name_len;
|
||||
ctx->script.data = nxt_mem_nalloc(r->mem_pool, ctx->script.len + 1);
|
||||
ctx->script.data = nxt_mp_nget(r->mem_pool, ctx->script.len + 1);
|
||||
|
||||
if (nxt_slow_path(ctx->script.data == NULL)) {
|
||||
return NXT_ERROR;
|
||||
@@ -565,7 +565,7 @@ nxt_php_register_variables(zval *track_vars_array TSRMLS_DC)
|
||||
ctx->content_length->len, track_vars_array TSRMLS_CC);
|
||||
}
|
||||
|
||||
var = nxt_mem_nalloc(r->mem_pool, sizeof(prefix) + ctx->max_name + 1);
|
||||
var = nxt_mp_nget(r->mem_pool, sizeof(prefix) + ctx->max_name + 1);
|
||||
|
||||
if (nxt_slow_path(var == NULL)) {
|
||||
return;
|
||||
|
||||
@@ -98,7 +98,6 @@ const nxt_event_interface_t nxt_poll_engine = {
|
||||
static const nxt_lvlhsh_proto_t nxt_poll_fd_hash_proto nxt_aligned(64) =
|
||||
{
|
||||
NXT_LVLHSH_LARGE_MEMALIGN,
|
||||
0,
|
||||
nxt_poll_fd_hash_test,
|
||||
nxt_lvlhsh_alloc,
|
||||
nxt_lvlhsh_free,
|
||||
|
||||
@@ -144,10 +144,10 @@ nxt_port_new_port_buf_completion(nxt_task_t *task, void *obj, void *data)
|
||||
void
|
||||
nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_port_t *port;
|
||||
nxt_process_t *process;
|
||||
nxt_runtime_t *rt;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_port_msg_new_port_t *new_port_msg;
|
||||
|
||||
rt = task->thread->runtime;
|
||||
@@ -165,7 +165,7 @@ nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
|
||||
return;
|
||||
}
|
||||
|
||||
mp = nxt_mem_pool_create(1024);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ struct nxt_port_s {
|
||||
nxt_port_handler_t handler;
|
||||
void *data;
|
||||
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
nxt_buf_t *free_bufs;
|
||||
nxt_socket_t pair[2];
|
||||
|
||||
|
||||
@@ -100,9 +100,9 @@ static void
|
||||
nxt_port_mmap_buf_completion(nxt_task_t *task, void *obj, void *data)
|
||||
{
|
||||
u_char *p;
|
||||
nxt_mp_t *mp;
|
||||
nxt_buf_t *b;
|
||||
nxt_chunk_id_t c;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_port_mmap_t *port_mmap;
|
||||
nxt_port_mmap_header_t *hdr;
|
||||
|
||||
@@ -448,7 +448,7 @@ nxt_port_mmap_get_buf(nxt_task_t *task, nxt_port_t *port, size_t size)
|
||||
|
||||
nxt_debug(task, "request %z bytes shm buffer", size);
|
||||
|
||||
b = nxt_mem_cache_zalloc0(port->mem_pool, NXT_BUF_PORT_MMAP_SIZE);
|
||||
b = nxt_mp_zalloc(port->mem_pool, NXT_BUF_PORT_MMAP_SIZE);
|
||||
if (nxt_slow_path(b == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -508,7 +508,7 @@ nxt_port_mmap_get_incoming_buf(nxt_task_t *task, nxt_port_t *port,
|
||||
nxt_buf_t *b;
|
||||
nxt_port_mmap_t *port_mmap;
|
||||
|
||||
b = nxt_mem_cache_zalloc0(port->mem_pool, NXT_BUF_PORT_MMAP_SIZE);
|
||||
b = nxt_mp_zalloc(port->mem_pool, NXT_BUF_PORT_MMAP_SIZE);
|
||||
if (nxt_slow_path(b == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ static void nxt_port_error_handler(nxt_task_t *task, void *obj, void *data);
|
||||
nxt_int_t
|
||||
nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, size_t max_size)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t sndbuf, rcvbuf, size;
|
||||
nxt_socket_t snd, rcv;
|
||||
nxt_mem_pool_t *mp;
|
||||
|
||||
port->socket.task = task;
|
||||
|
||||
@@ -30,7 +30,7 @@ nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, size_t max_size)
|
||||
|
||||
nxt_queue_init(&port->messages);
|
||||
|
||||
mp = nxt_mem_pool_create(1024);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ getsockopt_fail:
|
||||
|
||||
socketpair_fail:
|
||||
|
||||
nxt_mem_pool_destroy(port->mem_pool);
|
||||
nxt_mp_destroy(port->mem_pool);
|
||||
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ void
|
||||
nxt_port_destroy(nxt_port_t *port)
|
||||
{
|
||||
nxt_socket_close(port->socket.task, port->socket.fd);
|
||||
nxt_mem_pool_destroy(port->mem_pool);
|
||||
nxt_mp_destroy(port->mem_pool);
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, nxt_uint_t type,
|
||||
}
|
||||
}
|
||||
|
||||
msg = nxt_mem_cache_zalloc0(port->mem_pool, sizeof(nxt_port_send_msg_t));
|
||||
msg = nxt_mp_zalloc(port->mem_pool, sizeof(nxt_port_send_msg_t));
|
||||
if (nxt_slow_path(msg == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -289,8 +289,7 @@ nxt_port_write_handler(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
} else {
|
||||
nxt_queue_remove(link);
|
||||
nxt_mem_cache_free0(port->mem_pool, msg,
|
||||
sizeof(nxt_port_send_msg_t));
|
||||
nxt_mp_free(port->mem_pool, msg);
|
||||
}
|
||||
|
||||
} else if (nxt_slow_path(n == NXT_ERROR)) {
|
||||
|
||||
@@ -513,7 +513,7 @@ nxt_process_port_new(nxt_process_t *process)
|
||||
{
|
||||
nxt_port_t *port;
|
||||
|
||||
port = nxt_mem_cache_zalloc0(process->mem_pool, sizeof(nxt_port_t));
|
||||
port = nxt_mp_zalloc(process->mem_pool, sizeof(nxt_port_t));
|
||||
if (nxt_fast_path(port != NULL)) {
|
||||
port->id = process->last_port_id++;
|
||||
port->pid = process->pid;
|
||||
|
||||
@@ -49,7 +49,7 @@ struct nxt_process_init_s {
|
||||
|
||||
|
||||
typedef struct {
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
|
||||
nxt_pid_t pid;
|
||||
nxt_queue_t ports; /* of nxt_port_t */
|
||||
|
||||
@@ -17,26 +17,23 @@ static nxt_int_t nxt_router_stub_conf(nxt_task_t *task,
|
||||
nxt_router_temp_conf_t *tmcf);
|
||||
static nxt_int_t nxt_router_listen_sockets_stub_create(nxt_task_t *task,
|
||||
nxt_router_temp_conf_t *tmcf);
|
||||
static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_sockaddr_t *sa);
|
||||
static nxt_socket_conf_t *nxt_router_socket_conf(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_sockaddr_t *sa);
|
||||
static nxt_sockaddr_t *nxt_router_listen_sockaddr_stub(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, uint32_t port);
|
||||
nxt_mp_t *mp, uint32_t port);
|
||||
|
||||
static nxt_int_t nxt_router_engines_create(nxt_task_t *task,
|
||||
nxt_router_t *router, nxt_router_temp_conf_t *tmcf,
|
||||
const nxt_event_interface_t *interface);
|
||||
static nxt_int_t nxt_router_engine_conf_create(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_router_temp_conf_t *tmcf,
|
||||
nxt_router_engine_conf_t *recf);
|
||||
static nxt_int_t nxt_router_engine_conf_update(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_router_temp_conf_t *tmcf,
|
||||
nxt_router_engine_conf_t *recf);
|
||||
static nxt_int_t nxt_router_engine_conf_delete(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_router_temp_conf_t *tmcf,
|
||||
nxt_router_engine_conf_t *recf);
|
||||
static nxt_int_t nxt_router_engine_joints_create(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_router_engine_conf_t *recf, nxt_queue_t *sockets,
|
||||
nxt_array_t *array, nxt_work_handler_t handler);
|
||||
static nxt_int_t nxt_router_engine_conf_create(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_temp_conf_t *tmcf, nxt_router_engine_conf_t *recf);
|
||||
static nxt_int_t nxt_router_engine_conf_update(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_temp_conf_t *tmcf, nxt_router_engine_conf_t *recf);
|
||||
static nxt_int_t nxt_router_engine_conf_delete(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_temp_conf_t *tmcf, nxt_router_engine_conf_t *recf);
|
||||
static nxt_int_t nxt_router_engine_joints_create(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, nxt_array_t *array,
|
||||
nxt_work_handler_t handler);
|
||||
static nxt_int_t nxt_router_engine_joints_delete(nxt_task_t *task,
|
||||
nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, nxt_array_t *array);
|
||||
|
||||
@@ -133,16 +130,16 @@ nxt_router_start(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
static nxt_router_temp_conf_t *
|
||||
nxt_router_temp_conf(nxt_task_t *task, nxt_router_t *router)
|
||||
{
|
||||
nxt_mem_pool_t *mp, *tmp;
|
||||
nxt_mp_t *mp, *tmp;
|
||||
nxt_router_conf_t *rtcf;
|
||||
nxt_router_temp_conf_t *tmcf;
|
||||
|
||||
mp = nxt_mem_pool_create(1024);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rtcf = nxt_mem_zalloc(mp, sizeof(nxt_router_conf_t));
|
||||
rtcf = nxt_mp_zget(mp, sizeof(nxt_router_conf_t));
|
||||
if (nxt_slow_path(rtcf == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -151,12 +148,12 @@ nxt_router_temp_conf(nxt_task_t *task, nxt_router_t *router)
|
||||
rtcf->router = router;
|
||||
rtcf->count = 1;
|
||||
|
||||
tmp = nxt_mem_pool_create(1024);
|
||||
tmp = nxt_mp_create(1024, 128, 256, 32);
|
||||
if (nxt_slow_path(tmp == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
tmcf = nxt_mem_zalloc(tmp, sizeof(nxt_router_temp_conf_t));
|
||||
tmcf = nxt_mp_zget(tmp, sizeof(nxt_router_temp_conf_t));
|
||||
if (nxt_slow_path(tmcf == NULL)) {
|
||||
goto temp_fail;
|
||||
}
|
||||
@@ -180,11 +177,11 @@ nxt_router_temp_conf(nxt_task_t *task, nxt_router_t *router)
|
||||
|
||||
temp_fail:
|
||||
|
||||
nxt_mem_pool_destroy(tmp);
|
||||
nxt_mp_destroy(tmp);
|
||||
|
||||
fail:
|
||||
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -193,8 +190,8 @@ fail:
|
||||
static nxt_int_t
|
||||
nxt_router_stub_conf(nxt_task_t *task, nxt_router_temp_conf_t *tmcf)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_sockaddr_t *sa;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_socket_conf_t *skcf;
|
||||
|
||||
tmcf->conf->threads = 1;
|
||||
@@ -205,11 +202,6 @@ nxt_router_stub_conf(nxt_task_t *task, nxt_router_temp_conf_t *tmcf)
|
||||
skcf = nxt_router_socket_conf(task, mp, sa);
|
||||
|
||||
skcf->listen.handler = nxt_router_conn_init;
|
||||
skcf->listen.mem_pool_size = nxt_listen_socket_pool_min_size(&skcf->listen)
|
||||
+ sizeof(nxt_conn_proxy_t)
|
||||
+ sizeof(nxt_conn_t)
|
||||
+ 4 * sizeof(nxt_buf_t);
|
||||
|
||||
skcf->header_buffer_size = 2048;
|
||||
skcf->large_header_buffer_size = 8192;
|
||||
skcf->header_read_timeout = 5000;
|
||||
@@ -220,11 +212,6 @@ nxt_router_stub_conf(nxt_task_t *task, nxt_router_temp_conf_t *tmcf)
|
||||
skcf = nxt_router_socket_conf(task, mp, sa);
|
||||
|
||||
skcf->listen.handler = nxt_stream_connection_init;
|
||||
skcf->listen.mem_pool_size = nxt_listen_socket_pool_min_size(&skcf->listen)
|
||||
+ sizeof(nxt_conn_proxy_t)
|
||||
+ sizeof(nxt_conn_t)
|
||||
+ 4 * sizeof(nxt_buf_t);
|
||||
|
||||
skcf->header_read_timeout = 5000;
|
||||
|
||||
nxt_queue_insert_tail(&tmcf->pending, &skcf->link);
|
||||
@@ -234,11 +221,11 @@ nxt_router_stub_conf(nxt_task_t *task, nxt_router_temp_conf_t *tmcf)
|
||||
|
||||
|
||||
static nxt_socket_conf_t *
|
||||
nxt_router_socket_conf(nxt_task_t *task, nxt_mem_pool_t *mp, nxt_sockaddr_t *sa)
|
||||
nxt_router_socket_conf(nxt_task_t *task, nxt_mp_t *mp, nxt_sockaddr_t *sa)
|
||||
{
|
||||
nxt_socket_conf_t *conf;
|
||||
|
||||
conf = nxt_mem_zalloc(mp, sizeof(nxt_socket_conf_t));
|
||||
conf = nxt_mp_zget(mp, sizeof(nxt_socket_conf_t));
|
||||
if (nxt_slow_path(conf == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -255,8 +242,7 @@ nxt_router_socket_conf(nxt_task_t *task, nxt_mem_pool_t *mp, nxt_sockaddr_t *sa)
|
||||
|
||||
|
||||
static nxt_sockaddr_t *
|
||||
nxt_router_listen_sockaddr_stub(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
uint32_t port)
|
||||
nxt_router_listen_sockaddr_stub(nxt_task_t *task, nxt_mp_t *mp, uint32_t port)
|
||||
{
|
||||
nxt_sockaddr_t *sa;
|
||||
struct sockaddr_in sin;
|
||||
@@ -348,9 +334,9 @@ static nxt_int_t
|
||||
nxt_router_engines_create(nxt_task_t *task, nxt_router_t *router,
|
||||
nxt_router_temp_conf_t *tmcf, const nxt_event_interface_t *interface)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t ret;
|
||||
nxt_uint_t n, threads;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_queue_link_t *qlk;
|
||||
nxt_router_engine_conf_t *recf;
|
||||
|
||||
@@ -420,7 +406,7 @@ nxt_router_engines_create(nxt_task_t *task, nxt_router_t *router,
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_router_engine_conf_create(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_router_engine_conf_create(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_temp_conf_t *tmcf, nxt_router_engine_conf_t *recf)
|
||||
{
|
||||
nxt_int_t ret;
|
||||
@@ -442,7 +428,7 @@ nxt_router_engine_conf_create(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_router_engine_conf_update(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_router_engine_conf_update(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_temp_conf_t *tmcf, nxt_router_engine_conf_t *recf)
|
||||
{
|
||||
nxt_int_t ret;
|
||||
@@ -480,7 +466,7 @@ nxt_router_engine_conf_update(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_router_engine_conf_delete(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_router_engine_conf_delete(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_temp_conf_t *tmcf, nxt_router_engine_conf_t *recf)
|
||||
{
|
||||
nxt_int_t ret;
|
||||
@@ -502,7 +488,7 @@ nxt_router_engine_conf_delete(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_router_engine_joints_create(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_router_engine_joints_create(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_router_engine_conf_t *recf, nxt_queue_t *sockets, nxt_array_t *array,
|
||||
nxt_work_handler_t handler)
|
||||
{
|
||||
@@ -524,7 +510,7 @@ nxt_router_engine_joints_create(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
work->task = &recf->task;
|
||||
work->obj = recf->engine;
|
||||
|
||||
joint = nxt_mem_alloc(mp, sizeof(nxt_socket_conf_joint_t));
|
||||
joint = nxt_mp_alloc(mp, sizeof(nxt_socket_conf_joint_t));
|
||||
if (nxt_slow_path(joint == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -846,7 +832,7 @@ nxt_router_conf_release(nxt_task_t *task, nxt_socket_conf_joint_t *joint)
|
||||
nxt_thread_spin_unlock(lock);
|
||||
|
||||
if (rtcf != NULL) {
|
||||
nxt_mem_pool_destroy(rtcf->mem_pool);
|
||||
nxt_mp_destroy(rtcf->mem_pool);
|
||||
}
|
||||
|
||||
if (nxt_queue_is_empty(&joint->engine->joints)) {
|
||||
@@ -949,7 +935,7 @@ nxt_router_conn_http_header_parse(nxt_task_t *task, void *obj, void *data)
|
||||
nxt_debug(task, "router conn http header parse");
|
||||
|
||||
if (rp == NULL) {
|
||||
rp = nxt_mem_zalloc(c->mem_pool, sizeof(nxt_http_request_parse_t));
|
||||
rp = nxt_mp_zget(c->mem_pool, sizeof(nxt_http_request_parse_t));
|
||||
if (nxt_slow_path(rp == NULL)) {
|
||||
nxt_router_conn_close(task, c, data);
|
||||
return;
|
||||
@@ -1043,7 +1029,7 @@ nxt_router_conn_free(nxt_task_t *task, void *obj, void *data)
|
||||
joint = c->listen->socket.data;
|
||||
nxt_router_conf_release(task, joint);
|
||||
|
||||
nxt_mem_pool_destroy(c->mem_pool);
|
||||
nxt_mp_destroy(c->mem_pool);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ typedef struct {
|
||||
uint32_t count;
|
||||
uint32_t threads;
|
||||
nxt_router_t *router;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
} nxt_router_conf_t;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ typedef struct {
|
||||
|
||||
nxt_array_t *engines;
|
||||
nxt_router_conf_t *conf;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
} nxt_router_temp_conf_t;
|
||||
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ static nxt_int_t nxt_runtime_event_engine_change(nxt_task_t *task,
|
||||
static nxt_int_t nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt);
|
||||
static nxt_int_t nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt);
|
||||
static nxt_sockaddr_t *nxt_runtime_sockaddr_parse(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_str_t *addr);
|
||||
nxt_mp_t *mp, nxt_str_t *addr);
|
||||
static nxt_sockaddr_t *nxt_runtime_sockaddr_unix_parse(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_str_t *addr);
|
||||
nxt_mp_t *mp, nxt_str_t *addr);
|
||||
static nxt_sockaddr_t *nxt_runtime_sockaddr_inet6_parse(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_str_t *addr);
|
||||
nxt_mp_t *mp, nxt_str_t *addr);
|
||||
static nxt_sockaddr_t *nxt_runtime_sockaddr_inet_parse(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_str_t *addr);
|
||||
nxt_mp_t *mp, nxt_str_t *addr);
|
||||
static nxt_int_t nxt_runtime_hostname(nxt_task_t *task, nxt_runtime_t *rt);
|
||||
static nxt_int_t nxt_runtime_log_files_init(nxt_runtime_t *rt);
|
||||
static nxt_int_t nxt_runtime_log_files_create(nxt_task_t *task,
|
||||
@@ -51,19 +51,21 @@ static void nxt_runtime_thread_pool_destroy(nxt_task_t *task, nxt_runtime_t *rt,
|
||||
nxt_int_t
|
||||
nxt_runtime_create(nxt_task_t *task)
|
||||
{
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t ret;
|
||||
nxt_array_t *listen_sockets;
|
||||
nxt_runtime_t *rt;
|
||||
nxt_mem_pool_t *mp;
|
||||
|
||||
mp = nxt_mem_pool_create(1024);
|
||||
mp = nxt_mp_create(1024, 128, 256, 32);
|
||||
|
||||
if (nxt_slow_path(mp == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
/* This alloction cannot fail. */
|
||||
rt = nxt_mem_zalloc(mp, sizeof(nxt_runtime_t));
|
||||
rt = nxt_mp_zget(mp, sizeof(nxt_runtime_t));
|
||||
if (nxt_slow_path(rt == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
task->thread->runtime = rt;
|
||||
rt->mem_pool = mp;
|
||||
@@ -117,7 +119,7 @@ nxt_runtime_create(nxt_task_t *task)
|
||||
|
||||
fail:
|
||||
|
||||
nxt_mem_pool_destroy(mp);
|
||||
nxt_mp_destroy(mp);
|
||||
|
||||
return NXT_ERROR;
|
||||
}
|
||||
@@ -321,8 +323,6 @@ nxt_runtime_start(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
nxt_debug(task, "rt conf done");
|
||||
|
||||
nxt_mem_pool_debug_lock(rt->mem_pool, nxt_thread_tid(task->thread));
|
||||
|
||||
task->thread->log->ctx_handler = NULL;
|
||||
task->thread->log->ctx = NULL;
|
||||
|
||||
@@ -905,8 +905,7 @@ nxt_runtime_conf_read_cmd(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
|
||||
|
||||
static nxt_sockaddr_t *
|
||||
nxt_runtime_sockaddr_parse(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_str_t *addr)
|
||||
nxt_runtime_sockaddr_parse(nxt_task_t *task, nxt_mp_t *mp, nxt_str_t *addr)
|
||||
{
|
||||
u_char *p;
|
||||
size_t length;
|
||||
@@ -927,8 +926,7 @@ nxt_runtime_sockaddr_parse(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
|
||||
|
||||
static nxt_sockaddr_t *
|
||||
nxt_runtime_sockaddr_unix_parse(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_str_t *addr)
|
||||
nxt_runtime_sockaddr_unix_parse(nxt_task_t *task, nxt_mp_t *mp, nxt_str_t *addr)
|
||||
{
|
||||
#if (NXT_HAVE_UNIX_DOMAIN)
|
||||
u_char *p;
|
||||
@@ -1008,14 +1006,14 @@ nxt_runtime_sockaddr_unix_parse(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
|
||||
|
||||
static nxt_sockaddr_t *
|
||||
nxt_runtime_sockaddr_inet6_parse(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_runtime_sockaddr_inet6_parse(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_str_t *addr)
|
||||
{
|
||||
#if (NXT_INET6)
|
||||
u_char *p, *addr, *addr_end;
|
||||
size_t length;
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t port;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_sockaddr_t *sa;
|
||||
struct in6_addr *in6_addr;
|
||||
|
||||
@@ -1085,7 +1083,7 @@ invalid_address:
|
||||
|
||||
|
||||
static nxt_sockaddr_t *
|
||||
nxt_runtime_sockaddr_inet_parse(nxt_task_t *task, nxt_mem_pool_t *mp,
|
||||
nxt_runtime_sockaddr_inet_parse(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_str_t *string)
|
||||
{
|
||||
u_char *p, *ip;
|
||||
@@ -1182,7 +1180,7 @@ invalid_addr:
|
||||
nxt_listen_socket_t *
|
||||
nxt_runtime_listen_socket_add(nxt_runtime_t *rt, nxt_sockaddr_t *sa)
|
||||
{
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_mp_t *mp;
|
||||
nxt_listen_socket_t *ls;
|
||||
|
||||
ls = nxt_array_zero_add(rt->listen_sockets);
|
||||
@@ -1233,7 +1231,7 @@ nxt_runtime_hostname(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
length = nxt_strlen(hostname);
|
||||
rt->hostname.length = length;
|
||||
|
||||
rt->hostname.start = nxt_mem_nalloc(rt->mem_pool, length);
|
||||
rt->hostname.start = nxt_mp_nget(rt->mem_pool, length);
|
||||
|
||||
if (rt->hostname.start != NULL) {
|
||||
nxt_memcpy_lowcase(rt->hostname.start, (u_char *) hostname, length);
|
||||
@@ -1403,7 +1401,7 @@ nxt_runtime_listen_sockets_enable(nxt_task_t *task, nxt_runtime_t *rt)
|
||||
|
||||
|
||||
nxt_str_t *
|
||||
nxt_current_directory(nxt_mem_pool_t *mp)
|
||||
nxt_current_directory(nxt_mp_t *mp)
|
||||
{
|
||||
size_t length;
|
||||
u_char *p;
|
||||
@@ -1465,7 +1463,7 @@ nxt_runtime_process_new(nxt_runtime_t *rt)
|
||||
|
||||
/* TODO: memory failures. */
|
||||
|
||||
process = nxt_mem_cache_zalloc0(rt->mem_pool, sizeof(nxt_process_t));
|
||||
process = nxt_mp_zalloc(rt->mem_pool, sizeof(nxt_process_t));
|
||||
if (nxt_slow_path(process == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -1496,7 +1494,6 @@ nxt_runtime_lvlhsh_pid_test(nxt_lvlhsh_query_t *lhq, void *data)
|
||||
|
||||
static const nxt_lvlhsh_proto_t lvlhsh_processes_proto nxt_aligned(64) = {
|
||||
NXT_LVLHSH_DEFAULT,
|
||||
0,
|
||||
nxt_runtime_lvlhsh_pid_test,
|
||||
nxt_lvlhsh_alloc,
|
||||
nxt_lvlhsh_free,
|
||||
@@ -1528,7 +1525,6 @@ nxt_runtime_lvlhsh_port_test(nxt_lvlhsh_query_t *lhq, void *data)
|
||||
|
||||
static const nxt_lvlhsh_proto_t lvlhsh_ports_proto nxt_aligned(64) = {
|
||||
NXT_LVLHSH_DEFAULT,
|
||||
0,
|
||||
nxt_runtime_lvlhsh_port_test,
|
||||
nxt_lvlhsh_alloc,
|
||||
nxt_lvlhsh_free,
|
||||
|
||||
@@ -13,7 +13,7 @@ typedef void (*nxt_runtime_cont_t)(nxt_task_t *task);
|
||||
|
||||
|
||||
struct nxt_runtime_s {
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
|
||||
nxt_array_t *inherited_sockets; /* of nxt_listen_socket_t */
|
||||
nxt_array_t *listen_sockets; /* of nxt_listen_socket_t */
|
||||
@@ -112,7 +112,7 @@ nxt_port_t *nxt_runtime_port_find(nxt_runtime_t *rt, nxt_pid_t pid,
|
||||
/* STUB */
|
||||
nxt_int_t nxt_runtime_controller_socket(nxt_task_t *task, nxt_runtime_t *rt);
|
||||
|
||||
nxt_str_t *nxt_current_directory(nxt_mem_pool_t *mp);
|
||||
nxt_str_t *nxt_current_directory(nxt_mp_t *mp);
|
||||
|
||||
nxt_listen_socket_t *nxt_runtime_listen_socket_add(nxt_runtime_t *rt,
|
||||
nxt_sockaddr_t *sa);
|
||||
|
||||
@@ -58,7 +58,7 @@ static const nxt_service_t nxt_services[] = {
|
||||
|
||||
|
||||
nxt_array_t *
|
||||
nxt_services_init(nxt_mem_pool_t *mp)
|
||||
nxt_services_init(nxt_mp_t *mp)
|
||||
{
|
||||
nxt_uint_t n;
|
||||
nxt_array_t *services;
|
||||
|
||||
@@ -20,7 +20,7 @@ nxt_service_is_module(s) \
|
||||
((s)->type == NULL)
|
||||
|
||||
|
||||
NXT_EXPORT nxt_array_t *nxt_services_init(nxt_mem_pool_t *mp);
|
||||
NXT_EXPORT nxt_array_t *nxt_services_init(nxt_mp_t *mp);
|
||||
NXT_EXPORT nxt_int_t nxt_service_add(nxt_array_t *services,
|
||||
const nxt_service_t *service);
|
||||
NXT_EXPORT const void *nxt_service_get(nxt_array_t *services, const char *type,
|
||||
|
||||
@@ -17,7 +17,7 @@ static nxt_int_t nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs);
|
||||
|
||||
|
||||
nxt_sockaddr_t *
|
||||
nxt_sockaddr_alloc(nxt_mem_pool_t *mp, socklen_t socklen, size_t address_length)
|
||||
nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen, size_t address_length)
|
||||
{
|
||||
size_t size;
|
||||
nxt_sockaddr_t *sa;
|
||||
@@ -27,12 +27,12 @@ nxt_sockaddr_alloc(nxt_mem_pool_t *mp, socklen_t socklen, size_t address_length)
|
||||
/*
|
||||
* The current struct sockaddr's define 32-bit fields at maximum
|
||||
* and may define 64-bit AF_INET6 fields in the future. Alignment
|
||||
* of memory allocated by nxt_mem_zalloc() is enough for these fields.
|
||||
* of memory allocated by nxt_mp_zalloc() is enough for these fields.
|
||||
* If 128-bit alignment will be required then nxt_mem_malloc() and
|
||||
* nxt_memzero() should be used instead.
|
||||
*/
|
||||
|
||||
sa = nxt_mem_zalloc(mp, size);
|
||||
sa = nxt_mp_zalloc(mp, size);
|
||||
|
||||
if (nxt_fast_path(sa != NULL)) {
|
||||
sa->socklen = socklen;
|
||||
@@ -45,8 +45,8 @@ nxt_sockaddr_alloc(nxt_mem_pool_t *mp, socklen_t socklen, size_t address_length)
|
||||
|
||||
|
||||
nxt_sockaddr_t *
|
||||
nxt_sockaddr_create(nxt_mem_pool_t *mp, struct sockaddr *sockaddr,
|
||||
socklen_t length, size_t address_length)
|
||||
nxt_sockaddr_create(nxt_mp_t *mp, struct sockaddr *sockaddr, socklen_t length,
|
||||
size_t address_length)
|
||||
{
|
||||
size_t size, copy;
|
||||
nxt_sockaddr_t *sa;
|
||||
@@ -120,14 +120,14 @@ nxt_sockaddr_create(nxt_mem_pool_t *mp, struct sockaddr *sockaddr,
|
||||
|
||||
|
||||
nxt_sockaddr_t *
|
||||
nxt_sockaddr_copy(nxt_mem_pool_t *mp, nxt_sockaddr_t *src)
|
||||
nxt_sockaddr_copy(nxt_mp_t *mp, nxt_sockaddr_t *src)
|
||||
{
|
||||
size_t length;
|
||||
nxt_sockaddr_t *dst;
|
||||
|
||||
length = offsetof(nxt_sockaddr_t, u) + src->socklen;
|
||||
|
||||
dst = nxt_mem_alloc(mp, length);
|
||||
dst = nxt_mp_alloc(mp, length);
|
||||
|
||||
if (nxt_fast_path(dst != NULL)) {
|
||||
nxt_memcpy(dst, src, length);
|
||||
@@ -138,7 +138,7 @@ nxt_sockaddr_copy(nxt_mem_pool_t *mp, nxt_sockaddr_t *src)
|
||||
|
||||
|
||||
nxt_sockaddr_t *
|
||||
nxt_getsockname(nxt_task_t *task, nxt_mem_pool_t *mp, nxt_socket_t s)
|
||||
nxt_getsockname(nxt_task_t *task, nxt_mp_t *mp, nxt_socket_t s)
|
||||
{
|
||||
int ret;
|
||||
size_t length;
|
||||
@@ -608,7 +608,7 @@ nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs)
|
||||
#if (NXT_HAVE_UNIX_DOMAIN)
|
||||
size_t length, socklen;
|
||||
u_char *path;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_mp_t *mp;
|
||||
nxt_sockaddr_t *sa;
|
||||
|
||||
/*
|
||||
@@ -655,7 +655,7 @@ nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs)
|
||||
|
||||
mp = jbs->resolve.job.mem_pool;
|
||||
|
||||
jbs->resolve.sockaddrs = nxt_mem_alloc(mp, sizeof(void *));
|
||||
jbs->resolve.sockaddrs = nxt_mp_alloc(mp, sizeof(void *));
|
||||
|
||||
if (nxt_fast_path(jbs->resolve.sockaddrs != NULL)) {
|
||||
sa = nxt_sockaddr_alloc(mp, socklen, jbs->addr.length);
|
||||
@@ -690,8 +690,8 @@ nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs)
|
||||
#if (NXT_INET6)
|
||||
u_char *p, *addr, *addr_end;
|
||||
size_t length;
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t port;
|
||||
nxt_mem_pool_t *mp;
|
||||
nxt_sockaddr_t *sa;
|
||||
struct in6_addr *in6_addr;
|
||||
|
||||
@@ -706,7 +706,7 @@ nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs)
|
||||
|
||||
mp = jbs->resolve.job.mem_pool;
|
||||
|
||||
jbs->resolve.sockaddrs = nxt_mem_alloc(mp, sizeof(void *));
|
||||
jbs->resolve.sockaddrs = nxt_mp_alloc(mp, sizeof(void *));
|
||||
|
||||
if (nxt_slow_path(jbs->resolve.sockaddrs == NULL)) {
|
||||
return NXT_ERROR;
|
||||
@@ -782,9 +782,9 @@ nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs)
|
||||
{
|
||||
u_char *p, *host;
|
||||
size_t length;
|
||||
in_addr_t addr;
|
||||
nxt_mp_t *mp;
|
||||
nxt_int_t port;
|
||||
nxt_mem_pool_t *mp;
|
||||
in_addr_t addr;
|
||||
nxt_sockaddr_t *sa;
|
||||
|
||||
addr = INADDR_ANY;
|
||||
@@ -860,7 +860,7 @@ nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs)
|
||||
|
||||
mp = jbs->resolve.job.mem_pool;
|
||||
|
||||
jbs->resolve.sockaddrs = nxt_mem_alloc(mp, sizeof(void *));
|
||||
jbs->resolve.sockaddrs = nxt_mp_alloc(mp, sizeof(void *));
|
||||
if (nxt_slow_path(jbs->resolve.sockaddrs == NULL)) {
|
||||
return NXT_ERROR;
|
||||
}
|
||||
|
||||
@@ -69,17 +69,16 @@ typedef struct {
|
||||
} nxt_job_sockaddr_parse_t;
|
||||
|
||||
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_alloc(nxt_mem_pool_t *mp,
|
||||
socklen_t socklen, size_t address_length)
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_alloc(nxt_mp_t *mp, socklen_t socklen,
|
||||
size_t address_length)
|
||||
NXT_MALLOC_LIKE;
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_create(nxt_mem_pool_t *mp,
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_create(nxt_mp_t *mp,
|
||||
struct sockaddr *sockaddr, socklen_t socklen, size_t address_length)
|
||||
NXT_MALLOC_LIKE;
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_copy(nxt_mem_pool_t *mp,
|
||||
nxt_sockaddr_t *src)
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_sockaddr_copy(nxt_mp_t *mp, nxt_sockaddr_t *src)
|
||||
NXT_MALLOC_LIKE;
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_getsockname(nxt_task_t *task,
|
||||
nxt_mem_pool_t *mp, nxt_socket_t s)
|
||||
NXT_EXPORT nxt_sockaddr_t *nxt_getsockname(nxt_task_t *task, nxt_mp_t *mp,
|
||||
nxt_socket_t s)
|
||||
NXT_MALLOC_LIKE;
|
||||
NXT_EXPORT void nxt_sockaddr_text(nxt_sockaddr_t *sa);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ nxt_stream_connection_init(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
nxt_debug(task, "stream connection init");
|
||||
|
||||
up = nxt_mem_zalloc(c->mem_pool, sizeof(nxt_upstream_peer_t));
|
||||
up = nxt_mp_zget(c->mem_pool, sizeof(nxt_upstream_peer_t));
|
||||
if (nxt_slow_path(up == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ nxt_stream_connection_peer(nxt_task_t *task, nxt_upstream_peer_t *up)
|
||||
nxt_event_engine_t *engine;
|
||||
nxt_event_write_rate_t *rate;
|
||||
|
||||
rate = nxt_mem_alloc(c->mem_pool, sizeof(nxt_event_write_rate_t));
|
||||
rate = nxt_mp_get(c->mem_pool, sizeof(nxt_event_write_rate_t));
|
||||
|
||||
if (nxt_slow_path(rate == NULL)) {
|
||||
goto fail;
|
||||
@@ -126,5 +126,5 @@ nxt_stream_connection_close(nxt_task_t *task, void *obj, void *data)
|
||||
|
||||
nxt_log_debug(p->client->socket.log, "stream connection close");
|
||||
|
||||
nxt_mem_pool_destroy(p->client->mem_pool);
|
||||
nxt_mp_destroy(p->client->mem_pool);
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
|
||||
nxt_str_t *
|
||||
nxt_str_alloc(nxt_mem_pool_t *mp, size_t length)
|
||||
nxt_str_alloc(nxt_mp_t *mp, size_t length)
|
||||
{
|
||||
nxt_str_t *s;
|
||||
|
||||
/* The string start is allocated aligned to be close to nxt_str_t. */
|
||||
s = nxt_mem_alloc(mp, sizeof(nxt_str_t) + length);
|
||||
s = nxt_mp_get(mp, sizeof(nxt_str_t) + length);
|
||||
|
||||
if (nxt_fast_path(s != NULL)) {
|
||||
s->length = length;
|
||||
@@ -31,13 +31,13 @@ nxt_str_alloc(nxt_mem_pool_t *mp, size_t length)
|
||||
*/
|
||||
|
||||
nxt_str_t *
|
||||
nxt_str_dup(nxt_mem_pool_t *mp, nxt_str_t *dst, const nxt_str_t *src)
|
||||
nxt_str_dup(nxt_mp_t *mp, nxt_str_t *dst, const nxt_str_t *src)
|
||||
{
|
||||
u_char *p;
|
||||
|
||||
if (dst == NULL) {
|
||||
/* The string start is allocated aligned to be close to nxt_str_t. */
|
||||
dst = nxt_mem_alloc(mp, sizeof(nxt_str_t) + src->length);
|
||||
dst = nxt_mp_get(mp, sizeof(nxt_str_t) + src->length);
|
||||
if (nxt_slow_path(dst == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ nxt_str_dup(nxt_mem_pool_t *mp, nxt_str_t *dst, const nxt_str_t *src)
|
||||
dst->start = p;
|
||||
|
||||
} else {
|
||||
dst->start = nxt_mem_nalloc(mp, src->length);
|
||||
dst->start = nxt_mp_nget(mp, src->length);
|
||||
if (nxt_slow_path(dst->start == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -69,11 +69,11 @@ nxt_str_dup(nxt_mem_pool_t *mp, nxt_str_t *dst, const nxt_str_t *src)
|
||||
*/
|
||||
|
||||
char *
|
||||
nxt_str_copy(nxt_mem_pool_t *mp, const nxt_str_t *src)
|
||||
nxt_str_copy(nxt_mp_t *mp, const nxt_str_t *src)
|
||||
{
|
||||
char *p, *dst;
|
||||
|
||||
dst = nxt_mem_align(mp, 2, src->length + 1);
|
||||
dst = nxt_mp_align(mp, 2, src->length + 1);
|
||||
|
||||
if (nxt_fast_path(dst != NULL)) {
|
||||
p = nxt_cpymem(dst, src->start, src->length);
|
||||
|
||||
@@ -133,10 +133,10 @@ nxt_str_null(str) \
|
||||
} while (0)
|
||||
|
||||
|
||||
NXT_EXPORT nxt_str_t *nxt_str_alloc(nxt_mem_pool_t *mp, size_t length);
|
||||
NXT_EXPORT nxt_str_t *nxt_str_dup(nxt_mem_pool_t *mp, nxt_str_t *dst,
|
||||
NXT_EXPORT nxt_str_t *nxt_str_alloc(nxt_mp_t *mp, size_t length);
|
||||
NXT_EXPORT nxt_str_t *nxt_str_dup(nxt_mp_t *mp, nxt_str_t *dst,
|
||||
const nxt_str_t *src);
|
||||
NXT_EXPORT char *nxt_str_copy(nxt_mem_pool_t *mp, const nxt_str_t *src);
|
||||
NXT_EXPORT char *nxt_str_copy(nxt_mp_t *mp, const nxt_str_t *src);
|
||||
|
||||
|
||||
#define \
|
||||
|
||||
@@ -24,7 +24,7 @@ struct nxt_upstream_peer_s {
|
||||
in_port_t port;
|
||||
|
||||
nxt_str_t addr;
|
||||
nxt_mem_pool_t *mem_pool;
|
||||
nxt_mp_t *mem_pool;
|
||||
void (*ready_handler)(nxt_task_t *task, nxt_upstream_peer_t *up);
|
||||
|
||||
void (*protocol_handler)(nxt_upstream_source_t *us);
|
||||
|
||||
@@ -72,14 +72,14 @@ nxt_upstream_round_robin_create(nxt_task_t *task, void *obj, void *data)
|
||||
jbs = obj;
|
||||
up = jbs->resolve.job.data;
|
||||
|
||||
urr = nxt_mem_zalloc(up->mem_pool, sizeof(nxt_upstream_round_robin_t));
|
||||
urr = nxt_mp_zget(up->mem_pool, sizeof(nxt_upstream_round_robin_t));
|
||||
if (nxt_slow_path(urr == NULL)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
urr->npeers = jbs->resolve.count;
|
||||
|
||||
peer = nxt_mem_zalloc(up->mem_pool,
|
||||
peer = nxt_mp_zget(up->mem_pool,
|
||||
urr->npeers * sizeof(nxt_upstream_round_robin_peer_t));
|
||||
if (nxt_slow_path(peer == NULL)) {
|
||||
goto fail;
|
||||
|
||||
@@ -21,7 +21,7 @@ const nxt_lvlhsh_proto_t nxt_upstream_header_hash_proto nxt_aligned(64) = {
|
||||
|
||||
|
||||
nxt_int_t
|
||||
nxt_upstream_header_hash_add(nxt_mem_pool_t *mp, nxt_lvlhsh_t *lh,
|
||||
nxt_upstream_header_hash_add(nxt_mp_t *mp, nxt_lvlhsh_t *lh,
|
||||
const nxt_upstream_name_value_t *unv, nxt_uint_t n)
|
||||
{
|
||||
nxt_lvlhsh_query_t lhq;
|
||||
|
||||
@@ -72,7 +72,7 @@ struct nxt_upstream_source_s {
|
||||
#define nxt_upstream_name_value(s) sizeof(s) - 1, s
|
||||
|
||||
|
||||
NXT_EXPORT nxt_int_t nxt_upstream_header_hash_add(nxt_mem_pool_t *mp,
|
||||
NXT_EXPORT nxt_int_t nxt_upstream_header_hash_add(nxt_mp_t *mp,
|
||||
nxt_lvlhsh_t *lh, const nxt_upstream_name_value_t *unv, nxt_uint_t n);
|
||||
NXT_EXPORT nxt_int_t nxt_upstream_name_value_ignore(nxt_upstream_source_t *us,
|
||||
nxt_name_value_t *nv);
|
||||
|
||||
@@ -19,14 +19,14 @@ nxt_lvlhsh_unit_test_key_test(nxt_lvlhsh_query_t *lhq, void *data)
|
||||
|
||||
|
||||
static void *
|
||||
nxt_lvlhsh_unit_test_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc)
|
||||
nxt_lvlhsh_unit_test_pool_alloc(void *pool, size_t size)
|
||||
{
|
||||
return nxt_mp_align(pool, size, size);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nxt_lvlhsh_unit_test_pool_free(void *pool, void *p, size_t size)
|
||||
nxt_lvlhsh_unit_test_pool_free(void *pool, void *p)
|
||||
{
|
||||
nxt_mp_free(pool, p);
|
||||
}
|
||||
@@ -35,7 +35,6 @@ nxt_lvlhsh_unit_test_pool_free(void *pool, void *p, size_t size)
|
||||
static const nxt_lvlhsh_proto_t malloc_proto nxt_aligned(64) = {
|
||||
//NXT_LVLHSH_LARGE_MEMALIGN,
|
||||
NXT_LVLHSH_DEFAULT,
|
||||
0,
|
||||
nxt_lvlhsh_unit_test_key_test,
|
||||
nxt_lvlhsh_alloc,
|
||||
nxt_lvlhsh_free,
|
||||
@@ -43,7 +42,6 @@ static const nxt_lvlhsh_proto_t malloc_proto nxt_aligned(64) = {
|
||||
|
||||
static const nxt_lvlhsh_proto_t pool_proto nxt_aligned(64) = {
|
||||
NXT_LVLHSH_LARGE_SLAB,
|
||||
0,
|
||||
nxt_lvlhsh_unit_test_key_test,
|
||||
nxt_lvlhsh_unit_test_pool_alloc,
|
||||
nxt_lvlhsh_unit_test_pool_free,
|
||||
|
||||
Reference in New Issue
Block a user