public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wei Wang <wei.w.wang@intel.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, linux-kernel@vger.kernel.org
Cc: Khazhismel Kumykov <khazhy@google.com>,
	Jason Wang <jasowang@redhat.com>,
	virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts
Date: Tue, 19 Nov 2019 20:24:55 +0800	[thread overview]
Message-ID: <5DD3DF17.9050504@intel.com> (raw)
In-Reply-To: <20191119102838.39380-2-mst@redhat.com>

On 11/19/2019 06:29 PM, Michael S. Tsirkin wrote:
> We managed to get confused about the shift direction at least once.
> Let's switch to division/multiplcation instead. Add a number of pages
> macro for this purpose.  We still keep the order macro around too since
> this is what alloc/free pages want.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>   drivers/virtio/virtio_balloon.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index b6a95cd28d9f..dc1ebd638e9b 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -36,6 +36,7 @@
>   /* The size of a free page block in bytes */
>   #define VIRTIO_BALLOON_HINT_BLOCK_BYTES \
>   	(1 << (VIRTIO_BALLOON_HINT_BLOCK_ORDER + PAGE_SHIFT))
> +#define VIRTIO_BALLOON_HINT_BLOCK_PAGES (1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER)
>   
>   #ifdef CONFIG_BALLOON_COMPACTION
>   static struct vfsmount *balloon_mnt;
> @@ -765,11 +766,11 @@ static unsigned long shrink_free_pages(struct virtio_balloon *vb,
>   	unsigned long blocks_to_free, blocks_freed;
>   
>   	pages_to_free = round_up(pages_to_free,
> -				 1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER);
> -	blocks_to_free = pages_to_free >> VIRTIO_BALLOON_HINT_BLOCK_ORDER;
> +				 VIRTIO_BALLOON_HINT_BLOCK_PAGES);
> +	blocks_to_free = pages_to_free / VIRTIO_BALLOON_HINT_BLOCK_PAGES;
>   	blocks_freed = return_free_pages_to_mm(vb, blocks_to_free);
>   
> -	return blocks_freed << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
> +	return blocks_freed * VIRTIO_BALLOON_HINT_BLOCK_PAGES;
>   }
>   
>   static unsigned long leak_balloon_pages(struct virtio_balloon *vb,
> @@ -825,7 +826,7 @@ static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker,
>   	unsigned long count;
>   
>   	count = vb->num_pages / VIRTIO_BALLOON_PAGES_PER_PAGE;
> -	count += vb->num_free_page_blocks << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
> +	count += vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES;
>   
>   	return count;
>   }

Reviewed-by: Wei Wang <wei.w.wang@intel.com>

Best,
Wei

  parent reply	other threads:[~2019-11-19 12:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19 10:29 [PATCH 1/2] virtio_balloon: name cleanups Michael S. Tsirkin
2019-11-19 10:29 ` [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts Michael S. Tsirkin
2019-11-19 11:38   ` David Hildenbrand
2019-11-19 12:24   ` Wei Wang [this message]
2019-11-19 11:37 ` [PATCH 1/2] virtio_balloon: name cleanups David Hildenbrand
2019-11-19 12:18 ` Wei Wang

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=5DD3DF17.9050504@intel.com \
    --to=wei.w.wang@intel.com \
    --cc=jasowang@redhat.com \
    --cc=khazhy@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.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