New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ractor newobj cache #3842
Merged
Merged
Ractor newobj cache #3842
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko1
force-pushed
the
ractor_newobj_cache
branch
2 times, most recently
from
December 6, 2020 06:44
627eb49
to
81b0422
Compare
ko1
force-pushed
the
ractor_newobj_cache
branch
from
December 6, 2020 06:50
81b0422
to
9520266
Compare
On the Linux box, Warning[:experimental] = false
def task
i = 0
while i < 1_000_000
a = [[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]
i += 1
end
# 100_000.times{ [[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]] }
end
MODE = (ARGV.shift || :serial).to_sym
TN = 8
case MODE
when :serial
TN.times{ task }
when :r_serial
TN.times{
Ractor.new{
task
}.take
}
when :r_parallel
TN.times.map{
Ractor.new{
task
}
}.each{|r| r.take}
else
raise
end This program shows:
This patch improved the object allocation performance, especially on multi-ractor mode. |
With another task: def task
i = 0
s = '0,' * 1_000
while i < 1_000
a = s.split(/,/)
i += 1
end
end
It is still slower. Maybe because VM lock contention on the Encoding. |
ko1
force-pushed
the
ractor_newobj_cache
branch
from
December 6, 2020 15:11
9520266
to
7393d4c
Compare
Another task (Array#product to make many arrays): def task
i = 0
a = (1..100).to_a
while i < 1_000
as = a.product(a)
i += 1
end
end
This patch is effective (compare with master). |
ruby_multi_ractor was a flag that indicates the interpreter doesn't make any additional ractors (single ractor mode). Instead of boolean flag, ruby_single_main_ractor pointer is introduced which keeps main ractor's pointer if single ractor mode. If additional ractors are created, ruby_single_main_ractor becomes NULL.
accessing theap needs complicating synchronization but it reduce performance on multi-ractor mode. So simply stop using theap on multi-ractor mode. In future, theap should be replaced with more cleaver memory strategy.
Without this patch, Ruby doesn't show ractor's information when there is only 1 ractor. However it is hard to read the log when some ractors are created and terminated. This patch makes to keep showing ractor's information on multi-ractor mode.
This is variant of RB_VM_LOCK_ENTER_LEV, but accept current racotr's pointer.
Before this patch, there is no information to start locking.
Now object allocation requires VM global lock to synchronize objspace. However, of course, it introduces huge overhead. This patch caches some slots (in a page) by each ractor and use cached slots for object allocation. If there is no cached slots, acquire the global lock and get new cached slots, or start GC (marking or lazy sweeping).
NEWOBJ with current ec.
Passing current ec can improve performance of newobj. This patch tries it for Array and String literals ([] and '').
On windows, MJIT doesn't work without this patch because of the declaration of ruby_single_main_ractor. This patch fix this issue and move the definition of it from ractor.c to vm.c to locate near place of ruby_current_vm_ptr.
ko1
force-pushed
the
ractor_newobj_cache
branch
from
December 6, 2020 17:42
7393d4c
to
d9b7e85
Compare
ko1
added a commit
to ko1/ruby
that referenced
this pull request
Dec 10, 2020
Per ractor method cache (GH-ruby#3842) only cached 1 page and this patch caches several pages to keep at least 512 free slots if available. If you increase the number of cached free slots, all cached slots will be collected when the GC is invoked.
Merged
ko1
added a commit
that referenced
this pull request
Dec 10, 2020
Per ractor method cache (GH-#3842) only cached 1 page and this patch caches several pages to keep at least 512 free slots if available. If you increase the number of cached free slots, all cached slots will be collected when the GC is invoked.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now object allocation requires VM global lock to synchronize objspace.
However, of course, it introduces huge overhead.
This patch caches some slots (in a page) by each ractor and use cached
slots for object allocation. If there is no cached slots, acquire the global lock
and get new cached slots, or start GC (marking or lazy sweeping).