Hello,

On a Linux guest with Dynamic Memory, a single hot-add request larger
than 64 GiB seems to be truncated to its low 24 bits of page count.
The host then accounts for memory the guest never added, and later
balloons the guest far below its configured minimum.

Setup
  Host:  Windows Server 2022, build 10.0.20348.5756
  Guest: Debian 13, kernel 6.12.113+deb13-amd64, Generation 2 VM, 32 vCPUs
  VM memory: startup 32768 MB, minimum 32768 MB, maximum 131072 MB,
             buffer 20%, Dynamic Memory enabled
  hv_balloon: protocol version 2.0, hot_add=Y, auto_online_blocks=online,
              memory block size 128 MB

What happens
  The guest commits about 105 GiB (Committed_AS) shortly after boot.
  About 50 seconds after boot the host grows the VM to its maximum.

  Guest log:
    Memory: 32514644K/33553344K available
    hv_vmbus: hv_mmio=[mem 0xf8000000-0xfed3ffff],[mem 0xfe0000000-0xfffffffff]
    [   52.772118] hv_balloon: Max. dynamic memory size: 131072 MB
  No "hot_add memory failed" or "Memory hot add failed" messages.

  Host, same second (Hyper-V-Compute-Admin, event 10020):
    The dynamic memory balancer could not add memory to the virtual
    machine because its configured maximum has been reached

  Host view afterwards:
    Get-VM: MemoryAssigned 128 GiB
    Hyper-V Dynamic Memory VM counters:
      Memory Add Operations          2
      Added Memory                   98526 MB
      Guest Visible Physical Memory  131072 MB

  Guest view afterwards:
    MemTotal 63.3 GiB, lsmem: 64G online, 0 offline
      0x0000000000000000-0x00000000f7ffffff   3.9G
      0x0000000100000000-0x0000000fdfffffff  59.5G
      0x0000001000000000-0x0000001027ffffff   640M
    /sys/kernel/debug/hv-balloon:
      pages_added            : 8388608    (32768 MB)
      pages_onlined          : 8388608
      max_dynamic_page_count : 33554432

Arithmetic
  Boot memory ends at 0x808000000. The high MMIO window starts at
  0xfe0000000. If the host sends two hot-add requests,
    1) 0x808000000-0xfdfffffff     = 32128 MB
    2) from 0x1000000000 upwards   = 131072 - 32768 - 32128 = 66176 MB
  then request 2 is 16941056 pages, which does not fit into
    union dm_mem_page_range { struct { __u64 start_page:40;
                                       __u64 page_cnt:24; } finfo; ... }
  16941056 mod 2^24 = 163840 pages = 640 MB, which is exactly the size
  of the range the guest added above the MMIO window, and
  32128 + 640 = 32768 MB matches pages_added exactly.
  I did not capture the requests on the wire; the two sizes above are
  derived, not observed. The host counter shows 98526 MB added, which is
  222 MB more than 131072 - 32768; I cannot explain that difference.

Consequence
  The host believes the guest has 64 GiB more than it has. When the
  guest's committed memory dropped from about 107 GiB to 43 GiB, the host
  removed about 58 GiB by ballooning. The guest went from MemTotal
  63.3 GiB to about 4-5 GiB within 10 minutes (minimum is 32768 MB) and
  stayed there, logging
    hv_balloon: Balloon request will be partially fulfilled. Balloon floor 
reached.
  every 5 minutes. The host reported pressure 73 and returned nothing:
  assigned 68.4 GiB, demand 50.6 GiB by its accounting. At that point:
    pages_ballooned 15634328 (59.6 GiB), MemTotal 3.9 GiB.
  This happened twice, each time after a sharp drop of Committed_AS.

Control
  Another VM on the same host with the same kernel, startup 32768 MB and
  maximum 49152 MB shows no discrepancy: assigned 48 GiB, 48G online.

Questions
  1. Is page_cnt:24 the actual wire format, so that the host must not
     send a range above 2^24 - 1 pages, or does the host encode larger
     ranges differently?
  2. The guest reports resp.page_count for what it added. The host seems
     to account the full request anyway. Is that expected?

The page_cnt:24 field is the same in v6.12 and in current mainline.
As a workaround I plan to lower the VM maximum so that no single
hot-add range can exceed 64 GiB.

I can provide full dmesg, the debugfs output and host counters, and I
can test patches on this configuration.

Thanks,
Artem Matviichuk

Reply via email to