virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@parallels.com>
Cc: den@openvz.org, virtualization@lists.linux-foundation.org,
	Raushaniya Maksudova <rmaksudova@parallels.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [PATCH 1/2] virtio_balloon: return the amount of freed memory from leak_balloon()
Date: Wed,  8 Oct 2014 14:21:08 +0400	[thread overview]
Message-ID: <1412763669-2980-2-git-send-email-den@parallels.com> (raw)
In-Reply-To: <1412763669-2980-1-git-send-email-den@parallels.com>

From: Raushaniya Maksudova <rmaksudova@parallels.com>

This value would be useful in the next patch to provide the amount of
the freed memory for OOM killer.

Accessing to vb->num_pfns outside of vb->balloon_lock is wrong and unsafe.

Signed-off-by: Raushaniya Maksudova <rmaksudova@parallels.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Rusty Russell <rusty@rustcorp.com.au>
CC: Michael S. Tsirkin <mst@redhat.com>
CC: virtualization@lists.linux-foundation.org
---
 drivers/virtio/virtio_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 25ebe8e..213da41 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -168,8 +168,9 @@ static void release_pages_by_pfn(const u32 pfns[], unsigned int num)
 	}
 }
 
-static void leak_balloon(struct virtio_balloon *vb, size_t num)
+static unsigned leak_balloon(struct virtio_balloon *vb, size_t num)
 {
+	unsigned num_freed_pages;
 	struct page *page;
 	struct balloon_dev_info *vb_dev_info = vb->vb_dev_info;
 
@@ -186,6 +187,7 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
 		vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
 	}
 
+	num_freed_pages = vb->num_pfns;
 	/*
 	 * Note that if
 	 * virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
@@ -195,6 +197,7 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
 		tell_host(vb, vb->deflate_vq);
 	mutex_unlock(&vb->balloon_lock);
 	release_pages_by_pfn(vb->pfns, vb->num_pfns);
+	return num_freed_pages;
 }
 
 static inline void update_stat(struct virtio_balloon *vb, int idx,
-- 
1.9.1

  reply	other threads:[~2014-10-08 10:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-08 10:21 [PATCH 0/2] shrink virtio baloon on OOM in guest Denis V. Lunev
2014-10-08 10:21 ` Denis V. Lunev [this message]
2014-10-08 10:21 ` [PATCH 2/2] virtio_balloon: free some memory from baloon on OOM Denis V. Lunev
2014-10-13  5:32   ` Rusty Russell
2014-10-13  7:01     ` Denis V. Lunev
2014-10-13  7:22     ` Michael S. Tsirkin
2014-10-13 23:44       ` Rusty Russell
2014-10-14  9:10         ` Michael S. Tsirkin
2014-10-15  5:37           ` Rusty Russell
2014-10-15  6:32           ` Denis V. Lunev
  -- strict thread matches above, loose matches on Subject: below --
2014-10-15  4:38 [PATCH v2 0/2] shrink virtio baloon on OOM in guest Denis V. Lunev
2014-10-15  4:38 ` [PATCH 1/2] virtio_balloon: return the amount of freed memory from leak_balloon() Denis V. Lunev
2014-10-15 15:47 [PATCH v3 0/2] shrink virtio baloon on OOM in guest Denis V. Lunev
2014-10-15 15:47 ` [PATCH 1/2] virtio_balloon: return the amount of freed memory from leak_balloon() Denis V. Lunev

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=1412763669-2980-2-git-send-email-den@parallels.com \
    --to=den@parallels.com \
    --cc=den@openvz.org \
    --cc=mst@redhat.com \
    --cc=rmaksudova@parallels.com \
    --cc=virtualization@lists.linux-foundation.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 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).