Thread overview
Anonymous mapped regions increases unlimitely on spawn
Dec 14, 2018
unDEFER
Dec 14, 2018
unDEFER
Dec 14, 2018
unDEFER
Dec 14, 2018
unDEFER
Dec 14, 2018
Boris-Barboris
December 14, 2018
Hello!
I have the program which uses BDB and while testing often makes spawn. And after 12 hours of testing bdb said:
mmap: Cannot allocate memory

But the problem that I've found that it is not BDB created too many maps. Watching for /proc/[PID]/maps shows that number of anonymous mapped regions increases on 2 every spawn process, and never decreases even after finishing the spawned thread.
According to logs my program made 32543 spawns for test time. And my /proc/sys/vm/max_map_count = 65530. So only 444 maps was allocated by other reasons and 65086 by spawn.

So what to do? How to make spawn decrease count of anonymous mapped regions?
December 14, 2018
So in digging by this problem, I have made simple patch to druntime. I have added in druntime/src/core/thread.d to

final Thread start() nothrow

of class Thread

        import core.stdc.stdio;
        printf("start Thread\n");


And to

~this() nothrow @nogc

        import core.stdc.stdio;
        printf("detach Thread\n");

I recompiled phobos to apply changes to druntime and I see that "start Thread" there is, but "detach Thread" printed only at the end of process even if I do GC.collect().

So dtor of class Thread doesn't call on GC. Why?
December 14, 2018
So more digging..
dtor of Thread calls in GC.collect() if thread is finished.
But it's do nothing because

bool not_registered = !next && !prev && (sm_tbeg !is this);

is always true... So how to register the thread?
December 14, 2018
So it looks like a bug, and I have reported about it:

https://issues.dlang.org/show_bug.cgi?id=19487
December 14, 2018
On Friday, 14 December 2018 at 21:22:05 UTC, unDEFER wrote:
> So it looks like a bug, and I have reported about it:
>
> https://issues.dlang.org/show_bug.cgi?id=19487

Not an expert, but you may wish to try GC.minimize() (https://dlang.org/phobos/core_memory.html#.GC.minimize).