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

Commit

Permalink
Merge pull request #590 from clearcontainers/sameo/topic/mcastelino
Browse files Browse the repository at this point in the history
Configuration: Add support for fine grained control of memory management and debug
  • Loading branch information
Samuel Ortiz authored Sep 20, 2017
2 parents 32d2a37 + 2de68f7 commit 7fc11d5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ DEFVCPUS := 1
DEFMEMSZ := 2048

DEFDISABLEBLOCK := false
DEFENABLEMEMPREALLOC := false
DEFENABLESWAP := false
DEFENABLEDEBUG := false

SED = sed

Expand Down Expand Up @@ -175,6 +178,9 @@ USER_VARS += PAUSEDESTDIR
USER_VARS += DEFVCPUS
USER_VARS += DEFMEMSZ
USER_VARS += DEFDISABLEBLOCK
USER_VARS += DEFENABLEMEMPREALLOC
USER_VARS += DEFENABLESWAP
USER_VARS += DEFENABLEDEBUG


V = @
Expand Down Expand Up @@ -223,6 +229,9 @@ const pauseBinRelativePath = "$(PAUSEBINRELPATH)"
const defaultVCPUCount uint32 = $(DEFVCPUS)
const defaultMemSize uint32 = $(DEFMEMSZ) // MiB
const defaultDisableBlockDeviceUse bool = $(DEFDISABLEBLOCK)
const defaultEnableMemPrealloc bool = $(DEFENABLEMEMPREALLOC)
const defaultEnableSwap bool = $(DEFENABLESWAP)
const defaultEnableDebug bool = $(DEFENABLEDEBUG)

// Default config file used by stateless systems.
var defaultRuntimeConfiguration = "$(DESTCONFIG)"
Expand Down Expand Up @@ -281,6 +290,9 @@ $(CONFIG): $(CONFIG_IN) $(GENERATED_FILES)
-e "s|@DEFVCPUS@|$(DEFVCPUS)|g" \
-e "s|@DEFMEMSZ@|$(DEFMEMSZ)|g" \
-e "s|@DEFDISABLEBLOCK@|$(DEFDISABLEBLOCK)|g" \
-e "s|@DEFENABLEMEMPREALLOC@|$(DEFENABLEMEMPREALLOC)|g" \
-e "s|@DEFENABLEMSWAP@|$(DEFENABLESWAP)|g" \
-e "s|@DEFENABLEMSWAP@|$(DEFENABLEDEBUG)|g" \
$< > $@

generate-config: $(CONFIG)
Expand Down
9 changes: 9 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type hypervisor struct {
DefaultVCPUs int32 `toml:"default_vcpus"`
DefaultMemSz uint32 `toml:"default_memory"`
DisableBlockDeviceUse bool `toml:"disable_block_device_use"`
MemPrealloc bool `toml:"enable_mem_prealloc"`
Swap bool `toml:"enable_swap"`
Debug bool `toml:"enable_debug"`
}

type proxy struct {
Expand Down Expand Up @@ -207,6 +210,9 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
DefaultVCPUs: h.defaultVCPUs(),
DefaultMemSz: h.defaultMemSz(),
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
MemPrealloc: h.MemPrealloc,
Mlock: !h.Swap,
Debug: h.Debug,
}, nil
}

Expand Down Expand Up @@ -314,6 +320,9 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat
HypervisorMachineType: defaultMachineType,
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
MemPrealloc: defaultEnableMemPrealloc,
Mlock: !defaultEnableSwap,
Debug: defaultEnableDebug,
}

defaultAgentConfig := vc.HyperConfig{
Expand Down
26 changes: 26 additions & 0 deletions config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,43 @@ machine_type = "@MACHINETYPE@"
# For example, use `kernel_params = "vsyscall=emulate"` if you are having
# trouble running pre-2.15 glibc
kernel_params = "@KERNELPARAMS@"

# Default number of vCPUs per POD/VM:
# unspecified or 0 --> will be set to @DEFVCPUS@
# < 0 --> will be set to the actual number of physical cores
# > 0 <= 255 --> will be set to the specified number
# > 255 --> will be set to 255
default_vcpus = -1

# Default memory size in MiB for POD/VM.
# If unspecified then it will be set @DEFMEMSZ@ MiB.
#default_memory = @DEFMEMSZ@
disable_block_device_use = @DEFDISABLEBLOCK@

# Enable pre allocation of VM RAM, default false
# Enabling this will result in lower container density
# as all of the memory will be allocated and locked
# This is useful when you want to reserve all the memory
# upfront or in the cases where you want memory latencies
# to be very predictable
# Default false
#enable_mem_prealloc = true

# Enable swap of vm memory. Default false.
# The behaviour is undefined if mem_prealloc is also set to true
#enable_swap = true

# Debug changes the default hypervisor and kernel parameters to
# enable debug output where available.
# Default false
# these logs can be obtained in the cc-proxy logs when the
# proxy is set to run in debug mode
# /usr/libexec/clear-containers/cc-proxy -log debug
# or by stopping the cc-proxy service and running the cc-proxy
# explicitly using the same command line
#
#enable_debug = true

[proxy.cc]
url = "@PROXYURL@"

Expand Down
2 changes: 2 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
DisableBlockDeviceUse: disableBlockDevice,
Mlock: !defaultEnableSwap,
}

agentConfig := vc.HyperConfig{
Expand Down Expand Up @@ -609,6 +610,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
DefaultVCPUs: defaultVCPUCount,
DefaultMemSz: defaultMemSize,
DisableBlockDeviceUse: defaultDisableBlockDeviceUse,
Mlock: !defaultEnableSwap,
}

expectedAgentConfig := vc.HyperConfig{
Expand Down

0 comments on commit 7fc11d5

Please sign in to comment.