qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: "Peter Maydell" <peter.maydell@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>
Cc: "Daniel P. Berrange" <berrange@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [RFC PATCH] docs/devel: expand style section of memory management
Date: Mon, 15 Mar 2021 18:04:10 +0100	[thread overview]
Message-ID: <b5db40d9-1a51-3690-a1ac-0ac345619376@redhat.com> (raw)
In-Reply-To: <CAFEAcA8gnFdOprY=yj+voN+DJ44zx3+9ABM3yMPdWJSQ3X6QrQ@mail.gmail.com>

On 15/03/2021 17.57, Peter Maydell wrote:
> On Mon, 15 Mar 2021 at 16:53, Alex Bennée <alex.bennee@linaro.org> wrote:
>> -Prefer g_new(T, n) instead of g_malloc(sizeof(T) ``*`` n) for the following
>> +Care should be taken to avoid introducing places where the guest could
>> +trigger an exit. For example using ``g_malloc`` on start-up is fine
>> +if the result of a failure is going to be a fatal exit anyway. There
>> +may be some start-up cases where failing is unreasonable (for example
>> +speculatively loading debug symbols).
>> +
>> +However if we are doing an allocation because of something the guest
>> +has done we should never trigger an exit. The code may deal with this
>> +by trying to allocate less memory and continue or re-designed to allocate
>> +buffers on start-up.
> 
> I think this is overly strong. We want to avoid malloc-or-die for
> cases where the guest gets to decide how big the allocation is;
> but if we're doing a single small fixed-size allocation that happens
> to be triggered by a guest action we should be OK to g_malloc() that
> I think.

I agree with Peter. If the host is so much out-of-memory that we even can't 
allocate some few bytes anymore (let's say less than 4k), the system is 
pretty much dead anyway and it might be better to terminate the program 
immediately instead of continuing with the out-of-memory situation.

  Thomas



  reply	other threads:[~2021-03-15 17:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 16:53 [RFC PATCH] docs/devel: expand style section of memory management Alex Bennée
2021-03-15 16:57 ` Peter Maydell
2021-03-15 17:04   ` Thomas Huth [this message]
2021-03-15 17:09     ` Daniel P. Berrangé
2021-03-15 17:54       ` Alex Bennée
2021-03-15 18:06         ` Daniel P. Berrangé
2021-03-16  9:29       ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b5db40d9-1a51-3690-a1ac-0ac345619376@redhat.com \
    --to=thuth@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).