-
Notifications
You must be signed in to change notification settings - Fork 19
Fixes for memory leaks on thread termination + refactoring #144
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
This way I need to review the refactoring and the memory management stuff at the same time. |
|
|
|
Actually, the CI failure seems to be a bug in Phobos. The |
|
Related: dlang/phobos#7353 |
|
|
Hackerpilot
left a comment
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.
Looks good to me, but I'm not sure what to do about the CI issue.
|
This is strange to me: why does meson ever compile Phobos unittests we don't import? |
Not sure. I fixed this in dlang/phobos#7419 but that won't get the tests green until we either change the CI or a new DMD release is out. |
|
Is it a just minor inconvenience or it blocks merging? |
I think that we can still merge. We'll have to watch the CI failures carefully until the next DMD release. @WebFreak001 Can you take another look? |
WebFreak001
left a comment
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 like how the changes look but I haven't actually tested the code yet.
Add a basic unittest for the thread dtor stuff pls (creating a thread, doing some stuff, destroying the thread, and then outside doing more stuff)
|
I have an idea to actually check for a memory leak: version (linux)
unittest
{
// ...imports
// create and destroy a lot of dummy threads
foreach (j; 0 .. 100)
{
Thread[100] arr;
foreach (i; 0 .. 100)
arr[i] = new Thread({}).start();
foreach (i; 0 .. 100)
arr[i].join();
}
GC.collect();
GC.minimize();
// get Linux process statistics
const txt = fs.readText("/proc/self/stat");
const parts = split(txt);
// get the resident set size
const rss = to!long(parts[23]);
// check that it is less than some eyeballed threshold
assert(rss < 10_000);
}It spends 3 seconds to create and join 10000 threads, then checks if they inflated the process. This catches moderate leaks (> 4 kB). If threads allocate > 300 kB each, CI will kill the process ruthlessly. |
|
It works! |
WebFreak001
left a comment
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.
well anyway lgtm now
|
I'm going to override the CI given that the failure is unrelated. |
|
actually using the API now I'm not sure if it was the best idea to make istring have opCmp now with ptr comparision. Before it would have defaulted to the string (through alias this) and sorted by ascii ordering instead of random memory order. So this definitely might have changed some existing code depending on the order of istrings. |
|
It can be renamed to |
|
hm not sure if that's the best solution either. Currently there are 2 releases made with it already too so there should be some solid plan that integrates well |
|
We could at least start by documenting this in the release descriptions. |
|
ok actually it's actually changing in a few ways:
|
|
I don't want breakages, but if you leave your fields public and so vulnerable - you will never be sure that your abstraction works everywhere as intended: void f()
{
g(FUNCTION_SYMBOL_NAME);
}
void g(ref string str)
{
str = "fuck";
}dcd and dscanner compile, so the breakage is not as bad. |
When a thread terminates, global malloc-allocated things remain. Furthermore, destructors of thread-local objects aren't invoked either!
Tested on
serve-dusing Valgrind Massif.I hope you won't mind that I've done some refactoring and other stuff in the meantime.