On Tuesday 01 April 2008 06:57, Peter Zijlstra wrote:
I don't know, but the following definitely works for me:
#include <stdlib.h>
int main() {
void *p;
unsigned size = 1 << 20;
unsigned long total = 0;
while (size) {
p = malloc(size);
if (!p) size >>= 1;
else {
memset(p, 0x77, size);
total += size;
printf("Allocated %9u bytes, %12lu total\n", size, total);
}
}
printf("Cannot malloc more. Exiting\n");
return 0;
}
# softlimit -a 12000000 ./oom
Allocated 1048576 bytes, 1048576 total
Allocated 1048576 bytes, 2097152 total
Allocated 1048576 bytes, 3145728 total
Allocated 1048576 bytes, 4194304 total
Allocated 1048576 bytes, 5242880 total
Allocated 1048576 bytes, 6291456 total
Allocated 1048576 bytes, 7340032 total
Allocated 1048576 bytes, 8388608 total
Allocated 1048576 bytes, 9437184 total
Allocated 1048576 bytes, 10485760 total
Allocated 262144 bytes, 10747904 total
Cannot malloc more. Exiting
--
vda
--