www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Anonymous mapped regions increases unlimitely on spawn

reply unDEFER <undefer gmail.com> writes:
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?
Dec 14 2018
next sibling parent reply unDEFER <undefer gmail.com> writes:
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?
Dec 14 2018
parent unDEFER <undefer gmail.com> writes:
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?
Dec 14 2018
prev sibling parent reply unDEFER <undefer gmail.com> writes:
So it looks like a bug, and I have reported about it:

https://issues.dlang.org/show_bug.cgi?id=19487
Dec 14 2018
parent Boris-Barboris <ismailsiege gmail.com> writes:
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).
Dec 14 2018