summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_event_engine.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2019-11-14 16:39:48 +0300
committerIgor Sysoev <igor@sysoev.ru>2019-11-14 16:39:48 +0300
commit07c007af57501dc656b94476cbca41234dc077d6 (patch)
treeb86403c9dd959e22fb383e4321d050afae7c996c /src/nxt_event_engine.c
parentd4e3951c4de0d17db943ea4a6ee1c9f570979358 (diff)
downloadunit-07c007af57501dc656b94476cbca41234dc077d6.tar.gz
unit-07c007af57501dc656b94476cbca41234dc077d6.tar.bz2
Event engine memory cache refactored.
Diffstat (limited to 'src/nxt_event_engine.c')
-rw-r--r--src/nxt_event_engine.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/nxt_event_engine.c b/src/nxt_event_engine.c
index 31a35f6d..c2c66c82 100644
--- a/src/nxt_event_engine.c
+++ b/src/nxt_event_engine.c
@@ -556,19 +556,19 @@ nxt_event_engine_start(nxt_event_engine_t *engine)
void *
-nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint8_t *slot,
+nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint8_t *hint,
size_t size)
{
- uint8_t n;
+ uint32_t n;
nxt_uint_t items;
nxt_array_t *mem_cache;
nxt_mem_cache_t *cache;
nxt_mem_cache_block_t *block;
mem_cache = engine->mem_cache;
- n = *slot;
+ n = *hint;
- if (n == (uint8_t) -1) {
+ if (n == NXT_EVENT_ENGINE_NO_MEM_HINT) {
if (mem_cache == NULL) {
/* IPv4 nxt_sockaddr_t and HTTP/1 and HTTP/2 buffers. */
@@ -607,7 +607,9 @@ nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint8_t *slot,
found:
- *slot = n;
+ if (n < NXT_EVENT_ENGINE_NO_MEM_HINT) {
+ *hint = (uint8_t) n;
+ }
}
cache = mem_cache->elts;
@@ -626,15 +628,39 @@ nxt_event_engine_mem_alloc(nxt_event_engine_t *engine, uint8_t *slot,
void
-nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint8_t *slot, void *p)
+nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint8_t hint, void *p,
+ size_t size)
{
+ uint32_t n;
+ nxt_array_t *mem_cache;
nxt_mem_cache_t *cache;
nxt_mem_cache_block_t *block;
block = p;
+ mem_cache = engine->mem_cache;
+ cache = mem_cache->elts;
- cache = engine->mem_cache->elts;
- cache = cache + *slot;
+ n = hint;
+
+ if (nxt_slow_path(n == NXT_EVENT_ENGINE_NO_MEM_HINT)) {
+
+ if (size != 0) {
+ for (n = 0; n < mem_cache->nelts; n++) {
+ if (cache[n].size == size) {
+ goto found;
+ }
+ }
+
+ nxt_alert(&engine->task,
+ "event engine mem free(%p, %z) not found", p, size);
+ }
+
+ goto done;
+ }
+
+found:
+
+ cache = cache + n;
if (cache->count < 16) {
cache->count++;
@@ -644,6 +670,8 @@ nxt_event_engine_mem_free(nxt_event_engine_t *engine, uint8_t *slot, void *p)
return;
}
+done:
+
nxt_mp_free(engine->mem_pool, p);
}