[Info-vax] Running Alpha VMS under the ES40 emulator

Johnny Billquist bqt at softjar.se
Sun Oct 13 15:21:39 EDT 2013


On 2013-10-13 21:08, Simon Clubley wrote:
> On 2013-10-13, David Froble <davef at tsoft-inc.com> wrote:
>> Johnny Billquist wrote:
>>
>>> Memory usage and allocation patterns in most programs means that it's
>>> easy to allocate new chunks of memory, but it is hard to ever return any
>>> memory to the OS.
>>> The OS never reclaims anything until the program exits. Programs
>>> explicitly have to give the memory back to the OS. Normal memory
>>> allocation routines don't return any memory to the OS. They keep it
>>> around for later. (And because it is damned hard to return the memory.)
>>
>> I'm going to object to such a statement.  Freeing memory is easier than
>> acquiring it.  Now, determining what can be freed may be a tougher job.
>>
>
> I think Johnny's point is that in some environments (it's operating system
> and programming language support environment specific), once memory is
> mapped into virtual address space it tends to stay mapped into virtual
> address space even if, say, free() indicates at C RTL level that the
> memory is no longer required.

Correct. You normally cannot easily return memory in the middle of your 
memory space to the OS. Just as memory is expanded "at the end", freeing 
up also happens "from the end". The OS interface in Unix is normally 
brk(), although you also play with memory using mmap() these days.

malloc/free actually keep a list of free memory around. When you call 
free, the memory you free is placed in the free list, and malloc tries 
to grab memory from the free list first, before requesting more memory 
from the OS.

> I don't have a problem with that argument at a conceptual level although
> I have not investigated how true it is for Linux and glibc. I _do_ have a
> general problem with Firefox not reusing the newly available memory
> released after a tab or window is closed and instead deciding to allocate
> yet more memory. (At least, that's the behaviour as it appears to me.)
>
> Simon.
>
> PS: A thought just occurred to me: what if part of the problem is that
> some released memory is too fragmented (at a virtual address space level)
> to use again because of poor memory management and that's what is causing
> Firefox to expand it's memory usage ?

Right. If you ask for a larger chunk than exists contiguously in the 
free list, malloc have no choice more than requesting yet more memory 
from the OS. And if you request a small chunk, the previous large free 
chunk can get split off into a smaller free chunk, so depending on in 
which order you allocate the same amount of memory, you can get very 
different final results in the amount of memory you actually have in 
your address space.

	Johnny

-- 
Johnny Billquist                  || "I'm on a bus
                                   ||  on a psychedelic trip
email: bqt at softjar.se             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol



More information about the Info-vax mailing list