Fermer2
PpHdLe 26/12/2014 à 13:51
J'aimerais bien faire un petit sondage. Le but est de connaitre la mémoire virtuelle maximale allouable par un système.

Donc le petit programme suivant la "calcule" plus ou moins bien (plutôt moins que plus d'ailleurs) #include <stdlib.h> #include <stdio.h> #include <limits.h> size_t maxsize(void) { size_t n = 0; int i, j; void *s = &i; /* Find upper limit for stack size */ for (i = 10; i < (int) (CHAR_BIT*sizeof n) && s != NULL; i++) { n = 1UL << i; s = malloc (n); if (s != NULL) free (s); } n = 1UL << (i-2); for (j = i-3; j > i-8; j--) { s = malloc (n + (1UL << j)); if (s != NULL) { free (s); n += 1UL <<j; } } return n; } int main() { size_t n = maxsize(); void *p = malloc (n); double alloc = n; while (p != NULL) { p = malloc (n); alloc += n; } alloc -= n; printf ("Max allocatable virtual memory=%fGb\n", alloc/1024.0/1024.0/1024.0); return 0; }

Si possible, ça serait pour avoir des retours sur différents systèmes (curiosité lorsque tu nous tiens). Donc à votre bon cœur. C'est Noël ! grin
Les résultats:
Machine Linux 3.2.0-4-amd64 / RAM = 4GB / SWAP = 8 GB / Overcommit = ON / RESULT = 68470 GB to 131056.5 GB
Machine Linux mint 3.13.0-24 / RAM = 8GB / SWAP = 8GB / Overcommit = ON / RESULT = 63787GB to 65988Gb
Machine Linux 3.16.0-4-amd64 / RAM = 16GB / SWAP = 16 GB / Overcommit = ON / RESULT = 131040. GB
Machine Linux 3.2.0-4-amd64 / RAM = 4GB / SWAP = 8 GB / Overcommit = OFF / RESULT = 7.75Gb
Machine Linux mint 3.13.0-24 / RAM = 8GB / SWAP = 8GB / Overcommit = OFF / RESULT = 8.25Gb
Machine Linux 3.16.0-4-amd64 / RAM = 16GB / SWAP = 16 GB / Overcommit = OFF / RESULT = 22. GB
Machine Raspberry Pi B raspbian / RAM = 512MB / carte SD 2GB / RESULT = 2.734375Gb
Machine MacBook Air / RAM = 4Go / SWAP = ? = / RESULT = 129024Gb
Machine Windows 7 64bits / RAM = 4GB / SWAP = 4GB / 32 bits / RESULT = 1.781250Gb
Machine Windows 8.1 64 bits / RAM =  8 Go / SWAP= ? / 32 bits / RESULT = 1.972656Gb
Machine Windows 8.1 64 bits / RAM =  8 Go / SWAP= ? / 64 bits / RESULT = 17.859375Gb
Machine Windows 7 64bits / RAM = 16GB / SWAP = ? / 32 bits / RESULT = 1.812500Gb
Machine Windows 7 64bits / RAM = 16GB / SWAP = ? / 64 bits / RESULT = 23.625000Gb
Machine Windows 8.1 64bits / RAM = 16GB / SWAP = 16 Gb to ? / 64 bits / RESULT = 57.093750Gb


PS: Si vous utilisez clang, ne pas activer de directive d'optimisation Il freeze sur ce code (c'est un bug connu dans la base clang qui traine qui consiste à croire que malloc ne peut pas retourner NULL).
PPS: Sous Linux, overcommit ON: echo 0 > /proc/sys/vm/overcommit_memory / Overcommit OFF: echo 2 > /proc/sys/vm/overcommit_memory
EDIT: Update results