Beginner memory question.

Era Scarecrow rtcvb32 at yahoo.com
Tue Apr 19 17:01:15 UTC 2022


On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote:
> On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote:
>> Is virtual memory entering into the equation?
>
> Probably. Memory allocated doesn't physically exist until 
> written to a lot of the time.

This might be very much an OS implementation issue.

  In linux using zram i've allocated and made a compressed drive 
of 8Gb which took only 200k of space (*the data i needed to 
extract compresses very well and only be temporarily used*) as 
such saying i have said space even though i have only 4Gb of ram 
didn't seem to matter. All unallocated pages are assumed 
null/zero filled, and if you zeroize a block it will unallocate 
the space. Makes extracting memory bomb archives (*Terabytes of 
zeroized files to fill space*) becomes rather safe in that 
environment.

  I would think if it's a small space (*say 32Mb or under, or some 
percentage like less than 1% of available memory*) it would 
allocate the memory and immediately return it. If it's larger it 
may say it allocated a range of memory (*as long as RAM+VM could 
hold it*) and allocate as needed. The CPU issues page faults when 
you try to access unallocated memory or memory that's not in at 
the time and passes it to a handler; It would then allocate the 
page(*s*) and then resume as though it was always allocated 
(*alternatively suspend until it has free ram, or save the 
program to disk for later resuming if there's no open 
ports/writable-files, or just crash the program with a segment 
fault*). It will make some things faster, and other things slower.

  If it tries to allocate all memory all at once, it may fill up 
RAM, then swap pages out, then fill RAM up again until the said 
space is successful. Which could be wasteful and slow. Or maybe 
it will allocate/reserve necessary Swap space and then allocate 
as much memory as it can before returning to the process.

  When you run out of ram and there's tons of swapping, a fast 
computer can turn into a brick for several minutes for the 
simplest of commands, at which changing swap settings can improve 
things.




More information about the Digitalmars-d-learn mailing list