Re: Virtual Memory
- From: "glenfine@xxxxxxxxx" <glenfine@xxxxxxxxx>
- Date: Wed, 6 Aug 2008 17:25:16 -0700 (PDT)
Yes, memory is restricted to storage plus real memory, less the
kernel's overhead.
Simply what happens with respect to memory real, and virtual (swapped)
is that once the kernel (that supports swapping) is initializing it
will look at two items, real memory and the size of its swapper. It
will then create a pool (or pools) of memory handles (I won't go into
details of their different types, and uses). Then the kernel loads
device drivers, and then these take their chunks of memory from the
pool(s). Once the system is up and running there will be memory
handles left over for applications. The kernel will allocate and
restrict how much memory an application can ask for or how many memory
handles it can have. So, this means that when applications run they
can not demand certain types of memory (like kernel memory), nor can
they allocate memory beyond the size of the heap that has been
allocated to them. This is done so that if an application gets too
memory hungry, it will either not run or generate a memory
exception.
malloc() returns a pointer to the beginning of the memory it
allocated. If the pointer is NULL it failed. Usually malloc will fail
if you ask it for more memory than the system has to allocate. This
is done to protect the kernel and other applications being run. What I
think you are talking about is memory being "enstanciated" versus
being "allocated". You can set up a pointer(s) in C/C++ but until you
assign memory to it, it is considered enstanciated but not allocated.
Once you malloc, or assign memory to that pointer, then it becomes
allocated. In other words it is simply a reference until there is an
assignment of some sort. So you could say in a program:
pvoid BigMemoryChunk;
and it would mean nothing, and not take up any memory, until you
said :
BigMemoryChunk = malloc (30000000); // it would try to allocate
Thirty Million bytes.
In your example, where memory and storage are exhausted, the malloc
(above) would fail, and return a NULL pointer. You shouldn't even get
the chance to write to that memory. If, by some fluke, or
shortcoming, in the OS or the compiler, it did return a pointer, it
would fail the moment you start writing to it.
Flash drives covers a fairly big segment of non-rotating storage
media. USB keyfobs, Solid State Drives (SSD), DiskOnChip, etc. all
fall under this definition.
G
On Aug 4, 3:01 pm, NewToEmbeddedLinux <het...@xxxxxxxxx> wrote:
So, is it safe to say that any system can handle only as much memory
as it has in RAM and the storage device put together.
Somewhere I read that in Linux malloc() always returns requested
memory. Here, Linux does not have to reserve physical memory until the
application starts writing to it.
So, in my example: Lets say I used up all the available memory and the
storage (for swap entries). At this stage a process allocates (through
malloc) about 30 meg memory. What happens when it starts writing this
memory?
Thanks,
Eswar.
.
- References:
- Virtual Memory
- From: NewToEmbeddedLinux
- Re: Virtual Memory
- From: glenfine@xxxxxxxxx
- Re: Virtual Memory
- From: NewToEmbeddedLinux
- Virtual Memory
- Prev by Date: malloc_usable_size problem
- Next by Date: "Building Embedded Linux Systems"
- Previous by thread: Re: Virtual Memory
- Next by thread: Re: Opinions on FS for CF?
- Index(es):
Relevant Pages
|