<div dir="ltr">Hi Chris, Hi All,<div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 29, 2014 at 3:18 PM, Chris Muller <span dir="ltr">&lt;<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Hi Eliot, today I was working and remembered that you asked me to post<br>
a reminder request about the ability to restrict a Spur VM&#39;s memory<br>
expansion via -mmap or -memory parameters.<br>
<br>
It can be useful when you want to prevent an image from being able to<br>
consume more resources from the machine than you want.<br></blockquote><div><br></div><div>This is interesting.  I just took a look at implementing this and a few issues came up.</div><div><br></div><div>First is how frustrating the sprawling platform subsystem is.  The VW VM has a ell-defined set of interfaces between platform-specific code and the broader VM, which help guide the design and provide regularity across platforms.  This kind of thing only exists in some places in the Squeak VM.  And specifying memory is one example where its conspicuously absent. So in our VM there is a different variable for holding the max heap size on each platform:</div><div><br></div><div>Mac:<span class="" style="white-space:pre">                        </span>usqLong gMaxHeapSize</div><div>Plan9/Unix:<span class="" style="white-space:pre">        long </span>extraMemory</div><div>RiscOS:<span class="" style="white-space:pre">                long </span>objectHeadroom</div></div>win32:<span style="white-space:pre">                DWORD dwMemorySize</span></div><div class="gmail_extra"><span style="white-space:pre"><br></span></div><div class="gmail_extra"><span style="white-space:pre">Note that the lack of a defined interface makes room for bugs.  &quot;long&quot; is clearly wrong.  It must be an unsigned type to not restrict us to half the available memory.</span></div><div class="gmail_extra"><span style="white-space:pre"><br></span></div><div class="gmail_extra"><span style="white-space:pre">Now in Spur I&#39;ve reimplemented a smaller, common memory allocation interface for all platforms.  So I could simply add a common variable and change code so that it reads e.g.</span></div><div class="gmail_extra"><span style="white-space:pre"><br></span></div><div class="gmail_extra"><span style="white-space:pre">  else if (argc &gt; 1) {</span><br></div><div class="gmail_extra"><span style="white-space:pre">      if (!strcmp(argv[0], &quot;-memory&quot;))  {
 </span><span style="white-space:pre">#if SPURVM</span></div><div class="gmail_extra"><span style="white-space:pre">       maxMemory = strtolbkm(argv[1]);</span><span style="white-space:pre">
</span></div><div class="gmail_extra"><span style="white-space:pre">#else</span></div><div class="gmail_extra"><span style="white-space:pre">        gMaxHeapSize = strtolbkm(argv[1]);
</span><span style="white-space:pre">#endif</span><br style="white-space:pre"><span style="white-space:pre">        return 2; }</span></div><div class="gmail_extra"><br clear="all"><div>But then I thought why not move the responsibility up to the image?  In Spur the only interface to growing memory is </div><div>SmalltalkImage&gt;&gt;growMemoryByAtLeast: numBytes</div><div><span class="" style="white-space:pre">        </span>&quot;Grow memory by at least the requested number of bytes.</div><div><span class="" style="white-space:pre">        </span> Primitive.  Essential. Fail if no memory is available.&quot;</div><div><span class="" style="white-space:pre">        </span>&lt;primitive: 180&gt;</div><div><span class="" style="white-space:pre">        </span>(numBytes isInteger and: [numBytes &gt; 0]) ifTrue:</div><div><span class="" style="white-space:pre">                </span>[OutOfMemory signal].</div><div><span class="" style="white-space:pre">        </span>^self primitiveFailed</div><div><br></div><div>So that would be a place to introduce a MemoryPolicy class that could monitor memory from the VM via vmParameterAt: and be parameterisable e.g. by preferences, and then grow over time into something that can be controlled easily from the image.  What do you think?</div>-- <br><div class="gmail_signature">best,<div>Eliot</div></div>
</div></div>