DEV Community

Ganesh Viswanathan
Ganesh Viswanathan

Posted on

Storage for Kata Containers - 9pfs vs virtio-blk

9pfs (Plan 9 File System via virtio-9p) and virtio-blk are two different methods for providing storage to virtual machines, differing primarily in their level of abstraction (file-level vs. block-level).

Comparison table for 9pfs vs virtio-blk

9pfs (virtio-9p)

9pfs exposes a specific directory on the host machine directly to the guest. It is often used for "shared folders" where the host and guest need simultaneous access to the same files.

Pros:

  • Elasticity: Storage is only consumed by actual files on the host; no need to pre-allocate a large image file.
  • Ease of Use: Useful for development, where you want to edit code on the host and run it immediately in the guest.

Cons:

  • Performance: Generally slower than block devices because every file operation must go through the 9P protocol and host system calls.
  • Compatibility: While Linux support is excellent, Windows support is limited and often requires third-party drivers.
  • Modern Alternative: virtio-fs is the successor to 9pfs in many modern QEMU setups, offering significantly better performance and POSIX compliance.

virtio-blk

This presents a virtual raw block device (a "hard drive") to the guest. The guest OS treats it like a physical disk and manages its own filesystem (e.g., ext4, XFS) on top of it.

Pros:

  • High Performance: Optimized for low latency and high throughput. Features like IOThread Virtqueue Mapping (introduced in QEMU 9.0) allow it to scale across multiple vCPUs efficiently.
  • Full Feature Support: Supports TRIM/Discard (to reclaim space), bootable partitions, and standard disk management tools.

Cons:

  • Isolation: The host cannot easily "see" or edit files inside the block device while the guest is running without risking corruption.
  • Fixed Size: Typically requires pre-allocation or using "sparse" image formats (like QCOW2) which can have their own performance trade-offs.

When to use which

Use 9pfs when:

  • You need to share a host directory into a guest for development, simple file exchange, or testing.
  • You value ease of sharing over raw performance and strict isolation.​

Use virtio-blk when:

  • You are provisioning a root disk or data disk for a VM.
  • You care about performance, isolation, and standard disk semantics (snapshots, independent filesystems per VM).​

Top comments (0)