Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

cli: add configuration option to enable/disable vhost_net#706

Merged
bergwolf merged 2 commits intokata-containers:masterfrom
caoruidong:vhost
Sep 14, 2018
Merged

cli: add configuration option to enable/disable vhost_net#706
bergwolf merged 2 commits intokata-containers:masterfrom
caoruidong:vhost

Conversation

@caoruidong
Copy link
Member

@caoruidong caoruidong commented Sep 7, 2018

Add disable_vhost_net option to enable or disable the use of
vhost_net. Vhost_net can improve network performance.

Fixes: #169

Signed-off-by: Ruidong Cao caoruidong@huawei.com

@egernst egernst added the review label Sep 7, 2018
@opendev-zuul
Copy link

opendev-zuul bot commented Sep 7, 2018

Build failed (third-party-check pipeline) integration testing with
OpenStack. For information on how to proceed, see
http://docs.openstack.org/infra/manual/developers.html#automated-testing

@katacontainersbot
Copy link
Contributor

PSS Measurement:
Qemu: 169432 KB
Proxy: 4175 KB
Shim: 8789 KB

Memory inside container:
Total Memory: 2043460 KB
Free Memory: 2003596 KB

@bergwolf
Copy link
Member

bergwolf commented Sep 7, 2018

@caoruidong I believe you need to change the govmm code as well since it also has hardcoded vhost dependency there. Something like:

diff --git a/vendor/github.com/intel/govmm/qemu/qmp.go b/vendor/github.com/intel/govmm/qemu/qmp.go
index 58b8924..1e7ed25 100644
--- a/vendor/github.com/intel/govmm/qemu/qmp.go
+++ b/vendor/github.com/intel/govmm/qemu/qmp.go
@@ -794,13 +794,16 @@ func (q *QMP) ExecuteNetdevChardevAdd(ctx context.Context, netdevType, netdevID,
 // Must be valid QMP identifier.
 func (q *QMP) ExecuteNetdevAddByFds(ctx context.Context, netdevType, netdevID string, fdNames, vhostFdNames []string) error {
        fdNameStr := strings.Join(fdNames, ":")
-       vhostFdNameStr := strings.Join(vhostFdNames, ":")
        args := map[string]interface{}{
-               "type":     netdevType,
-               "id":       netdevID,
-               "fds":      fdNameStr,
-               "vhost":    "on",
-               "vhostfds": vhostFdNameStr,
+               "type": netdevType,
+               "id":   netdevID,
+               "fds":  fdNameStr,
+       }
+
+       if len(vhostFdNames) != 0 {
+               vhostFdNameStr := strings.Join(vhostFdNames, ":")
+               args["vhost"] = "on"
+               args["vhostfds"] = vhostFdNameStr
        }

        return q.executeCommand(ctx, "netdev_add", args, nil)
@@ -832,7 +835,7 @@ func (q *QMP) ExecuteNetPCIDeviceAdd(ctx context.Context, netdevID, devID, macAd
                args["bus"] = bus
        }

-       if queues > 0 {
+       if queues > 1 {
                // (2N+2 vectors, N for tx queues, N for rx queues, 1 for config, and one for possible control vq)
                // -device virtio-net-pci,mq=on,vectors=2N+2...
                // enable mq in guest by 'ethtool -L eth0 combined $queue_num'

Copy link
Member

@bergwolf bergwolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change govmm and update vendor here.

@caoruidong
Copy link
Member Author

See #169 (comment). So we assume kata can still run without vhost_net?

@katacontainersbot
Copy link
Contributor

PSS Measurement:
Qemu: 165962 KB
Proxy: 4098 KB
Shim: 8751 KB

Memory inside container:
Total Memory: 2043460 KB
Free Memory: 2003572 KB

@katacontainersbot
Copy link
Contributor

PSS Measurement:
Qemu: 169679 KB
Proxy: 4066 KB
Shim: 8841 KB

Memory inside container:
Total Memory: 2043460 KB
Free Memory: 2003720 KB

@opendev-zuul
Copy link

opendev-zuul bot commented Sep 7, 2018

Build failed (third-party-check pipeline) integration testing with
OpenStack. For information on how to proceed, see
http://docs.openstack.org/infra/manual/developers.html#automated-testing

@bergwolf
Copy link
Member

bergwolf commented Sep 7, 2018

@caoruidong yes, I think so and I did succeed running kata w/o vhost locally.

@sboeuf
Copy link

sboeuf commented Sep 10, 2018

@caoruidong please add @jiulongzaitian to the Signed-off-by section, since he's also part of this PR.

@caoruidong
Copy link
Member Author

OK. The original commit has Soby. I'll squash them into one for clarity.

@codecov
Copy link

codecov bot commented Sep 11, 2018

Codecov Report

Merging #706 into master will increase coverage by 0.07%.
The diff coverage is 80%.

@@            Coverage Diff             @@
##           master     #706      +/-   ##
==========================================
+ Coverage   65.25%   65.33%   +0.07%     
==========================================
  Files          85       85              
  Lines        9956     9951       -5     
==========================================
+ Hits         6497     6501       +4     
+ Misses       2807     2798       -9     
  Partials      652      652

@katacontainersbot
Copy link
Contributor

PSS Measurement:
Qemu: 173671 KB
Proxy: 4035 KB
Shim: 8889 KB

Memory inside container:
Total Memory: 2043460 KB
Free Memory: 2003548 KB

@opendev-zuul
Copy link

opendev-zuul bot commented Sep 11, 2018

Build failed (third-party-check pipeline) integration testing with
OpenStack. For information on how to proceed, see
http://docs.openstack.org/infra/manual/developers.html#automated-testing

@sboeuf
Copy link

sboeuf commented Sep 11, 2018

@caoruidong looks fine to me! Please rebase.

@jodh-intel
Copy link

jodh-intel commented Sep 11, 2018

lgtm

Approved with PullApprove

@sboeuf
Copy link

sboeuf commented Sep 11, 2018

@bergwolf PTAL and update your review!

@amshinde
Copy link
Member

Sorry, I am just seeing this PR.
I am not in favor of detecting if vhost is available during runtime.
This means we perform an exec, anytime we need to attach a network device.

cmd := exec.Command(modInfoCmd, module)

I think this should really be an explicit runtime configuration, set to true by default and documented.
What do others think about this?
cc @egernst

@sboeuf
Copy link

sboeuf commented Sep 11, 2018

@amshinde actually I think you're totally right. A lot of exec are going to be performed eventually...
Having this, part of the hypervisor configuration would be the best place, but would require a bit of rework regarding network.go to make sure it can access the hypervisor config.

Copy link

@sboeuf sboeuf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @amshinde this patch will result in a lot of exec at runtime, which will impact performance.

@bergwolf
Copy link
Member

I agree with @amshinde that this should be a config option and if vhost is enabled by configuration, try to modprobe it if it doesn't exist yet. And maybe we want another option to say if we want to fallback when vhost-net module doesn't exist.

@caoruidong
Copy link
Member Author

caoruidong commented Sep 12, 2018

I agree this patch doesn't work now. We create vhost fds without judgement.

vhostFds, err := createVhostFds(defaultQueues)
if err != nil {
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
}
netPair.VhostFds = vhostFds

Our codes strongly depend on vhost_net. @bergwolf How do you run kata without vhost_net? Do you change the code?

@jodh-intel
Copy link

Good catch @amshinde - agreed!

@sboeuf sboeuf added the enhancement Improvement to an existing feature label Sep 12, 2018
@caoruidong caoruidong changed the title virtcontainers: set VHost to false when host doesn't have vhost_net.ko cli: add configuration option to enable/disable vhost_net Sep 13, 2018
@katacontainersbot
Copy link
Contributor

PSS Measurement:
Qemu: 169613 KB
Proxy: 4029 KB
Shim: 9154 KB

Memory inside container:
Total Memory: 2043460 KB
Free Memory: 2003432 KB

@opendev-zuul
Copy link

opendev-zuul bot commented Sep 13, 2018

Build succeeded (third-party-check pipeline).

Copy link
Member

@bergwolf bergwolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just one comment on the new option explanation.


# If host doesn't support vhost_net, set to true. Thus we won't create vhost fds for nics.
# Default false
#disable_vhost_net = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we no longger modprobe vhost-net, neither we fallback to non-vhost case, right? Please document it here that vhost-net kernel module needs to be builtin or inserted if vhost_net is enabled. Otherwise we'll fail to create the network endpoint for containers.

Copy link
Member Author

@caoruidong caoruidong Sep 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If vhost_net.ko exists but is not inserted, when someone accesses /dev/vhost-net, vhost_net.ko will be auto loaded. So we don't need to modprobe it by hand.
If vhost is enabled but actually ko doesn't exist, we won't know until we try to create vhost fds. So I wonder whether that is a good time to fallback to non-vhost when we meet error.

vhostFds, err := createVhostFds(defaultQueues)
if err != nil {
return fmt.Errorf("Could not setup vhost fds %s : %s", netPair.VirtIface.Name, err)
}
netPair.VhostFds = vhostFds
Both just error out and fallback are OK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK to just fail in such case. Thanks for the info that vhost_net.ko is automatically loaded.

@bergwolf
Copy link
Member

LGTM, thanks! @caoruidong Please rebase though since it conflicts with new changes merged in #719.

@bergwolf
Copy link
Member

@sboeuf @amshinde ptal

…-net

If the length of vhostfds is zero, it means host doesn't support vhost. So
do not pass vhost="on" in QMP.
Full list:
    1a1fee7 qemu/qmp: nic can works without vhost

Fixes kata-containers#169

Signed-off-by: Ruidong Cao <caoruidong@huawei.com>
Add `disable_vhost_net` option to enable or disable the use of
vhost_net. Vhost_net can improve network performance.

Signed-off-by: Ruidong Cao <caoruidong@huawei.com>
@katacontainersbot
Copy link
Contributor

PSS Measurement:
Qemu: 169415 KB
Proxy: 3998 KB
Shim: 8743 KB

Memory inside container:
Total Memory: 2043460 KB
Free Memory: 2006332 KB

@opendev-zuul
Copy link

opendev-zuul bot commented Sep 13, 2018

Build failed (third-party-check pipeline) integration testing with
OpenStack. For information on how to proceed, see
http://docs.openstack.org/infra/manual/developers.html#automated-testing

@bergwolf bergwolf merged commit d6e4a98 into kata-containers:master Sep 14, 2018
@egernst egernst removed the review label Sep 14, 2018
@caoruidong caoruidong deleted the vhost branch September 14, 2018 07:20
egernst pushed a commit to egernst/runtime that referenced this pull request Feb 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement Improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants