Nixpkgs: runInLinuxVM, test-driver: investigate virtiofs as 9p replacement

Created on 19 Apr 2020  路  6Comments  路  Source: NixOS/nixpkgs

qemu 4.2.0 (released Dec 12th 2019) has new mechanism to pass a host folder into a VM: virtiofs.

We should investigate replacing 9p which is currently using to pass host's /nix/store folder into VM in runInLinuxVM, test-driver, ... and also 3rd party projects such as declarative VMs.

One of the reason could be poor performance of 9p (once upon a time NixOS had a kernel patch to improve 9p performance which has been removed because it brought some bugs and none wanted to dig in)

cc @dezgeg

enhancement testing

Most helpful comment

I will also work for my research on an alternative virtiofsd implementation. I will consider the nix use case, maybe we could use this implementation than instead so no patches are necessary.

All 6 comments

This could possibly also get rid of our 9p patches for QEMU.

Okay dug a bit into it and if I understand this correctly, we'd need even more patches:

  • We possibly need to trim down sandbox initialisation during Nix builds to only do seccomp BPF and possibly also make sure that the FS root is correctly recognised (since we can't do pivot_root in Nix builds).
  • Mapping UID to 0 might still be needed, since we do have a few programs (sudo, cups, whatnot...) that expect the store being owned by UID 0. However within Nix builds, we're already within a user namespace and so we get UID 65534 (nobody) and GID 65534 (nobody) instead.

The advantage however is that we only need to patch virtiofsd, so it might be easier to maintain.

So I guess if the performance gains really make a huge difference, I think it's worth introducing one more patch.

Basing my work on #86291, with a patch for virtiofsd to not write to /var/run/virtiofsd and this patch to spawn a userns, I have the store working on virtiofs, when run outside of a nix-build context. There is a >1s speedup, even without DAX (both with qemu5):

image

It turns out that DAX support hasn't yet been merged into upstream QEMU. I am working currently on trying it out against a dev build.

More info to come on getting it working from within a nix-build context.

I ran some better benchmarks against some random tests:

results

Only one regression without DAX enabled, and none with (on the latest virtio-fs-dev commit from gitlab.com/virtio-fs/qemu)

I'll get it cleaned up and pushed tonight or tomorrow (as well as properly investigating what is or is not broken :)

I will also work for my research on an alternative virtiofsd implementation. I will consider the nix use case, maybe we could use this implementation than instead so no patches are necessary.

Kata Containers is adopting virtiofs and patches qemu to improve virtiofs performance (https://github.com/kata-containers/kata-containers/pull/945)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

matthiasbeyer picture matthiasbeyer  路  3Comments

domenkozar picture domenkozar  路  3Comments

retrry picture retrry  路  3Comments

chris-martin picture chris-martin  路  3Comments