From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael S. Tsirkin" Subject: Re: [PATCH v3 1/4] balloon: Allow multiple inhibit users Date: Tue, 7 Aug 2018 22:44:11 +0300 Message-ID: <20180807224339-mutt-send-email-mst@kernel.org> References: <20180807193125.30378-1-alex.williamson@redhat.com> <20180807193125.30378-2-alex.williamson@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Cornelia Huck , david@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, kvm@vger.kernel.org To: Alex Williamson Return-path: Content-Disposition: inline In-Reply-To: <20180807193125.30378-2-alex.williamson@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel2=m.gmane.org@nongnu.org Sender: "Qemu-devel" List-Id: kvm.vger.kernel.org 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 > Reviewed-by: Peter Xu > Reviewed-by: Cornelia Huck > Signed-off-by: Alex Williamson > --- > 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