From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJ5jD-0003u0-Vu for qemu-devel@nongnu.org; Thu, 27 Feb 2014 13:30:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WJ5j5-0008E0-Id for qemu-devel@nongnu.org; Thu, 27 Feb 2014 13:30:39 -0500 Received: from mail-qc0-x236.google.com ([2607:f8b0:400d:c01::236]:46851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJ5j5-0008Dv-BK for qemu-devel@nongnu.org; Thu, 27 Feb 2014 13:30:31 -0500 Received: by mail-qc0-f182.google.com with SMTP id e16so1873153qcx.41 for ; Thu, 27 Feb 2014 10:30:30 -0800 (PST) Sender: Paolo Bonzini Message-ID: <530F8442.7090007@redhat.com> Date: Thu, 27 Feb 2014 19:30:26 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <20140204184153.GA25368@amt.cnet> In-Reply-To: <20140204184153.GA25368@amt.cnet> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] file_ram_alloc: unify mem-path, mem-prealloc error handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcelo Tosatti , qemu-devel , kvm-devel Il 04/02/2014 19:41, Marcelo Tosatti ha scritto: > > -mem-prealloc asks to preallocate memory residing on -mem-path path. > > Currently QEMU exits in case: > > - Memory file has been created but allocation via explicit write > fails. > > And it fallbacks to malloc in case: > - Querying huge page size fails. > - Lack of sync MMU support. > - Open fails. > - mmap fails. > > Have the same behaviour for all cases: fail in case -mem-path and > -mem-prealloc are specified for regions where the requested size is > suitable for hugepages. > > Signed-off-by: Marcelo Tosatti Once we introduce memdev, I believe -mem-path should always exit, and never fall back to malloc/MAP_ANON. For 2.0, I'm applying the patch to uq/master. Paolo > diff --git a/exec.c b/exec.c > index 9ad0a4b..1da1ba7 100644 > --- a/exec.c > +++ b/exec.c > @@ -996,7 +996,7 @@ static void *file_ram_alloc(RAMBlock *block, > > hpagesize = gethugepagesize(path); > if (!hpagesize) { > - return NULL; > + goto error; > } > > if (memory < hpagesize) { > @@ -1005,7 +1005,7 @@ static void *file_ram_alloc(RAMBlock *block, > > if (kvm_enabled() && !kvm_has_sync_mmu()) { > fprintf(stderr, "host lacks kvm mmu notifiers, -mem-path unsupported\n"); > - return NULL; > + goto error; > } > > /* Make name safe to use with mkstemp by replacing '/' with '_'. */ > @@ -1023,7 +1023,7 @@ static void *file_ram_alloc(RAMBlock *block, > if (fd < 0) { > perror("unable to create backing store for hugepages"); > g_free(filename); > - return NULL; > + goto error; > } > unlink(filename); > g_free(filename); > @@ -1043,7 +1043,7 @@ static void *file_ram_alloc(RAMBlock *block, > if (area == MAP_FAILED) { > perror("file_ram_alloc: can't mmap RAM pages"); > close(fd); > - return (NULL); > + goto error; > } > > if (mem_prealloc) { > @@ -1087,6 +1087,12 @@ static void *file_ram_alloc(RAMBlock *block, > > block->fd = fd; > return area; > + > +error: > + if (mem_prealloc) { > + exit(1); > + } > + return NULL; > } > #else > static void *file_ram_alloc(RAMBlock *block, >