qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Tell users about out-of-memory errors
@ 2010-01-20 21:16 Stefan Weil
  2010-01-20 23:13 ` malc
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Weil @ 2010-01-20 21:16 UTC (permalink / raw)
  To: QEMU Developers

Aborting without an error message when memory is short
is not helpful, so print the reason for the abort.

Try
	qemu -m 1000000
to force an out-of-memory error.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 osdep.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/osdep.c b/osdep.c
index 1310684..5d4e810 100644
--- a/osdep.c
+++ b/osdep.c
@@ -52,6 +52,7 @@
 static void *oom_check(void *ptr)
 {
     if (ptr == NULL) {
+        perror("qemu (memory allocation)");
         abort();
     }
     return ptr;
@@ -91,8 +92,11 @@ void *qemu_memalign(size_t alignment, size_t size)
     int ret;
     void *ptr;
     ret = posix_memalign(&ptr, alignment, size);
-    if (ret != 0)
+    if (ret != 0) {
+        fprintf(stderr, "Failed to allocate %zu B: %s\n",
+                size, strerror(errno));
         abort();
+    }
     return ptr;
 #elif defined(CONFIG_BSD)
     return oom_check(valloc(size));
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Tell users about out-of-memory errors
  2010-01-20 21:16 [Qemu-devel] [PATCH] Tell users about out-of-memory errors Stefan Weil
@ 2010-01-20 23:13 ` malc
  2010-01-21 21:24   ` Stefan Weil
  0 siblings, 1 reply; 4+ messages in thread
From: malc @ 2010-01-20 23:13 UTC (permalink / raw)
  To: Stefan Weil; +Cc: QEMU Developers

On Wed, 20 Jan 2010, Stefan Weil wrote:

> Aborting without an error message when memory is short
> is not helpful, so print the reason for the abort.
> 
> Try
> 	qemu -m 1000000
> to force an out-of-memory error.

The patch is wrong for, at least, Windows.

> 
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  osdep.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/osdep.c b/osdep.c
> index 1310684..5d4e810 100644
> --- a/osdep.c
> +++ b/osdep.c
> @@ -52,6 +52,7 @@
>  static void *oom_check(void *ptr)
>  {
>      if (ptr == NULL) {
> +        perror("qemu (memory allocation)");
>          abort();
>      }
>      return ptr;
> @@ -91,8 +92,11 @@ void *qemu_memalign(size_t alignment, size_t size)
>      int ret;
>      void *ptr;
>      ret = posix_memalign(&ptr, alignment, size);
> -    if (ret != 0)
> +    if (ret != 0) {
> +        fprintf(stderr, "Failed to allocate %zu B: %s\n",
> +                size, strerror(errno));
>          abort();
> +    }
>      return ptr;
>  #elif defined(CONFIG_BSD)
>      return oom_check(valloc(size));
> 

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH] Tell users about out-of-memory errors
  2010-01-20 23:13 ` malc
@ 2010-01-21 21:24   ` Stefan Weil
  2010-01-27  0:06     ` Anthony Liguori
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Weil @ 2010-01-21 21:24 UTC (permalink / raw)
  To: QEMU Developers, av1474

Aborting without an error message when memory is short
is not helpful, so print the reason for the abort.

Try
	qemu -m 1000000
or
	qemu -m 2000 (win32)

to force an out-of-memory error.

v2:
* Fix error message for win32.
* Fix error message for posix_memalign.

Thanks to malc for the hints.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 osdep.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/osdep.c b/osdep.c
index 1310684..9b47066 100644
--- a/osdep.c
+++ b/osdep.c
@@ -52,6 +52,11 @@
 static void *oom_check(void *ptr)
 {
     if (ptr == NULL) {
+#if defined(_WIN32)
+        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
+#else
+        fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno));
+#endif
         abort();
     }
     return ptr;
@@ -91,8 +96,11 @@ void *qemu_memalign(size_t alignment, size_t size)
     int ret;
     void *ptr;
     ret = posix_memalign(&ptr, alignment, size);
-    if (ret != 0)
+    if (ret != 0) {
+        fprintf(stderr, "Failed to allocate %zu B: %s\n",
+                size, strerror(ret));
         abort();
+    }
     return ptr;
 #elif defined(CONFIG_BSD)
     return oom_check(valloc(size));
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Tell users about out-of-memory errors
  2010-01-21 21:24   ` Stefan Weil
@ 2010-01-27  0:06     ` Anthony Liguori
  0 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2010-01-27  0:06 UTC (permalink / raw)
  To: Stefan Weil; +Cc: QEMU Developers

On 01/21/2010 03:24 PM, Stefan Weil wrote:
> Aborting without an error message when memory is short
> is not helpful, so print the reason for the abort.
>
> Try
> 	qemu -m 1000000
> or
> 	qemu -m 2000 (win32)
>
> to force an out-of-memory error.
>
> v2:
> * Fix error message for win32.
> * Fix error message for posix_memalign.
>
> Thanks to malc for the hints.
>
> Signed-off-by: Stefan Weil<weil@mail.berlios.de>
>    

Applied.  Thanks.

Regards,

Anthony Liguori
> ---
>   osdep.c |   10 +++++++++-
>   1 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/osdep.c b/osdep.c
> index 1310684..9b47066 100644
> --- a/osdep.c
> +++ b/osdep.c
> @@ -52,6 +52,11 @@
>   static void *oom_check(void *ptr)
>   {
>       if (ptr == NULL) {
> +#if defined(_WIN32)
> +        fprintf(stderr, "Failed to allocate memory: %lu\n", GetLastError());
> +#else
> +        fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno));
> +#endif
>           abort();
>       }
>       return ptr;
> @@ -91,8 +96,11 @@ void *qemu_memalign(size_t alignment, size_t size)
>       int ret;
>       void *ptr;
>       ret = posix_memalign(&ptr, alignment, size);
> -    if (ret != 0)
> +    if (ret != 0) {
> +        fprintf(stderr, "Failed to allocate %zu B: %s\n",
> +                size, strerror(ret));
>           abort();
> +    }
>       return ptr;
>   #elif defined(CONFIG_BSD)
>       return oom_check(valloc(size));
>    

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-27  0:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-20 21:16 [Qemu-devel] [PATCH] Tell users about out-of-memory errors Stefan Weil
2010-01-20 23:13 ` malc
2010-01-21 21:24   ` Stefan Weil
2010-01-27  0:06     ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).