Renamed Container property Ram to Memory before it is too late

This commit is contained in:
Sam Alba 2013-03-11 19:25:02 -07:00
parent 4e5ae88372
commit 948961831a
3 changed files with 26 additions and 26 deletions

View File

@ -51,13 +51,13 @@ type Container struct {
}
type Config struct {
Hostname string
User string
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
Hostname string
User string
Memory int64 // Memory limit (in bytes)
MemorySwap int64 // Total memory usage (memory + 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
}
type NetworkSettings struct {

View File

@ -24,7 +24,7 @@ func TestStart(t *testing.T) {
[]string{"-al"},
[]string{testLayerPath},
&Config{
Ram: 33554432,
Memory: 33554432,
},
)
if err != nil {
@ -60,7 +60,7 @@ func TestRun(t *testing.T) {
[]string{"-al"},
[]string{testLayerPath},
&Config{
Ram: 33554432,
Memory: 33554432,
},
)
if err != nil {
@ -589,11 +589,11 @@ func TestLXCConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
// Ram is allocated randomly for testing
// Memory is allocated randomly for testing
rand.Seed(time.Now().UTC().UnixNano())
ramMin := 33554432
ramMax := 536870912
ram := ramMin + rand.Intn(ramMax-ramMin)
memMin := 33554432
memMax := 536870912
mem := memMin + rand.Intn(memMax-memMin)
container, err := docker.Create(
"config_test",
"/bin/true",
@ -601,7 +601,7 @@ func TestLXCConfig(t *testing.T) {
[]string{testLayerPath},
&Config{
Hostname: "foobar",
Ram: int64(ram),
Memory: int64(mem),
},
)
if err != nil {
@ -611,9 +611,9 @@ func TestLXCConfig(t *testing.T) {
container.generateLXCConfig()
grepFile(t, container.lxcConfigPath, "lxc.utsname = foobar")
grepFile(t, container.lxcConfigPath,
fmt.Sprintf("lxc.cgroup.memory.limit_in_bytes = %d", ram))
fmt.Sprintf("lxc.cgroup.memory.limit_in_bytes = %d", mem))
grepFile(t, container.lxcConfigPath,
fmt.Sprintf("lxc.cgroup.memory.memsw.limit_in_bytes = %d", ram*2))
fmt.Sprintf("lxc.cgroup.memory.memsw.limit_in_bytes = %d", mem*2))
}
func BenchmarkRunSequencial(b *testing.B) {

View File

@ -85,10 +85,10 @@ lxc.mount.entry = /etc/resolv.conf {{$ROOTFS}}/etc/resolv.conf none bind,ro 0 0
lxc.cap.drop = audit_control audit_write mac_admin mac_override mknod net_raw setfcap setpcap sys_admin sys_boot sys_module sys_nice sys_pacct sys_rawio sys_resource sys_time sys_tty_config
# limits
{{if .Config.Ram}}
lxc.cgroup.memory.limit_in_bytes = {{.Config.Ram}}
lxc.cgroup.memory.soft_limit_in_bytes = {{.Config.Ram}}
{{with $ramSwap := getRamSwap .Config}}
{{if .Config.Memory}}
lxc.cgroup.memory.limit_in_bytes = {{.Config.Memory}}
lxc.cgroup.memory.soft_limit_in_bytes = {{.Config.Memory}}
{{with $ramSwap := getMemorySwap .Config}}
lxc.cgroup.memory.memsw.limit_in_bytes = {{$ramSwap}}
{{end}}
{{end}}
@ -96,19 +96,19 @@ lxc.cgroup.memory.memsw.limit_in_bytes = {{$ramSwap}}
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 {
func getMemorySwap(config *Config) int64 {
// By default, MemorySwap is set to twice the size of RAM.
// If you want to omit MemorySwap, set it to `-1'.
if config.MemorySwap < 0 {
return 0
}
return config.Ram * 2
return config.Memory * 2
}
func init() {
var err error
funcMap := template.FuncMap{
"getRamSwap": getRamSwap,
"getMemorySwap": getMemorySwap,
}
LxcTemplateCompiled, err = template.New("lxc").Funcs(funcMap).Parse(LxcTemplate)
if err != nil {