Repository navigation
Pin CoreRT OS modules in memory - #7011
Conversation
filipnavara
left a comment
There was a problem hiding this comment.
Makes sense as a stopgap solution.
Is there any major reason why proper unloading would not be possible, or is it just a lot of small issues like the missing FlsFree?
|
It is both a lot of small issues like |
CoreRT is not designed to be unloadable. Unloading modules before process shutdown leads to crashes and memory leaks. Fixes #6993
Is there any documentation on how that worked with CLR and the I would imagine that one way to solve it is to keep the DLL unloadable as long as any CLR thread is running. Something like ThreadPool may need some special handling though. |
CLR itself was never unloadable. Assemblies loaded into AppDomain were unloadable via |
Interesting. We have implemented Simple MAPI as .NET .dll with exports running on full CLR. I never realised that it would not unload (partly due to some indirection on newer Windows versions that allowed for 32-bit/64-bit compatibility and could have hidden that from us). I'll have to do some more tests on it since we planned to replace it with CoreRT eventually. |
|
Would it be a lot of work to introduce such an API that at least can forcefully shut down runtime and managed code threads for CoreRT only? Thread.Abort could be brought back in some form? |
|
What would be the reliability guarantees provided by such API? How often (under what circumstances) is it ok for it to crash or hang; and how much it can leak? |
|
It can’t crash or hang. Maybe the leak is tolerable in some scenarios, but ideally we would get to fixing all the issues. I’ve found a new use case for CoreRT modules, think of like it once accessed or infrequently accessed bloated code that adds a ton of dependencies to your main long running app that you may not desire for let’s say perf of security footprint purposes. It gets loaded at startup, does its job and gets unloaded. So reliability has to be there but leaking some memory maybe ok in the beginning. Assuming no static constructors and their running is not involved can there be other issues with Thread.Abort like behavior? |
|
The problem with |
|
I think that is a reasonable start. Guaranteeing no managed code running for unloading such components will not be terribly hard for my cases. If there is a list somewhere of what needs fixing we can all start contributing. |
There is no list. You would need to come up with one. |
|
Started a quick list.
Are there any handles we need to free? I guess one way to find out will be to load/unload the module as see what handles stay ... or track all handles created and ensure they get cleaned up at free time. I think all the memory is going through the ClrVirtualAlloc abstraction (at least in CoreCLR it was), so maybe that'll be easy to audit as well. |
| FreeLibrary(handle); | ||
| #else | ||
| // TODO: How to pin the library in memory on Unix? | ||
| // dlclose(handle); |
There was a problem hiding this comment.
For reference, dlopen has RTLD_NODELETE flag. It seems to be available on both Linux and macOS.
CoreRT is not designed to be unloadable. Unloading modules before process shutdown leads to crashes and memory leaks.
Fixes #6993