Files
Reims-Go/patches/reims-ctl-virtio-discard-iothread.patch
T

54 lines
2.1 KiB
Diff

diff --git a/crates/reims-ctl/src/qemu.rs b/crates/reims-ctl/src/qemu.rs
index 4c80cfb..66c7952 100644
--- a/crates/reims-ctl/src/qemu.rs
+++ b/crates/reims-ctl/src/qemu.rs
@@ -398,12 +398,15 @@ fn q35(vm: &Vm, ctx: &Ctx, a: &mut Vec<String>) -> Result<()> {
"-device",
&format!("ide-hd,bus=sata.{},drive=disk,rotation_rate=1", q.disk_port),
]),
- // SATA's drive options, at the first slot no other device takes.
+ // Pass guest TRIMs (`discard=unmap`) like NVMe and offload block handling to a dedicated
+ // iothread so disk completions do not contend with QEMU's main event loop.
DiskController::Virtio => push(&[
+ "-object",
+ "iothread,id=io0",
"-drive",
- &disk,
+ &format!("{disk},discard=unmap"),
"-device",
- "virtio-blk-pci,drive=disk,addr=0x6",
+ "virtio-blk-pci,drive=disk,iothread=io0,addr=0x6",
]),
}
// The installer, on port 4, past OpenCore's, or on 5 past an AHCI disk on 4.
@@ -1754,10 +1757,12 @@ pub(crate) mod tests {
assert!(has(
&a,
&[
+ "-object",
+ "iothread,id=io0",
"-drive",
- "id=disk,if=none,format=qcow2,file=/vms/t/disk.qcow2",
+ "id=disk,if=none,format=qcow2,file=/vms/t/disk.qcow2,discard=unmap",
"-device",
- "virtio-blk-pci,drive=disk,addr=0x6",
+ "virtio-blk-pci,drive=disk,iothread=io0,addr=0x6",
]
));
assert!(
@@ -1782,10 +1787,12 @@ pub(crate) mod tests {
assert!(has(
&a,
&[
+ "-object",
+ "iothread,id=io0",
"-drive",
- "id=disk,if=none,format=qcow2,file=/vms/t/disk.qcow2,cache.no-flush=on",
+ "id=disk,if=none,format=qcow2,file=/vms/t/disk.qcow2,cache.no-flush=on,discard=unmap",
"-device",
- "virtio-blk-pci,drive=disk,addr=0x6",
+ "virtio-blk-pci,drive=disk,iothread=io0,addr=0x6",
]
));
}