Received: from eggs.gnu.org ([2001:4830:134:3::10]:47369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aA2NK-0000CO-4X for qemu-devel@nongnu.org; Fri, 18 Dec 2015 16:15:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aA2NG-00078M-Pk for qemu-devel@nongnu.org; Fri, 18 Dec 2015 16:15:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43154) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aA2NG-00078H-Jx for qemu-devel@nongnu.org; Fri, 18 Dec 2015 16:15:38 -0500 From: Markus Armbruster References: <1450452647-118105-1-git-send-email-imammedo@redhat.com> <1450452647-118105-3-git-send-email-imammedo@redhat.com> <20151218164823.GH7228@redhat.com> <567441AA.1010309@redhat.com> Date: Fri, 18 Dec 2015 22:15:35 +0100 In-Reply-To: <567441AA.1010309@redhat.com> (Eric Blake's message of "Fri, 18 Dec 2015 10:26:02 -0700") Message-ID: <87wpsbwj9k.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 2/2] qdev: safely fail device_add if unable to allocate device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Igor Mammedov , qemu-devel@nongnu.org, afaerber@suse.de, pbonzini@redhat.com Eric Blake writes: > On 12/18/2015 09:48 AM, Daniel P. Berrange wrote: >> On Fri, Dec 18, 2015 at 04:30:47PM +0100, Igor Mammedov wrote: >>> qdev_device_add() currently uses object_new() which >>> will abort if there memory allocation for device instance >>> fails. While it's fine it startup, it is not desirable >>> diring hotplug. >>> >>> Try to allocate memory for object first and fail safely >>> if allocation fails. >>> > >> This just avoids one small malloc failure. >> >>> + object_initialize(dev, obj_size, driver); >> >> This is going to call g_new many more times, so you'll >> still hit OOM almost immediately. eg the call to >> g_hash_table_new_full() in object_initialize_with_type >> will abort on OOM, not to mention anything run in a >> instance constructor function registered against the >> class. There's no way to avoid this given that we have >> chosen to use GLib in QEMU, so I don't really see any >> point in replacing the 'object_new' call with g_try_malloc Seconded. > We just had a recent thread on it, and I tend to agree that this series > isn't helpful. > > https://lists.gnu.org/archive/html/qemu-devel/2015-12/threads.html#01238 Plenty of arguments there why recovering from scattered random allocation failures isn't useful, and recovering from all of them isn't practical. Limit recovery attempts to big allocations, and spend (some of) the saved cycles on actually testing the recovery code. [...]