I came across one situation while trying to debug one program for segmentation fault. I found the program is able to allocate 4GB of dynamic memory while the available memory in the /proc/meminfo is only 1GB. Please find below the program and the my system RAM info.
program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *buf;
buf=malloc(1<<31);
fgets(buf,1024,stdin);
printf("%s\n",buf);
//return 1;
}
#vim /proc/meminfo
MemTotal: 1032984 kB
MemFree: 743620 kB
Buffers: 54156 kB
Cached: 175424 kB
SwapCached: 0 kB
Active: 91436 kB
Inactive: 158196 kB
HighTotal: 129440 kB
HighFree: 252 kB
LowTotal: 903544 kB
LowFree: 743368 kB
SwapTotal: 10241428 kB
SwapFree: 10241428 kB
Dirty: 0 kB
Writeback: 0 kB
Mapped: 32740 kB
Slab: 25748 kB
CommitLimit: 10757920 kB
Committed_AS: 74952 kB
PageTables: 1316 kB
VmallocTotal: 106488 kB
VmallocUsed: 7004 kB
VmallocChunk: 99300 kB
This one is really confusing me. Kindly suggest me.