All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Cornelia Huck <cohuck@redhat.com>,
	david@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com,
	kvm@vger.kernel.org
Subject: Re: [PATCH v3 1/4] balloon: Allow multiple inhibit users
Date: Tue, 7 Aug 2018 22:44:11 +0300	[thread overview]
Message-ID: <20180807224339-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20180807193125.30378-2-alex.williamson@redhat.com>

On Tue, Aug 07, 2018 at 01:31:22PM -0600, Alex Williamson wrote:
> A simple true/false internal state does not allow multiple users.  Fix
> this within the existing interface by converting to a counter, so long
> as the counter is elevated, ballooning is inhibited.
> 
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Peter Xu <peterx@redhat.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>  balloon.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/balloon.c b/balloon.c
> index 6bf0a9681377..931987983858 100644
> --- a/balloon.c
> +++ b/balloon.c
> @@ -26,6 +26,7 @@
>  
>  #include "qemu/osdep.h"
>  #include "qemu-common.h"
> +#include "qemu/atomic.h"
>  #include "exec/cpu-common.h"
>  #include "sysemu/kvm.h"
>  #include "sysemu/balloon.h"
> @@ -37,16 +38,22 @@
>  static QEMUBalloonEvent *balloon_event_fn;
>  static QEMUBalloonStatus *balloon_stat_fn;
>  static void *balloon_opaque;
> -static bool balloon_inhibited;
> +static int balloon_inhibit_count;
>  
>  bool qemu_balloon_is_inhibited(void)
>  {
> -    return balloon_inhibited;
> +    return atomic_read(&balloon_inhibit_count) > 0;
>  }
>  
>  void qemu_balloon_inhibit(bool state)
>  {
> -    balloon_inhibited = state;
> +    if (state) {
> +        atomic_inc(&balloon_inhibit_count);
> +    } else {
> +        atomic_dec(&balloon_inhibit_count);
> +    }
> +
> +    assert(atomic_read(&balloon_inhibit_count) >= 0);
>  }
>  
>  static bool have_balloon(Error **errp)

This blocks QEMU_MADV_WONTNEED but it also blocks QEMU_MADV_WILLNEED.
Is this necessarily a good idea?

> -- 
> 2.18.0

WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: qemu-devel@nongnu.org, peterx@redhat.com,
	Cornelia Huck <cohuck@redhat.com>,
	kvm@vger.kernel.org, david@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 1/4] balloon: Allow multiple inhibit users
Date: Tue, 7 Aug 2018 22:44:11 +0300	[thread overview]
Message-ID: <20180807224339-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20180807193125.30378-2-alex.williamson@redhat.com>

On Tue, Aug 07, 2018 at 01:31:22PM -0600, Alex Williamson wrote:
> A simple true/false internal state does not allow multiple users.  Fix
> this within the existing interface by converting to a counter, so long
> as the counter is elevated, ballooning is inhibited.
> 
> Reviewed-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Peter Xu <peterx@redhat.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>  balloon.c | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/balloon.c b/balloon.c
> index 6bf0a9681377..931987983858 100644
> --- a/balloon.c
> +++ b/balloon.c
> @@ -26,6 +26,7 @@
>  
>  #include "qemu/osdep.h"
>  #include "qemu-common.h"
> +#include "qemu/atomic.h"
>  #include "exec/cpu-common.h"
>  #include "sysemu/kvm.h"
>  #include "sysemu/balloon.h"
> @@ -37,16 +38,22 @@
>  static QEMUBalloonEvent *balloon_event_fn;
>  static QEMUBalloonStatus *balloon_stat_fn;
>  static void *balloon_opaque;
> -static bool balloon_inhibited;
> +static int balloon_inhibit_count;
>  
>  bool qemu_balloon_is_inhibited(void)
>  {
> -    return balloon_inhibited;
> +    return atomic_read(&balloon_inhibit_count) > 0;
>  }
>  
>  void qemu_balloon_inhibit(bool state)
>  {
> -    balloon_inhibited = state;
> +    if (state) {
> +        atomic_inc(&balloon_inhibit_count);
> +    } else {
> +        atomic_dec(&balloon_inhibit_count);
> +    }
> +
> +    assert(atomic_read(&balloon_inhibit_count) >= 0);
>  }
>  
>  static bool have_balloon(Error **errp)

This blocks QEMU_MADV_WONTNEED but it also blocks QEMU_MADV_WILLNEED.
Is this necessarily a good idea?

> -- 
> 2.18.0

  reply	other threads:[~2018-08-07 19:44 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07 19:31 [PATCH v3 0/4] Balloon inhibit enhancements, vfio restriction Alex Williamson
2018-08-07 19:31 ` [Qemu-devel] " Alex Williamson
2018-08-07 19:31 ` [PATCH v3 1/4] balloon: Allow multiple inhibit users Alex Williamson
2018-08-07 19:31   ` [Qemu-devel] " Alex Williamson
2018-08-07 19:44   ` Michael S. Tsirkin [this message]
2018-08-07 19:44     ` Michael S. Tsirkin
2018-08-07 20:08     ` Alex Williamson
2018-08-07 20:08       ` [Qemu-devel] " Alex Williamson
2018-08-08  0:07       ` Michael S. Tsirkin
2018-08-08  0:07         ` [Qemu-devel] " Michael S. Tsirkin
2018-08-07 19:31 ` [PATCH v3 2/4] kvm: Use inhibit to prevent ballooning without synchronous mmu Alex Williamson
2018-08-07 19:31   ` [Qemu-devel] " Alex Williamson
2018-08-16 18:15   ` Alex Williamson
2018-08-16 18:15     ` [Qemu-devel] " Alex Williamson
2018-08-17  7:46     ` Paolo Bonzini
2018-08-17  7:46       ` [Qemu-devel] " Paolo Bonzini
2018-08-07 19:31 ` [PATCH v3 3/4] vfio: Inhibit ballooning based on group attachment to a container Alex Williamson
2018-08-07 19:31   ` [Qemu-devel] " Alex Williamson
2018-08-08  3:38   ` Peter Xu
2018-08-08  3:38     ` [Qemu-devel] " Peter Xu
2018-08-07 19:31 ` [PATCH v3 4/4] vfio/ccw/pci: Allow devices to opt-in for ballooning Alex Williamson
2018-08-07 19:31   ` [Qemu-devel] " Alex Williamson
2018-08-07 19:44 ` [PATCH v3 0/4] Balloon inhibit enhancements, vfio restriction Michael S. Tsirkin
2018-08-07 19:44   ` [Qemu-devel] " Michael S. Tsirkin
2018-08-07 19:53   ` Alex Williamson
2018-08-07 19:53     ` [Qemu-devel] " Alex Williamson
2018-08-07 21:58     ` Michael S. Tsirkin
2018-08-07 21:58       ` [Qemu-devel] " Michael S. Tsirkin
2018-08-07 22:40       ` Alex Williamson
2018-08-07 22:40         ` [Qemu-devel] " Alex Williamson
2018-08-08  0:02         ` Michael S. Tsirkin
2018-08-08  0:02           ` [Qemu-devel] " Michael S. Tsirkin
2018-08-08  3:45       ` Peter Xu
2018-08-08  3:45         ` [Qemu-devel] " Peter Xu
2018-08-08 22:23         ` Alex Williamson
2018-08-08 22:23           ` [Qemu-devel] " Alex Williamson
2018-08-09  9:20           ` Michael S. Tsirkin
2018-08-09  9:20             ` [Qemu-devel] " Michael S. Tsirkin
2018-08-09  9:23         ` Michael S. Tsirkin
2018-08-09  9:23           ` [Qemu-devel] " Michael S. Tsirkin
2018-08-09  9:37           ` Peter Xu
2018-08-09  9:37             ` [Qemu-devel] " Peter Xu
2018-08-09 10:13             ` Michael S. Tsirkin
2018-08-09 10:13               ` [Qemu-devel] " Michael S. Tsirkin

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=20180807224339-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.