summaryrefslogtreecommitdiff
path: root/cont.c
AgeCommit message (Collapse)Author
2019-08-27rb_proc_new / rb_fiber_new now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_proc_new / rb_fiber_new, and applies RB_BLOCK_CALL_FUNC_ARGLIST wherever necessary.
2019-08-27rb_ensure now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
2019-08-19cont.c: remove unused STACK_GROW_DIR_DETECTIONYusuke Endoh
to suppress a waring for "unused variable"
2019-08-17Use more different arguments in Fiber.yield documentation to make it clear ↵Iain Barnett
(#2170) https://github.com/ruby/ruby/pull/2170#issuecomment-489880700 Documentation is for those who don't know, remember, or understand (to any degree) the language, it should attempt to be clear above all other things. The example given is needlessly unclear because if you use a block it's common for arguments to be reused on every entry to the block. In Fiber's case this is not so. First time round 10 goes in, 12 comes out. Second time round 14 goes in, 14 comes out… was that because 14 is 12 + 2 or because it's "the return value of the call to Fiber.yield". It's the latter because it says so but why does the example need to make anyone think the former? Using different numbers makes it immediately clear what's happening whether the description is there or not.
2019-08-12Rename rb_gc_mark_no_pin -> rb_gc_mark_movableAaron Patterson
Renaming this function. "No pin" leaks some implementation details. We just want users to know that if they mark this object, the reference may move and they'll need to update the reference accordingly.
2019-08-13Fix a typo [ci skip]Kazuhiro NISHIYAMA
2019-07-29Fix unused variableKazuhiro NISHIYAMA
2019-07-25Use PRIuSIZE instead of "%zu"Nobuyoshi Nakada
2019-07-19Add documentation to `fiber_pool_allocate_memory`.Samuel Williams
2019-07-19Fix 32-bit build and typo.Samuel Williams
"Therefore, `fiber_pool_stack_free(&vacancy->stack)` can do the wrong thing..." should be "... `fiber_pool_stack_free(stack)` ...".
2019-07-19Ensure that madvise does not clobber vacancy data.Samuel Williams
After calling `fiber_pool_vacancy_reset`, `vacancy->stack` and `stack` are no longer in sync. Therefore, `fiber_pool_stack_free(&vacancy->stack)` can do the wrong thing and clobber the vacancy data. Additionally, when testing using VM_CHECK_MODE > 0, use MADV_DONTNEED if possible, to catch issues w.r.t. clobbered vacancy data earlier.
2019-07-19Better usage of `rb_ec_clear_vm_stack` to maintain invariants.Samuel Williams
2019-07-19Improve ec assertions.Samuel Williams
2019-07-19initialize only Fiber's cfp.Koichi Sasada
fiber->cont.saved_ec.cfp should be initialized by NULL because no vm_stack is allocated. However, cont_init() captures current Fiber's cfp for continuation, so it should only initialize fibers.
2019-07-19Revert "Ensure cfp is initialized to NULL."Samuel Williams
This reverts commit d7fdf45a4ae1bcb6fac30a24b025d4f20149ba0a.
2019-07-19Ensure cfp is initialized to NULL.Samuel Williams
`cont_init` didn't initialize `cont->saved_ec.cfp`. Calling `cont_mark` would result in an invalid `cfp` in `rb_execution_context_mark`. Because fibers lazy-initialize the stack, fibers that are created but not resumed could cause this problem to occur.
2019-07-19Remove `rb_vm_push_frame` as it is no longer used.Samuel Williams
2019-07-19Adjust styles and indentsNobuyoshi Nakada
2019-07-18check saved_ec.cfpKoichi Sasada
2019-07-19Ensure we don't have dangling cfp.Samuel Williams
2019-07-18* remove trailing spaces.git
2019-07-18Improve `fiber_pool_expand` allocation strategy.Samuel Williams
If `mmap` fails to allocate memory, try half the size, and so on. Limit FIBER_POOL_ALLOCATION_MAXIMUM_SIZE to 1024 stacks. In typical configurations this limits the memory mapped region to ~128MB per allocation.
2019-07-18Add experimental `RUBY_SHARED_FIBER_POOL_FREE_STACKS` to control madvise.Samuel Williams
2019-07-18Make fiber_pool more conservative on platforms with limited address space.Samuel Williams
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.
2019-07-18Add `struct fiber_pool {int free_stacks;}` to control usage of madvise.Samuel Williams
`madvise(free)` and similar operations are good because they avoid swap usage by clearing the dirty bit on memory pages which are mapped but no longer needed. However, there is some performance penalty if there is no memory pressure. Therefore, we do it by default, but it can be avoided.
2019-07-18Add FIBER_POOL_ALLOCATION_FREE to control allocation/free strategy.Samuel Williams
2019-07-18Limit expansion of fiber pool on 32-bit platforms.Samuel Williams
On 32-bit platforms, expanding the fiber pool by a large amount may fail, even if a smaller amount may succeed. We limit the maximum size of a single allocation to maximise the number of fibers that can be allocated. Additionally, we implement the book-keeping required to free allocations when their usage falls to zero.
2019-07-18Enable `madvise` to release stack space back to OS.Samuel Williams
2019-07-18Improve build process and coroutine implementation selection.Samuel Williams
2019-07-18Stack copying implementation of coroutines.Samuel Williams
2019-07-18Implement fiber pool for reduced fiber allocation overhead.Samuel Williams
Replace previous stack cache with fiber pool cache. The fiber pool allocates many stacks in a single memory region. Stack allocation becomes O(log N) and fiber creation is amortized O(1). Around 10x performance improvement was measured in micro-benchmarks.
2019-07-18Make FIBER_USE_NATIVE the default and reformat code.Samuel Williams
2019-07-08* expand tabs.git
2019-07-08Fix indentNobuyoshi Nakada
2019-07-08Renamed fib to fiberNobuyoshi Nakada
2019-06-26Use native coroutine implementation on OpenBSD-amd64Jeremy Evans
When using native fibers, do not load ucontext, as it isn't needed.
2019-06-26Add `ucontext` coroutine implementation for generic fallback.Samuel Williams
2019-06-24* remove trailing spaces.git
2019-06-24Print warning if not using native coroutine.Samuel Williams
2019-06-20Transition root fiber into state FIBER_TERMINATED.Samuel Williams
During fork, it's possible that threads with root fibers are terminated, but fiber state is not updated. `fiber_verify` will subsequently fail. We forcefully enter the FIBER_TERMINATED state when terminating the root fiber.
2019-06-20Ensure that vm_stack is cleared in `thread_cleanup_func_before_exec`.Samuel Williams
If `vm_stack` is left dangling in a forked process, the gc attempts to scan it, but it is invalid and will cause a segfault. Therefore, we clear it before forking. In order to simplify this, `rb_ec_clear_vm_stack` was introduced.
2019-06-20Revert failed attempt at fixing invalid usage of vm_stack.Samuel Williams
2019-06-20Ensure `vm_stack` is cleared after fork.Samuel Williams
2019-06-20Set `cfp` to null (along with vm_stack) in `rb_fiber_close`.Samuel Williams
2019-06-19Adjust indentNobuyoshi Nakada
2019-06-19Remove IA64 support.Samuel Williams
2019-06-19Use shared implementation of `rb_ec_initialize_vm_stack`.Samuel Williams
2019-06-19Track how stack was allocated for `cont_free`.Samuel Williams
2019-06-19Better handling of root fiber.Samuel Williams
2019-06-12* expand tabs.git