Commit 6bae7ed8b900bc0f1fb1df0f70ceed5e8cca0ca1

Authored by bellard
1 parent 74c161bd

informative message about low memory on /dev/shm


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1388 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 27 additions and 0 deletions
... ... @@ -323,6 +323,7 @@ void qemu_vfree(void *ptr)
323 323  
324 324 #elif defined(USE_KQEMU)
325 325  
  326 +#include <sys/vfs.h>
326 327 #include <sys/mman.h>
327 328 #include <fcntl.h>
328 329  
... ... @@ -333,11 +334,37 @@ void *qemu_vmalloc(size_t size)
333 334 const char *tmpdir;
334 335 char phys_ram_file[1024];
335 336 void *ptr;
  337 + struct statfs stfs;
336 338  
337 339 if (phys_ram_fd < 0) {
338 340 tmpdir = getenv("QEMU_TMPDIR");
339 341 if (!tmpdir)
340 342 tmpdir = "/dev/shm";
  343 + if (statfs(tmpdir, &stfs) == 0) {
  344 + int64_t free_space;
  345 + int ram_mb;
  346 +
  347 + extern int ram_size;
  348 + free_space = (int64_t)stfs.f_bavail * stfs.f_bsize;
  349 + if ((ram_size + 8192 * 1024) >= free_space) {
  350 + ram_mb = (ram_size / (1024 * 1024));
  351 + fprintf(stderr,
  352 + "You do not have enough space in '%s' for the %d MB of QEMU virtual RAM.\n",
  353 + tmpdir, ram_mb);
  354 + if (strcmp(tmpdir, "/dev/shm") == 0) {
  355 + fprintf(stderr, "To have more space available provided you have enough RAM and swap, do as root:\n"
  356 + "umount /dev/shm\n"
  357 + "mount -t tmpfs -o size=%dm none /dev/shm\n",
  358 + ram_mb + 16);
  359 + } else {
  360 + fprintf(stderr,
  361 + "Use the '-m' option of QEMU to diminish the amount of virtual RAM or use the\n"
  362 + "QEMU_TMPDIR environment variable to set another directory where the QEMU\n"
  363 + "temporary RAM file will be opened.\n");
  364 + }
  365 + exit(1);
  366 + }
  367 + }
341 368 snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
342 369 tmpdir);
343 370 if (mkstemp(phys_ram_file) < 0) {
... ...