-
Notifications
You must be signed in to change notification settings - Fork 118
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
Fix/2 mem issues #91
Fix/2 mem issues #91
Conversation
Hi @dtynn ! Thanks for the suggestions. But how you would collect allocated C memory if finalizers are not set? The idea was to track all C allocations, from e.g. |
@@ -251,10 +248,7 @@ func (gen *Generator) unpackSlice(buf1 io.Writer, buf2 *reverseBuffer, cgoSpec t | |||
gen.submitHelper(sizeOfPtr) | |||
gen.submitHelper(cgoAllocMap) | |||
|
|||
fmt.Fprintf(buf1, `allocs = new(cgoAllocMap) | |||
defer runtime.SetFinalizer(&unpacked, func(*%s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How this removal is compensated? There are some cases like media player where packets of [][][]float32
are being allocated per second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is for the 1st issue, that gc caused fatal address inside the packSGogcPublicReplicaInfo
call
since functions like unpackXXX & packXXX are private, i think that we could just focus on the uintptr's lifetime, thus the unpack/pack cycle.
we should keep the uintptr alive until the pack things are completed.
but adding a single runtime.KeepAlive
of the uintptr, and leaving the SetFinalizer
untouched seems to be useless in my tests.
so, i removed these SetFinalizers here, and added a defer freeing
of the returned allocMap after every unpack call, right in the arg proxy logic.
pls correct me if i misunderstood anything~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i also made some nested slices to be generated by my patch, to see if it would cause some troubles
i think that all the allocations are tracked by the root alloc map, am i right on this?
hey max, your words +++++++++ |
Now I like it! :) Because in mutimedia apps leaks are more likely to occur. |
@xlab any update here? I'm really itching to get this fix :) |
Sorry I had crazy week! :) |
Any luck? :) |
@xlab We are still using this fix. Could you please have another look, it would be great if you could switch to a proper upstream version. Is there any way I can help getting this PR merged? |
Sorry to all people that were blocked by this PR! I just realized that there are enough external projects who can do testing and verification of the changes. In the past, I relied on my own test suite of bindings, but due to a shortage of time, it's better to trust the community now. Cheers! |
hi max, appreciate your great work!
during my usage of
c-for-go
, i found 2 mem issues. so i made this pr.descriptions
fatal address (SIGSEGV), most likely related to the gc of a uintptr, since go does not keep track of things inside uintptrs
unexpected
ENOMEM
while there is still plenty of mem availablereproducing
you can use the demo codes
sorry that i have to use rust to provide the underlying lib
here are some details:
use
run-gcfatal
for issue-1 andrun-enomem
for issue-2codes in
gen
are purely generated byc-for-go
codes in
gen_no_set_finalizer
are modified to manually free the alloc map, based ongen
issue-1 can be reproduced on macOS / centos 7.7 within seconds
issue-2 can be reproduced on centos 7.7 / ubuntu 19.04 with
ptmalloc2
fromglibc
it will take tens of seconds. we can restart the demo a couple of times to make it happen fastser
for issue-2, the
ENOMEM
always comes along with a non-NULL ptr from calloc.ptmalloc2
totcmalloc
, theENOMEM
just disappearslogs
gc caused SIGSEGV
unexpected enomem