From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZvQn-0000Pu-JR for qemu-devel@nongnu.org; Tue, 26 Jan 2010 19:06:49 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZvQj-0000OK-0l for qemu-devel@nongnu.org; Tue, 26 Jan 2010 19:06:49 -0500 Received: from [199.232.76.173] (port=60596 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZvQi-0000OC-Pc for qemu-devel@nongnu.org; Tue, 26 Jan 2010 19:06:44 -0500 Received: from mail-iw0-f188.google.com ([209.85.223.188]:39899) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NZvQi-00063J-64 for qemu-devel@nongnu.org; Tue, 26 Jan 2010 19:06:44 -0500 Received: by mail-iw0-f188.google.com with SMTP id 26so5513513iwn.14 for ; Tue, 26 Jan 2010 16:06:43 -0800 (PST) Message-ID: <4B5F8390.5080807@codemonkey.ws> Date: Tue, 26 Jan 2010 18:06:40 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] Tell users about out-of-memory errors References: <1264109098-14373-1-git-send-email-weil@mail.berlios.de> In-Reply-To: <1264109098-14373-1-git-send-email-weil@mail.berlios.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 > 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)); >