linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] virtio_balloon: name cleanups
@ 2019-11-19 10:29 Michael S. Tsirkin
  2019-11-19 10:29 ` [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts Michael S. Tsirkin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2019-11-19 10:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: Wei Wang, Khazhismel Kumykov, Jason Wang, virtualization

free_page_order is a confusing name. It's not a page order
actually, it's the order of the block of memory we are hinting.
Rename to hint_block_order. Also, rename SIZE to BYTES
to make it clear it's the block size in bytes.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/virtio/virtio_balloon.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 65df40f261ab..b6a95cd28d9f 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -32,10 +32,10 @@
 #define VIRTIO_BALLOON_FREE_PAGE_ALLOC_FLAG (__GFP_NORETRY | __GFP_NOWARN | \
 					     __GFP_NOMEMALLOC)
 /* The order of free page blocks to report to host */
-#define VIRTIO_BALLOON_FREE_PAGE_ORDER (MAX_ORDER - 1)
+#define VIRTIO_BALLOON_HINT_BLOCK_ORDER (MAX_ORDER - 1)
 /* The size of a free page block in bytes */
-#define VIRTIO_BALLOON_FREE_PAGE_SIZE \
-	(1 << (VIRTIO_BALLOON_FREE_PAGE_ORDER + PAGE_SHIFT))
+#define VIRTIO_BALLOON_HINT_BLOCK_BYTES \
+	(1 << (VIRTIO_BALLOON_HINT_BLOCK_ORDER + PAGE_SHIFT))
 
 #ifdef CONFIG_BALLOON_COMPACTION
 static struct vfsmount *balloon_mnt;
@@ -380,7 +380,7 @@ static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
 		if (!page)
 			break;
 		free_pages((unsigned long)page_address(page),
-			   VIRTIO_BALLOON_FREE_PAGE_ORDER);
+			   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
 	}
 	vb->num_free_page_blocks -= num_returned;
 	spin_unlock_irq(&vb->free_page_list_lock);
@@ -582,7 +582,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
 		;
 
 	page = alloc_pages(VIRTIO_BALLOON_FREE_PAGE_ALLOC_FLAG,
-			   VIRTIO_BALLOON_FREE_PAGE_ORDER);
+			   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
 	/*
 	 * When the allocation returns NULL, it indicates that we have got all
 	 * the possible free pages, so return -EINTR to stop.
@@ -591,13 +591,13 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
 		return -EINTR;
 
 	p = page_address(page);
-	sg_init_one(&sg, p, VIRTIO_BALLOON_FREE_PAGE_SIZE);
+	sg_init_one(&sg, p, VIRTIO_BALLOON_HINT_BLOCK_BYTES);
 	/* There is always 1 entry reserved for the cmd id to use. */
 	if (vq->num_free > 1) {
 		err = virtqueue_add_inbuf(vq, &sg, 1, p, GFP_KERNEL);
 		if (unlikely(err)) {
 			free_pages((unsigned long)p,
-				   VIRTIO_BALLOON_FREE_PAGE_ORDER);
+				   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
 			return err;
 		}
 		virtqueue_kick(vq);
@@ -610,7 +610,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
 		 * The vq has no available entry to add this page block, so
 		 * just free it.
 		 */
-		free_pages((unsigned long)p, VIRTIO_BALLOON_FREE_PAGE_ORDER);
+		free_pages((unsigned long)p, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
 	}
 
 	return 0;
@@ -765,11 +765,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_FREE_PAGE_ORDER);
-	blocks_to_free = pages_to_free >> VIRTIO_BALLOON_FREE_PAGE_ORDER;
+				 1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER);
+	blocks_to_free = pages_to_free >> VIRTIO_BALLOON_HINT_BLOCK_ORDER;
 	blocks_freed = return_free_pages_to_mm(vb, blocks_to_free);
 
-	return blocks_freed << VIRTIO_BALLOON_FREE_PAGE_ORDER;
+	return blocks_freed << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
 }
 
 static unsigned long leak_balloon_pages(struct virtio_balloon *vb,
@@ -825,7 +825,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_FREE_PAGE_ORDER;
+	count += vb->num_free_page_blocks << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
 
 	return count;
 }
-- 
MST


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts
  2019-11-19 10:29 [PATCH 1/2] virtio_balloon: name cleanups Michael S. Tsirkin
@ 2019-11-19 10:29 ` Michael S. Tsirkin
  2019-11-19 11:38   ` David Hildenbrand
  2019-11-19 12:24   ` Wei Wang
  2019-11-19 11:37 ` [PATCH 1/2] virtio_balloon: name cleanups David Hildenbrand
  2019-11-19 12:18 ` Wei Wang
  2 siblings, 2 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2019-11-19 10:29 UTC (permalink / raw)
  To: linux-kernel; +Cc: Wei Wang, Khazhismel Kumykov, Jason Wang, virtualization

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;
 }
-- 
MST


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] virtio_balloon: name cleanups
  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:37 ` David Hildenbrand
  2019-11-19 12:18 ` Wei Wang
  2 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2019-11-19 11:37 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: Wei Wang, Khazhismel Kumykov, Jason Wang, virtualization

On 19.11.19 11:29, Michael S. Tsirkin wrote:
> free_page_order is a confusing name. It's not a page order
> actually, it's the order of the block of memory we are hinting.
> Rename to hint_block_order. Also, rename SIZE to BYTES
> to make it clear it's the block size in bytes.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>   drivers/virtio/virtio_balloon.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 65df40f261ab..b6a95cd28d9f 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -32,10 +32,10 @@
>   #define VIRTIO_BALLOON_FREE_PAGE_ALLOC_FLAG (__GFP_NORETRY | __GFP_NOWARN | \
>   					     __GFP_NOMEMALLOC)
>   /* The order of free page blocks to report to host */
> -#define VIRTIO_BALLOON_FREE_PAGE_ORDER (MAX_ORDER - 1)
> +#define VIRTIO_BALLOON_HINT_BLOCK_ORDER (MAX_ORDER - 1)
>   /* The size of a free page block in bytes */
> -#define VIRTIO_BALLOON_FREE_PAGE_SIZE \
> -	(1 << (VIRTIO_BALLOON_FREE_PAGE_ORDER + PAGE_SHIFT))
> +#define VIRTIO_BALLOON_HINT_BLOCK_BYTES \
> +	(1 << (VIRTIO_BALLOON_HINT_BLOCK_ORDER + PAGE_SHIFT))
>   
>   #ifdef CONFIG_BALLOON_COMPACTION
>   static struct vfsmount *balloon_mnt;
> @@ -380,7 +380,7 @@ static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
>   		if (!page)
>   			break;
>   		free_pages((unsigned long)page_address(page),
> -			   VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +			   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   	}
>   	vb->num_free_page_blocks -= num_returned;
>   	spin_unlock_irq(&vb->free_page_list_lock);
> @@ -582,7 +582,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
>   		;
>   
>   	page = alloc_pages(VIRTIO_BALLOON_FREE_PAGE_ALLOC_FLAG,
> -			   VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +			   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   	/*
>   	 * When the allocation returns NULL, it indicates that we have got all
>   	 * the possible free pages, so return -EINTR to stop.
> @@ -591,13 +591,13 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
>   		return -EINTR;
>   
>   	p = page_address(page);
> -	sg_init_one(&sg, p, VIRTIO_BALLOON_FREE_PAGE_SIZE);
> +	sg_init_one(&sg, p, VIRTIO_BALLOON_HINT_BLOCK_BYTES);
>   	/* There is always 1 entry reserved for the cmd id to use. */
>   	if (vq->num_free > 1) {
>   		err = virtqueue_add_inbuf(vq, &sg, 1, p, GFP_KERNEL);
>   		if (unlikely(err)) {
>   			free_pages((unsigned long)p,
> -				   VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +				   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   			return err;
>   		}
>   		virtqueue_kick(vq);
> @@ -610,7 +610,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
>   		 * The vq has no available entry to add this page block, so
>   		 * just free it.
>   		 */
> -		free_pages((unsigned long)p, VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +		free_pages((unsigned long)p, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   	}
>   
>   	return 0;
> @@ -765,11 +765,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_FREE_PAGE_ORDER);
> -	blocks_to_free = pages_to_free >> VIRTIO_BALLOON_FREE_PAGE_ORDER;
> +				 1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER);
> +	blocks_to_free = pages_to_free >> VIRTIO_BALLOON_HINT_BLOCK_ORDER;
>   	blocks_freed = return_free_pages_to_mm(vb, blocks_to_free);
>   
> -	return blocks_freed << VIRTIO_BALLOON_FREE_PAGE_ORDER;
> +	return blocks_freed << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
>   }
>   
>   static unsigned long leak_balloon_pages(struct virtio_balloon *vb,
> @@ -825,7 +825,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_FREE_PAGE_ORDER;
> +	count += vb->num_free_page_blocks << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
>   
>   	return count;
>   }
> 

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 

Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts
  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
  1 sibling, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2019-11-19 11:38 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: Wei Wang, Khazhismel Kumykov, Jason Wang, virtualization

On 19.11.19 11:29, 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: David Hildenbrand <david@redhat.com>

-- 

Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] virtio_balloon: name cleanups
  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:37 ` [PATCH 1/2] virtio_balloon: name cleanups David Hildenbrand
@ 2019-11-19 12:18 ` Wei Wang
  2 siblings, 0 replies; 6+ messages in thread
From: Wei Wang @ 2019-11-19 12:18 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: Khazhismel Kumykov, Jason Wang, virtualization

On 11/19/2019 06:29 PM, Michael S. Tsirkin wrote:
> free_page_order is a confusing name. It's not a page order
> actually, it's the order of the block of memory we are hinting.
> Rename to hint_block_order. Also, rename SIZE to BYTES
> to make it clear it's the block size in bytes.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>   drivers/virtio/virtio_balloon.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 65df40f261ab..b6a95cd28d9f 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -32,10 +32,10 @@
>   #define VIRTIO_BALLOON_FREE_PAGE_ALLOC_FLAG (__GFP_NORETRY | __GFP_NOWARN | \
>   					     __GFP_NOMEMALLOC)
>   /* The order of free page blocks to report to host */
> -#define VIRTIO_BALLOON_FREE_PAGE_ORDER (MAX_ORDER - 1)
> +#define VIRTIO_BALLOON_HINT_BLOCK_ORDER (MAX_ORDER - 1)
>   /* The size of a free page block in bytes */
> -#define VIRTIO_BALLOON_FREE_PAGE_SIZE \
> -	(1 << (VIRTIO_BALLOON_FREE_PAGE_ORDER + PAGE_SHIFT))
> +#define VIRTIO_BALLOON_HINT_BLOCK_BYTES \
> +	(1 << (VIRTIO_BALLOON_HINT_BLOCK_ORDER + PAGE_SHIFT))
>   
>   #ifdef CONFIG_BALLOON_COMPACTION
>   static struct vfsmount *balloon_mnt;
> @@ -380,7 +380,7 @@ static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
>   		if (!page)
>   			break;
>   		free_pages((unsigned long)page_address(page),
> -			   VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +			   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   	}
>   	vb->num_free_page_blocks -= num_returned;
>   	spin_unlock_irq(&vb->free_page_list_lock);
> @@ -582,7 +582,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
>   		;
>   
>   	page = alloc_pages(VIRTIO_BALLOON_FREE_PAGE_ALLOC_FLAG,
> -			   VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +			   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   	/*
>   	 * When the allocation returns NULL, it indicates that we have got all
>   	 * the possible free pages, so return -EINTR to stop.
> @@ -591,13 +591,13 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
>   		return -EINTR;
>   
>   	p = page_address(page);
> -	sg_init_one(&sg, p, VIRTIO_BALLOON_FREE_PAGE_SIZE);
> +	sg_init_one(&sg, p, VIRTIO_BALLOON_HINT_BLOCK_BYTES);
>   	/* There is always 1 entry reserved for the cmd id to use. */
>   	if (vq->num_free > 1) {
>   		err = virtqueue_add_inbuf(vq, &sg, 1, p, GFP_KERNEL);
>   		if (unlikely(err)) {
>   			free_pages((unsigned long)p,
> -				   VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +				   VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   			return err;
>   		}
>   		virtqueue_kick(vq);
> @@ -610,7 +610,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
>   		 * The vq has no available entry to add this page block, so
>   		 * just free it.
>   		 */
> -		free_pages((unsigned long)p, VIRTIO_BALLOON_FREE_PAGE_ORDER);
> +		free_pages((unsigned long)p, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
>   	}
>   
>   	return 0;
> @@ -765,11 +765,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_FREE_PAGE_ORDER);
> -	blocks_to_free = pages_to_free >> VIRTIO_BALLOON_FREE_PAGE_ORDER;
> +				 1 << VIRTIO_BALLOON_HINT_BLOCK_ORDER);
> +	blocks_to_free = pages_to_free >> VIRTIO_BALLOON_HINT_BLOCK_ORDER;
>   	blocks_freed = return_free_pages_to_mm(vb, blocks_to_free);
>   
> -	return blocks_freed << VIRTIO_BALLOON_FREE_PAGE_ORDER;
> +	return blocks_freed << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
>   }
>   
>   static unsigned long leak_balloon_pages(struct virtio_balloon *vb,
> @@ -825,7 +825,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_FREE_PAGE_ORDER;
> +	count += vb->num_free_page_blocks << VIRTIO_BALLOON_HINT_BLOCK_ORDER;
>   
>   	return count;
>   }


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

Best,
Wei


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] virtio_balloon: divide/multiply instead of shifts
  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
  1 sibling, 0 replies; 6+ messages in thread
From: Wei Wang @ 2019-11-19 12:24 UTC (permalink / raw)
  To: Michael S. Tsirkin, linux-kernel
  Cc: Khazhismel Kumykov, Jason Wang, virtualization

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-19 12:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-11-19 11:37 ` [PATCH 1/2] virtio_balloon: name cleanups David Hildenbrand
2019-11-19 12:18 ` Wei Wang

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).