I am writing a kernel and I need (and want) to put several stacks and heaps in virtual memory, but I cannot figure out how to efficiently allocate them. How do regular programs do this?
How (or where) are the stacks and heaps placed in the limited virtual memory provided by the 32-bit system, so that they have as much room for growth as possible?
For example, when a trivial program is loaded into memory, the layout of its address space may look like this:
[ Code Data BSS Heap-> ... <-Stack ]
In this case, the heap can grow as much as virtual memory allows (for example, to the stack), and I believe that this is how the heap works for most programs. There is no predefined upper bound.
Many programs have shared libraries that are placed somewhere in the virtual address space. Then there are multithreaded programs that have several stacks, one for each thread. And there are several heaps in .NET programs , all of which should be able to grow anyway.
I just don’t see how this is done quite efficiently without putting a predefined limit on the size of all heaps and stacks.
, , , . , usermode . , , 64 (16 ) . . 4GB/64KB = 64K x 2 . , , .
VM , 1 . , , 1 . , , , . , , -.
. - lookaside, . , 8 , . 8 16 , 16 32 .. . , . VM.
lookaside VM. . , . , . , . , VM.
.
, , .
, . , . , , ( ). malloc()/free(), , , ( , ).
malloc()
free()
, . , , , ( C) ( ).
(DLL), , , , , , CODE/DATA/etc, . , , , . , , CODE/DATA/BSS/etc.
, , . ,
1KB call ( , ), 10 - 10240 call -s. , , .
call