作者:
lf5471 (lf)
2015-02-13 21:08:37※ 引述《LORDJACK (文亞南)》之銘言:
: 最近公司的linux server有個問題
: 以前裝32G的ram工作正常, 記憶體超過了就用page
: 最近把ram加到64G, 發生奇怪的問題
: 記憶體用量到24G時就會整個系統卡住, 連page也不用了
: 因此我想寫一個程式如下
沒有真的跑, 試看看吧.
簡單說就是一直 fork 到 fork 不了為止
#define SIZE_4GB 0x100000000UL
int g_n = 0;
int main(void)
{
pid_t pid;
char *buf;
pid = fork();
if (pid < 0) // fork fail
{
printf("\nFork fail! => total malloc size = %d (GB)\n", 4*g_n);
return 1;
}
// else, fork success
if (pid == 0) // child process
{
if ((buf = (char *)malloc(SIZE_4GB)) != NULL)
{
memset(buf, 0x00, SIZE_4GB);
g_n++;
printf("child (%6d) : %d\n", pid, g_n);
}
else
printf("child (%6d) : malloc fail! g_n = %d\n", pid, g_n);
}
else
{
//Parent process, do nothing.
printf("parent (%6d) : do nothing\n", getpid());
}
return 0;
}