microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
10.58k stars 863 forks source link

Mimalloc v2.0.6 conflicts with Nvidia Nsight #626

Open vauki opened 2 years ago

vauki commented 2 years ago

Hello!

I found an issue while using mimalloc v2.0.6 and Nvidia Nsight. Here are the steps:

  1. You need an application with mimalloc integrated (D:/app.exe for example)
  2. Run it using Nvidia Nsight: image
  3. In the debug configuration we get an assert: image
  4. Here is the mimalloc output: image

It looks like the problem is that Nvidia Nsight conflicts with mimalloc. Both are injected into the DLL load order to intercept the messages they need, and in this case Nsight is loaded first and prevents mimalloc from properly intercepting malloc/free calls.

Any thoughts on how this can be fixed?

vauki commented 2 years ago

Can you provide source code for mimalloc-redirect.dll so I can try to find some workaround or some good fix?

daanx commented 2 years ago

Ah I see. I cannot check this but if it is indeed the case that the insight dll is injected earlier than mimalloc, then you should try to move the mimalloc-redirect.dll earlier in the import table of the application. This can be done manually on the exe using tools like CFF explorer. However, if you get a recent version of dev-slice the bin directory contains the minject program that you can run on you executable to do this automatically. (run minject --help for options). This may fix the problem

vauki commented 2 years ago

Ah I see. I cannot check this but if it is indeed the case that the insight dll is injected earlier than mimalloc, then you should try to move the mimalloc-redirect.dll earlier in the import table of the application. This can be done manually on the exe using tools like CFF explorer. However, if you get a recent version of dev-slice the bin directory contains the minject program that you can run on you executable to do this automatically. (run minject --help for options). This may fix the problem

I already tried this and it didn't help :(

daanx commented 1 year ago

Mmm, I'll try to run Nvidia Nsight and try to see what is going on. I guess because nsight runs the application it injects it's dll earlier than anything else so it may be difficult to get around this... tbc