diff --git a/src/admin.cc b/src/admin.cc index 487c7400b99d75cc112793870f690dbaed71517d..9f21ece81058d82e35ff3d394ff4557554c63c93 100644 --- a/src/admin.cc +++ b/src/admin.cc @@ -88,7 +88,7 @@ admin_handler(va_list ap) * a remote client: it's used in Lua * stored procedures. */ - session_create(coio.fd, *(uint64_t *) addr); + (void) session_create(coio.fd, *(uint64_t *) addr); for (;;) { if (admin_dispatch(&coio, iobuf, L) < 0) diff --git a/src/coro.cc b/src/coro.cc index 9adbcca5d0b925e9f558fca279657bf63ea1dfb2..3e1bdc6a3f5b7990bc9a8210bd2de90add9ca789 100644 --- a/src/coro.cc +++ b/src/coro.cc @@ -35,6 +35,7 @@ #include <sys/mman.h> #include "third_party/valgrind/memcheck.h" +#include "memory.h" void tarantool_coro_create(struct tarantool_coro *coro, @@ -45,17 +46,18 @@ tarantool_coro_create(struct tarantool_coro *coro, memset(coro, 0, sizeof(*coro)); /* TODO: guard pages */ - coro->stack_size = page * 16; - coro->stack = mmap(0, coro->stack_size, PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + coro->stack_size = page * 16 - slab_sizeof(); + coro->stack = (char *) slab_get(slabc_runtime, coro->stack_size) + + slab_sizeof(); - if (coro->stack == MAP_FAILED) { + if (coro->stack == NULL) { tnt_raise(LoggedError, ER_MEMORY_ISSUE, sizeof(coro->stack_size), "mmap", "coro stack"); } - (void) VALGRIND_STACK_REGISTER(coro->stack, (char *) coro->stack + coro->stack_size); + (void) VALGRIND_STACK_REGISTER(coro->stack, (char *) + coro->stack + coro->stack_size); coro_create(&coro->ctx, f, data, coro->stack, coro->stack_size); } @@ -63,6 +65,8 @@ tarantool_coro_create(struct tarantool_coro *coro, void tarantool_coro_destroy(struct tarantool_coro *coro) { - if (coro->stack != NULL && coro->stack != MAP_FAILED) - munmap(coro->stack, coro->stack_size); + if (coro->stack != NULL) { + slab_put(slabc_runtime, (struct slab *) + ((char *) coro->stack - slab_sizeof())); + } } diff --git a/src/fiber.cc b/src/fiber.cc index 305385d524989fd3aa12c9214ab3d9e4540ed981..aaf78fc46b34c5878e24953a2cbdb3a747503bfd 100644 --- a/src/fiber.cc +++ b/src/fiber.cc @@ -47,6 +47,7 @@ static __thread uint32_t last_used_fid; static __thread struct mh_i32ptr_t *fiber_registry; static __thread struct rlist fibers, zombie_fibers, ready_fibers; static __thread ev_async ready_async; +static struct mempool fiber_pool; static void update_last_stack_frame(struct fiber *fiber) @@ -426,7 +427,8 @@ fiber_new(const char *name, void (*f) (va_list)) fiber = rlist_first_entry(&zombie_fibers, struct fiber, link); rlist_move_entry(&fibers, fiber, link); } else { - fiber = (struct fiber *) calloc(1, sizeof(*fiber)); + fiber = (struct fiber *) mempool_alloc(&fiber_pool); + memset(fiber, 0, sizeof(*fiber)); tarantool_coro_create(&fiber->coro, fiber_loop, NULL); @@ -484,6 +486,7 @@ fiber_destroy_all() void fiber_init(void) { + mempool_create(&fiber_pool, slabc_runtime, sizeof(struct fiber)); rlist_create(&fibers); rlist_create(&ready_fibers); rlist_create(&zombie_fibers); diff --git a/src/iobuf.cc b/src/iobuf.cc index fc8b0779b849bbfa2f3946b457a50474dffd3a02..6e6731c9614383022192dcec98175f0bda790526 100644 --- a/src/iobuf.cc +++ b/src/iobuf.cc @@ -30,6 +30,8 @@ #include "coio_buf.h" #include "memory.h" +struct mempool iobuf_pool; + /* {{{ struct ibuf */ /** Initialize an input buffer. */ @@ -274,7 +276,7 @@ iobuf_new(const char *name) { struct iobuf *iobuf; if (SLIST_EMPTY(&iobuf_cache)) { - iobuf = (struct iobuf *) malloc(sizeof(struct iobuf)); + iobuf = (struct iobuf *) mempool_alloc(&iobuf_pool); region_create(&iobuf->pool, slabc_runtime); /* Note: do not allocate memory upfront. */ ibuf_create(&iobuf->in, &iobuf->pool); @@ -342,4 +344,11 @@ iobuf_gc(struct iobuf *iobuf) int cfg_readahead; +void +iobuf_init(int readahead) +{ + mempool_create(&iobuf_pool, slabc_runtime, sizeof(struct iobuf)); + cfg_readahead = readahead; +} + /* struct iobuf }}} */ diff --git a/src/iobuf.h b/src/iobuf.h index 3a7fead9f0fa3ee2e1f3dbe5033351c5acff8862..ff65bd70ff41de4ad2e161da83ba306e9b4186ee 100644 --- a/src/iobuf.h +++ b/src/iobuf.h @@ -240,11 +240,8 @@ iobuf_is_idle(struct iobuf *iobuf) */ extern int cfg_readahead; -static inline void -iobuf_init_readahead(int readahead) -{ - cfg_readahead = readahead; -} +void +iobuf_init(int readahead); /* }}} */ diff --git a/src/iproto.cc b/src/iproto.cc index 0316f24eaaef8b24ad9a23451ac48a3e01dd3927..0563b9e7f5521508f0e729257b3210ef34ebdaad 100644 --- a/src/iproto.cc +++ b/src/iproto.cc @@ -41,6 +41,7 @@ #include "evio.h" #include "session.h" #include "scoped_guard.h" +#include "memory.h" static struct iproto_header dummy_header = { 0, 0, 0 }; const uint32_t msg_ping = 0xff00; @@ -283,6 +284,8 @@ struct iproto_session SLIST_HEAD(, iproto_session) iproto_session_cache = SLIST_HEAD_INITIALIZER(iproto_session_cache); +static struct mempool iproto_session_pool; + /** * A session is idle when the client is gone * and there are no outstanding requests in the request queue. @@ -334,7 +337,8 @@ iproto_session_create(const char *name, int fd, struct sockaddr_in *addr, { struct iproto_session *session; if (SLIST_EMPTY(&iproto_session_cache)) { - session = (struct iproto_session *) malloc(sizeof(*session)); + session = (struct iproto_session *) + mempool_alloc(&iproto_session_pool); session->input.data = session->output.data = session; } else { session = SLIST_FIRST(&iproto_session_cache); @@ -791,5 +795,7 @@ iproto_init(const char *bind_ipaddr, int primary_port, } iproto_queue_init(&request_queue, IPROTO_REQUEST_QUEUE_SIZE, iproto_queue_handler); + mempool_create(&iproto_session_pool, slabc_runtime, + sizeof(struct iproto_session)); } diff --git a/src/tarantool.cc b/src/tarantool.cc index f52f6c74e4f427a5d5d6badab99662443a437c33..49a314802666fd16d727a4dbb5d422747f3b2853 100644 --- a/src/tarantool.cc +++ b/src/tarantool.cc @@ -777,7 +777,7 @@ main(int argc, char **argv) ev_default_loop(EVFLAG_AUTO); fiber_init(); replication_prefork(); - iobuf_init_readahead(cfg.readahead); + iobuf_init(cfg.readahead); coeio_init(); signal_init();