内存:堆栈和交换
Memory: Stack and Swap
当没有足够的 RAM 时,堆上动态分配的变量可以利用磁盘上的交换 space(尽管会导致性能下降)。我的问题是内存中的堆栈是否也可以利用交换 space。
例如,下面的程序将一个大数组放在堆栈上。 (当然,通常我们会在堆上动态分配大变量。)如果这个程序在运行时崩溃了,我可以通过添加swapspace使它运行成功吗?
int main()
{
int myArray[1000000];
return 0;
}
其实就是swap的作用,交换程序数据和栈space:
http://www.linuxjournal.com/article/10678
These are placed in anonymous pages, so named because they have no
named filesystem source. Once modified, an anonymous page must remain
in RAM for the duration of the program unless there is secondary
storage to write it to. The secondary storage used for these modified
anonymous pages is what we call swap space.
The classic recommendation on systems that do strict VM accounting
vary, but most of them hover around a “twice the amount of RAM”
figure. That number assumes your memory mostly will be filled with a
bunch of small interactive programs (where their stack space is
possibly their largest memory demand).
Say you're running a Web server with 500 threads, each with 8MB of
stack space. That stack space alone is going to require that you have
4GB of swap space configured for the memory accountant to be happy.
当没有足够的 RAM 时,堆上动态分配的变量可以利用磁盘上的交换 space(尽管会导致性能下降)。我的问题是内存中的堆栈是否也可以利用交换 space。
例如,下面的程序将一个大数组放在堆栈上。 (当然,通常我们会在堆上动态分配大变量。)如果这个程序在运行时崩溃了,我可以通过添加swapspace使它运行成功吗?
int main()
{
int myArray[1000000];
return 0;
}
其实就是swap的作用,交换程序数据和栈space:
http://www.linuxjournal.com/article/10678
These are placed in anonymous pages, so named because they have no named filesystem source. Once modified, an anonymous page must remain in RAM for the duration of the program unless there is secondary storage to write it to. The secondary storage used for these modified anonymous pages is what we call swap space.
The classic recommendation on systems that do strict VM accounting vary, but most of them hover around a “twice the amount of RAM” figure. That number assumes your memory mostly will be filled with a bunch of small interactive programs (where their stack space is possibly their largest memory demand).
Say you're running a Web server with 500 threads, each with 8MB of stack space. That stack space alone is going to require that you have 4GB of swap space configured for the memory accountant to be happy.