FreeBSD 和 bhyve 即将支持实时迁移
Live-migration support in FreeBSD and bhyve coming

原始链接: https://gyptazy.com/blog/freebsd-bhyve-live-migration-support-rfc/

这是一个在 FreeBSD 15.1 上实现首个可用 bhyve 实时迁移的进行中 RFC。amd64 客户机可通过 TCP 在主机间迁移,仅最终停机拷贝阶段暂停。它基于实验性快照支持,增加内核脏页跟踪以及 bhyve/bhyvectl 中的迁移协议。迁移采用预拷贝:先发送已填充内存,然后反复发送脏页,随后暂停并发送最终脏页及快照状态;目标端验证几何配置、恢复状态,并仅在 GO 提交后启动。它支持多 vCPU 握手、内存一致性检查、磁盘写入验证以及已测试失败情形。一个缓慢脏化的 512 MiB 客户机停机时间约为 138–171 毫秒。上游化前的阻塞项包括:证明脏日志正确性、定义兼容性契约、加固传输/协议、明确提交/设备边界、规定存储/网络交接、构建自动化测试,以及将变更拆分为可审查的补丁。

Hacker News 新 | 过去 | 评论 | 提问 | 展示 | 工作 | 提交 登录 FreeBSD 与 bhyve 的实时迁移支持即将到来 ( gyptazy.com ) 20 分,由 JohnDohnBohn 发布,1 小时前 | 隐藏 | 过去 | 收藏 | 2 条评论 帮助 JohnDohnBohn 1 小时前 | 下一个 [–] 这看起来可能真的会改变使用 bhyve 的 FreeBSD 用户的游戏规则。作者经常抱怨缺少这个功能,他也曾为 Sylve 项目作贡献。看起来他正在打造一些东西。 回复 bashhq_r 22 分钟前 | 上一个 [–] 所以 bhyve 终于支持实时迁移,意味着 sylve 可能真正能用于生产集群了,我一直在等这个。 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

This project presents a first working state for live migration of bhyve guests on FreeBSD 15.1. A running amd64 guest can move between two hosts over TCP while continuing to run; it is paused only for the final stop-and-copy phase. The work builds on bhyve's experimental snapshot support and adds dirty-page tracking in the vmm kernel module together with a migration protocol in bhyve and bhyvectl.

Live migration of a VM in FreeBSD with bhyve
Live migration of a VM in FreeBSD with bhyve

I previously discussed the state of bhyve live migration, its historical development, existing limitations, and why it matters for the future of FreeBSD virtualization in my article bhyve on FreeBSD and VM Live Migration – Quo vadis?.

The goal is deliberately practical: make it possible to test, discuss, and improve a real implementation rather than discuss live migration only in the abstract. The current code and test tooling are being published as a WIP RFC so that the next steps can be shaped in the open. A more detailed demonstration of a VM being live migrated can be watched on my YouTube channel.

Why this matters

Live migration is an important building block for enterprise virtualisation. It enables host maintenance, hardware replacement, load balancing, and failure-domain management with far less disruption to workloads. It is also central to the Sylve project, which aims to offer a Proxmox-like virtualisation solution for FreeBSD. Migration is not an optional convenience in that kind of platform; it is one of the capabilities that makes clustered operations practical.

It is equally important for BoxyBSD, where I offer free BSD-based VPS instances to individuals. Without a credible migration path, routine host work can require a guest outage. That makes live migration a current show stopper for the project, and is why this work is being pushed toward a testable, reviewable state.

How the current implementation works

The source starts with a pre-copy phase. It sends populated guest memory, then repeatedly obtains a bitmap of pages changed since the previous scan and sends only those pages. Once the remaining dirty set fits the configured downtime target, stops shrinking, or reaches the configured round limit, bhyve pauses the guest and its devices. It then sends the final dirty pages and the existing snapshot state for the vCPUs, kernel state, and emulated devices.

The destination validates the basic VM geometry, receives memory and state, restores it, and reports that it is ready. Only then does the source send GO, the commit point. Before GO, a failed migration can resume the source guest. The destination does not start the guest if it does not receive that commit message. A warm, stop-and-copy mode is available too, which is useful both as a fallback and as a comparison baseline.

What is implemented today

  • Pre-copy and warm migration: live pre-copy is configurable with downtime and maximum-round controls; explicit stop-and-copy migration is also supported.
  • Multi-vCPU protocol support: the migration handshake carries the guest vCPU count, the destination refuses a count mismatch, and all guest vCPUs are paused and resumed as part of migration. The published test bed has primarily exercised a one-vCPU guest, so multi-vCPU stress and race testing remain required before making broader claims.
  • Memory consistency checks: dirty-page tracking covers guest and mapped emulation writes through page dirty state, while vmm write holds are recorded separately. The test workload rewrites and verifies guest memory and reports any missing or stale page as a mismatch. Repeated ping-pong migrations have been used to check that the workload continues without errors.
  • Disk-write validation: a guest-side workload repeatedly writes and fsyncs files, verifies checksums, and is checked again after a cold reboot. This is intended to exercise the device pause, drain, and restore path.
  • Failure handling: destination refusal, an unreachable target, and a target disappearing during both pre-copy and stop-and-copy have been tested. Before commit, the source is intended to resume the paused guest after failure.
  • Basic destination checks: protocol version, page size, memory layout, and vCPU count are checked before data transfer. The migration socket is opened by bhyvectl and passed into bhyve so that bhyve can remain inside its Capsicum sandbox.
  • Supported scope: this is amd64-only and depends on the experimental BHYVE_SNAPSHOT support. It relies on snapshot-capable emulated devices; PCI passthrough is not migratablem, yet.

Observed results

In the current two-host test environment, repeated live migrations, memory-rewrite workloads, and fsync-heavy disk workloads have completed successfully. For a slowly dirtying 512 MiB guest, observed downtime has been roughly 138–171 ms. A rapidly dirtying guest may not converge during pre-copy, but still falls back to a correct stop-and-copy completion with a longer pause. These are encouraging engineering results, not a production support promise or a complete correctness proof.

Blockers before upstreaming can be evaluated further

The following are neutral engineering requirements, not criticism of the value of the prototype. They need to be addressed first before further upstreaming into FreeBSD can be evaluated responsibly.


  • Prove and harden dirty-log correctness. The kernel-side dirty-page algorithm must be demonstrated not to lose a write while dirty bits are examined and cleared. It needs focused concurrency, paging, emulation-write, and multi-vCPU stress coverage, plus a reviewable locking and memory-ordering argument.
  • Define a complete compatibility contract. Matching memory size and vCPU count is not enough. A destination should verify guest identity, CPU capabilities, bhyve/vmm and snapshot format compatibility, device topology and capabilities, and shared-storage identity before accepting a migration.
  • Harden the transport and protocol. The current TCP transport has no authentication or encryption and uses a first-version native protocol. A stable protocol needs explicit wire formats, bounded message handling, timeouts, version negotiation, authentication or a supported external secure transport model, and clear operational guidance.
  • Clarify the commit and device-side-effect boundary. The source/destination handoff must be reviewed so that device restoration cannot cause externally visible work before the source has committed, and so that the unavoidable uncertain outcome after a lost post-commit acknowledgement is operationally recoverable.
  • Specify storage and network handoff. Shared storage must have defined coherency, durability, and fencing assumptions. Network migration also needs a clear answer for tap/bridge handling, MAC/IP movement, and traffic convergence.
  • Build an in-tree test strategy. The current scripts and test-bed workloads are useful, but upstream review will need automated regression coverage and a documented support matrix across CPU counts, memory sizes, supported devices, host CPUs, and failure cases.
  • Separate the work into reviewable patches. Dirty-page tracking, snapshot API refactoring, protocol/receiver work, CLI changes, and tests should be independently reviewable. This will make design feedback more actionable and reduce the risk of merging coupled changes.

Next steps

We have already had deeper discussions about these questions in the Sylve Discord. Publishing this current state is intended to make those discussions more concrete, bring in wider FreeBSD and bhyve feedback, and turn the prototype into a clear roadmap. The immediate focus is correctness, compatibility validation, transport safety, and repeatable tests—not adding performance features first. Currently, some peopel already have access to it and it's planned ot publish this at least as a proposal on my git and GitHub at:


Compression, zero-page elision, broader device coverage, richer orchestration, and performance tuning can follow once the foundation is sound. If you operate bhyve, work on FreeBSD virtualisation, or are interested in Sylve or BoxyBSD, testing the RFC and contributing design feedback would be especially valuable.

Status: WIP RFC for a first working bhyve live-migration implementation on FreeBSD 15.1.

联系我们 contact @ memedata.com