Open YYF233333 opened 19 hours ago
Nice to see mimalloc integration in Godot! Let me know if you need further help or have suggestions.
That is a strange error (potential lock-inversion) from TSAN; I only recently added a lock to mimalloc for the Python integration but it is hardly used otherwise (it is there to protect huge abandoned segments that are allocated outside arena's). I think that may be the pthread_mutex_lock
you see in the error messages? (the other locks seem from Godot itself). Since the mimalloc lock is only acquired / released internally without calling out to other code this should always be fine and not lead to lock inversion -- I think? (I will check the mimalloc code again as well to make sure the lock is always released)
So, not sure. However, since TSAN is only sampling, it might be that the mimalloc lock exposes now a lock inversion scenario in Godot that was undetected before? Or it may be just a false positive?
Both of the two locks are from godot side (std::recursive_mutex), not from mimalloc. I agree that it may be a hidden bug previously not detected in godot itself (if not false positive), because ptmalloc probably add an global lock while malloc
from multi-thread, which limits the parallelism. But in mimalloc we don't have that lock (right?).
Thanks for the quick reply, I'll test if adding this lock back solve the problem. Edit: It doesn't work, sadly.
Hello, I'm trying to integrate mimalloc into godot in this PR. Everything works fine except CI report some potential deadlock when tsan is enabled. I have no idea why replacing malloc interact with lock behaviour. Is this something related to mimalloc internal or just false positive? (no deadlock found in real usage)
log
```bash ================== WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=7667) Cycle in lock order graph: M0 (0x7f6bff809c10) => M1 (0x7f6bff80bc10) => M0 Mutex M1 acquired here while holding mutex M0 in main thread: #0 pthread_mutex_lockHow I integrate: include
mimalloc.h
, compilesrc/static.c
and statically link to final binary.