Skip to content

vhost: multiple worker support

Mike Christie linux-scsi target-devel virtualization 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest12 patches 1 replyIn review
  2. v412 patches 0 repliesSuperseded
  3. v311 patches 24 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1 RFC14 patches7 repliesSuperseded

Changes in v5 from the cover letter

- Rebase against user_worker patchset.
- Rebase against flush patchset.
- Redo vhost-scsi tmf flush handling so it doesn't access vq->worker. V4:
- fix vhost-sock VSOCK_VQ_RX use.
- name functions called directly by ioctl cmd's to match the ioctl cmd.
- break up VHOST_SET_VRING_WORKER into a new, free and attach cmd.
- document worker lifetime, and cgroup, namespace, mm, rlimit inheritance, make it clear we currently only support sharing within the device.
- add support to attach workers while IO is running.
- instead of passing a pid_t of the kernel thread, pass a int allocated by the vhost layer with an idr.

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12vhost: add vhost_worker pointer to vhost_virtqueuedrivers/vhost/vhost.c drivers/vhost/vhost.h+14 -110 replies
2/12vhost, vhost-net: add helper to check if vq has workdrivers/vhost/net.c drivers/vhost/vhost.c drivers/vhost/vhost.h+5 -50 replies
3/12vhost: take worker or vq instead of dev for queueingdrivers/vhost/vhost.c drivers/vhost/vhost.h+29 -160 replies
4/12vhost: take worker or vq instead of dev for flushingdrivers/vhost/vhost.c+15 -90 replies
5/12vhost: convert poll work to be vq baseddrivers/vhost/net.c drivers/vhost/vhost.c drivers/vhost/vhost.h+12 -60 replies
6/12vhost-sock: convert to vhost_vq_work_queuedrivers/vhost/vsock.c+2 -20 replies
7/12vhost-scsi: make SCSI cmd completion per vqdrivers/vhost/scsi.c+25 -230 replies
8/12vhost-scsi: convert to vhost_vq_work_queuedrivers/vhost/scsi.c+10 -100 replies
9/12vhost: remove vhost_work_queuedrivers/vhost/vhost.c drivers/vhost/vhost.h+0 -70 replies
10/12vhost-scsi: flush IO vqs then send TMF rspdrivers/vhost/scsi.c+7 -10 replies
11/12vhost: allow userspace to create workersdrivers/vhost/vhost.c drivers/vhost/vhost.h include/uapi/linux/vhost.h +1 more+188 -170 replies
12/12vhost: allow worker attachment after initial setupdrivers/vhost/vhost.c drivers/vhost/vhost.h include/uapi/linux/vhost.h+57 -230 replies

Reviews trailers per patch

1 of 12 patches has a Reviewed-by or Acked-by.

PatchStefan Hajnoczi
1/12
2/12
3/12
4/12
5/12
6/12
7/12R-b
8/12
9/12
10/12
11/12
12/12

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH V5 00/12] vhost: multiple worker support

The following patches apply over linus's tree and the user_worker patchset here:

https://lore.kernel.org/virtualization/[email protected]/T/#t

which allows us to check the vhost owner thread's RLIMITs, and they are built over Andrey's flush cleanups:

https://lore.kernel.org/virtualization/[email protected]/T/#t

The patches allow us to support multiple vhost workers per device. The design is a modified version of Stefan's original idea where userspace has the kernel create a worker and we pass back the pid. In this version, V4, instead of passing the pid between user/kernel space we use a worker_id which is just an integer managed by the vhost driver and we allow userspace to create and free workers and then attach them to virtqueues at setup time or while IO is running.

All review comments from the past reviews should be handled. If I didn't reply to a review comment, I agreed with the comment and should have handled it in this posting. Let me know if I missed one.

Results:
--------

fio jobs 1 2 4 8 12 16
----------------------------------------------------------

1 worker        84k    492k    510k    -       -       -
worker per vq   184k   380k    744k    1422k   2256k   2434k

Notes:
0. This used a simple fio command:

fio --filename=/dev/sdb --direct=1 --rw=randrw --bs=4k \
--ioengine=libaio --iodepth=128 --numjobs=$JOBS_ABOVE

and I used a VM with 16 vCPUs and 16 virtqueues.

1. The patches were tested with emulate_pr=0 and these patches:

https://lore.kernel.org/all/[email protected]/t/

which are in mkp's scsi branches for the next kernel. They fix the perf issues where IOPs dropped at 12 vqs/jobs.

2. Because we have a hard limit of 1024 cmds, if the num jobs * iodepth was greater than 1024, I would decrease iodepth. So 12 jobs used 85 cmds, and 16 used 64.

3. The perf issue above at 2 jobs is because when we only have 1 worker we execute more cmds per vhost_work due to all vqs funneling to one worker. This results in less context switches and better batching without having to tweak any settings. I'm working on patches to add back batching during lio completion and do polling on the submission side.

We will still want the threading patches, because if we batch at the fio level plus use the vhost theading patches, we can see a big boost like below. So hopefully doing it at the kernel will allow apps to just work without having to be smart like fio.

fio using io_uring and batching with the iodepth_batch* settings:

fio jobs 1 2 4 8 12 16
-------------------------------------------------------------

1 worker        494k    520k    -       -       -       -
worker per vq   496k    878k    1542k   2436k   2304k   2590k

V5:
- Rebase against user_worker patchset.
- Rebase against flush patchset.
- Redo vhost-scsi tmf flush handling so it doesn't access vq->worker. V4:
- fix vhost-sock VSOCK_VQ_RX use.
- name functions called directly by ioctl cmd's to match the ioctl cmd.
- break up VHOST_SET_VRING_WORKER into a new, free and attach cmd.
- document worker lifetime, and cgroup, namespace, mm, rlimit inheritance, make it clear we currently only support sharing within the device.
- add support to attach workers while IO is running.
- instead of passing a pid_t of the kernel thread, pass a int allocated by the vhost layer with an idr.

V3:
- fully convert vhost code to use vq based APIs instead of leaving it half per dev and half per vq.
- rebase against kernel worker API.
- Drop delayed worker creation. We always create the default worker at VHOST_SET_OWNER time. Userspace can create and bind workers after that.

V2:
- change loop that we take a refcount to the worker in
- replaced pid == -1 with define.
- fixed tabbing/spacing coding style issue
- use hash instead of list to lookup workers.
- I dropped the patch that added an ioctl cmd to get a vq's worker's pid. I saw we might do a generic netlink interface instead.