[#83096] File.setuid? on IO (Re: [ruby-cvs:67289] normal:r60108 (trunk): file.c: release GVL in File.{setuid?, setgid?, sticky?}) — Nobuyoshi Nakada <nobu@...>
On 2017/10/04 8:47, normal@ruby-lang.org wrote:
5 messages
2017/10/04
[#83100] Re: File.setuid? on IO (Re: [ruby-cvs:67289] normal:r60108 (trunk): file.c: release GVL in File.{setuid?, setgid?, sticky?})
— Eric Wong <normalperson@...>
2017/10/04
Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
[#83105] Re: File.setuid? on IO (Re: [ruby-cvs:67289] normal:r60108 (trunk): file.c: release GVL in File.{setuid?, setgid?, sticky?})
— Nobuyoshi Nakada <nobu@...>
2017/10/04
On 2017/10/04 15:55, Eric Wong wrote:
[#83107] Alias Enumerable#include? to Enumerable#includes? — Alberto Almagro <albertoalmagro@...>
Hello,
9 messages
2017/10/04
[#83113] Re: Alias Enumerable#include? to Enumerable#includes?
— "Urabe, Shyouhei" <shyouhei@...>
2017/10/05
This has been requested countless times, then rejected each and every time.
[#83129] Re: Alias Enumerable#include? to Enumerable#includes?
— Alberto Almagro <albertoalmagro@...>
2017/10/05
Sorry I didn't found it on the core mail list's archive.
[#83138] Re: Alias Enumerable#include? to Enumerable#includes?
— "Urabe, Shyouhei" <shyouhei@...>
2017/10/06
Ruby has not been made of popular votes so far. You have to show us
[#83149] Re: Alias Enumerable#include? to Enumerable#includes?
— Eric Wong <normalperson@...>
2017/10/06
Alberto Almagro <albertoalmagro@gmail.com> wrote:
[#83200] [Ruby trunk Feature#13996] [PATCH] file.c: apply2files releases GVL — normalperson@...
Issue #13996 has been reported by normalperson (Eric Wong).
4 messages
2017/10/10
[ruby-core:83472] [Ruby trunk Feature#14038] Use rb_execution_context_t instead of rb_thread_t to represent execution context
From:
ko1@...
Date:
2017-10-21 16:18:13 UTC
List:
ruby-core #83472
Issue #14038 has been reported by ko1 (Koichi Sasada).
----------------------------------------
Feature #14038: Use rb_execution_context_t instead of rb_thread_t to represent execution context
https://bugs.ruby-lang.org/issues/14038
* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 2.5
----------------------------------------
# Summary
This ticket proposes the following three changes.
* (1) Separate `rb_execution_context_t` from `rb_thread_t`.
* (2) Allocate `rb_fiber_t` for each Thread even if Threads don't make Fiber.
* (3) Use `rb_execution_context_t *ec` to represent VM states instead of `rb_thread_t *th`
Current patch is here:
https://github.com/ruby/ruby/compare/trunk...ko1:sep_con
https://github.com/ruby/ruby/compare/trunk...ko1:sep_con.patch
# Background
Recently Eric Wong introduced `rb_execution_context_t` to represent the "context", state of VM (program counter, stack pointer and so on).
You can find this discussion around this mailing list threads:
`[ ruby-core:81054] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip]`
Before introduction of `rb_execution_context_t`, VM status are contained by threads (`rb_thread_t`) and we need to copy status from `rb_thread_t` to switch Fiber context. I gathered all of states into `rb_execution_context_t` and now we only need to copy one sequential data `rb_execution_context_t` to switch Fiber context.
# Proposal
## Proposal (1) Separate `rb_execution_context_t` from `rb_thread_t`.
On this ticket I propose to separate `rb_execution_context_t` from `rb_thread_t` and `rb_thread_t` only contains pointer to separated `rb_execution_context_t` data. `rb_execution_context_t` memory are managed by `rb_fiber_t`.
Before:
```
struct rb_thread_t {
...;
rb_execution_context_t ec;
...;
}
```
After:
```
struct rb_thread_t {
...;
rb_execution_context_t *ec; /* points rb_fiber_t::ec_body */
...;
}
```
With this change, we only need to swap `ec` pointers to switch Fiber context.
## Proposal (2) Allocate `rb_fiber_t` for each Thread even if Threads don't make Fiber.
Now root Fiber (and `rb_fiber_t`) is allocated just after another Fiber is created.
For proposal (1), we need to allocate `rb_fiber_t` to prepare ec body.
We can optimize this allocation with several techniques, but it introduce complexity. So that I allocated `rb_fiber_t` for each thread.
## Proposal (3) Use `rb_execution_context_t *ec` to represent VM states instead of `rb_thread_t *th`
Now many functions accept `rb_thread_t *th` as first argument to represent VM states. For now most of states are in `rb_execution_context_t` so that we need to introduce indirect access `th->ec->...` to access VM states.
To overcome this performance overhead, we need to use `ec` instead of `th` as the first argument.
# Evaluation
Comparison with trunk and modified version, `vm2_fiber_switch` benchmarks 10% speedup (not so big impact).
```
name trunk modified
loop_whileloop2 0.113 0.116
vm2_fiber_switch* 2.500 2.242
Speedup ratio: compare with the result of `trunk' (greater is better)
name modified
loop_whileloop2 0.974
vm2_fiber_switch* 1.115
```
However, other micro-benchmarks show slowdown becuase of indirect access I explained at Proposal (3).
```
name trunk modified
loop_whileloop 0.436 0.444
vm1_simplereturn* 0.487 0.672
Speedup ratio: compare with the result of `trunk' (greater is better)
name modified
loop_whileloop 0.981
vm1_simplereturn* 0.726
```
I believe we can improve by "Proposal (3)".
# Foresight
For Guild proposal, context passing by `ec` is important.
I want to introduce many other APIs to accept `ec` as first argument and we don't need to call `GET_THREAD()` or `GET_EC()`, which cause system native thread-local-storage.
I will introduce this patch soon because this patch is only internal changes. Ruby users can't observe any incompatible changes (hopefully).
Thanks,
Koichi
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>