From nobody Thu Apr 9 05:26:26 2026 X-Original-To: virtualization@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4frpMK0JSlz6YVMG for ; Thu, 09 Apr 2026 05:26:37 +0000 (UTC) (envelope-from xiangzhedev@gmail.com) Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4frpMH3JmFz3qPN for ; Thu, 09 Apr 2026 05:26:35 +0000 (UTC) (envelope-from xiangzhedev@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20251104 header.b=ISDyuCKG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of xiangzhedev@gmail.com designates 2607:f8b0:4864:20::430 as permitted sender) smtp.mailfrom=xiangzhedev@gmail.com Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-82ce2e2880cso351683b3a.0 for ; Wed, 08 Apr 2026 22:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775712389; x=1776317189; darn=freebsd.org; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=ygDWgX8m6eyprTLnOn0S5Va/07VzX0lSeXVVfIkv/Po=; b=ISDyuCKGKGMfzl8gBan7s5gEYqZZAZ5lVKNULDsj6je/EcZnosC3FKMpAuObJSd0Xq A3Zn0dxeGyeXwkFvH3PaZz1pMxLUlFVVe952QJxUZxq8M13N8sUEx/bK3OYDYDoYZKsT Kz1kRSZPWkRTcRMLW34bD2Z6ech3RFHT1kZE9uoEjO9fSjelWAh7JPMjhaYyu1tTDdXq L+bVjOOpBO0WcHNSE7w0VSEWFPrK96BaQ6+23nwFCWacwmaigawxIgqZT/fTYZBLQkBv 3HyThxqSZY3vELjc4Oo/U+yYjzcKFHucEVESwMjDv7MPrJC6RLQDMtbdq97XazxBcFlS juaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775712389; x=1776317189; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ygDWgX8m6eyprTLnOn0S5Va/07VzX0lSeXVVfIkv/Po=; b=QEmj8ZatEkaClOA3NxDuY2DtCXKmHdmovjhSHh5f/4C2TgUyYLSV3GPblEhTOny7Pf kdxmbFdPYBonVEvmKAveJdy4Bo8ZPtL+yEOQ2VCvID6M18HNPiEzYtFtMRw+gjqfP0VV T2ByUB/Ejfy/smgTGEuiuZtd0NO+V+5shjWMaiw/IDBJ+vKnq4ftS2EyA+0dwfM6I8SJ ZvdgEXkAEE0Wr0ymMZw93nLaiE075HATI5CeZEfL5qN+cLKB5tmXnU391a9bQ6K/kWgi NcYu02r37wxHV7P3QRsgpuziF/AAdZIZv8gGIYFzy6au5MHBC5WM/i5blS6ndNPBgBCs jCow== X-Gm-Message-State: AOJu0YypFLzjV7X5EaTBrP5S5+4jBZv5w3oRVgl+qILldtdC28ECw1ks Qfq8yDydWhTdiwAFZb5pKfRL2mREDhES5gZuerNpdB/wigQzYNQXuTlaAjQqEGrwLZpxpQ== X-Gm-Gg: AeBDietJ19HD4U1uHlbydir7BiUjVhrxytfKKFI5UrrrHTxzqvD4FmScXmg3e4um8eK 7hJX5nglMdvfN6MiERJczmJQUsMWndrOO0UsRMNurRMFjY7Fx9Gg8+X9u6OSDyKJhTmZSvcJpHW GvarCVQmj5GscSY1T6OtpKnUQ0MqRIR711O3HKbvMlOYcGOGNt7O/aF5hU98jPcj8YxVjOpsim3 +LGSu/Cbd8RGwQlIgcJdm/LuuSTfe7T6xi27Wj5cjKaYcUC8vCJHLy5uXRhIsTgQff2GZCxCEyu EvsY/sI/cWMd4nVqDg/xHgbHgX5dpMGPOiy1ZZYUQIOR47KRNBKfLsMw4GZEUzpu1Wn4iTWK8+S c/8HxWGGwgLzlIh3mtoUHyQWoYijiWE/IjN6idOlPy7EGmTu6f0ZHLqxv3NJbOEt8tTju2lgyfA Q2kyJ9974RKbnWb/UQcxCSdhNrCQ== X-Received: by 2002:a05:6a00:1d9e:b0:82c:68f6:a18 with SMTP id d2e1a72fcca58-82d0db5b47amr23453142b3a.34.1775712389038; Wed, 08 Apr 2026 22:26:29 -0700 (PDT) Received: from [198.18.0.1] ([103.142.140.57]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9c9cbf6sm24304001b3a.52.2026.04.08.22.26.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Apr 2026 22:26:28 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------mUBkeZLWyLH0vpynXXVZj0do" Message-ID: Date: Thu, 9 Apr 2026 13:26:26 +0800 List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: freebsd-virtualization@freebsd.org Sender: owner-freebsd-virtualization@FreeBSD.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: virtualization@FreeBSD.org Cc: jhb@FreeBSD.org From: xiangzhe Subject: [PATCH] virtio_balloon: implement STATS_VQ, DEFLATE_ON_OOM, and fix OOM re-inflation X-Spamd-Result: default: False [-3.97 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.97)[-0.974]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4864::/56]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20251104]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; DKIM_TRACE(0.00)[gmail.com:+]; FREEMAIL_FROM(0.00)[gmail.com]; FREEMAIL_ENVFROM(0.00)[gmail.com]; RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ARC_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MLMMJ_DEST(0.00)[virtualization@freebsd.org]; PREVIOUSLY_DELIVERED(0.00)[virtualization@freebsd.org]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::430:from] X-Rspamd-Queue-Id: 4frpMH3JmFz3qPN X-Spamd-Bar: --- This is a multi-part message in MIME format. --------------mUBkeZLWyLH0vpynXXVZj0do Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, I've submitted a patch series to enhance the FreeBSD virtio_balloon driver with features that have been in Linux for years but are missing in FreeBSD. The patches are available for review as a GitHub PR: https://github.com/freebsd/freebsd-src/pull/2116 The series contains 5 commits:   1. virtio_balloon: implement VIRTIO_BALLOON_F_STATS_VQ support      Add memory statistics reporting via the stats virtqueue, enabling hypervisors (QEMU/Proxmox/libvirt) to monitor guest memory and make informed ballooning decisions.   2. virtio_balloon: implement VIRTIO_BALLOON_F_DEFLATE_ON_OOM support      Register a vm_lowmem event handler so the balloon automatically deflates under memory pressure before the OOM killer is invoked.   3. virtio_balloon: fix OOM deflation immediately re-inflated by balloon thread      After OOM deflation, the balloon thread would immediately re-inflate because it re-read the unchanged host target. Add a WANTSIZE flag so inflate/deflate only runs on explicit host config change interrupts.   4. virtio_balloon: replace unconditional OOM log with proper observability      Replace noisy per-event device_printf with sysctl counters and a per-instance debug toggle.   5. virtio_balloon: improve S_AVAIL to match virtio spec available memory semantics      Replace (free + inactive) with a FreeBSD analogue of Linux's si_mem_available() for more accurate reporting. Motivation: Without STATS_VQ, hypervisors have no visibility into guest memory usage and cannot make informed ballooning decisions. Without DEFLATE_ON_OOM, guests under memory pressure have no way to automatically reclaim balloon pages before processes are killed. These are standard virtio features supported by Linux and NetBSD guests, and their absence in FreeBSD has been reported multiple times. Related Bugzilla PR:   - PR 292570: [virtio] virtio-balloon does not balloon correctly Tested on FreeBSD 15-CURRENT and OPNsense (backport to FreeBSD 14 kernel) under QEMU/KVM with libvirt, confirming stats reporting works in Proxmox and OOM deflation prevents unnecessary process kills. Review and feedback welcome. Thanks, Xiangzhe --------------mUBkeZLWyLH0vpynXXVZj0do Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi,
I've submitted a patch series to enhance the FreeBSD virtio_balloon driver with features that have been in Linux for years but are missing in FreeBSD. The patches are available for review as a GitHub PR:
  https://github.com/freebsd/freebsd-src/pull/2116
The series contains 5 commits:
  1. virtio_balloon: implement VIRTIO_BALLOON_F_STATS_VQ support
     Add memory statistics reporting via the stats virtqueue, enabling hypervisors (QEMU/Proxmox/libvirt) to monitor guest memory and make informed ballooning decisions.
  2. virtio_balloon: implement VIRTIO_BALLOON_F_DEFLATE_ON_OOM support
     Register a vm_lowmem event handler so the balloon automatically deflates under memory pressure before the OOM killer is invoked.
  3. virtio_balloon: fix OOM deflation immediately re-inflated by balloon thread
     After OOM deflation, the balloon thread would immediately re-inflate because it re-read the unchanged host target. Add a WANTSIZE flag so inflate/deflate only runs on explicit host config change interrupts.
  4. virtio_balloon: replace unconditional OOM log with proper observability
     Replace noisy per-event device_printf with sysctl counters and a per-instance debug toggle.
  5. virtio_balloon: improve S_AVAIL to match virtio spec available memory semantics
     Replace (free + inactive) with a FreeBSD analogue of Linux's si_mem_available() for more accurate reporting.
Motivation:
Without STATS_VQ, hypervisors have no visibility into guest memory usage and cannot make informed ballooning decisions. Without DEFLATE_ON_OOM, guests under memory pressure have no way to automatically reclaim balloon pages before processes are killed. These are standard virtio features supported by Linux and NetBSD guests, and their absence in FreeBSD has been reported multiple times.
Related Bugzilla PR:
  - PR 292570: [virtio] virtio-balloon does not balloon correctly
Tested on FreeBSD 15-CURRENT and OPNsense (backport to FreeBSD 14 kernel) under QEMU/KVM with libvirt, confirming stats reporting works in Proxmox and OOM deflation prevents unnecessary process kills.
Review and feedback welcome.
Thanks,
Xiangzhe

--------------mUBkeZLWyLH0vpynXXVZj0do--