From: Dmitry Volyntsev Date: Mon, 28 Jan 2019 18:18:43 +0000 (+0300) Subject: Renaming nxt_mem_cache_pool_t related structures and fields. X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=72f685ac662354ad4cd2850f91bd72c7010fd4a0;p=njs.git Renaming nxt_mem_cache_pool_t related structures and fields. nxt_mem_cache_pool_t -> nxt_mp_t. nxt_mem_cache_* -> nxt_mp_*. vm->mem_cache_pool -> vm->mem_pool. --- diff --git a/Makefile b/Makefile index 7adb3bb5..5ba6393e 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ $(NXT_BUILDDIR)/libnjs.a: \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_time.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ + $(NXT_BUILDDIR)/nxt_mp.o \ ar -r -c $(NXT_BUILDDIR)/libnjs.a \ $(NXT_BUILDDIR)/njs_shell.o \ @@ -96,7 +96,7 @@ $(NXT_BUILDDIR)/libnjs.a: \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_time.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ + $(NXT_BUILDDIR)/nxt_mp.o \ all: test lib_test diff --git a/njs/njs.c b/njs/njs.c index c59aa22b..19c4f805 100644 --- a/njs/njs.c +++ b/njs/njs.c @@ -49,7 +49,7 @@ njs_free(void *mem, void *p) } -const nxt_mem_proto_t njs_vm_mem_cache_pool_proto = { +const nxt_mem_proto_t njs_vm_mp_proto = { njs_alloc, njs_zalloc, njs_align, @@ -63,14 +63,14 @@ const nxt_mem_proto_t njs_vm_mem_cache_pool_proto = { static void * njs_array_mem_alloc(void *mem, size_t size) { - return nxt_mem_cache_alloc(mem, size); + return nxt_mp_alloc(mem, size); } static void njs_array_mem_free(void *mem, void *p) { - nxt_mem_cache_free(mem, p); + nxt_mp_free(mem, p); } @@ -88,22 +88,22 @@ const nxt_mem_proto_t njs_array_mem_proto = { njs_vm_t * njs_vm_create(njs_vm_opt_t *options) { + nxt_mp_t *mp; njs_vm_t *vm; nxt_int_t ret; nxt_array_t *debug; - nxt_mem_cache_pool_t *mcp; njs_regexp_pattern_t *pattern; - mcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, - NULL, 2 * nxt_pagesize(), 128, 512, 16); - if (nxt_slow_path(mcp == NULL)) { + mp = nxt_mp_create(&njs_vm_mp_proto, NULL, NULL, 2 * nxt_pagesize(), + 128, 512, 16); + if (nxt_slow_path(mp == NULL)) { return NULL; } - vm = nxt_mem_cache_zalign(mcp, sizeof(njs_value_t), sizeof(njs_vm_t)); + vm = nxt_mp_zalign(mp, sizeof(njs_value_t), sizeof(njs_vm_t)); if (nxt_fast_path(vm != NULL)) { - vm->mem_cache_pool = mcp; + vm->mem_pool = mp; ret = njs_regexp_init(vm); if (nxt_slow_path(ret != NXT_OK)) { @@ -116,7 +116,7 @@ njs_vm_create(njs_vm_opt_t *options) vm->shared = options->shared; } else { - vm->shared = nxt_mem_cache_zalloc(mcp, sizeof(njs_vm_shared_t)); + vm->shared = nxt_mp_zalloc(mp, sizeof(njs_vm_shared_t)); if (nxt_slow_path(vm->shared == NULL)) { return NULL; } @@ -125,7 +125,7 @@ njs_vm_create(njs_vm_opt_t *options) nxt_lvlhsh_init(&vm->shared->keywords_hash); - ret = njs_lexer_keywords_init(mcp, &vm->shared->keywords_hash); + ret = njs_lexer_keywords_init(mp, &vm->shared->keywords_hash); if (nxt_slow_path(ret != NXT_OK)) { return NULL; } @@ -154,7 +154,7 @@ njs_vm_create(njs_vm_opt_t *options) vm->external_objects = nxt_array_create(4, sizeof(void *), &njs_array_mem_proto, - vm->mem_cache_pool); + vm->mem_pool); if (nxt_slow_path(vm->external_objects == NULL)) { return NULL; } @@ -169,8 +169,7 @@ njs_vm_create(njs_vm_opt_t *options) if (options->backtrace) { debug = nxt_array_create(4, sizeof(njs_function_debug_t), - &njs_array_mem_proto, - vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(debug == NULL)) { return NULL; } @@ -210,7 +209,7 @@ njs_vm_destroy(njs_vm_t *vm) } } - nxt_mem_cache_pool_destroy(vm->mem_cache_pool); + nxt_mp_destroy(vm->mem_pool); } @@ -222,7 +221,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) njs_parser_t *parser, *prev; njs_generator_t *generator; - parser = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_parser_t)); + parser = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_parser_t)); if (nxt_slow_path(parser == NULL)) { return NJS_ERROR; } @@ -234,7 +233,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) prev = vm->parser; vm->parser = parser; - lexer = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_lexer_t)); + lexer = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_lexer_t)); if (nxt_slow_path(lexer == NULL)) { return NJS_ERROR; } @@ -269,8 +268,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) */ vm->code = NULL; - generator = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - sizeof(njs_generator_t)); + generator = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + sizeof(njs_generator_t)); if (nxt_slow_path(generator == NULL)) { goto fail; @@ -310,11 +309,11 @@ fail: njs_vm_t * njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) { - njs_vm_t *nvm; - uint32_t items; - nxt_int_t ret; - nxt_array_t *externals; - nxt_mem_cache_pool_t *nmcp; + nxt_mp_t *nmp; + njs_vm_t *nvm; + uint32_t items; + nxt_int_t ret; + nxt_array_t *externals; nxt_thread_log_debug("CLONE:"); @@ -322,16 +321,16 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) return NULL; } - nmcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, - NULL, 2 * nxt_pagesize(), 128, 512, 16); - if (nxt_slow_path(nmcp == NULL)) { + nmp = nxt_mp_create(&njs_vm_mp_proto, NULL, NULL, 2 * nxt_pagesize(), + 128, 512, 16); + if (nxt_slow_path(nmp == NULL)) { return NULL; } - nvm = nxt_mem_cache_zalign(nmcp, sizeof(njs_value_t), sizeof(njs_vm_t)); + nvm = nxt_mp_zalign(nmp, sizeof(njs_value_t), sizeof(njs_vm_t)); if (nxt_fast_path(nvm != NULL)) { - nvm->mem_cache_pool = nmcp; + nvm->mem_pool = nmp; nvm->shared = vm->shared; nvm->trace = vm->trace; @@ -345,7 +344,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) items = vm->external_objects->items; externals = nxt_array_create(items + 4, sizeof(void *), - &njs_array_mem_proto, nvm->mem_cache_pool); + &njs_array_mem_proto, nvm->mem_pool); if (nxt_slow_path(externals == NULL)) { return NULL; @@ -380,7 +379,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) fail: - nxt_mem_cache_pool_destroy(nmcp); + nxt_mp_destroy(nmp); return NULL; } @@ -400,7 +399,7 @@ njs_vm_init(njs_vm_t *vm) size = NJS_GLOBAL_FRAME_SIZE + scope_size + NJS_FRAME_SPARE_SIZE; size = nxt_align_size(size, NJS_FRAME_SPARE_SIZE); - frame = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), size); + frame = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), size); if (nxt_slow_path(frame == NULL)) { return NXT_ERROR; } @@ -436,7 +435,7 @@ njs_vm_init(njs_vm_t *vm) if (vm->debug != NULL) { backtrace = nxt_array_create(4, sizeof(njs_backtrace_entry_t), - &njs_array_mem_proto, vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(backtrace == NULL)) { return NXT_ERROR; } @@ -486,7 +485,7 @@ njs_vm_add_event(njs_vm_t *vm, njs_function_t *function, nxt_uint_t once, { njs_event_t *event; - event = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_event_t)); + event = nxt_mp_alloc(vm->mem_pool, sizeof(njs_event_t)); if (nxt_slow_path(event == NULL)) { return NULL; } @@ -542,8 +541,7 @@ njs_vm_post_event(njs_vm_t *vm, njs_vm_event_t vm_event, if (nargs != 0 && !event->posted) { event->nargs = nargs; - event->args = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_value_t) * nargs); + event->args = nxt_mp_alloc(vm->mem_pool, sizeof(njs_value_t) * nargs); if (nxt_slow_path(event->args == NULL)) { return NJS_ERROR; } @@ -709,7 +707,7 @@ njs_vm_object_alloc(njs_vm_t *vm, njs_value_t *retval, ...) } lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.proto = &njs_object_hash_proto; njs_string_get(name, &lhq.key); diff --git a/njs/njs.h b/njs/njs.h index 638b886d..62024ebd 100644 --- a/njs/njs.h +++ b/njs/njs.h @@ -273,6 +273,6 @@ NXT_EXPORT njs_ret_t njs_vm_object_alloc(njs_vm_t *vm, njs_value_t *retval, NXT_EXPORT njs_value_t *njs_vm_object_prop(njs_vm_t *vm, const njs_value_t *value, const nxt_str_t *key); -extern const nxt_mem_proto_t njs_vm_mem_cache_pool_proto; +extern const nxt_mem_proto_t njs_vm_mp_proto; #endif /* _NJS_H_INCLUDED_ */ diff --git a/njs/njs_array.c b/njs/njs_array.c index e8ae019b..834c1053 100644 --- a/njs/njs_array.c +++ b/njs/njs_array.c @@ -130,7 +130,7 @@ njs_array_alloc(njs_vm_t *vm, uint32_t length, uint32_t spare) uint64_t size; njs_array_t *array; - array = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_array_t)); + array = nxt_mp_alloc(vm->mem_pool, sizeof(njs_array_t)); if (nxt_slow_path(array == NULL)) { goto memory_error; } @@ -141,8 +141,8 @@ njs_array_alloc(njs_vm_t *vm, uint32_t length, uint32_t spare) goto memory_error; } - array->data = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - size * sizeof(njs_value_t)); + array->data = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + size * sizeof(njs_value_t)); if (nxt_slow_path(array->data == NULL)) { goto memory_error; } @@ -224,8 +224,8 @@ njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, goto memory_error; } - start = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - (prepend + size) * sizeof(njs_value_t)); + start = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + (prepend + size) * sizeof(njs_value_t)); if (nxt_slow_path(start == NULL)) { goto memory_error; } @@ -240,7 +240,7 @@ njs_array_expand(njs_vm_t *vm, njs_array_t *array, uint32_t prepend, array->start = start; - nxt_mem_cache_free(vm->mem_cache_pool, old); + nxt_mp_free(vm->mem_pool, old); return NXT_OK; @@ -970,8 +970,8 @@ njs_array_prototype_join(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, } if (max != 0) { - values = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - sizeof(njs_value_t) * max); + values = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + sizeof(njs_value_t) * max); if (nxt_slow_path(values == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -1105,7 +1105,7 @@ njs_array_prototype_join_continuation(njs_vm_t *vm, njs_value_t *args, njs_release(vm, &values[i]); } - nxt_mem_cache_free(vm->mem_cache_pool, values); + nxt_mp_free(vm->mem_pool, values); return NXT_OK; } diff --git a/njs/njs_builtin.c b/njs/njs_builtin.c index 4605e655..76ef5a36 100644 --- a/njs/njs_builtin.c +++ b/njs/njs_builtin.c @@ -284,12 +284,12 @@ njs_builtin_objects_create(njs_vm_t *vm) } lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; for (p = njs_module_init; *p != NULL; p++) { obj = *p; - module = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_module_t)); + module = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_module_t)); if (nxt_slow_path(module == NULL)) { return NJS_ERROR; } @@ -629,7 +629,7 @@ njs_builtin_completions(njs_vm_t *vm, nxt_array_t *array) njs_string_get(&prop->name, &string); len = obj->name.length + string.length + 2; - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + compl = nxt_mp_zalloc(vm->mem_pool, len); if (compl == NULL) { return NULL; } @@ -649,7 +649,7 @@ njs_builtin_completions(njs_vm_t *vm, nxt_array_t *array) njs_string_get(&prop->name, &string); len = string.length + 2; - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + compl = nxt_mp_zalloc(vm->mem_pool, len); if (compl == NULL) { return NULL; } @@ -679,7 +679,7 @@ njs_builtin_completions(njs_vm_t *vm, nxt_array_t *array) njs_string_get(&prop->name, &string); len = obj->name.length + string.length + 2; - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + compl = nxt_mp_zalloc(vm->mem_pool, len); if (compl == NULL) { return NULL; } @@ -705,7 +705,7 @@ njs_builtin_completions(njs_vm_t *vm, nxt_array_t *array) nxt_lvlhsh_each_init(&lhe_prop, &njs_extern_hash_proto); len = ev->name.length + 1; - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + compl = nxt_mp_zalloc(vm->mem_pool, len); if (compl == NULL) { return NULL; } @@ -723,7 +723,7 @@ njs_builtin_completions(njs_vm_t *vm, nxt_array_t *array) } len = ev->name.length + ev->name.length + 2; - compl = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + compl = nxt_mp_zalloc(vm->mem_pool, len); if (compl == NULL) { return NULL; } @@ -753,8 +753,7 @@ njs_vm_completions(njs_vm_t *vm, nxt_str_t *expression) size = njs_builtin_completions_size(vm); completions = nxt_array_create(size, sizeof(nxt_str_t), - &njs_array_mem_proto, - vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(completions == NULL)) { return NULL; @@ -879,7 +878,7 @@ njs_object_completions(njs_vm_t *vm, njs_object_t *object) } while (o != NULL); completions = nxt_array_create(size, sizeof(nxt_str_t), - &njs_array_mem_proto, vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(completions == NULL)) { return NULL; @@ -993,7 +992,7 @@ njs_builtin_match_native_function(njs_vm_t *vm, njs_function_t *function, njs_string_get(&prop->name, &string); len = obj->name.length + string.length + sizeof("."); - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + buf = nxt_mp_zalloc(vm->mem_pool, len); if (buf == NULL) { return NXT_ERROR; } @@ -1012,7 +1011,7 @@ njs_builtin_match_native_function(njs_vm_t *vm, njs_function_t *function, njs_string_get(&prop->name, &string); len = obj->name.length + string.length + sizeof(".prototype."); - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + buf = nxt_mp_zalloc(vm->mem_pool, len); if (buf == NULL) { return NXT_ERROR; } @@ -1031,7 +1030,7 @@ njs_builtin_match_native_function(njs_vm_t *vm, njs_function_t *function, njs_string_get(&prop->name, &string); len = obj->name.length + string.length + sizeof("."); - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + buf = nxt_mp_zalloc(vm->mem_pool, len); if (buf == NULL) { return NXT_ERROR; } @@ -1060,7 +1059,7 @@ njs_builtin_match_native_function(njs_vm_t *vm, njs_function_t *function, njs_string_get(&prop->name, &string); len = obj->name.length + string.length + sizeof("."); - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + buf = nxt_mp_zalloc(vm->mem_pool, len); if (buf == NULL) { return NXT_ERROR; } diff --git a/njs/njs_core.h b/njs/njs_core.h index 4ec9b134..bfb10991 100644 --- a/njs/njs_core.h +++ b/njs/njs_core.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include diff --git a/njs/njs_crypto.c b/njs/njs_crypto.c index fa8a8db1..ff40e630 100644 --- a/njs/njs_crypto.c +++ b/njs/njs_crypto.c @@ -132,7 +132,7 @@ njs_crypto_object_value_alloc(njs_vm_t *vm, nxt_uint_t proto) { njs_object_value_t *ov; - ov = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_value_t)); + ov = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_value_t)); if (nxt_fast_path(ov != NULL)) { nxt_lvlhsh_init(&ov->object.hash); @@ -177,7 +177,7 @@ njs_crypto_create_hash(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, return NJS_ERROR; } - dgst = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_digest_t)); + dgst = nxt_mp_alloc(vm->mem_pool, sizeof(njs_digest_t)); if (nxt_slow_path(dgst == NULL)) { njs_memory_error(vm); return NJS_ERROR; @@ -408,7 +408,7 @@ njs_crypto_create_hmac(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_string_get(&args[2], &key); - ctx = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_hmac_t)); + ctx = nxt_mp_alloc(vm->mem_pool, sizeof(njs_hmac_t)); if (nxt_slow_path(ctx == NULL)) { njs_memory_error(vm); return NJS_ERROR; diff --git a/njs/njs_date.c b/njs/njs_date.c index 591e46b8..bfb77d88 100644 --- a/njs/njs_date.c +++ b/njs/njs_date.c @@ -127,7 +127,7 @@ njs_date_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, done: - date = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_date_t)); + date = nxt_mp_alloc(vm->mem_pool, sizeof(njs_date_t)); if (nxt_slow_path(date == NULL)) { njs_memory_error(vm); return NXT_ERROR; diff --git a/njs/njs_error.c b/njs/njs_error.c index 7b5e6c17..2a777df6 100644 --- a/njs/njs_error.c +++ b/njs/njs_error.c @@ -57,7 +57,7 @@ njs_error_alloc(njs_vm_t *vm, njs_value_type_t type, const njs_value_t *name, njs_object_prop_t *prop; nxt_lvlhsh_query_t lhq; - error = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_t)); + error = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_t)); if (nxt_slow_path(error == NULL)) { njs_memory_error(vm); return NULL; @@ -71,7 +71,7 @@ njs_error_alloc(njs_vm_t *vm, njs_value_type_t type, const njs_value_t *name, error->__proto__ = &vm->prototypes[njs_error_prototype_index(type)].object; lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; if (name != NULL) { lhq.key = nxt_string_value("name"); diff --git a/njs/njs_event.c b/njs/njs_event.c index 5444f76e..a042b8c7 100644 --- a/njs/njs_event.c +++ b/njs/njs_event.c @@ -52,7 +52,7 @@ njs_add_event(njs_vm_t *vm, njs_event_t *event) lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); lhq.value = event; lhq.proto = &njs_event_hash_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_insert(&vm->events_hash, &lhq); if (nxt_slow_path(ret != NXT_OK)) { @@ -86,7 +86,7 @@ njs_del_event(njs_vm_t *vm, njs_event_t *ev, nxt_uint_t action) njs_string_get(&ev->id, &lhq.key); lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); lhq.proto = &njs_event_hash_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; if (ev->posted) { ev->posted = 0; diff --git a/njs/njs_extern.c b/njs/njs_extern.c index 18db6f64..bc3dd545 100644 --- a/njs/njs_extern.c +++ b/njs/njs_extern.c @@ -79,7 +79,7 @@ njs_vm_external_add(njs_vm_t *vm, nxt_lvlhsh_t *hash, njs_external_t *external, nxt_lvlhsh_query_t lhq; do { - ext = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_extern_t)); + ext = nxt_mp_alloc(vm->mem_pool, sizeof(njs_extern_t)); if (nxt_slow_path(ext == NULL)) { goto memory_error; } @@ -97,14 +97,13 @@ njs_vm_external_add(njs_vm_t *vm, nxt_lvlhsh_t *hash, njs_external_t *external, ext->data = external->data; if (external->method != NULL) { - function = nxt_mem_cache_zalloc(vm->mem_cache_pool, - sizeof(njs_function_t)); + function = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_function_t)); if (nxt_slow_path(function == NULL)) { goto memory_error; } /* - * nxt_mem_cache_zalloc() does also: + * nxt_mp_zalloc() does also: * nxt_lvlhsh_init(&function->object.hash); * function->object.__proto__ = NULL; */ @@ -139,7 +138,7 @@ njs_vm_external_add(njs_vm_t *vm, nxt_lvlhsh_t *hash, njs_external_t *external, lhq.key = ext->name; lhq.replace = 0; lhq.value = ext; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.proto = &njs_extern_hash_proto; ret = nxt_lvlhsh_insert(hash, &lhq); @@ -182,7 +181,7 @@ njs_vm_external_create(njs_vm_t *vm, njs_value_t *ext_val, } obj = nxt_array_add(vm->external_objects, &njs_array_mem_proto, - vm->mem_cache_pool); + vm->mem_pool); if (nxt_slow_path(obj == NULL)) { return NXT_ERROR; } @@ -210,8 +209,8 @@ njs_vm_external_bind(njs_vm_t *vm, const nxt_str_t *var_name, return NXT_ERROR; } - ev = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - sizeof(njs_extern_value_t)); + ev = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + sizeof(njs_extern_value_t)); if (nxt_slow_path(ev == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -225,7 +224,7 @@ njs_vm_external_bind(njs_vm_t *vm, const nxt_str_t *var_name, lhq.proto = &njs_extern_value_hash_proto; lhq.value = ev; lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_insert(&vm->externals_hash, &lhq); if (nxt_slow_path(ret != NXT_OK)) { @@ -367,7 +366,7 @@ found: len += pr->str.length + nxt_length("."); } - buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len); + buf = nxt_mp_zalloc(vm->mem_pool, len); if (buf == NULL) { return NXT_ERROR; } diff --git a/njs/njs_fs.c b/njs/njs_fs.c index 2a03b554..da43cfde 100644 --- a/njs/njs_fs.c +++ b/njs/njs_fs.c @@ -903,7 +903,7 @@ static njs_ret_t njs_fs_error(njs_vm_t *vm, const char *syscall, } lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; if (errn != 0) { lhq.key = nxt_string_value("errno"); diff --git a/njs/njs_function.c b/njs/njs_function.c index b9ddf0e6..9aeaea4f 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -18,11 +18,11 @@ njs_function_alloc(njs_vm_t *vm) { njs_function_t *function; - function = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_function_t)); + function = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_function_t)); if (nxt_fast_path(function != NULL)) { /* - * nxt_mem_cache_zalloc() does also: + * nxt_mp_zalloc() does also: * nxt_lvlhsh_init(&function->object.hash); * function->object.__proto__ = NULL; */ @@ -33,8 +33,8 @@ njs_function_alloc(njs_vm_t *vm) function->object.extensible = 1; function->args_offset = 1; - function->u.lambda = nxt_mem_cache_zalloc(vm->mem_cache_pool, - sizeof(njs_function_lambda_t)); + function->u.lambda = nxt_mp_zalloc(vm->mem_pool, + sizeof(njs_function_lambda_t)); if (nxt_slow_path(function->u.lambda == NULL)) { njs_memory_error(vm); return NULL; @@ -66,7 +66,7 @@ njs_function_value_copy(njs_vm_t *vm, njs_value_t *value) size = sizeof(njs_function_t) + nesting * sizeof(njs_closure_t *); - copy = nxt_mem_cache_alloc(vm->mem_cache_pool, size); + copy = nxt_mp_alloc(vm->mem_pool, size); if (nxt_slow_path(copy == NULL)) { njs_memory_error(vm); return NULL; @@ -134,7 +134,7 @@ njs_function_arguments_object_init(njs_vm_t *vm, njs_native_frame_t *frame) njs_string_get(&prop->name, &lhq.key); lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.proto = &njs_object_hash_proto; ret = nxt_lvlhsh_insert(&arguments->hash, &lhq); @@ -369,8 +369,7 @@ njs_function_frame_alloc(njs_vm_t *vm, size_t size) return NULL; } - frame = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - spare_size); + frame = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), spare_size); if (nxt_slow_path(frame == NULL)) { njs_memory_error(vm); return NULL; @@ -454,8 +453,7 @@ njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size = lambda->closure_size; if (size != 0) { - closure = nxt_mem_cache_align(vm->mem_cache_pool, - sizeof(njs_value_t), size); + closure = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), size); if (nxt_slow_path(closure == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -706,7 +704,7 @@ njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame) if (frame->size != 0) { vm->stack_size -= frame->size; - nxt_mem_cache_free(vm->mem_cache_pool, frame); + nxt_mp_free(vm->mem_pool, frame); } frame = previous; @@ -994,7 +992,7 @@ njs_function_prototype_bind(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, return NXT_ERROR; } - function = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_function_t)); + function = nxt_mp_alloc(vm->mem_pool, sizeof(njs_function_t)); if (nxt_slow_path(function == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -1017,10 +1015,10 @@ njs_function_prototype_bind(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, function->args_offset = nargs; size = nargs * sizeof(njs_value_t); - values = nxt_mem_cache_alloc(vm->mem_cache_pool, size); + values = nxt_mp_alloc(vm->mem_pool, size); if (nxt_slow_path(values == NULL)) { njs_memory_error(vm); - nxt_mem_cache_free(vm->mem_cache_pool, function); + nxt_mp_free(vm->mem_pool, function); return NXT_ERROR; } diff --git a/njs/njs_generator.c b/njs/njs_generator.c index ab6317c5..9b392e6b 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -461,7 +461,7 @@ njs_generate_reserve(njs_vm_t *vm, njs_generator_t *generator, size_t size) size += size / 2; } - p = nxt_mem_cache_alloc(vm->mem_cache_pool, size); + p = nxt_mp_alloc(vm->mem_pool, size); if (nxt_slow_path(p == NULL)) { njs_memory_error(vm); return NULL; @@ -472,7 +472,7 @@ njs_generate_reserve(njs_vm_t *vm, njs_generator_t *generator, size_t size) size = generator->code_end - generator->code_start; memcpy(p, generator->code_start, size); - nxt_mem_cache_free(vm->mem_cache_pool, generator->code_start); + nxt_mp_free(vm->mem_pool, generator->code_start); generator->code_start = p; generator->code_end = p + size; @@ -880,8 +880,7 @@ njs_generate_switch_statement(njs_vm_t *vm, njs_generator_t *generator, return ret; } - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_generator_patch_t)); + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); if (nxt_slow_path(patch == NULL)) { return NXT_ERROR; } @@ -921,7 +920,7 @@ njs_generate_switch_statement(njs_vm_t *vm, njs_generator_t *generator, next = patch->next; - nxt_mem_cache_free(vm->mem_cache_pool, patch); + nxt_mp_free(vm->mem_pool, patch); patch = next; node = branch->right; @@ -1259,8 +1258,7 @@ njs_generate_start_block(njs_vm_t *vm, njs_generator_t *generator, { njs_generator_block_t *block; - block = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_generator_block_t)); + block = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_block_t)); if (nxt_fast_path(block != NULL)) { block->next = generator->block; @@ -1301,8 +1299,7 @@ njs_generate_make_continuation_patch(njs_vm_t *vm, njs_generator_t *generator, { njs_generator_patch_t *patch; - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_generator_patch_t)); + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); if (nxt_slow_path(patch == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -1327,7 +1324,7 @@ njs_generate_patch_block(njs_vm_t *vm, njs_generator_t *generator, njs_code_update_offset(generator, patch); next = patch->next; - nxt_mem_cache_free(vm->mem_cache_pool, patch); + nxt_mp_free(vm->mem_pool, patch); } } @@ -1338,8 +1335,7 @@ njs_generate_make_exit_patch(njs_vm_t *vm, njs_generator_t *generator, { njs_generator_patch_t *patch; - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_generator_patch_t)); + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); if (nxt_slow_path(patch == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -1364,7 +1360,7 @@ njs_generate_patch_block_exit(njs_vm_t *vm, njs_generator_t *generator) njs_generate_patch_block(vm, generator, block->exit); - nxt_mem_cache_free(vm->mem_cache_pool, block); + nxt_mp_free(vm->mem_pool, block); } @@ -1391,8 +1387,7 @@ njs_generate_continue_statement(njs_vm_t *vm, njs_generator_t *generator, /* TODO: LABEL */ - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_generator_patch_t)); + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); if (nxt_fast_path(patch != NULL)) { patch->next = block->continuation; @@ -1441,8 +1436,7 @@ njs_generate_break_statement(njs_vm_t *vm, njs_generator_t *generator, /* TODO: LABEL: loop and switch may have label, block must have label. */ - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_generator_patch_t)); + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); if (nxt_fast_path(patch != NULL)) { patch->next = block->exit; @@ -2293,8 +2287,8 @@ njs_generate_function_scope(njs_vm_t *vm, njs_function_lambda_t *lambda, nxt_array_t *closure; njs_generator_t *generator; - generator = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - sizeof(njs_generator_t)); + generator = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + sizeof(njs_generator_t)); if (nxt_slow_path(generator == NULL)) { return NXT_ERROR; } @@ -2326,7 +2320,7 @@ njs_generate_function_scope(njs_vm_t *vm, njs_function_lambda_t *lambda, lambda->start = generator->code_start; } - nxt_mem_cache_free(vm->mem_cache_pool, generator); + nxt_mp_free(vm->mem_pool, generator); return ret; } @@ -2346,7 +2340,7 @@ njs_generate_scope(njs_vm_t *vm, njs_generator_t *generator, generator->code_size = 128; - p = nxt_mem_cache_alloc(vm->mem_cache_pool, generator->code_size); + p = nxt_mp_alloc(vm->mem_pool, generator->code_size); if (nxt_slow_path(p == NULL)) { return NXT_ERROR; } @@ -2371,8 +2365,7 @@ njs_generate_scope(njs_vm_t *vm, njs_generator_t *generator, scope_size -= NJS_INDEX_GLOBAL_OFFSET; } - generator->local_scope = nxt_mem_cache_alloc(vm->mem_cache_pool, - scope_size); + generator->local_scope = nxt_mp_alloc(vm->mem_pool, scope_size); if (nxt_slow_path(generator->local_scope == NULL)) { return NXT_ERROR; } @@ -2392,13 +2385,13 @@ njs_generate_scope(njs_vm_t *vm, njs_generator_t *generator, if (vm->code == NULL) { vm->code = nxt_array_create(4, sizeof(njs_vm_code_t), - &njs_array_mem_proto, vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(vm->code == NULL)) { return NXT_ERROR; } } - code = nxt_array_add(vm->code, &njs_array_mem_proto, vm->mem_cache_pool); + code = nxt_array_add(vm->code, &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(code == NULL)) { return NXT_ERROR; } @@ -2489,8 +2482,7 @@ njs_generate_return_statement(njs_vm_t *vm, njs_generator_t *generator, return NXT_OK; } - patch = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_generator_patch_t)); + patch = nxt_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); if (nxt_slow_path(patch == NULL)) { return NXT_ERROR; } @@ -3087,8 +3079,8 @@ njs_generate_temp_index_get(njs_vm_t *vm, njs_generator_t *generator, * all global variables are allocated in absolute scope * to simplify global scope handling. */ - value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - sizeof(njs_value_t)); + value = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + sizeof(njs_value_t)); if (nxt_slow_path(value == NULL)) { return NJS_INDEX_ERROR; } @@ -3097,7 +3089,7 @@ njs_generate_temp_index_get(njs_vm_t *vm, njs_generator_t *generator, } else { value = nxt_array_add(scope->values[0], &njs_array_mem_proto, - vm->mem_cache_pool); + vm->mem_pool); if (nxt_slow_path(value == NULL)) { return NJS_INDEX_ERROR; } @@ -3153,7 +3145,7 @@ njs_generate_index_release(njs_vm_t *vm, njs_generator_t *generator, if (cache == NULL) { cache = nxt_array_create(4, sizeof(njs_value_t *), - &njs_array_mem_proto, vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(cache == NULL)) { return NXT_ERROR; } @@ -3161,7 +3153,7 @@ njs_generate_index_release(njs_vm_t *vm, njs_generator_t *generator, generator->index_cache = cache; } - last = nxt_array_add(cache, &njs_array_mem_proto, vm->mem_cache_pool); + last = nxt_array_add(cache, &njs_array_mem_proto, vm->mem_pool); if (nxt_fast_path(last != NULL)) { *last = index; return NXT_OK; @@ -3177,7 +3169,7 @@ njs_generate_function_debug(njs_vm_t *vm, nxt_str_t *name, { njs_function_debug_t *debug; - debug = nxt_array_add(vm->debug, &njs_array_mem_proto, vm->mem_cache_pool); + debug = nxt_array_add(vm->debug, &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(debug == NULL)) { return NXT_ERROR; } diff --git a/njs/njs_json.c b/njs/njs_json.c index 79cf818d..7704f082 100644 --- a/njs/njs_json.c +++ b/njs/njs_json.c @@ -13,7 +13,7 @@ typedef struct { njs_vm_t *vm; - nxt_mem_cache_pool_t *pool; + nxt_mp_t *pool; nxt_uint_t depth; const u_char *start; const u_char *end; @@ -82,7 +82,7 @@ typedef struct { njs_value_t key; njs_vm_t *vm; - nxt_mem_cache_pool_t *pool; + nxt_mp_t *pool; njs_chb_node_t *nodes; njs_chb_node_t *last; nxt_array_t stack; @@ -169,7 +169,7 @@ njs_json_parse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_string_prop_t string; njs_json_parse_ctx_t ctx; - value = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_value_t)); + value = nxt_mp_alloc(vm->mem_pool, sizeof(njs_value_t)); if (nxt_slow_path(value == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -187,7 +187,7 @@ njs_json_parse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, end = p + string.size; ctx.vm = vm; - ctx.pool = vm->mem_cache_pool; + ctx.pool = vm->mem_pool; ctx.depth = 32; ctx.start = string.start; ctx.end = end; @@ -220,7 +220,7 @@ njs_json_parse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, parse->function = args[2].data.u.function; if (nxt_array_init(&parse->stack, NULL, 4, sizeof(njs_json_state_t), - &njs_array_mem_proto, vm->mem_cache_pool) + &njs_array_mem_proto, vm->mem_pool) == NULL) { goto memory_error; @@ -262,7 +262,7 @@ njs_json_stringify(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, stringify = njs_vm_continuation(vm); stringify->vm = vm; - stringify->pool = vm->mem_cache_pool; + stringify->pool = vm->mem_pool; stringify->u.cont.function = njs_json_stringify_continuation; stringify->nodes = NULL; stringify->last = NULL; @@ -293,8 +293,8 @@ njs_json_stringify(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, num = nxt_min(num, 10); stringify->space.length = (size_t) num; - stringify->space.start = nxt_mem_cache_alloc(vm->mem_cache_pool, - (size_t) num + 1); + stringify->space.start = nxt_mp_alloc(vm->mem_pool, + (size_t) num + 1); if (nxt_slow_path(stringify->space.start == NULL)) { goto memory_error; } @@ -307,7 +307,7 @@ njs_json_stringify(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, } if (nxt_array_init(&stringify->stack, NULL, 4, sizeof(njs_json_state_t), - &njs_array_mem_proto, vm->mem_cache_pool) + &njs_array_mem_proto, vm->mem_pool) == NULL) { goto memory_error; @@ -427,7 +427,7 @@ njs_json_parse_object(njs_json_parse_ctx_t *ctx, njs_value_t *value, goto error_token; } - prop_name = nxt_mem_cache_alloc(ctx->pool, sizeof(njs_value_t)); + prop_name = nxt_mp_alloc(ctx->pool, sizeof(njs_value_t)); if (nxt_slow_path(prop_name == NULL)) { goto memory_error; } @@ -448,7 +448,7 @@ njs_json_parse_object(njs_json_parse_ctx_t *ctx, njs_value_t *value, goto error_end; } - prop_value = nxt_mem_cache_alloc(ctx->pool, sizeof(njs_value_t)); + prop_value = nxt_mp_alloc(ctx->pool, sizeof(njs_value_t)); if (nxt_slow_path(prop_value == NULL)) { goto memory_error; } @@ -554,7 +554,7 @@ njs_json_parse_array(njs_json_parse_ctx_t *ctx, njs_value_t *value, break; } - element = nxt_mem_cache_alloc(ctx->pool, sizeof(njs_value_t)); + element = nxt_mp_alloc(ctx->pool, sizeof(njs_value_t)); if (nxt_slow_path(element == NULL)) { njs_memory_error(ctx->vm); return NULL; @@ -721,7 +721,7 @@ njs_json_parse_string(njs_json_parse_ctx_t *ctx, njs_value_t *value, if (surplus != 0) { p = start; - dst = nxt_mem_cache_alloc(ctx->pool, size); + dst = nxt_mp_alloc(ctx->pool, size); if (nxt_slow_path(dst == NULL)) { njs_memory_error(ctx->vm);; return NULL; @@ -968,7 +968,7 @@ njs_json_parse_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); lhq.replace = 1; lhq.proto = &njs_object_hash_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; if (njs_is_void(&parse->retval)) { ret = nxt_lvlhsh_delete(&state->value.data.u.object->hash, @@ -1082,8 +1082,7 @@ njs_json_push_parse_state(njs_vm_t *vm, njs_json_parse_t *parse, { njs_json_state_t *state; - state = nxt_array_add(&parse->stack, &njs_array_mem_proto, - vm->mem_cache_pool); + state = nxt_array_add(&parse->stack, &njs_array_mem_proto, vm->mem_pool); if (state != NULL) { state = nxt_array_last(&parse->stack); state->value = *value; @@ -1633,7 +1632,7 @@ njs_json_push_stringify_state(njs_vm_t *vm, njs_json_stringify_t *stringify, } state = nxt_array_add(&stringify->stack, &njs_array_mem_proto, - vm->mem_cache_pool); + vm->mem_pool); if (nxt_slow_path(state == NULL)) { njs_memory_error(vm); return NULL; @@ -1873,7 +1872,7 @@ njs_json_wrap_value(njs_vm_t *vm, njs_value_t *value) njs_object_prop_t *prop; nxt_lvlhsh_query_t lhq; - wrapper = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_value_t)); + wrapper = nxt_mp_alloc(vm->mem_pool, sizeof(njs_value_t)); if (nxt_slow_path(wrapper == NULL)) { return NULL; } @@ -1888,7 +1887,7 @@ njs_json_wrap_value(njs_vm_t *vm, njs_value_t *value) lhq.replace = 0; lhq.proto = &njs_object_hash_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.key = nxt_string_value(""); lhq.key_hash = NXT_DJB_HASH_INIT; @@ -1946,7 +1945,7 @@ njs_json_buf_reserve(njs_json_stringify_t *stringify, size_t size) size = NJS_JSON_BUF_MIN_SIZE; } - n = nxt_mem_cache_alloc(stringify->pool, sizeof(njs_chb_node_t) + size); + n = nxt_mp_alloc(stringify->pool, sizeof(njs_chb_node_t) + size); if (nxt_slow_path(n == NULL)) { return NULL; } @@ -1997,7 +1996,7 @@ njs_json_buf_pullup(njs_json_stringify_t *stringify, nxt_str_t *str) n = n->next; } - start = nxt_mem_cache_alloc(stringify->pool, size); + start = nxt_mp_alloc(stringify->pool, size); if (nxt_slow_path(start == NULL)) { return NXT_ERROR; } @@ -2296,15 +2295,14 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_t *retval, const njs_value_t *value, goto exception; } - stringify = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_json_stringify_t)); + stringify = nxt_mp_alloc(vm->mem_pool, sizeof(njs_json_stringify_t)); if (nxt_slow_path(stringify == NULL)) { goto memory_error; } stringify->vm = vm; - stringify->pool = vm->mem_cache_pool; + stringify->pool = vm->mem_pool; stringify->nodes = NULL; stringify->last = NULL; @@ -2318,7 +2316,7 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_t *retval, const njs_value_t *value, } stringify->space.length = indent; - stringify->space.start = nxt_mem_cache_alloc(vm->mem_cache_pool, indent); + stringify->space.start = nxt_mp_alloc(vm->mem_pool, indent); if (nxt_slow_path(stringify->space.start == NULL)) { goto memory_error; } @@ -2326,7 +2324,7 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_t *retval, const njs_value_t *value, nxt_memset(stringify->space.start, ' ', indent); if (nxt_array_init(&stringify->stack, NULL, 4, sizeof(njs_json_state_t), - &njs_array_mem_proto, vm->mem_cache_pool) + &njs_array_mem_proto, vm->mem_pool) == NULL) { goto memory_error; diff --git a/njs/njs_lexer_keyword.c b/njs/njs_lexer_keyword.c index ba7dd9b7..7db41468 100644 --- a/njs/njs_lexer_keyword.c +++ b/njs/njs_lexer_keyword.c @@ -156,7 +156,7 @@ const nxt_lvlhsh_proto_t njs_keyword_hash_proto nxt_int_t -njs_lexer_keywords_init(nxt_mem_cache_pool_t *mcp, nxt_lvlhsh_t *hash) +njs_lexer_keywords_init(nxt_mp_t *mcp, nxt_lvlhsh_t *hash) { nxt_uint_t n; nxt_lvlhsh_query_t lhq; diff --git a/njs/njs_object.c b/njs/njs_object.c index c6414d20..f9885d0d 100644 --- a/njs/njs_object.c +++ b/njs/njs_object.c @@ -33,7 +33,7 @@ njs_object_alloc(njs_vm_t *vm) { njs_object_t *object; - object = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_t)); + object = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_t)); if (nxt_fast_path(object != NULL)) { nxt_lvlhsh_init(&object->hash); @@ -62,7 +62,7 @@ njs_object_value_copy(njs_vm_t *vm, njs_value_t *value) return object; } - object = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_t)); + object = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_t)); if (nxt_fast_path(object != NULL)) { *object = *value->data.u.object; @@ -84,7 +84,7 @@ njs_object_value_alloc(njs_vm_t *vm, const njs_value_t *value, nxt_uint_t type) nxt_uint_t index; njs_object_value_t *ov; - ov = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_value_t)); + ov = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_value_t)); if (nxt_fast_path(ov != NULL)) { nxt_lvlhsh_init(&ov->object.hash); @@ -116,7 +116,7 @@ njs_object_hash_create(njs_vm_t *vm, nxt_lvlhsh_t *hash, lhq.replace = 0; lhq.proto = &njs_object_hash_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; while (n != 0) { njs_string_get(&prop->name, &lhq.key); @@ -188,8 +188,8 @@ njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name, { njs_object_prop_t *prop; - prop = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - sizeof(njs_object_prop_t)); + prop = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + sizeof(njs_object_prop_t)); if (nxt_fast_path(prop != NULL)) { /* GC: retain. */ @@ -743,7 +743,7 @@ njs_method_private_copy(njs_vm_t *vm, njs_property_query_t *pq) njs_function_t *function; njs_object_prop_t *prop, *shared; - prop = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_object_prop_t)); + prop = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_prop_t)); if (nxt_slow_path(prop == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -759,7 +759,7 @@ njs_method_private_copy(njs_vm_t *vm, njs_property_query_t *pq) pq->lhq.replace = 0; pq->lhq.value = prop; - pq->lhq.pool = vm->mem_cache_pool; + pq->lhq.pool = vm->mem_pool; return nxt_lvlhsh_insert(&pq->prototype->hash, &pq->lhq); } @@ -1441,7 +1441,7 @@ njs_define_property(njs_vm_t *vm, njs_value_t *object, const njs_value_t *name, } else { pq.lhq.value = desc; pq.lhq.replace = 0; - pq.lhq.pool = vm->mem_cache_pool; + pq.lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_insert(&object->data.u.object->hash, &pq.lhq); if (nxt_slow_path(ret != NXT_OK)) { @@ -1633,7 +1633,7 @@ njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args, lhq.proto = &njs_object_hash_proto; lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.proto = &njs_object_hash_proto; lhq.key = nxt_string_value("value"); @@ -2050,7 +2050,7 @@ njs_property_prototype_create(njs_vm_t *vm, nxt_lvlhsh_t *hash, lhq.key_hash = NJS_PROTOTYPE_HASH; lhq.key = nxt_string_value("prototype"); lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.proto = &njs_object_hash_proto; ret = nxt_lvlhsh_insert(hash, &lhq); @@ -2308,7 +2308,7 @@ njs_property_constructor_create(njs_vm_t *vm, nxt_lvlhsh_t *hash, lhq.key_hash = NJS_CONSTRUCTOR_HASH; lhq.key = nxt_string_value("constructor"); lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.proto = &njs_object_hash_proto; ret = nxt_lvlhsh_insert(hash, &lhq); diff --git a/njs/njs_parser.c b/njs/njs_parser.c index b5038b70..1e4a393a 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -91,7 +91,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *parser, njs_parser_t *prev) lhq.proto = &njs_variables_hash_proto; lhq.replace = 0; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; variables = &parser->scope->variables; prev_variables = &prev->scope->variables; @@ -178,7 +178,7 @@ njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser, njs_scope_t type) } } - scope = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_parser_scope_t)); + scope = nxt_mp_alloc(vm->mem_pool, sizeof(njs_parser_scope_t)); if (nxt_slow_path(scope == NULL)) { return NXT_ERROR; } @@ -210,7 +210,7 @@ njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser, njs_scope_t type) if (scope->type < NJS_SCOPE_BLOCK) { values = nxt_array_create(4, sizeof(njs_value_t), &njs_array_mem_proto, - vm->mem_cache_pool); + vm->mem_pool); if (nxt_slow_path(values == NULL)) { return NXT_ERROR; } @@ -450,7 +450,7 @@ njs_parser_block(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token) if (node != NULL && node->token == NJS_TOKEN_BLOCK) { parser->node = node->left; - nxt_mem_cache_free(vm->mem_cache_pool, node); + nxt_mp_free(vm->mem_pool, node); } return token; @@ -609,8 +609,7 @@ njs_parser_function_expression(njs_vm_t *vm, njs_parser_t *parser) } else { /* Anonymous function. */ - lambda = nxt_mem_cache_zalloc(vm->mem_cache_pool, - sizeof(njs_function_lambda_t)); + lambda = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_function_lambda_t)); if (nxt_slow_path(lambda == NULL)) { return NJS_TOKEN_ERROR; } @@ -1706,7 +1705,7 @@ njs_parser_try_block(njs_vm_t *vm, njs_parser_t *parser) if (node != NULL && node->token == NJS_TOKEN_BLOCK) { parser->node = node->left; - nxt_mem_cache_free(vm->mem_cache_pool, node); + nxt_mp_free(vm->mem_pool, node); } return token; diff --git a/njs/njs_parser.h b/njs/njs_parser.h index 7f4e1c81..e90a683a 100644 --- a/njs/njs_parser.h +++ b/njs/njs_parser.h @@ -284,7 +284,7 @@ struct njs_parser_node_s { #define njs_parser_node_alloc(vm) \ - nxt_mem_cache_zalloc((vm)->mem_cache_pool, sizeof(njs_parser_node_t)) + nxt_mp_zalloc((vm)->mem_pool, sizeof(njs_parser_node_t)) struct njs_parser_s { @@ -303,8 +303,7 @@ typedef struct { njs_token_t njs_lexer_token(njs_lexer_t *lexer); void njs_lexer_rollback(njs_lexer_t *lexer); -nxt_int_t njs_lexer_keywords_init(nxt_mem_cache_pool_t *mcp, - nxt_lvlhsh_t *hash); +nxt_int_t njs_lexer_keywords_init(nxt_mp_t *mcp, nxt_lvlhsh_t *hash); njs_token_t njs_lexer_keyword(njs_lexer_t *lexer); njs_value_t *njs_parser_external(njs_vm_t *vm, njs_parser_t *parser); diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index 461cc49f..e8cf15ad 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -32,7 +32,7 @@ njs_ret_t njs_regexp_init(njs_vm_t *vm) { vm->regex_context = nxt_regex_context_create(njs_regexp_malloc, - njs_regexp_free, vm->mem_cache_pool); + njs_regexp_free, vm->mem_pool); if (nxt_slow_path(vm->regex_context == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -53,14 +53,14 @@ njs_regexp_init(njs_vm_t *vm) static void * njs_regexp_malloc(size_t size, void *memory_data) { - return nxt_mem_cache_alloc(memory_data, size); + return nxt_mp_alloc(memory_data, size); } static void njs_regexp_free(void *p, void *memory_data) { - nxt_mem_cache_free(memory_data, p); + nxt_mp_free(memory_data, p); } @@ -269,9 +269,9 @@ njs_regexp_pattern_create(njs_vm_t *vm, u_char *start, size_t length, size += ((flags & NJS_REGEXP_IGNORE_CASE) != 0); size += ((flags & NJS_REGEXP_MULTILINE) != 0); - pattern = nxt_mem_cache_zalloc(vm->mem_cache_pool, - sizeof(njs_regexp_pattern_t) - + 1 + length + size + 1); + pattern = nxt_mp_zalloc(vm->mem_pool, + sizeof(njs_regexp_pattern_t) + + 1 + length + size + 1); if (nxt_slow_path(pattern == NULL)) { njs_memory_error(vm); return NULL; @@ -328,12 +328,12 @@ njs_regexp_pattern_create(njs_vm_t *vm, u_char *start, size_t length, if (nxt_slow_path((u_int) ret != pattern->ncaptures)) { njs_internal_error(vm, "regexp pattern compile failed"); - nxt_mem_cache_free(vm->mem_cache_pool, pattern); + nxt_mp_free(vm->mem_pool, pattern); return NULL; } } else if (ret != NXT_DECLINED) { - nxt_mem_cache_free(vm->mem_cache_pool, pattern); + nxt_mp_free(vm->mem_pool, pattern); return NULL; } @@ -430,7 +430,7 @@ njs_regexp_alloc(njs_vm_t *vm, njs_regexp_pattern_t *pattern) { njs_regexp_t *regexp; - regexp = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_regexp_t)); + regexp = nxt_mp_alloc(vm->mem_pool, sizeof(njs_regexp_t)); if (nxt_fast_path(regexp != NULL)) { nxt_lvlhsh_init(®exp->object.hash); @@ -752,7 +752,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, njs_utf8_t utf8, lhq.key = nxt_string_value("index"); lhq.replace = 0; lhq.value = prop; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; lhq.proto = &njs_object_hash_proto; ret = nxt_lvlhsh_insert(&array->object.hash, &lhq); diff --git a/njs/njs_shell.c b/njs/njs_shell.c index b36de0e0..232e26d7 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -331,8 +331,7 @@ njs_externals_init(njs_vm_t *vm, njs_console_t *console) return NXT_ERROR; } - value = nxt_mem_cache_zalloc(vm->mem_cache_pool, - sizeof(njs_opaque_value_t)); + value = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_opaque_value_t)); if (value == NULL) { return NXT_ERROR; } @@ -981,7 +980,7 @@ njs_console_set_timer(njs_external_ptr_t external, uint64_t delay, console = external; vm = console->vm; - ev = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_ev_t)); + ev = nxt_mp_alloc(vm->mem_pool, sizeof(njs_ev_t)); if (nxt_slow_path(ev == NULL)) { return NULL; } @@ -995,7 +994,7 @@ njs_console_set_timer(njs_external_ptr_t external, uint64_t delay, lhq.replace = 0; lhq.value = ev; lhq.proto = &lvlhsh_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_insert(&console->events, &lhq); if (nxt_slow_path(ret != NXT_OK)) { @@ -1026,7 +1025,7 @@ njs_console_clear_timer(njs_external_ptr_t external, njs_host_event_t event) lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); lhq.proto = &lvlhsh_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; if (ev->link.prev != NULL) { nxt_queue_remove(&ev->link); @@ -1037,7 +1036,7 @@ njs_console_clear_timer(njs_external_ptr_t external, njs_host_event_t event) fprintf(stderr, "nxt_lvlhsh_delete() failed\n"); } - nxt_mem_cache_free(vm->mem_cache_pool, ev); + nxt_mp_free(vm->mem_pool, ev); } @@ -1059,13 +1058,13 @@ lvlhsh_key_test(nxt_lvlhsh_query_t *lhq, void *data) static void * lvlhsh_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc) { - return nxt_mem_cache_align(pool, size, size); + return nxt_mp_align(pool, size, size); } static void lvlhsh_pool_free(void *pool, void *p, size_t size) { - nxt_mem_cache_free(pool, p); + nxt_mp_free(pool, p); } diff --git a/njs/njs_string.c b/njs/njs_string.c index 3c9ad326..fa0c24b9 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -145,7 +145,7 @@ njs_string_create(njs_vm_t *vm, njs_value_t *value, u_char *start, value->long_string.external = 0xff; value->long_string.size = size; - string = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_string_t)); + string = nxt_mp_alloc(vm->mem_pool, sizeof(njs_string_t)); if (nxt_slow_path(string == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -214,8 +214,7 @@ njs_string_alloc(njs_vm_t *vm, njs_value_t *value, uint32_t size, total = size; } - string = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_string_t) + total); + string = nxt_mp_alloc(vm->mem_pool, sizeof(njs_string_t) + total); if (nxt_fast_path(string != NULL)) { value->long_string.data = string; @@ -484,7 +483,7 @@ njs_string_validate(njs_vm_t *vm, njs_string_prop_t *string, njs_value_t *value) map_offset = njs_string_map_offset(size); new_size = map_offset + njs_string_map_size(length); - start = nxt_mem_cache_alloc(vm->mem_cache_pool, new_size); + start = nxt_mp_alloc(vm->mem_pool, new_size); if (nxt_slow_path(start == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -2955,7 +2954,7 @@ njs_string_prototype_replace(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, /* This cannot fail. */ r->part = nxt_array_init(&r->parts, &r->array, 3, sizeof(njs_string_replace_part_t), - &njs_array_mem_proto, vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); r->substitutions = NULL; r->function = NULL; @@ -3050,13 +3049,13 @@ njs_string_replace_regexp(njs_vm_t *vm, njs_value_t *args, } else { if (r->part != r->parts.start) { r->part = nxt_array_add(&r->parts, &njs_array_mem_proto, - vm->mem_cache_pool); + vm->mem_pool); if (nxt_slow_path(r->part == NULL)) { return NXT_ERROR; } r->part = nxt_array_add(&r->parts, &njs_array_mem_proto, - vm->mem_cache_pool); + vm->mem_pool); if (nxt_slow_path(r->part == NULL)) { return NXT_ERROR; } @@ -3101,7 +3100,7 @@ njs_string_replace_regexp(njs_vm_t *vm, njs_value_t *args, nxt_regex_match_data_free(r->match_data, vm->regex_context); - nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_cache_pool); + nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_pool); njs_string_copy(&vm->retval, &args[0]); @@ -3122,8 +3121,7 @@ njs_string_replace_regexp_function(njs_vm_t *vm, njs_value_t *args, r->u.cont.function = njs_string_replace_regexp_continuation; njs_set_invalid(&r->retval); - arguments = nxt_mem_cache_alloc(vm->mem_cache_pool, - (n + 3) * sizeof(njs_value_t)); + arguments = nxt_mp_alloc(vm->mem_pool, (n + 3) * sizeof(njs_value_t)); if (nxt_slow_path(arguments == NULL)) { return NXT_ERROR; } @@ -3315,7 +3313,7 @@ njs_string_replace_parse(njs_vm_t *vm, njs_string_replace_t *r, u_char *p, njs_string_subst_t *s; r->substitutions = nxt_array_create(4, sizeof(njs_string_subst_t), - &njs_array_mem_proto, vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(r->substitutions == NULL)) { return NXT_ERROR; @@ -3330,8 +3328,7 @@ njs_string_replace_parse(njs_vm_t *vm, njs_string_replace_t *r, u_char *p, copy: if (s == NULL) { - s = nxt_array_add(r->substitutions, &njs_array_mem_proto, - vm->mem_cache_pool); + s = nxt_array_add(r->substitutions, &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(s == NULL)) { return NXT_ERROR; } @@ -3395,8 +3392,7 @@ skip: goto copy; } - s = nxt_array_add(r->substitutions, &njs_array_mem_proto, - vm->mem_cache_pool); + s = nxt_array_add(r->substitutions, &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(s == NULL)) { return NXT_ERROR; } @@ -3419,8 +3415,8 @@ njs_string_replace_substitute(njs_vm_t *vm, njs_string_replace_t *r, last = r->substitutions->items; - part = nxt_array_add_multiple(&r->parts, &njs_array_mem_proto, - vm->mem_cache_pool, last + 1); + part = nxt_array_add_multiple(&r->parts, &njs_array_mem_proto, vm->mem_pool, + last + 1); if (nxt_slow_path(part == NULL)) { return NXT_ERROR; } @@ -3528,7 +3524,7 @@ njs_string_replace_join(njs_vm_t *vm, njs_string_replace_t *r) /* GC: release valid values. */ } - nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_cache_pool); + nxt_array_destroy(&r->parts, &njs_array_mem_proto, vm->mem_pool); return NXT_OK; } @@ -3744,7 +3740,7 @@ njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value) } } - data = nxt_mem_cache_alloc(vm->mem_cache_pool, size + 1); + data = nxt_mp_alloc(vm->mem_pool, size + 1); if (nxt_slow_path(data == NULL)) { njs_memory_error(vm); return NULL; @@ -4406,8 +4402,8 @@ njs_value_index(njs_vm_t *vm, const njs_value_t *src, nxt_uint_t runtime) } } - value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - value_size + size); + value = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + value_size + size); if (nxt_slow_path(value == NULL)) { return NJS_INDEX_NONE; } @@ -4427,7 +4423,7 @@ njs_value_index(njs_vm_t *vm, const njs_value_t *src, nxt_uint_t runtime) lhq.replace = 0; lhq.value = value; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; values_hash = runtime ? &vm->values_hash : &vm->shared->values_hash; diff --git a/njs/njs_time.c b/njs/njs_time.c index 2ed33369..f5b1fafe 100644 --- a/njs/njs_time.c +++ b/njs/njs_time.c @@ -41,7 +41,7 @@ njs_set_timer(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, delay = args[2].data.u.number; } - event = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_event_t)); + event = nxt_mp_alloc(vm->mem_pool, sizeof(njs_event_t)); if (nxt_slow_path(event == NULL)) { goto memory_error; } @@ -55,8 +55,8 @@ njs_set_timer(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, event->posted = 0; if (event->nargs != 0) { - event->args = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_value_t) * event->nargs); + event->args = nxt_mp_alloc(vm->mem_pool, + sizeof(njs_value_t) * event->nargs); if (nxt_slow_path(event->args == NULL)) { goto memory_error; } @@ -115,7 +115,7 @@ njs_clear_timeout(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, (unsigned) args[1].data.u.number); lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); lhq.proto = &njs_event_hash_proto; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_find(&vm->events_hash, &lhq); if (ret == NXT_OK) { diff --git a/njs/njs_variable.c b/njs/njs_variable.c index c7549da4..a3b44f8d 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -75,7 +75,7 @@ njs_variable_add(njs_vm_t *vm, njs_parser_scope_t *scope, nxt_str_t *name, lhq.replace = 0; lhq.value = var; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_insert(&scope->variables, &lhq); @@ -83,8 +83,8 @@ njs_variable_add(njs_vm_t *vm, njs_parser_scope_t *scope, nxt_str_t *name, return var; } - nxt_mem_cache_free(vm->mem_cache_pool, var->name.start); - nxt_mem_cache_free(vm->mem_cache_pool, var); + nxt_mp_free(vm->mem_pool, var->name.start); + nxt_mp_free(vm->mem_pool, var); njs_type_error(vm, "lvlhsh insert failed"); @@ -141,7 +141,7 @@ njs_variable_reference(njs_vm_t *vm, njs_parser_scope_t *scope, lhq.proto = &njs_reference_hash_proto; lhq.replace = 0; lhq.value = node; - lhq.pool = vm->mem_cache_pool; + lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_insert(&scope->references, &lhq); @@ -337,8 +337,8 @@ njs_variable_resolve(njs_vm_t *vm, njs_parser_node_t *node) * global variables should be allocated in absolute scope * to share them among consecutive VM invocations. */ - value = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), - sizeof(njs_value_t)); + value = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t), + sizeof(njs_value_t)); if (nxt_slow_path(value == NULL)) { njs_memory_error(vm); return NULL; @@ -351,7 +351,7 @@ njs_variable_resolve(njs_vm_t *vm, njs_parser_node_t *node) if (values == NULL) { values = nxt_array_create(4, sizeof(njs_value_t), - &njs_array_mem_proto, vm->mem_cache_pool); + &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(values == NULL)) { return NULL; } @@ -359,7 +359,7 @@ njs_variable_resolve(njs_vm_t *vm, njs_parser_node_t *node) vr->scope->values[scope_index] = values; } - value = nxt_array_add(values, &njs_array_mem_proto, vm->mem_cache_pool); + value = nxt_array_add(values, &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(value == NULL)) { return NULL; } @@ -454,7 +454,7 @@ njs_variable_alloc(njs_vm_t *vm, nxt_str_t *name, njs_variable_type_t type) njs_ret_t ret; njs_variable_t *var; - var = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_variable_t)); + var = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_variable_t)); if (nxt_slow_path(var == NULL)) { njs_memory_error(vm); return NULL; @@ -468,7 +468,7 @@ njs_variable_alloc(njs_vm_t *vm, nxt_str_t *name, njs_variable_type_t type) return var; } - nxt_mem_cache_free(vm->mem_cache_pool, var); + nxt_mp_free(vm->mem_pool, var); njs_memory_error(vm); @@ -481,7 +481,7 @@ njs_name_copy(njs_vm_t *vm, nxt_str_t *dst, nxt_str_t *src) { dst->length = src->length; - dst->start = nxt_mem_cache_alloc(vm->mem_cache_pool, src->length); + dst->start = nxt_mp_alloc(vm->mem_pool, src->length); if (nxt_slow_path(dst->start != NULL)) { (void) memcpy(dst->start, src->start, src->length); diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 80649b0a..228e6c7d 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -236,7 +236,7 @@ start: if (frame->native.size != 0) { vm->stack_size -= frame->native.size; - nxt_mem_cache_free(vm->mem_cache_pool, frame); + nxt_mp_free(vm->mem_pool, frame); } } } @@ -289,11 +289,11 @@ njs_value_release(njs_vm_t *vm, njs_value_t *value) if ((u_char *) string + sizeof(njs_string_t) != string->start) { - nxt_memcache_pool_free(vm->mem_cache_pool, + nxt_memcache_pool_free(vm->mem_pool, string->start); } - nxt_memcache_pool_free(vm->mem_cache_pool, string); + nxt_memcache_pool_free(vm->mem_pool, string); } #endif } @@ -377,7 +377,7 @@ njs_vmcode_function(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2) size = sizeof(njs_function_t) + nesting * sizeof(njs_closure_t *); - function = nxt_mem_cache_zalloc(vm->mem_cache_pool, size); + function = nxt_mp_zalloc(vm->mem_pool, size); if (nxt_slow_path(function == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -592,7 +592,7 @@ njs_vmcode_property_set(njs_vm_t *vm, njs_value_t *object, pq.lhq.replace = 0; pq.lhq.value = prop; - pq.lhq.pool = vm->mem_cache_pool; + pq.lhq.pool = vm->mem_pool; ret = nxt_lvlhsh_insert(&object->data.u.object->hash, &pq.lhq); if (nxt_slow_path(ret != NXT_OK)) { @@ -765,8 +765,7 @@ njs_vmcode_property_foreach(njs_vm_t *vm, njs_value_t *object, njs_vmcode_prop_foreach_t *code; if (njs_is_object(object)) { - next = nxt_mem_cache_alloc(vm->mem_cache_pool, - sizeof(njs_property_next_t)); + next = nxt_mp_alloc(vm->mem_pool, sizeof(njs_property_next_t)); if (nxt_slow_path(next == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -849,7 +848,7 @@ njs_vmcode_property_next(njs_vm_t *vm, njs_value_t *object, njs_value_t *value) } } - nxt_mem_cache_free(vm->mem_cache_pool, next); + nxt_mp_free(vm->mem_pool, next); } else if (njs_is_external(object)) { ext_proto = object->external.proto; @@ -2343,7 +2342,7 @@ njs_vmcode_try_start(njs_vm_t *vm, njs_value_t *exception_value, njs_vmcode_try_start_t *try_start; if (vm->top_frame->exception.catch != NULL) { - e = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_exception_t)); + e = nxt_mp_alloc(vm->mem_pool, sizeof(njs_exception_t)); if (nxt_slow_path(e == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -2436,7 +2435,7 @@ njs_vmcode_try_end(njs_vm_t *vm, njs_value_t *invld, njs_value_t *offset) } else { vm->top_frame->exception = *e; - nxt_mem_cache_free(vm->mem_cache_pool, e); + nxt_mp_free(vm->mem_pool, e); } return (njs_ret_t) offset; @@ -3104,7 +3103,7 @@ again: size = value.short_string.size; if (size != NJS_STRING_LONG) { - start = nxt_mem_cache_alloc(vm->mem_cache_pool, size); + start = nxt_mp_alloc(vm->mem_pool, size); if (nxt_slow_path(start == NULL)) { njs_memory_error(vm); return NXT_ERROR; @@ -3157,7 +3156,7 @@ again: prev = &be[i]; } - p = nxt_mem_cache_alloc(vm->mem_cache_pool, len); + p = nxt_mp_alloc(vm->mem_pool, len); if (p == NULL) { njs_memory_error(vm); return NXT_ERROR; @@ -3513,7 +3512,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm, njs_frame_t *frame) native_frame = &frame->native; function = native_frame->function; - be = nxt_array_add(vm->backtrace, &njs_array_mem_proto, vm->mem_cache_pool); + be = nxt_array_add(vm->backtrace, &njs_array_mem_proto, vm->mem_pool); if (nxt_slow_path(be == NULL)) { return NXT_ERROR; } @@ -3631,12 +3630,12 @@ njs_debug(njs_index_t index, njs_value_t *value) void * njs_lvlhsh_alloc(void *data, size_t size, nxt_uint_t nalloc) { - return nxt_mem_cache_align(data, size, size); + return nxt_mp_align(data, size, size); } void njs_lvlhsh_free(void *data, void *p, size_t size) { - nxt_mem_cache_free(data, p); + nxt_mp_free(data, p); } diff --git a/njs/njs_vm.h b/njs/njs_vm.h index f267b25d..bdf0aa2d 100644 --- a/njs/njs_vm.h +++ b/njs/njs_vm.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #define NJS_MAX_STACK_SIZE (16 * 1024 * 1024) @@ -1053,7 +1053,7 @@ struct njs_vm_s { njs_object_prototype_t prototypes[NJS_PROTOTYPE_MAX]; njs_function_t constructors[NJS_CONSTRUCTOR_MAX]; - nxt_mem_cache_pool_t *mem_cache_pool; + nxt_mp_t *mem_pool; njs_value_t *global_scope; size_t scope_size; diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 2a456c9d..046e6e84 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -11099,7 +11099,7 @@ static njs_unit_test_t njs_tz_test[] = typedef struct { nxt_lvlhsh_t hash; const njs_extern_t *proto; - nxt_mem_cache_pool_t *mem_cache_pool; + nxt_mp_t *pool; uint32_t a; nxt_str_t uri; @@ -11138,14 +11138,14 @@ lvlhsh_unit_test_key_test(nxt_lvlhsh_query_t *lhq, void *data) static void * lvlhsh_unit_test_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc) { - return nxt_mem_cache_align(pool, size, size); + return nxt_mp_align(pool, size, size); } static void lvlhsh_unit_test_pool_free(void *pool, void *p, size_t size) { - nxt_mem_cache_free(pool, p); + nxt_mp_free(pool, p); } @@ -11159,12 +11159,12 @@ static const nxt_lvlhsh_proto_t lvlhsh_proto nxt_aligned(64) = { static njs_unit_test_prop_t * -lvlhsh_unit_test_alloc(nxt_mem_cache_pool_t *pool, const njs_value_t *name, +lvlhsh_unit_test_alloc(nxt_mp_t *pool, const njs_value_t *name, const njs_value_t *value) { njs_unit_test_prop_t *prop; - prop = nxt_mem_cache_alloc(pool, sizeof(njs_unit_test_prop_t)); + prop = nxt_mp_alloc(pool, sizeof(njs_unit_test_prop_t)); if (prop == NULL) { return NULL; } @@ -11187,7 +11187,7 @@ lvlhsh_unit_test_add(njs_unit_test_req_t *r, njs_unit_test_prop_t *prop) lhq.replace = 1; lhq.value = (void *) prop; lhq.proto = &lvlhsh_proto; - lhq.pool = r->mem_cache_pool; + lhq.pool = r->pool; switch (nxt_lvlhsh_insert(&r->hash, &lhq)) { @@ -11318,7 +11318,7 @@ njs_unit_test_r_set_vars(njs_vm_t *vm, void *obj, uintptr_t data, njs_string_create(vm, &name, key->start, key->length, 0); njs_string_create(vm, &val, value->start, value->length, 0); - prop = lvlhsh_unit_test_alloc(vm->mem_cache_pool, &name, &val); + prop = lvlhsh_unit_test_alloc(vm->mem_pool, &name, &val); if (prop == NULL) { njs_memory_error(vm); return NXT_ERROR; @@ -11468,18 +11468,18 @@ njs_unit_test_create_external(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, return NJS_ERROR; } - value = nxt_mem_cache_zalloc(r->mem_cache_pool, sizeof(njs_opaque_value_t)); + value = nxt_mp_zalloc(r->pool, sizeof(njs_opaque_value_t)); if (value == NULL) { goto memory_error; } - sr = nxt_mem_cache_zalloc(r->mem_cache_pool, sizeof(njs_unit_test_req_t)); + sr = nxt_mp_zalloc(r->pool, sizeof(njs_unit_test_req_t)); if (sr == NULL) { goto memory_error; } sr->uri = uri; - sr->mem_cache_pool = r->mem_cache_pool; + sr->pool = r->pool; sr->proto = r->proto; ret = njs_vm_external_create(vm, value, sr->proto, sr); @@ -11704,9 +11704,9 @@ njs_externals_init(njs_vm_t *vm) return NXT_ERROR; } - requests = nxt_mem_cache_zalloc(vm->mem_cache_pool, - nxt_nitems(nxt_test_requests) - * sizeof(njs_unit_test_req_t)); + requests = nxt_mp_zalloc(vm->mem_pool, + nxt_nitems(nxt_test_requests) + * sizeof(njs_unit_test_req_t)); if (requests == NULL) { return NXT_ERROR; } @@ -11714,7 +11714,7 @@ njs_externals_init(njs_vm_t *vm) for (i = 0; i < nxt_nitems(nxt_test_requests); i++) { requests[i] = nxt_test_requests[i].request; - requests[i].mem_cache_pool = vm->mem_cache_pool; + requests[i].pool = vm->mem_pool; requests[i].proto = proto; ret = njs_vm_external_create(vm, njs_value_arg(&requests[i].value), @@ -11732,7 +11732,7 @@ njs_externals_init(njs_vm_t *vm) } for (j = 0; j < nxt_nitems(nxt_test_requests[i].props); j++) { - prop = lvlhsh_unit_test_alloc(vm->mem_cache_pool, + prop = lvlhsh_unit_test_alloc(vm->mem_pool, &nxt_test_requests[i].props[j].name, &nxt_test_requests[i].props[j].value); diff --git a/nxt/Makefile b/nxt/Makefile index 426c45d6..45bd0451 100644 --- a/nxt/Makefile +++ b/nxt/Makefile @@ -21,7 +21,7 @@ $(NXT_BUILDDIR)/libnxt.a: \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_trace.o \ $(NXT_BUILDDIR)/nxt_time.o \ - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ + $(NXT_BUILDDIR)/nxt_mp.o \ ar -r -c $(NXT_BUILDDIR)/libnxt.a \ $(NXT_BUILDDIR)/nxt_diyfp.o \ @@ -40,7 +40,7 @@ $(NXT_BUILDDIR)/libnxt.a: \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_time.o \ $(NXT_BUILDDIR)/nxt_trace.o \ - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ + $(NXT_BUILDDIR)/nxt_mp.o \ $(NXT_BUILDDIR)/nxt_diyfp.o: \ $(NXT_LIB)/nxt_types.h \ @@ -231,17 +231,17 @@ $(NXT_BUILDDIR)/nxt_trace.o: \ -I$(NXT_LIB) \ $(NXT_LIB)/nxt_trace.c -$(NXT_BUILDDIR)/nxt_mem_cache_pool.o: \ +$(NXT_BUILDDIR)/nxt_mp.o: \ $(NXT_LIB)/nxt_types.h \ $(NXT_LIB)/nxt_clang.h \ $(NXT_LIB)/nxt_alignment.h \ $(NXT_LIB)/nxt_queue.h \ $(NXT_LIB)/nxt_rbtree.h \ - $(NXT_LIB)/nxt_mem_cache_pool.h \ - $(NXT_LIB)/nxt_mem_cache_pool.c \ + $(NXT_LIB)/nxt_mp.h \ + $(NXT_LIB)/nxt_mp.c \ - $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_mem_cache_pool.o $(NXT_CFLAGS) \ + $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_mp.o $(NXT_CFLAGS) \ -I$(NXT_LIB) \ - $(NXT_LIB)/nxt_mem_cache_pool.c + $(NXT_LIB)/nxt_mp.c include $(NXT_LIB)/test/Makefile diff --git a/nxt/nxt_mem_cache_pool.h b/nxt/nxt_mem_cache_pool.h deleted file mode 100644 index 67f380e2..00000000 --- a/nxt/nxt_mem_cache_pool.h +++ /dev/null @@ -1,40 +0,0 @@ - -/* - * Copyright (C) Igor Sysoev - * Copyright (C) NGINX, Inc. - */ - -#ifndef _NXT_MEM_CACHE_POOL_H_INCLUDED_ -#define _NXT_MEM_CACHE_POOL_H_INCLUDED_ - - -typedef struct nxt_mem_cache_pool_s nxt_mem_cache_pool_t; - - -NXT_EXPORT nxt_mem_cache_pool_t * - nxt_mem_cache_pool_create(const nxt_mem_proto_t *proto, void *mem, - void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, - size_t min_chunk_size) - NXT_MALLOC_LIKE; -NXT_EXPORT nxt_mem_cache_pool_t * - nxt_mem_cache_pool_fast_create(const nxt_mem_proto_t *proto, void *mem, - void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, - size_t min_chunk_size) - NXT_MALLOC_LIKE; -NXT_EXPORT nxt_bool_t nxt_mem_cache_pool_is_empty(nxt_mem_cache_pool_t *pool); -NXT_EXPORT void nxt_mem_cache_pool_destroy(nxt_mem_cache_pool_t *pool); - -NXT_EXPORT void *nxt_mem_cache_alloc(nxt_mem_cache_pool_t *pool, size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void *nxt_mem_cache_zalloc(nxt_mem_cache_pool_t *pool, size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void *nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, - size_t alignment, size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void *nxt_mem_cache_zalign(nxt_mem_cache_pool_t *pool, - size_t alignment, size_t size) - NXT_MALLOC_LIKE; -NXT_EXPORT void nxt_mem_cache_free(nxt_mem_cache_pool_t *pool, void *p); - - -#endif /* _NXT_MEM_CACHE_POOL_H_INCLUDED_ */ diff --git a/nxt/nxt_mem_cache_pool.c b/nxt/nxt_mp.c similarity index 50% rename from nxt/nxt_mem_cache_pool.c rename to nxt/nxt_mp.c index aadf96bf..18976d37 100644 --- a/nxt/nxt_mem_cache_pool.c +++ b/nxt/nxt_mp.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -39,7 +39,7 @@ typedef struct { nxt_queue_link_t link; /* - * Size of chunks or page shifted by pool->chunk_size_shift. + * Size of chunks or page shifted by mp->chunk_size_shift. * Zero means that page is free. */ uint8_t size; @@ -57,35 +57,35 @@ typedef struct { /* Chunk bitmap. There can be no more than 32 chunks in a page. */ uint8_t map[4]; -} nxt_mem_cache_page_t; +} nxt_mp_page_t; typedef enum { /* Block of cluster. The block is allocated apart of the cluster. */ - NXT_MEM_CACHE_CLUSTER_BLOCK = 0, + NXT_MP_CLUSTER_BLOCK = 0, /* * Block of large allocation. * The block is allocated apart of the allocation. */ - NXT_MEM_CACHE_DISCRETE_BLOCK, + NXT_MP_DISCRETE_BLOCK, /* * Block of large allocation. * The block is allocated just after of the allocation. */ - NXT_MEM_CACHE_EMBEDDED_BLOCK, -} nxt_mem_cache_block_type_t; + NXT_MP_EMBEDDED_BLOCK, +} nxt_mp_block_type_t; typedef struct { NXT_RBTREE_NODE (node); - nxt_mem_cache_block_type_t type:8; + nxt_mp_block_type_t type:8; /* Block size must be less than 4G. */ uint32_t size; u_char *start; - nxt_mem_cache_page_t pages[]; -} nxt_mem_cache_block_t; + nxt_mp_page_t pages[]; +} nxt_mp_block_t; typedef struct { @@ -100,11 +100,11 @@ typedef struct { /* Maximum number of free chunks in chunked page. */ uint8_t chunks; -} nxt_mem_cache_slot_t; +} nxt_mp_slot_t; -struct nxt_mem_cache_pool_s { - /* rbtree of nxt_mem_cache_block_t. */ +struct nxt_mp_s { + /* rbtree of nxt_mp_block_t. */ nxt_rbtree_t blocks; nxt_queue_t free_pages; @@ -119,19 +119,19 @@ struct nxt_mem_cache_pool_s { void *mem; void *trace; - nxt_mem_cache_slot_t slots[]; + nxt_mp_slot_t slots[]; }; -#define nxt_mem_cache_chunk_is_free(map, chunk) \ +#define nxt_mp_chunk_is_free(map, chunk) \ ((map[chunk / 8] & (0x80 >> (chunk & 7))) == 0) -#define nxt_mem_cache_chunk_set_free(map, chunk) \ +#define nxt_mp_chunk_set_free(map, chunk) \ map[chunk / 8] &= ~(0x80 >> (chunk & 7)) -#define nxt_mem_cache_free_junk(p, size) \ +#define nxt_mp_free_junk(p, size) \ nxt_memset((p), 0x5A, size) @@ -139,27 +139,24 @@ struct nxt_mem_cache_pool_s { ((((value) - 1) & (value)) == 0) -static nxt_uint_t nxt_mem_cache_shift(nxt_uint_t n); +static nxt_uint_t nxt_mp_shift(nxt_uint_t n); #if !(NXT_DEBUG_MEMORY) -static void *nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size); -static nxt_uint_t nxt_mem_cache_alloc_chunk(u_char *map, nxt_uint_t size); -static nxt_mem_cache_page_t * - nxt_mem_cache_alloc_page(nxt_mem_cache_pool_t *pool); -static nxt_mem_cache_block_t * - nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool); +static void *nxt_mp_alloc_small(nxt_mp_t *mp, size_t size); +static nxt_uint_t nxt_mp_alloc_chunk(u_char *map, nxt_uint_t size); +static nxt_mp_page_t *nxt_mp_alloc_page(nxt_mp_t *mp); +static nxt_mp_block_t *nxt_mp_alloc_cluster(nxt_mp_t *mp); #endif -static void *nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool, - size_t alignment, size_t size); -static intptr_t nxt_mem_cache_rbtree_compare(nxt_rbtree_node_t *node1, +static void *nxt_mp_alloc_large(nxt_mp_t *mp, size_t alignment, size_t size); +static intptr_t nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2); -static nxt_mem_cache_block_t *nxt_mem_cache_find_block(nxt_rbtree_t *tree, +static nxt_mp_block_t *nxt_mp_find_block(nxt_rbtree_t *tree, + u_char *p); +static const char *nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster, u_char *p); -static const char *nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, - nxt_mem_cache_block_t *cluster, u_char *p); -nxt_mem_cache_pool_t * -nxt_mem_cache_pool_create(const nxt_mem_proto_t *proto, void *mem, +nxt_mp_t * +nxt_mp_create(const nxt_mem_proto_t *proto, void *mem, void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, size_t min_chunk_size) { @@ -185,20 +182,19 @@ nxt_mem_cache_pool_create(const nxt_mem_proto_t *proto, void *mem, return NULL; } - return nxt_mem_cache_pool_fast_create(proto, mem, trace, - cluster_size, page_alignment, - page_size, min_chunk_size); + return nxt_mp_fast_create(proto, mem, trace, cluster_size, page_alignment, + page_size, min_chunk_size); } -nxt_mem_cache_pool_t * -nxt_mem_cache_pool_fast_create(const nxt_mem_proto_t *proto, void *mem, +nxt_mp_t * +nxt_mp_fast_create(const nxt_mem_proto_t *proto, void *mem, void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, size_t min_chunk_size) { - nxt_uint_t slots, chunk_size; - nxt_mem_cache_slot_t *slot; - nxt_mem_cache_pool_t *pool; + nxt_mp_t *mp; + nxt_uint_t slots, chunk_size; + nxt_mp_slot_t *slot; slots = 0; chunk_size = page_size; @@ -208,19 +204,18 @@ nxt_mem_cache_pool_fast_create(const nxt_mem_proto_t *proto, void *mem, chunk_size /= 2; } while (chunk_size > min_chunk_size); - pool = proto->zalloc(mem, sizeof(nxt_mem_cache_pool_t) - + slots * sizeof(nxt_mem_cache_slot_t)); + mp = proto->zalloc(mem, sizeof(nxt_mp_t) + slots * sizeof(nxt_mp_slot_t)); - if (nxt_fast_path(pool != NULL)) { - pool->proto = proto; - pool->mem = mem; - pool->trace = trace; + if (nxt_fast_path(mp != NULL)) { + mp->proto = proto; + mp->mem = mem; + mp->trace = trace; - pool->page_size = page_size; - pool->page_alignment = nxt_max(page_alignment, NXT_MAX_ALIGNMENT); - pool->cluster_size = cluster_size; + mp->page_size = page_size; + mp->page_alignment = nxt_max(page_alignment, NXT_MAX_ALIGNMENT); + mp->cluster_size = cluster_size; - slot = pool->slots; + slot = mp->slots; do { nxt_queue_init(&slot->pages); @@ -233,20 +228,20 @@ nxt_mem_cache_pool_fast_create(const nxt_mem_proto_t *proto, void *mem, chunk_size *= 2; } while (chunk_size < page_size); - pool->chunk_size_shift = nxt_mem_cache_shift(min_chunk_size); - pool->page_size_shift = nxt_mem_cache_shift(page_size); + mp->chunk_size_shift = nxt_mp_shift(min_chunk_size); + mp->page_size_shift = nxt_mp_shift(page_size); - nxt_rbtree_init(&pool->blocks, nxt_mem_cache_rbtree_compare); + nxt_rbtree_init(&mp->blocks, nxt_mp_rbtree_compare); - nxt_queue_init(&pool->free_pages); + nxt_queue_init(&mp->free_pages); } - return pool; + return mp; } static nxt_uint_t -nxt_mem_cache_shift(nxt_uint_t n) +nxt_mp_shift(nxt_uint_t n) { nxt_uint_t shift; @@ -263,65 +258,65 @@ nxt_mem_cache_shift(nxt_uint_t n) nxt_bool_t -nxt_mem_cache_pool_is_empty(nxt_mem_cache_pool_t *pool) +nxt_mp_is_empty(nxt_mp_t *mp) { - return (nxt_rbtree_is_empty(&pool->blocks) - && nxt_queue_is_empty(&pool->free_pages)); + return (nxt_rbtree_is_empty(&mp->blocks) + && nxt_queue_is_empty(&mp->free_pages)); } void -nxt_mem_cache_pool_destroy(nxt_mem_cache_pool_t *pool) +nxt_mp_destroy(nxt_mp_t *mp) { - void *p; - nxt_rbtree_node_t *node, *next; - nxt_mem_cache_block_t *block; + void *p; + nxt_mp_block_t *block; + nxt_rbtree_node_t *node, *next; - next = nxt_rbtree_root(&pool->blocks); + next = nxt_rbtree_root(&mp->blocks); - while (next != nxt_rbtree_sentinel(&pool->blocks)) { + while (next != nxt_rbtree_sentinel(&mp->blocks)) { - node = nxt_rbtree_destroy_next(&pool->blocks, &next); - block = (nxt_mem_cache_block_t *) node; + node = nxt_rbtree_destroy_next(&mp->blocks, &next); + block = (nxt_mp_block_t *) node; p = block->start; - if (block->type != NXT_MEM_CACHE_EMBEDDED_BLOCK) { - pool->proto->free(pool->mem, block); + if (block->type != NXT_MP_EMBEDDED_BLOCK) { + mp->proto->free(mp->mem, block); } - pool->proto->free(pool->mem, p); + mp->proto->free(mp->mem, p); } - pool->proto->free(pool->mem, pool); + mp->proto->free(mp->mem, mp); } void * -nxt_mem_cache_alloc(nxt_mem_cache_pool_t *pool, size_t size) +nxt_mp_alloc(nxt_mp_t *mp, size_t size) { - if (pool->proto->trace != NULL) { - pool->proto->trace(pool->trace, "mem cache alloc: %zd", size); + if (mp->proto->trace != NULL) { + mp->proto->trace(mp->trace, "mem cache alloc: %zd", size); } #if !(NXT_DEBUG_MEMORY) - if (size <= pool->page_size) { - return nxt_mem_cache_alloc_small(pool, size); + if (size <= mp->page_size) { + return nxt_mp_alloc_small(mp, size); } #endif - return nxt_mem_cache_alloc_large(pool, NXT_MAX_ALIGNMENT, size); + return nxt_mp_alloc_large(mp, NXT_MAX_ALIGNMENT, size); } void * -nxt_mem_cache_zalloc(nxt_mem_cache_pool_t *pool, size_t size) +nxt_mp_zalloc(nxt_mp_t *mp, size_t size) { void *p; - p = nxt_mem_cache_alloc(pool, size); + p = nxt_mp_alloc(mp, size); if (nxt_fast_path(p != NULL)) { nxt_memzero(p, size); @@ -332,11 +327,11 @@ nxt_mem_cache_zalloc(nxt_mem_cache_pool_t *pool, size_t size) void * -nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size) +nxt_mp_align(nxt_mp_t *mp, size_t alignment, size_t size) { - if (pool->proto->trace != NULL) { - pool->proto->trace(pool->trace, - "mem cache align: @%zd:%zd", alignment, size); + if (mp->proto->trace != NULL) { + mp->proto->trace(mp->trace, + "mem cache align: @%zd:%zd", alignment, size); } /* Alignment must be a power of 2. */ @@ -345,17 +340,17 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size) #if !(NXT_DEBUG_MEMORY) - if (size <= pool->page_size && alignment <= pool->page_alignment) { + if (size <= mp->page_size && alignment <= mp->page_alignment) { size = nxt_max(size, alignment); - if (size <= pool->page_size) { - return nxt_mem_cache_alloc_small(pool, size); + if (size <= mp->page_size) { + return nxt_mp_alloc_small(mp, size); } } #endif - return nxt_mem_cache_alloc_large(pool, alignment, size); + return nxt_mp_alloc_large(mp, alignment, size); } return NULL; @@ -363,11 +358,11 @@ nxt_mem_cache_align(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size) void * -nxt_mem_cache_zalign(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size) +nxt_mp_zalign(nxt_mp_t *mp, size_t alignment, size_t size) { void *p; - p = nxt_mem_cache_align(pool, alignment, size); + p = nxt_mp_align(mp, alignment, size); if (nxt_fast_path(p != NULL)) { nxt_memzero(p, size); @@ -380,55 +375,55 @@ nxt_mem_cache_zalign(nxt_mem_cache_pool_t *pool, size_t alignment, size_t size) #if !(NXT_DEBUG_MEMORY) nxt_inline u_char * -nxt_mem_cache_page_addr(nxt_mem_cache_pool_t *pool, nxt_mem_cache_page_t *page) +nxt_mp_page_addr(nxt_mp_t *mp, nxt_mp_page_t *page) { - nxt_mem_cache_block_t *block; + nxt_mp_block_t *block; - block = (nxt_mem_cache_block_t *) - ((u_char *) page - page->number * sizeof(nxt_mem_cache_page_t) - - offsetof(nxt_mem_cache_block_t, pages)); + block = (nxt_mp_block_t *) + ((u_char *) page - page->number * sizeof(nxt_mp_page_t) + - offsetof(nxt_mp_block_t, pages)); - return block->start + (page->number << pool->page_size_shift); + return block->start + (page->number << mp->page_size_shift); } static void * -nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size) +nxt_mp_alloc_small(nxt_mp_t *mp, size_t size) { - u_char *p; - nxt_queue_link_t *link; - nxt_mem_cache_page_t *page; - nxt_mem_cache_slot_t *slot; + u_char *p; + nxt_mp_page_t *page; + nxt_mp_slot_t *slot; + nxt_queue_link_t *link; p = NULL; - if (size <= pool->page_size / 2) { + if (size <= mp->page_size / 2) { /* Find a slot with appropriate chunk size. */ - for (slot = pool->slots; slot->size < size; slot++) { /* void */ } + for (slot = mp->slots; slot->size < size; slot++) { /* void */ } size = slot->size; if (nxt_fast_path(!nxt_queue_is_empty(&slot->pages))) { link = nxt_queue_first(&slot->pages); - page = nxt_queue_link_data(link, nxt_mem_cache_page_t, link); + page = nxt_queue_link_data(link, nxt_mp_page_t, link); - p = nxt_mem_cache_page_addr(pool, page); - p += nxt_mem_cache_alloc_chunk(page->map, size); + p = nxt_mp_page_addr(mp, page); + p += nxt_mp_alloc_chunk(page->map, size); page->chunks--; if (page->chunks == 0) { /* - * Remove full page from the pool chunk slot list + * Remove full page from the mp chunk slot list * of pages with free chunks. */ nxt_queue_remove(&page->link); } } else { - page = nxt_mem_cache_alloc_page(pool); + page = nxt_mp_alloc_page(mp); if (nxt_fast_path(page != NULL)) { @@ -442,29 +437,28 @@ nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size) /* slot->chunks are already one less. */ page->chunks = slot->chunks; - page->size = size >> pool->chunk_size_shift; + page->size = size >> mp->chunk_size_shift; - p = nxt_mem_cache_page_addr(pool, page); + p = nxt_mp_page_addr(mp, page); } } } else { - page = nxt_mem_cache_alloc_page(pool); + page = nxt_mp_alloc_page(mp); if (nxt_fast_path(page != NULL)) { - page->size = pool->page_size >> pool->chunk_size_shift; + page->size = mp->page_size >> mp->chunk_size_shift; - p = nxt_mem_cache_page_addr(pool, page); + p = nxt_mp_page_addr(mp, page); } #if (NXT_DEBUG) - size = pool->page_size; + size = mp->page_size; #endif } - if (pool->proto->trace != NULL) { - pool->proto->trace(pool->trace, "mem cache chunk:%uz alloc: %p", - size, p); + if (mp->proto->trace != NULL) { + mp->proto->trace(mp->trace, "mem cache chunk:%uz alloc: %p", size, p); } return p; @@ -472,7 +466,7 @@ nxt_mem_cache_alloc_small(nxt_mem_cache_pool_t *pool, size_t size) static nxt_uint_t -nxt_mem_cache_alloc_chunk(uint8_t *map, nxt_uint_t size) +nxt_mp_alloc_chunk(uint8_t *map, nxt_uint_t size) { uint8_t mask; nxt_uint_t n, offset; @@ -509,58 +503,59 @@ nxt_mem_cache_alloc_chunk(uint8_t *map, nxt_uint_t size) } -static nxt_mem_cache_page_t * -nxt_mem_cache_alloc_page(nxt_mem_cache_pool_t *pool) +static nxt_mp_page_t * +nxt_mp_alloc_page(nxt_mp_t *mp) { - nxt_queue_link_t *link; - nxt_mem_cache_page_t *page; - nxt_mem_cache_block_t *cluster; + nxt_mp_page_t *page; + nxt_mp_block_t *cluster; + nxt_queue_link_t *link; - if (nxt_queue_is_empty(&pool->free_pages)) { - cluster = nxt_mem_cache_alloc_cluster(pool); + if (nxt_queue_is_empty(&mp->free_pages)) { + cluster = nxt_mp_alloc_cluster(mp); if (nxt_slow_path(cluster == NULL)) { return NULL; } } - link = nxt_queue_first(&pool->free_pages); + link = nxt_queue_first(&mp->free_pages); nxt_queue_remove(link); - page = nxt_queue_link_data(link, nxt_mem_cache_page_t, link); + page = nxt_queue_link_data(link, nxt_mp_page_t, link); return page; } -static nxt_mem_cache_block_t * -nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool) +static nxt_mp_block_t * +nxt_mp_alloc_cluster(nxt_mp_t *mp) { - nxt_uint_t n; - nxt_mem_cache_block_t *cluster; + nxt_uint_t n; + nxt_mp_block_t *cluster; - n = pool->cluster_size >> pool->page_size_shift; + n = mp->cluster_size >> mp->page_size_shift; - cluster = pool->proto->zalloc(pool->mem, sizeof(nxt_mem_cache_block_t) - + n * sizeof(nxt_mem_cache_page_t)); + cluster = mp->proto->zalloc(mp->mem, + sizeof(nxt_mp_block_t) + + n * sizeof(nxt_mp_page_t)); if (nxt_slow_path(cluster == NULL)) { return NULL; } - /* NXT_MEM_CACHE_CLUSTER_BLOCK type is zero. */ + /* NXT_MP_CLUSTER_BLOCK type is zero. */ - cluster->size = pool->cluster_size; + cluster->size = mp->cluster_size; - cluster->start = pool->proto->align(pool->mem, pool->page_alignment, - pool->cluster_size); + cluster->start = mp->proto->align(mp->mem, mp->page_alignment, + mp->cluster_size); if (nxt_slow_path(cluster->start == NULL)) { - pool->proto->free(pool->mem, cluster); + mp->proto->free(mp->mem, cluster); return NULL; } n--; cluster->pages[n].number = n; - nxt_queue_insert_head(&pool->free_pages, &cluster->pages[n].link); + nxt_queue_insert_head(&mp->free_pages, &cluster->pages[n].link); while (n != 0) { n--; @@ -569,7 +564,7 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool) &cluster->pages[n].link); } - nxt_rbtree_insert(&pool->blocks, &cluster->node); + nxt_rbtree_insert(&mp->blocks, &cluster->node); return cluster; } @@ -578,13 +573,12 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool) static void * -nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool, size_t alignment, - size_t size) +nxt_mp_alloc_large(nxt_mp_t *mp, size_t alignment, size_t size) { - u_char *p; - size_t aligned_size; - uint8_t type; - nxt_mem_cache_block_t *block; + u_char *p; + size_t aligned_size; + uint8_t type; + nxt_mp_block_t *block; /* Allocation must be less than 4G. */ if (nxt_slow_path(size >= UINT32_MAX)) { @@ -592,84 +586,84 @@ nxt_mem_cache_alloc_large(nxt_mem_cache_pool_t *pool, size_t alignment, } if (nxt_is_power_of_two(size)) { - block = pool->proto->alloc(pool->mem, sizeof(nxt_mem_cache_block_t)); + block = mp->proto->alloc(mp->mem, sizeof(nxt_mp_block_t)); if (nxt_slow_path(block == NULL)) { return NULL; } - p = pool->proto->align(pool->mem, alignment, size); + p = mp->proto->align(mp->mem, alignment, size); if (nxt_slow_path(p == NULL)) { - pool->proto->free(pool->mem, block); + mp->proto->free(mp->mem, block); return NULL; } - type = NXT_MEM_CACHE_DISCRETE_BLOCK; + type = NXT_MP_DISCRETE_BLOCK; } else { aligned_size = nxt_align_size(size, sizeof(uintptr_t)); - p = pool->proto->align(pool->mem, alignment, - aligned_size + sizeof(nxt_mem_cache_block_t)); + p = mp->proto->align(mp->mem, alignment, + aligned_size + sizeof(nxt_mp_block_t)); if (nxt_slow_path(p == NULL)) { return NULL; } - block = (nxt_mem_cache_block_t *) (p + aligned_size); - type = NXT_MEM_CACHE_EMBEDDED_BLOCK; + block = (nxt_mp_block_t *) (p + aligned_size); + type = NXT_MP_EMBEDDED_BLOCK; } block->type = type; block->size = size; block->start = p; - nxt_rbtree_insert(&pool->blocks, &block->node); + nxt_rbtree_insert(&mp->blocks, &block->node); return p; } static intptr_t -nxt_mem_cache_rbtree_compare(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2) +nxt_mp_rbtree_compare(nxt_rbtree_node_t *node1, nxt_rbtree_node_t *node2) { - nxt_mem_cache_block_t *block1, *block2; + nxt_mp_block_t *block1, *block2; - block1 = (nxt_mem_cache_block_t *) node1; - block2 = (nxt_mem_cache_block_t *) node2; + block1 = (nxt_mp_block_t *) node1; + block2 = (nxt_mp_block_t *) node2; return (uintptr_t) block1->start - (uintptr_t) block2->start; } void -nxt_mem_cache_free(nxt_mem_cache_pool_t *pool, void *p) +nxt_mp_free(nxt_mp_t *mp, void *p) { - const char *err; - nxt_mem_cache_block_t *block; + const char *err; + nxt_mp_block_t *block; - if (pool->proto->trace != NULL) { - pool->proto->trace(pool->trace, "mem cache free %p", p); + if (mp->proto->trace != NULL) { + mp->proto->trace(mp->trace, "mem cache free %p", p); } - block = nxt_mem_cache_find_block(&pool->blocks, p); + block = nxt_mp_find_block(&mp->blocks, p); if (nxt_fast_path(block != NULL)) { - if (block->type == NXT_MEM_CACHE_CLUSTER_BLOCK) { - err = nxt_mem_cache_chunk_free(pool, block, p); + if (block->type == NXT_MP_CLUSTER_BLOCK) { + err = nxt_mp_chunk_free(mp, block, p); if (nxt_fast_path(err == NULL)) { return; } } else if (nxt_fast_path(p == block->start)) { - nxt_rbtree_delete(&pool->blocks, &block->node); + nxt_rbtree_delete(&mp->blocks, &block->node); - if (block->type == NXT_MEM_CACHE_DISCRETE_BLOCK) { - pool->proto->free(pool->mem, block); + if (block->type == NXT_MP_DISCRETE_BLOCK) { + mp->proto->free(mp->mem, block); } - pool->proto->free(pool->mem, p); + mp->proto->free(mp->mem, p); return; @@ -678,27 +672,27 @@ nxt_mem_cache_free(nxt_mem_cache_pool_t *pool, void *p) } } else { - err = "freed pointer is out of pool: %p"; + err = "freed pointer is out of mp: %p"; } - if (pool->proto->alert != NULL) { - pool->proto->alert(pool->trace, err, p); + if (mp->proto->alert != NULL) { + mp->proto->alert(mp->trace, err, p); } } -static nxt_mem_cache_block_t * -nxt_mem_cache_find_block(nxt_rbtree_t *tree, u_char *p) +static nxt_mp_block_t * +nxt_mp_find_block(nxt_rbtree_t *tree, u_char *p) { - nxt_rbtree_node_t *node, *sentinel; - nxt_mem_cache_block_t *block; + nxt_mp_block_t *block; + nxt_rbtree_node_t *node, *sentinel; node = nxt_rbtree_root(tree); sentinel = nxt_rbtree_sentinel(tree); while (node != sentinel) { - block = (nxt_mem_cache_block_t *) node; + block = (nxt_mp_block_t *) node; if (p < block->start) { node = node->left; @@ -716,17 +710,17 @@ nxt_mem_cache_find_block(nxt_rbtree_t *tree, u_char *p) static const char * -nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, - nxt_mem_cache_block_t *cluster, u_char *p) +nxt_mp_chunk_free(nxt_mp_t *mp, nxt_mp_block_t *cluster, + u_char *p) { - u_char *start; - uintptr_t offset; - nxt_uint_t n, size, chunk; - nxt_mem_cache_page_t *page; - nxt_mem_cache_slot_t *slot; + u_char *start; + uintptr_t offset; + nxt_uint_t n, size, chunk; + nxt_mp_page_t *page; + nxt_mp_slot_t *slot; - n = (p - cluster->start) >> pool->page_size_shift; - start = cluster->start + (n << pool->page_size_shift); + n = (p - cluster->start) >> mp->page_size_shift; + start = cluster->start + (n << mp->page_size_shift); page = &cluster->pages[n]; @@ -734,44 +728,44 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, return "freed pointer points to already free page: %p"; } - size = page->size << pool->chunk_size_shift; + size = page->size << mp->chunk_size_shift; - if (size != pool->page_size) { + if (size != mp->page_size) { - offset = (uintptr_t) (p - start) & (pool->page_size - 1); + offset = (uintptr_t) (p - start) & (mp->page_size - 1); chunk = offset / size; if (nxt_slow_path(offset != chunk * size)) { return "freed pointer points to wrong chunk: %p"; } - if (nxt_slow_path(nxt_mem_cache_chunk_is_free(page->map, chunk))) { + if (nxt_slow_path(nxt_mp_chunk_is_free(page->map, chunk))) { return "freed pointer points to already free chunk: %p"; } - nxt_mem_cache_chunk_set_free(page->map, chunk); + nxt_mp_chunk_set_free(page->map, chunk); /* Find a slot with appropriate chunk size. */ - for (slot = pool->slots; slot->size < size; slot++) { /* void */ } + for (slot = mp->slots; slot->size < size; slot++) { /* void */ } if (page->chunks != slot->chunks) { page->chunks++; if (page->chunks == 1) { /* - * Add the page to the head of pool chunk slot list + * Add the page to the head of mp chunk slot list * of pages with free chunks. */ nxt_queue_insert_head(&slot->pages, &page->link); } - nxt_mem_cache_free_junk(p, size); + nxt_mp_free_junk(p, size); return NULL; } else { /* - * All chunks are free, remove the page from pool chunk slot + * All chunks are free, remove the page from mp chunk slot * list of pages with free chunks. */ nxt_queue_remove(&page->link); @@ -781,17 +775,17 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, return "invalid pointer to chunk: %p"; } - /* Add the free page to the pool's free pages tree. */ + /* Add the free page to the mp's free pages tree. */ page->size = 0; - nxt_queue_insert_head(&pool->free_pages, &page->link); + nxt_queue_insert_head(&mp->free_pages, &page->link); - nxt_mem_cache_free_junk(p, size); + nxt_mp_free_junk(p, size); /* Test if all pages in the cluster are free. */ page = cluster->pages; - n = pool->cluster_size >> pool->page_size_shift; + n = mp->cluster_size >> mp->page_size_shift; do { if (page->size != 0) { @@ -805,7 +799,7 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, /* Free cluster. */ page = cluster->pages; - n = pool->cluster_size >> pool->page_size_shift; + n = mp->cluster_size >> mp->page_size_shift; do { nxt_queue_remove(&page->link); @@ -813,12 +807,12 @@ nxt_mem_cache_chunk_free(nxt_mem_cache_pool_t *pool, n--; } while (n != 0); - nxt_rbtree_delete(&pool->blocks, &cluster->node); + nxt_rbtree_delete(&mp->blocks, &cluster->node); p = cluster->start; - pool->proto->free(pool->mem, cluster); - pool->proto->free(pool->mem, p); + mp->proto->free(mp->mem, cluster); + mp->proto->free(mp->mem, p); return NULL; } diff --git a/nxt/nxt_mp.h b/nxt/nxt_mp.h new file mode 100644 index 00000000..77a9b210 --- /dev/null +++ b/nxt/nxt_mp.h @@ -0,0 +1,37 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#ifndef _NXT_MP_H_INCLUDED_ +#define _NXT_MP_H_INCLUDED_ + + +typedef struct nxt_mp_s nxt_mp_t; + + +NXT_EXPORT nxt_mp_t *nxt_mp_create(const nxt_mem_proto_t *proto, void *mem, + void *trace, size_t cluster_size, size_t page_alignment, size_t page_size, + size_t min_chunk_size) + NXT_MALLOC_LIKE; +NXT_EXPORT nxt_mp_t * nxt_mp_fast_create(const nxt_mem_proto_t *proto, + void *mem, void *trace, size_t cluster_size, size_t page_alignment, + size_t page_size, size_t min_chunk_size) + NXT_MALLOC_LIKE; +NXT_EXPORT nxt_bool_t nxt_mp_is_empty(nxt_mp_t *mp); +NXT_EXPORT void nxt_mp_destroy(nxt_mp_t *mp); + +NXT_EXPORT void *nxt_mp_alloc(nxt_mp_t *mp, size_t size) + NXT_MALLOC_LIKE; +NXT_EXPORT void *nxt_mp_zalloc(nxt_mp_t *mp, size_t size) + NXT_MALLOC_LIKE; +NXT_EXPORT void *nxt_mp_align(nxt_mp_t *mp, size_t alignment, size_t size) + NXT_MALLOC_LIKE; +NXT_EXPORT void *nxt_mp_zalign(nxt_mp_t *mp, + size_t alignment, size_t size) + NXT_MALLOC_LIKE; +NXT_EXPORT void nxt_mp_free(nxt_mp_t *mp, void *p); + + +#endif /* _NXT_MP_H_INCLUDED_ */ diff --git a/nxt/test/Makefile b/nxt/test/Makefile index 53e04970..9b3bda70 100644 --- a/nxt/test/Makefile +++ b/nxt/test/Makefile @@ -34,7 +34,7 @@ $(NXT_BUILDDIR)/rbtree_unit_test: \ $(NXT_BUILDDIR)/lvlhsh_unit_test: \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ $(NXT_BUILDDIR)/nxt_murmur_hash.o \ - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ + $(NXT_BUILDDIR)/nxt_mp.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_LIB)/test/lvlhsh_unit_test.c \ @@ -44,7 +44,7 @@ $(NXT_BUILDDIR)/lvlhsh_unit_test: \ $(NXT_BUILDDIR)/nxt_lvlhsh.o \ $(NXT_BUILDDIR)/nxt_rbtree.o \ $(NXT_BUILDDIR)/nxt_murmur_hash.o \ - $(NXT_BUILDDIR)/nxt_mem_cache_pool.o \ + $(NXT_BUILDDIR)/nxt_mp.o \ $(NXT_BUILDDIR)/nxt_malloc.o $(NXT_BUILDDIR)/random_unit_test: \ diff --git a/nxt/test/lvlhsh_unit_test.c b/nxt/test/lvlhsh_unit_test.c index ca750227..92848895 100644 --- a/nxt/test/lvlhsh_unit_test.c +++ b/nxt/test/lvlhsh_unit_test.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -32,14 +32,14 @@ lvlhsh_unit_test_key_test(nxt_lvlhsh_query_t *lhq, void *data) static void * lvlhsh_unit_test_pool_alloc(void *pool, size_t size, nxt_uint_t nalloc) { - return nxt_mem_cache_align(pool, size, size); + return nxt_mp_align(pool, size, size); } static void lvlhsh_unit_test_pool_free(void *pool, void *p, size_t size) { - nxt_mem_cache_free(pool, p); + nxt_mp_free(pool, p); } @@ -182,7 +182,7 @@ lvlhsh_alert(void *mem, const char *fmt, ...) } -static const nxt_mem_proto_t mem_cache_pool_proto = { +static const nxt_mem_proto_t lvl_mp_proto = { lvlhsh_malloc, lvlhsh_zalloc, lvlhsh_align, @@ -196,20 +196,19 @@ static const nxt_mem_proto_t mem_cache_pool_proto = { static nxt_int_t lvlhsh_unit_test(nxt_uint_t n) { - uint32_t key; - nxt_uint_t i; - nxt_lvlhsh_t lh; - nxt_lvlhsh_each_t lhe; - nxt_mem_cache_pool_t *pool; - - const size_t min_chunk_size = 32; - const size_t page_size = 1024; - const size_t page_alignment = 128; - const size_t cluster_size = 4096; - - pool = nxt_mem_cache_pool_create(&mem_cache_pool_proto, NULL, NULL, - cluster_size, page_alignment, - page_size, min_chunk_size); + nxt_mp_t *pool; + uint32_t key; + nxt_uint_t i; + nxt_lvlhsh_t lh; + nxt_lvlhsh_each_t lhe; + + const size_t min_chunk_size = 32; + const size_t page_size = 1024; + const size_t page_alignment = 128; + const size_t cluster_size = 4096; + + pool = nxt_mp_create(&lvl_mp_proto, NULL, NULL, cluster_size, + page_alignment, page_size, min_chunk_size); if (pool == NULL) { return NXT_ERROR; } @@ -260,12 +259,12 @@ lvlhsh_unit_test(nxt_uint_t n) } } - if (!nxt_mem_cache_pool_is_empty(pool)) { + if (!nxt_mp_is_empty(pool)) { printf("mem cache pool is not empty\n"); return NXT_ERROR; } - nxt_mem_cache_pool_destroy(pool); + nxt_mp_destroy(pool); printf("lvlhsh unit test passed\n");