All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: mhklinux@outlook.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, linux-kernel@vger.kernel.org,
	linux-hyperv@vger.kernel.org
Subject: Re: [PATCH 1/1] hv_balloon: Enable hot-add for memblock sizes > 128 Mbytes
Date: Fri, 26 Apr 2024 10:58:56 +0200	[thread overview]
Message-ID: <30d66f75-60c8-4ebf-8451-839806400dd4@redhat.com> (raw)
In-Reply-To: <20240311181238.1241-1-mhklinux@outlook.com>

On 11.03.24 19:12, mhkelley58@gmail.com wrote:
> From: Michael Kelley <mhklinux@outlook.com>
> 
> The Hyper-V balloon driver supports hot-add of memory in addition
> to ballooning. Current code hot-adds in fixed size chunks of
> 128 Mbytes (fixed constant HA_CHUNK in the code).  While this works
> in Hyper-V VMs with 64 Gbytes or less or memory where the Linux
> memblock size is 128 Mbytes, the hot-add fails for larger memblock
> sizes because add_memory() expects memory to be added in chunks
> that match the memblock size. Messages like the following are
> reported when Linux has a 256 Mbyte memblock size:
> 
> [  312.668859] Block size [0x10000000] unaligned hotplug range:
>                 start 0x310000000, size 0x8000000
> [  312.668880] hv_balloon: hot_add memory failed error is -22
> [  312.668984] hv_balloon: Memory hot add failed
> 
> Larger memblock sizes are usually used in VMs with more than
> 64 Gbytes of memory, depending on the alignment of the VM's
> physical address space.

Right, that's the case since 2018.


> 
> Fix this problem by having the Hyper-V balloon driver determine
> the Linux memblock size, and process hot-add requests in that
> chunk size instead of a fixed 128 Mbytes. Also update the hot-add
> alignment requested of the Hyper-V host to match the memblock
> size instead of being a fixed 128 Mbytes.

That way, we should never be getting unaligned ranges IIRC, correct? I 
think we added ways in QEMU to guarantee that for the HV-balloon 
implementation as well.

> 
> The code changes look significant, but in fact are just a

Nah, it's okay :)

> simple text substitution of a new global variable for the
> previous HA_CHUNK constant. No algorithms are changed except
> to initialize the new global variable and to calculate the
> alignment value to pass to Hyper-V. Testing with memblock
> sizes of 256 Mbytes and 2 Gbytes shows correct operation.
> 
> Signed-off-by: Michael Kelley <mhklinux@outlook.com>
> ---
>   drivers/hv/hv_balloon.c | 64 ++++++++++++++++++++++++-----------------
>   1 file changed, 37 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
> index e000fa3b9f97..d3bfbf3d274a 100644
> --- a/drivers/hv/hv_balloon.c
> +++ b/drivers/hv/hv_balloon.c
> @@ -425,11 +425,11 @@ struct dm_info_msg {
>    * The range start_pfn : end_pfn specifies the range
>    * that the host has asked us to hot add. The range
>    * start_pfn : ha_end_pfn specifies the range that we have
> - * currently hot added. We hot add in multiples of 128M
> - * chunks; it is possible that we may not be able to bring
> - * online all the pages in the region. The range
> + * currently hot added. We hot add in chunks equal to the
> + * memory block size; it is possible that we may not be able
> + * to bring online all the pages in the region. The range
>    * covered_start_pfn:covered_end_pfn defines the pages that can
> - * be brough online.
> + * be brought online.
>    */
>   
>   struct hv_hotadd_state {
> @@ -505,8 +505,9 @@ enum hv_dm_state {
>   
>   static __u8 recv_buffer[HV_HYP_PAGE_SIZE];
>   static __u8 balloon_up_send_buffer[HV_HYP_PAGE_SIZE];
> +static unsigned long ha_chunk_pgs;

Why not stick to PAGES_IN_2M and call this

ha_pages_in_chunk? Much easier to get than "pgs".

Apart from that looks good. Some helper macros to convert size to chunks 
etc. might make the code even more readable.

-- 
Cheers,

David / dhildenb


  parent reply	other threads:[~2024-04-26  8:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 18:12 [PATCH 1/1] hv_balloon: Enable hot-add for memblock sizes > 128 Mbytes mhkelley58
2024-04-25 14:31 ` Michael Kelley
2024-04-26  8:58 ` David Hildenbrand [this message]
2024-04-26 16:35   ` Michael Kelley
2024-04-29 15:30     ` Michael Kelley
2024-04-30  8:52       ` David Hildenbrand

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=30d66f75-60c8-4ebf-8451-839806400dd4@redhat.com \
    --to=david@redhat.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=wei.liu@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.