Skip to content

qemu: carry upstream's discard accounting for virtio-blk - #79

Merged
aledbf merged 3 commits into
mainfrom
qemu/account-discard
Oct 1, 2026
Merged

aledbf merged 3 commits into
mainfrom
qemu/account-discard

Conversation

@aledbf

@aledbf aledbf commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

QEMU 11.1.1's virtio-blk never starts accounting for a DISCARD (virtio_blk_handle_discard_write_zeroes calls block_acct_start only for WRITE_ZEROES), so query-blockstats shows unmap_operations: 0 however much a guest trims. The page-cache lab trimmed 1.1 GiB and saw 0 (run 36815822140).

Upstream fixed it in 331ce936c133 ("hw/virtio-blk: Account discard operations", Hanna Czenczek, reviewed by mst and Stefan Hajnoczi). It was merged to master on 2026-09-11 and is in no tag yet, v11.1.2 included.

  • qemu/patches/0002-… is that commit unchanged, plus a note below --- saying why it is carried and when to drop it. The note says to delete it in the bump that brings it in; it would no longer apply (--forward).
  • The patch applies with --fuzz=0 to v11.1.1's hw/block/virtio-blk.c.
  • boot/pagecache_test.go: the discard note now fails when the guest's fstrim leaves QEMU with 0 unmap operations.

This is a new QEMU binary, so it changes the machine fingerprint. The release cycle decides when it ships.

Validation: the QEMU workflow builds this branch, then boot:page-cache runs on construct with qemu_run set to that build and variant=instead.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

aledbf and others added 3 commits October 1, 2026 12:20
QEMU 11.1.1's virtio-blk never starts accounting for a DISCARD, so
query-blockstats reports 0 unmap operations however much a guest trims:
the page-cache lab trimmed 1.1 GiB and saw 0 (run 36815822140), and
could only see the trim in the overlay's allocation. Upstream fixed it
in 331ce936c133 (master, 2026-09-11); no release has it yet, v11.1.2
included. This is that commit unchanged, to delete in the bump that
brings it.

A new QEMU binary, so a new machine fingerprint.

The page-cache probe now fails when the guest's fstrim is not counted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ns.yaml

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@aledbf

aledbf commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Validated on construct, lab run 36884702758 (boot:page-cache caches, this branch's QEMU 36883820118, variant=instead): after the guest's fstrim QEMU counts 10-12 unmap operations and 1123 MB, matching the ~1.1 GiB trimmed. The release QEMU counted 0 on the same probe (run 36881456066).

@aledbf
aledbf merged commit aaf2d86 into main Oct 1, 2026
4 of 5 checks passed
@aledbf
aledbf deleted the qemu/account-discard branch October 1, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant