Added support for RamSwap in the generated LXC config (to limit the swap and have the right default settings)

This commit is contained in:
Sam Alba 2013-03-11 17:40:54 -07:00
parent a3a946703b
commit 75d04a5a75
2 changed files with 18 additions and 2 deletions

View File

@ -53,7 +53,8 @@ type Container struct {
type Config struct {
Hostname string
User string
Ram int64
Ram int64 // Memory limit (in bytes)
RamSwap int64 // Total memory usage (ram + swap); set `-1' to disable swap
Ports []int
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
OpenStdin bool // Open stdin

View File

@ -88,14 +88,29 @@ lxc.cap.drop = audit_control audit_write mac_admin mac_override mknod net_raw se
{{if .Config.Ram}}
lxc.cgroup.memory.limit_in_bytes = {{.Config.Ram}}
lxc.cgroup.memory.soft_limit_in_bytes = {{.Config.Ram}}
{{with $ramSwap := getRamSwap .Config}}
lxc.cgroup.memory.memsw.limit_in_bytes = {{$ramSwap}}
{{end}}
{{end}}
`
var LxcTemplateCompiled *template.Template
func getRamSwap(config *Config) int64 {
// By default, RamSwap is set to twice the size of RAM.
// If you want to omit RamSwap, set it to `-1'.
if config.RamSwap < 0 {
return 0
}
return config.Ram * 2
}
func init() {
var err error
LxcTemplateCompiled, err = template.New("lxc").Parse(LxcTemplate)
funcMap := template.FuncMap{
"getRamSwap": getRamSwap,
}
LxcTemplateCompiled, err = template.New("lxc").Funcs(funcMap).Parse(LxcTemplate)
if err != nil {
panic(err)
}