[erlang-questions] moving process state - copy on write - heap memory increase
Yiannis Tsiouris
gtsiour@REDACTED
Wed Sep 12 09:11:48 CEST 2012
On 09/12/2012 04:10 AM, Björn-Egil Dahlberg wrote:
> Hi,
>
> Sharing within a compounded data term is not preserved on send nor
> in term to binary.
>
> One way to reinstate sharing is to walk through the compounded term
> and look for sharing (Wind3d uses this trick).
>
> Ex. Ls = <list of items>, {Sh,_} = lists:mapfold(fun(I, T) -> case
> gb_trees:lookup(I,T) of none -> {I, gb_trees:enter(I,I,T)}; {value,
> V} -> {V, T} end end, gb_trees:empty(), Ls), Sh.
>
> (disclaimer: I am writing code when sleepy and I always forget the
> mapfold syntax. But you get the idea.)
>
> This approach requires some knowledge about the structure of the
> data to be reshared. It will also temporary increase the total memory
> while performing the resharing.
>
> I'm sure there are other, perhaps much better, approaches as well to
> this problem.
>
> There exists several proposals on preserved sharing on send, but
> none are currently implemented in the vm.
>
> // Björn-Egil
>
> Skickat från min iPad
>
> 11 sep 2012 kl. 23:45 skrev Roland
> <roland.koelbel@REDACTED>:
>
>> Hello!
>>
>> I want to move the state of my process to another process.
>> Unfortunately this is not possible without a huge increase in
>> memory consumption as by copying the state the "copy on write
>> semantics" are lost.
>>
>> This behaviour is demonstrated in my attached simplified t_process
>> module.
>>
>> -> {ok, Pid} = t_process:start_link(). -> t_process:bloat(Pid). -->
>> memory consumption of the process is at 6657256 after "bloat" is
>> finished -> t_process:reload_bag(P1). --> memory consumption is at
>> 26295176 (4 times as much)
>>
>> No data has not been modified in any way, the data stays the same.
>>
>> My question is: Despite what i want to do with this state transfer,
>> is there any way to copy the state of a process without losing the
>> "copy on write semantics", so that the target process has the same
>> memory footprint as the original one?
>>
>> Can someone point me to any direction/documentation on how i can
>> get arround this issue?
Hi,
Actually that's funny because there is some work [1] by Nikos Papaspyrou
and Kostis Sagonas that will be presented on Friday the 14th on the
Erlang Workshop in Copenhagen! It's an (experimental) implementation of
a copy that preserves sharing...
Maybe you could take a look at the code in that repo. :-)
Best regards,
Yiannis
[1]: https://github.com/nickie/otp
--
Yiannis Tsiouris
Ph.D. student,
Software Engineering Laboratory,
National Technical University of Athens
WWW: http://www.softlab.ntua.gr/~gtsiour
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120912/a4a5dc7a/attachment.htm>
More information about the erlang-questions
mailing list