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

Commit

Permalink
VMCache: the new function that creates VMs as caches before using it
Browse files Browse the repository at this point in the history
VM cache helps speeding up new container creation.
To use it,  need set option "enable_vm_cache" to true and use
"kata-vmcache" command start the VM cache server that created
some VMs as VM cache.  Then each kata-runtime will request VM from
VM cache server.

Currently, VM cache still cannot work with VM templating and vsock.
And just support qemu.

Fixes: #52

Signed-off-by: Hui Zhu <[email protected]>
  • Loading branch information
teawater committed Feb 12, 2019
1 parent 75d9212 commit 48df99c
Show file tree
Hide file tree
Showing 34 changed files with 1,245 additions and 143 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
/cli/config/configuration-fc.toml
/cli/config/configuration-qemu.toml
/cli/config-generated.go
/cli/kata-vmcache/config-generated.go
/cli/coverage.html
/containerd-shim-kata-v2
/data/kata-collect-data.sh
/kata-netmon
/kata-runtime
/kata-vmcache
/virtcontainers/hack/virtc/virtc
/virtcontainers/hook/mock/hook
/virtcontainers/profile.cov
Expand Down
65 changes: 61 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ SHIMV2 = containerd-shim-kata-v2
SHIMV2_OUTPUT = $(CURDIR)/$(SHIMV2)
SHIMV2_DIR = $(CLI_DIR)/$(SHIMV2)

VMCACHE = kata-vmcache
VMCACHE_OUTPUT = $(CURDIR)/$(VMCACHE)
VMCACHE_DIR = $(CLI_DIR)/$(VMCACHE)

SOURCES := $(shell find . 2>&1 | grep -E '.*\.(c|h|go)$$')
VERSION := ${shell cat ./VERSION}
COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true)
Expand Down Expand Up @@ -357,7 +361,7 @@ define SHOW_ARCH
$(shell printf "\\t%s%s\\\n" "$(1)" $(if $(filter $(ARCH),$(1))," (default)",""))
endef

all: runtime containerd-shim-v2 netmon
all: runtime containerd-shim-v2 netmon $(VMCACHE)

containerd-shim-v2: $(SHIMV2_OUTPUT)

Expand All @@ -366,6 +370,11 @@ netmon: $(NETMON_TARGET_OUTPUT)
$(NETMON_TARGET_OUTPUT): $(SOURCES)
$(QUIET_BUILD)(cd $(NETMON_DIR) && go build $(BUILDFLAGS) -o $@ -ldflags "-X main.version=$(VERSION)")

$(VMCACHE): $(VMCACHE_OUTPUT)

$(VMCACHE_OUTPUT): $(TARGET_OUTPUT)
$(QUIET_BUILD)(cd $(VMCACHE_DIR)/ && go build -i -o $@ .)

runtime: $(TARGET_OUTPUT) $(CONFIGS)
.DEFAULT: default

Expand Down Expand Up @@ -420,6 +429,45 @@ endef

export GENERATED_CODE

define VMCACHE_GENERATED_CODE
// WARNING: This file is auto-generated - DO NOT EDIT!
//
// Note that some variables are "var" to allow them to be modified
// by the tests.
package main

import (
"fmt"
)

// name is the name of the runtime
const name = "$(VMCACHE)"

// name of the project
const project = "$(PROJECT_NAME)"

// prefix used to denote non-standard CLI commands and options.
const projectPrefix = "$(PROJECT_TYPE)"

// commit is the git commit the runtime is compiled from.
var commit = "$(COMMIT)"

// version is the runtime version.
var version = "$(VERSION)"

// project-specific option names
var configFilePathOption = fmt.Sprintf("%s-config", projectPrefix)

// Default config file used by stateless systems.
var defaultRuntimeConfiguration = "$(CONFIG_PATH)"

// Alternate config file that takes precedence over
// defaultRuntimeConfiguration.
var defaultSysConfRuntimeConfiguration = "$(SYSCONFIG)"
endef

export VMCACHE_GENERATED_CODE

#Install an executable file
# params:
# $1 : file to install
Expand All @@ -443,12 +491,16 @@ $(if $(findstring uncompressed,$1),vmlinux.container,vmlinuz.container)
endef

GENERATED_CONFIG = $(CLI_DIR)/config-generated.go
VMCACHE_GENERATED_CONFIG = $(VMCACHE_DIR)/config-generated.go

GENERATED_GO_FILES += $(GENERATED_CONFIG)
GENERATED_GO_FILES += $(GENERATED_CONFIG) $(VMCACHE_GENERATED_CONFIG)

$(GENERATED_CONFIG): Makefile VERSION
$(QUIET_GENERATE)echo "$$GENERATED_CODE" >$@

$(VMCACHE_GENERATED_CONFIG): Makefile VERSION
$(QUIET_GENERATE)echo "$$VMCACHE_GENERATED_CODE" >$@

$(TARGET_OUTPUT): $(EXTRA_DEPS) $(SOURCES) $(GENERATED_GO_FILES) $(GENERATED_FILES) Makefile | show-summary
$(QUIET_BUILD)(cd $(CLI_DIR) && go build $(BUILDFLAGS) -o $@ .)

Expand Down Expand Up @@ -539,14 +591,17 @@ check-go-static:
coverage:
$(QUIET_TEST).ci/go-test.sh html-coverage

install: default runtime install-scripts install-completions install-configs install-bin install-containerd-shim-v2 install-bin-libexec
install: default runtime install-scripts install-completions install-configs install-bin install-containerd-shim-v2 install-kata-vmcache install-bin-libexec

install-bin: $(BINLIST)
$(QUIET_INST)$(foreach f,$(BINLIST),$(call INSTALL_EXEC,$f,$(BINDIR)))

install-containerd-shim-v2: $(SHIMV2)
$(QUIET_INST)$(call INSTALL_EXEC,$<,$(BINDIR))

install-kata-vmcache: $(VMCACHE)
$(QUIET_INST)$(call INSTALL_EXEC,$<,$(BINDIR))

install-bin-libexec: $(BINLIBEXECLIST)
$(QUIET_INST)$(foreach f,$(BINLIBEXECLIST),$(call INSTALL_EXEC,$f,$(PKGLIBEXECDIR)))

Expand All @@ -561,7 +616,7 @@ install-completions:
$(QUIET_INST)install --mode 0644 -D $(BASH_COMPLETIONS) $(DESTDIR)/$(BASH_COMPLETIONSDIR)/$(notdir $(BASH_COMPLETIONS));

clean:
$(QUIET_CLEAN)rm -f $(TARGET) $(SHIMV2) $(NETMON_TARGET) $(CONFIGS) $(GENERATED_GO_FILES) $(GENERATED_FILES) $(COLLECT_SCRIPT)
$(QUIET_CLEAN)rm -f $(TARGET) $(SHIMV2) $(VMCACHE_OUTPUT) $(NETMON_TARGET) $(CONFIGS) $(GENERATED_GO_FILES) $(GENERATED_FILES) $(COLLECT_SCRIPT)

show-usage: show-header
@printf "• Overview:\n"
Expand Down Expand Up @@ -635,6 +690,8 @@ endif
"$(foreach b,$(sort $(BINLIST)),$(shell printf "\\t - $(shell readlink -m $(DESTDIR)/$(BINDIR)/$(b))\\\n"))"
@printf \
"$(foreach b,$(sort $(SHIMV2)),$(shell printf "\\t - $(shell readlink -m $(DESTDIR)/$(BINDIR)/$(b))\\\n"))"
@printf \
"$(foreach b,$(sort $(VMCACHE)),$(shell printf "\\t - $(shell readlink -m $(DESTDIR)/$(BINDIR)/$(b))\\\n"))"
@printf \
"$(foreach b,$(sort $(BINLIBEXECLIST)),$(shell printf "\\t - $(shell readlink -m $(DESTDIR)/$(PKGLIBEXECDIR)/$(b))\\\n"))"
@printf \
Expand Down
15 changes: 15 additions & 0 deletions cli/config/configuration-qemu.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ enable_iothreads = @DEFENABLEIOTHREADS@
# Default false
#enable_template = true

# VM cache support. Once enabled, need use "kata-vmcache" command start
# the VM cache server that created some VMs (number is set by option number)
# as VM cache. Each kata-runtime will request VM from VM cache server
# through vm_cache_endpoint.
# It helps speeding up new container creation.
#
# Default false
#enable_vm_cache = true

# Specify the endpoint of transport VM from the VM cache server to runtime.
# "kata-vmcache" will start a gRPC server in this endpoint.
# Each kata-runtime will request VM through gRPC protocol.
# Default /var/run/kata-containers/cache.sock
#vm_cache_endpoint = "/var/run/kata-containers/cache.sock"

[proxy.@PROJECT_TYPE@]
path = "@PROXYPATH@"

Expand Down
8 changes: 4 additions & 4 deletions cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func getProxyInfo(config oci.RuntimeConfig) (ProxyInfo, error) {
proxyConfig := config.ProxyConfig
version, err := getCommandVersion(proxyConfig.Path)
if err != nil {
version = unknown
version = katautils.Unknown
}

proxy := ProxyInfo{
Expand All @@ -265,7 +265,7 @@ func getNetmonInfo(config oci.RuntimeConfig) (NetmonInfo, error) {

version, err := getCommandVersion(netmonConfig.Path)
if err != nil {
version = unknown
version = katautils.Unknown
}

netmon := NetmonInfo{
Expand All @@ -292,7 +292,7 @@ func getShimInfo(config oci.RuntimeConfig) (ShimInfo, error) {

version, err := getCommandVersion(shimPath)
if err != nil {
version = unknown
version = katautils.Unknown
}

shim := ShimInfo{
Expand All @@ -318,7 +318,7 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {

version, err := getCommandVersion(hypervisorPath)
if err != nil {
version = unknown
version = katautils.Unknown
}

return HypervisorInfo{
Expand Down
10 changes: 5 additions & 5 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func TestEnvGetEnvInfoNoHypervisorVersion(t *testing.T) {
err = os.Remove(config.HypervisorConfig.HypervisorPath)
assert.NoError(err)

expectedEnv.Hypervisor.Version = unknown
expectedEnv.Hypervisor.Version = katautils.Unknown

env, err := getEnvInfo(configFile, config)
assert.NoError(err)
Expand Down Expand Up @@ -696,7 +696,7 @@ func TestEnvGetProxyInfoNoVersion(t *testing.T) {
err = os.Remove(config.ProxyConfig.Path)
assert.NoError(t, err)

expectedProxy.Version = unknown
expectedProxy.Version = katautils.Unknown

proxy, err := getProxyInfo(config)
assert.NoError(t, err)
Expand Down Expand Up @@ -740,7 +740,7 @@ func TestEnvGetNetmonInfoNoVersion(t *testing.T) {
err = os.Remove(config.NetmonConfig.Path)
assert.NoError(t, err)

expectedNetmon.Version = unknown
expectedNetmon.Version = katautils.Unknown

netmon, err := getNetmonInfo(config)
assert.NoError(t, err)
Expand Down Expand Up @@ -787,7 +787,7 @@ func TestEnvGetShimInfoNoVersion(t *testing.T) {
exit 1`)
assert.NoError(t, err)

expectedShim.Version = unknown
expectedShim.Version = katautils.Unknown

shim, err := getShimInfo(config)
assert.NoError(t, err)
Expand Down Expand Up @@ -1227,5 +1227,5 @@ func TestGetHypervisorInfo(t *testing.T) {
assert.NoError(err)

info = getHypervisorInfo(config)
assert.Equal(info.Version, unknown)
assert.Equal(info.Version, katautils.Unknown)
}
Loading

0 comments on commit 48df99c

Please sign in to comment.