mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make fiber_pool more conservative on platforms with limited address space.
We use COROUTINE_LIMITED_ADDRESS_SPACE to select platforms where address space is 32-bits or less. Fiber pool implementation enables more book keeping, and reduces upper limits, in order to minimise address space utilisation.
This commit is contained in:
parent
385ea910fc
commit
001f187ed6
6 changed files with 23 additions and 12 deletions
24
cont.c
24
cont.c
|
@ -37,7 +37,16 @@ static VALUE rb_cFiberPool;
|
|||
#endif
|
||||
|
||||
#define CAPTURE_JUST_VALID_VM_STACK 1
|
||||
//#define FIBER_POOL_ALLOCATION_FREE
|
||||
|
||||
// Defined in `coroutine/$arch/Context.h`:
|
||||
#ifdef COROUTINE_LIMITED_ADDRESS_SPACE
|
||||
#define FIBER_POOL_ALLOCATION_FREE
|
||||
#define FIBER_POOL_INITIAL_SIZE 8
|
||||
#define FIBER_POOL_ALLOCATION_MAXIMUM_SIZE 32
|
||||
#else
|
||||
#define FIBER_POOL_INITIAL_SIZE 32
|
||||
#define FIBER_POOL_ALLOCATION_MAXIMUM_SIZE 4096
|
||||
#endif
|
||||
|
||||
enum context_type {
|
||||
CONTINUATION_CONTEXT = 0,
|
||||
|
@ -461,15 +470,6 @@ fiber_pool_expand(struct fiber_pool * fiber_pool, size_t count)
|
|||
return allocation;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
fiber_pool_default_allocation_count_limit() {
|
||||
if (sizeof(void*) <= 4) {
|
||||
return 32;
|
||||
} else {
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the specified fiber pool with the given number of stacks.
|
||||
// @param vm_stack_size The size of the vm stack to allocate.
|
||||
static void
|
||||
|
@ -542,7 +542,7 @@ fiber_pool_stack_acquire(struct fiber_pool * fiber_pool) {
|
|||
if (DEBUG) fprintf(stderr, "fiber_pool_stack_acquire: %p used=%zu\n", fiber_pool->vacancies, fiber_pool->used);
|
||||
|
||||
if (!vacancy) {
|
||||
const size_t maximum = fiber_pool_default_allocation_count_limit();
|
||||
const size_t maximum = FIBER_POOL_ALLOCATION_MAXIMUM_SIZE;
|
||||
const size_t minimum = fiber_pool->initial_count;
|
||||
|
||||
size_t count = fiber_pool->count;
|
||||
|
@ -2335,7 +2335,7 @@ Init_Cont(void)
|
|||
#endif
|
||||
SET_MACHINE_STACK_END(&th->ec->machine.stack_end);
|
||||
|
||||
fiber_pool_initialize(&shared_fiber_pool, stack_size, 8, vm_stack_size);
|
||||
fiber_pool_initialize(&shared_fiber_pool, stack_size, FIBER_POOL_INITIAL_SIZE, vm_stack_size);
|
||||
|
||||
rb_cFiber = rb_define_class("Fiber", rb_cObject);
|
||||
rb_define_alloc_func(rb_cFiber, fiber_alloc);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#define COROUTINE __attribute__((noreturn)) void
|
||||
#define COROUTINE_LIMITED_ADDRESS_SPACE
|
||||
|
||||
enum {COROUTINE_REGISTERS = 8};
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
|
||||
#define COROUTINE __attribute__((noreturn)) void
|
||||
|
||||
#if INTPTR_MAX <= INT32_MAX
|
||||
#define COROUTINE_LIMITED_ADDRESS_SPACE
|
||||
#endif
|
||||
|
||||
// This stack copying implementation which uses a private stack for each coroutine, including the main one.
|
||||
#define COROUTINE_PRIVATE_STACK
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
#define COROUTINE __attribute__((noreturn)) void
|
||||
|
||||
#if INTPTR_MAX <= INT32_MAX
|
||||
#define COROUTINE_LIMITED_ADDRESS_SPACE
|
||||
#endif
|
||||
|
||||
struct coroutine_context
|
||||
{
|
||||
ucontext_t state;
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#define COROUTINE __declspec(noreturn) void __fastcall
|
||||
#define COROUTINE_LIMITED_ADDRESS_SPACE
|
||||
|
||||
/* This doesn't include thread information block */
|
||||
enum {COROUTINE_REGISTERS = 4};
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#define COROUTINE __attribute__((noreturn, fastcall)) void
|
||||
#define COROUTINE_LIMITED_ADDRESS_SPACE
|
||||
|
||||
enum {COROUTINE_REGISTERS = 4};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue