diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index dd93c9a6c286e398710e969c2d5c02d7d90cc5ae..5bc522f85787c3986c0674c42efb7bd061383ecd 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -29,7 +29,7 @@ local default_sophia_cfg = { local default_cfg = { listen = nil, slab_alloc_arena = 1.0, - slab_alloc_minimal = 64, + slab_alloc_minimal = 16, slab_alloc_maximal = 1024 * 1024, slab_alloc_factor = 1.1, work_dir = nil, diff --git a/src/ipc.cc b/src/ipc.cc index b2bb737a7740fb2d38d817ef055f75e6da4a2530..637f64435f32f7e70a3f5d3e27e2581e5d5ef5b6 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -177,11 +177,11 @@ ipc_channel_shutdown(struct ipc_channel *ch) ch->readonly = true; struct fiber *f; - while(!rlist_empty(&ch->readers)) { + while (!rlist_empty(&ch->readers)) { f = rlist_first_entry(&ch->readers, struct fiber, state); ipc_channel_close_waiter(ch, f); } - while(!rlist_empty(&ch->writers)) { + while (!rlist_empty(&ch->writers)) { f = rlist_first_entry(&ch->writers, struct fiber, state); ipc_channel_close_waiter(ch, f); } diff --git a/src/lib/small/slab_arena.c b/src/lib/small/slab_arena.c index f9e28236cae162258c872e8085a625dd153464b5..a233e538fc0bde3f6a7605c710b1f483c6c15874 100644 --- a/src/lib/small/slab_arena.c +++ b/src/lib/small/slab_arena.c @@ -61,17 +61,28 @@ mmap_checked(size_t size, size_t align, int flags) /* The size must be a multiple of alignment */ assert((size & (align - 1)) == 0); /* - * mmap twice the requested amount to be able to align - * the mapped address. - * @todo all mappings except the first are likely to - * be aligned already. Find out if trying to map - * optimistically exactly the requested amount and fall - * back to double-size mapping is a viable strategy. + * All mappings except the first are likely to + * be aligned already. Be optimistic by trying + * to map exactly the requested amount. */ - void *map = mmap(NULL, size + align, PROT_READ | PROT_WRITE, + void *map = mmap(NULL, size, PROT_READ | PROT_WRITE, flags | MAP_ANONYMOUS, -1, 0); if (map == MAP_FAILED) return NULL; + if (((intptr_t) map & (align - 1)) == 0) + return map; + munmap_checked(map, size); + + /* + * mmap twice the requested amount to be able to align + * the mapped address. This can lead to virtual memory + * fragmentation depending on the kernels allocation + * strategy. + */ + map = mmap(NULL, size + align, PROT_READ | PROT_WRITE, + flags | MAP_ANONYMOUS, -1, 0); + if (map == MAP_FAILED) + return NULL; /* Align the mapped address around slab size. */ size_t offset = (intptr_t) map & (align - 1); diff --git a/src/lib/small/small.c b/src/lib/small/small.c index b065d524700b1b6c5ce1ffc713a864a9b0083030..240f6239d691603a6f58e92a562e556a1f993ceb 100644 --- a/src/lib/small/small.c +++ b/src/lib/small/small.c @@ -141,6 +141,7 @@ small_alloc_create(struct small_alloc *alloc, struct slab_cache *cache, factor_tree_new(&alloc->factor_pools); (void) factor_pool_create(alloc, NULL, alloc->objsize_max); + lifo_init(&alloc->delayed); alloc->is_delayed_free_mode = false; } diff --git a/test/app/float_value.result b/test/app/float_value.result index f592757013664b3edab859e613102ffcabc88a88..4fd16c37bd6d54aa142a3bcc6b0765919d933d86 100644 --- a/test/app/float_value.result +++ b/test/app/float_value.result @@ -10,7 +10,7 @@ box.cfg 9 logger_nonblock:true 10 snap_dir:. 11 coredump:false -12 slab_alloc_minimal:64 +12 slab_alloc_minimal:16 13 sophia_dir:. 14 wal_mode:write 15 wal_dir:. diff --git a/test/app/init_script.result b/test/app/init_script.result index 03ef3f3517410971252831ec43c0bbcb6899bec2..dc7f846591c7a41d79e030e02046b727620f5385 100644 --- a/test/app/init_script.result +++ b/test/app/init_script.result @@ -14,7 +14,7 @@ box.cfg 9 logger_nonblock:true 10 snap_dir:. 11 coredump:false -12 slab_alloc_minimal:64 +12 slab_alloc_minimal:16 13 sophia_dir:. 14 wal_mode:write 15 rows_per_wal:500000 diff --git a/test/box/admin.result b/test/box/admin.result index 30217aee9a5eb3ee37f3f58fc503faebccd5c6c8..7c3ef8b360bcc2325670073e00ddfb1d4922b1f2 100644 --- a/test/box/admin.result +++ b/test/box/admin.result @@ -34,7 +34,7 @@ box.cfg logger_nonblock: true snap_dir: . coredump: false - slab_alloc_minimal: 64 + slab_alloc_minimal: 16 sophia_dir: . wal_mode: write wal_dir: . diff --git a/test/box/cfg.result b/test/box/cfg.result index bab6b13c6faaf3f2946f6bd057ae1b0d58f6e06a..a6849cc41ce108a9045a448baf5a5aa70acfd192 100644 --- a/test/box/cfg.result +++ b/test/box/cfg.result @@ -20,7 +20,7 @@ t - 'logger_nonblock: true' - 'snap_dir: .' - 'coredump: false' - - 'slab_alloc_minimal: 64' + - 'slab_alloc_minimal: 16' - 'sophia_dir: .' - 'wal_mode: write' - 'wal_dir: .' @@ -54,7 +54,7 @@ t - 'logger_nonblock: true' - 'snap_dir: .' - 'coredump: false' - - 'slab_alloc_minimal: 64' + - 'slab_alloc_minimal: 16' - 'sophia_dir: .' - 'wal_mode: write' - 'wal_dir: .' diff --git a/test/wal_off/oom.result b/test/wal_off/oom.result index 4619a92bebec234a0a9fde5c86725e68e0698ce8..f547528c4d156b01e85f7aa23f41a1eb4e1e9fea 100644 --- a/test/wal_off/oom.result +++ b/test/wal_off/oom.result @@ -15,11 +15,11 @@ while true do i = i + 1 end; --- -- error: Failed to allocate 24643 bytes in slab allocator for tuple +- error: Failed to allocate 25031 bytes in slab allocator for tuple ... space:len(); --- -- 6155 +- 6252 ... i = 1; --- @@ -29,11 +29,11 @@ while true do i = i + 1 end; --- -- error: Failed to allocate 5187 bytes in slab allocator for tuple +- error: Failed to allocate 4167 bytes in slab allocator for tuple ... space:len(); --- -- 7446 +- 7288 ... i = 1; --- @@ -43,12 +43,12 @@ while true do i = i + 1 end; --- -- error: Failed to allocate 2751 bytes in slab allocator for tuple +- error: Failed to allocate 2123 bytes in slab allocator for tuple ... --# setopt delimiter '' space:len() --- -- 8128 +- 7813 ... space.index['primary']:get{0} ---