-
Notifications
You must be signed in to change notification settings - Fork 337
Protect FFI::Function with Write Barrier #991
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
Conversation
a5e0a26
to
905fbf3
Compare
Hum, look like I missed one of the
|
Ok, I figured why I couldn't run tests locally. I had some old Now I also located the actual error.
And is sometimes passed to
So there's some kind of polymorphism going on, which I need to find a solution to preserve. |
769af75
to
c74087a
Compare
Ok, I found a solution, I think the result isn't too bad. I just refactored @larskanis I know it's quite a big change, but is this something you'd be interested on? The reason we're interested in this is that we're trying to improve GC performance and we noticed we have over a thousand instance of FFI objects that have to be marked on every minors even though they never change:
|
Sorry Jean for not responding earlier! Sure I'm interested. Nevertheless I think this can be solved better by converting all derivations of
|
No worries, the PR was not passing a single test yet, I wasn't expecting any response at that stage :)
Right, I was trying to do bite sized changes over multiple PRs to make it easier. But if you are down to migrate all the derivatives of
Ah I see, you use I'll try to find some time to convert more types soon, I'll let you know how it goes. Thanks for the pointers! |
Thank you for this concise description of write-barriers in ruby! I never understood the description in https://github.com/ruby/ruby/blob/master/doc/extension.rdoc#write-barriers- , so that I think it should be added or replaced there. |
7512624
to
cb889c6
Compare
Ok, so there wasn't as many as I feared, I converted all the derivations of However it seems like I introduced a GC bug that I'm having a hard time tracking down. It doesn't happen on all test suite runs:
I'll see if Peter can help me figure that one out. |
Nevermind I found a way to identify the bug. It's from |
Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the `RB_BJ_WRITE` macro MUST be used to set references, otherwise the referenced object may be garbaged collected.
cb889c6
to
1a2c653
Compare
Ok, that should be fixed, I had to check for |
@casperisfine One spec failed with a segfault in rb_gc_call_finalizer_at_exit . This didn't happen before this PR. Will you double check this? |
Looking. |
Hum, I tried to figure it out, but the failure being on windows with little information, I can't figure it out. I think this PR grew too much in scope, which makes it hard to debug. If that's OK with you I think I'll try to do this again but more incrementally. I'll try to do small focused PRs to migrate types one by one to |
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated and this new one open the door to write barriers, compaction, memsize etc.
Ref: ffi#991 The old untyped DATA API is soft deprecated 8000 and this new one open the door to write barriers, compaction, memsize etc.
Closing this as it derived way too much now that we migrated all types to |
Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed.
And FFI::DynamicLibrary::Symbol Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed. While I was at it, I moved `Symbol.library` into the unused `Symbol.base.rbParent` which seemed appropriate and saves a pointer.
And FFI::DynamicLibrary::Symbol Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed. While I was at it, I moved `Symbol.library` into the unused `Symbol.base.rbParent` which seemed appropriate and saves a pointer.
And FFI::DynamicLibrary::Symbol Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed. While I was at it, I moved `Symbol.library` into the unused `Symbol.base.rbParent` which seemed appropriate and saves a pointer.
Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. While I was at it I removed the `strdup` of `BuiltinType.name`, I don't see why we wouldn't directly point at static memory, that saves copying type names, and makes freeing builtin types easier.
Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed.
And FFI::DynamicLibrary::Symbol Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed. While I was at it, I moved `Symbol.library` into the unused `Symbol.base.rbParent` which seemed appropriate and saves a pointer.
Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. While I was at it I removed the `strdup` of `BuiltinType.name`, I don't see why we wouldn't directly point at static memory, that saves copying type names, and makes freeing builtin types easier.
Ref: ffi#991 Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC. The downside is that the RB_BJ_WRITE macro MUST be used to set references, otherwise the referenced object may be garbaged collected. This commit also implement a `dsize` function so that these instance report a more relevant size in various memory profilers. It's not counting everything because some types are opaque right now, so a larger refactoring would be needed.
Write barrier protected objects are allowed to be promoted to the old generation, which means they only get marked on major GC.
The downside is that the
RB_BJ_WRITE
macro MUST be used to set references, otherwise the referenced object may be garbaged collected.cc @peterzhu2118
NB: The test suite use an X86_64 fixtures, so I can't run it locally. I did check that the extension does compile though.