<div dir="ltr">Hi Jesper,<div><br></div><div>This is a great explanation, I was able to connect the missing dots.</div><div><br></div><div>Thank you very much, Gerhard.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 2, 2018 at 1:51 PM, Jesper Louis Andersen <span dir="ltr"><<a href="mailto:jesper.louis.andersen@gmail.com" target="_blank">jesper.louis.andersen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">On Tue, May 1, 2018 at 3:06 PM Gerhard Lazu <<a href="mailto:gerhard@lazu.co.uk" target="_blank">gerhard@lazu.co.uk</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div>During this exploration, there's a specific thing that's been bugging us: why is RSS smaller than the allocated memory? </div><div><br></div></div></blockquote><br></div></span><div class="gmail_quote">This seems fairly obvious to me, but perhaps I am missing something. The Erlang system has allocated memory from the kernel, but the kernel has not yet handed that memory out to the process, and hence it is not in the RSS (Resident Set Size). As you hit new pages, there should be kernel traps, a page is allocated to the process (bumping RSS) and the program is resumed. If you allocate a larger carrier the "inner parts" of it might not be allocated before the first access.<br><br></div><div class="gmail_quote">The other situation is that you have excessive memory pressure and the system starts removing pages which are possible to remove (they either bear no data, have already been written to the page/swap file on disk, have libraries in them, or madvise(2) have been called and told the OS that the pages are not needed[0]).<br><br></div><div class="gmail_quote">In general, most systems with a GC doesn't give memory back to the OS straight away. They either keep it indefinitely (perhaps with an madvise(2) on the areas they don't need), or they have a reaper later on which can give back fully unused "spans" of memory (Go does this, for instance, but it isn't instant).<br></div><div class="gmail_quote"><br><br></div><div class="gmail_quote">[0] Be *very* cautious with madvise(2) since its implementation semantics are slightly different on Linux/BSD/Illumos. especially around DONTNEED/FREE and friends, which have different semantics. In particular, if a don't need a page right now, is the operating system allowed to hand me a zeroed page later if I start going for that memory again. Bryan Cantrill has some interesting pointers w.r.t. Lx-branded Illumos Zones and this :)<br><br></div></div>
</blockquote></div><br></div>