From: Khazhismel Kumykov <khazhy@google.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: jasowang@redhat.com, wei.w.wang@intel.com,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 1/2] virtio_balloon: fix pages_to_free calculation
Date: Mon, 18 Nov 2019 15:20:47 -0800 [thread overview]
Message-ID: <CACGdZYLQ9R0nrLu7vftWx5feK=rGSiOmwes2-Wv6xSHN7a-dhA@mail.gmail.com> (raw)
In-Reply-To: <20191118175648-mutt-send-email-mst@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 2730 bytes --]
On Mon, Nov 18, 2019 at 3:09 PM Michael S. Tsirkin <mst@redhat.com> wrote:
>
>
> So I really think we should do something like the below instead.
> Limit playing with balloon pages so we can gradually limit it to legacy.
> Testing, review would be appreciated.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
>
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 226fbb995fb0..7cee05cdf3fb 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -772,6 +772,13 @@ static unsigned long shrink_free_pages(struct virtio_balloon *vb,
> return blocks_freed << VIRTIO_BALLOON_FREE_PAGE_ORDER;
> }
>
> +static unsigned long leak_balloon_pages(struct virtio_balloon *vb,
> + unsigned long pages_to_free)
> +{
> + return leak_balloon(vb, pages_to_free * VIRTIO_BALLOON_PAGES_PER_PAGE) /
> + VIRTIO_BALLOON_PAGES_PER_PAGE;
> +}
> +
> static unsigned long shrink_balloon_pages(struct virtio_balloon *vb,
> unsigned long pages_to_free)
> {
> @@ -782,11 +789,9 @@ static unsigned long shrink_balloon_pages(struct virtio_balloon *vb,
> * VIRTIO_BALLOON_ARRAY_PFNS_MAX balloon pages, so we call it
> * multiple times to deflate pages till reaching pages_to_free.
> */
> - while (vb->num_pages && pages_to_free) {
> - pages_freed += leak_balloon(vb, pages_to_free) /
> - VIRTIO_BALLOON_PAGES_PER_PAGE;
> - pages_to_free -= pages_freed;
> - }
> + while (vb->num_pages && pages_freed < pages_to_free)
> + pages_freed += leak_balloon_pages(vb, pages_to_free);
> +
> update_balloon_size(vb);
>
> return pages_freed;
> @@ -799,7 +804,7 @@ static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker,
> struct virtio_balloon *vb = container_of(shrinker,
> struct virtio_balloon, shrinker);
>
> - pages_to_free = sc->nr_to_scan * VIRTIO_BALLOON_PAGES_PER_PAGE;
> + pages_to_free = sc->nr_to_scan;
>
> if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
> pages_freed = shrink_free_pages(vb, pages_to_free);
>
I got confused about shrink_free_pages, since, looking at the
operations the function *should* return the same units it takes in.
However, it does look like it should be operating on system pages
(VIRTIO_BALLOON_FREE_PAGE_ORDER is the order of our real page
allocations), so the multiplication on nr_to_scan is where we messed
up. OK. Sorry for the mixup :)
Your patch looks correct to me.
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4843 bytes --]
next prev parent reply other threads:[~2019-11-18 23:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-15 22:55 [PATCH] virtio_balloon: fix shrinker pages_to_free calculation Khazhismel Kumykov
2019-11-18 4:01 ` Wei Wang
2019-11-18 5:30 ` Michael S. Tsirkin
2019-11-18 7:42 ` Wei Wang
2019-11-18 8:26 ` Michael S. Tsirkin
2019-11-18 10:31 ` Wei Wang
2019-11-18 5:26 ` Michael S. Tsirkin
2019-11-18 21:30 ` Khazhismel Kumykov
2019-11-18 21:38 ` [PATCH 1/2] virtio_balloon: fix " Khazhismel Kumykov
2019-11-18 21:38 ` [PATCH 2/2] virtio_balloon: fix shrinker_scan return units Khazhismel Kumykov
2019-11-18 22:56 ` Michael S. Tsirkin
2019-11-18 22:52 ` [PATCH 1/2] virtio_balloon: fix pages_to_free calculation Michael S. Tsirkin
2019-11-18 23:08 ` Michael S. Tsirkin
2019-11-18 23:20 ` Khazhismel Kumykov [this message]
2019-11-19 5:38 ` Wei Wang
2019-11-19 9:37 ` 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='CACGdZYLQ9R0nrLu7vftWx5feK=rGSiOmwes2-Wv6xSHN7a-dhA@mail.gmail.com' \
--to=khazhy@google.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=wei.w.wang@intel.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).