Addition of "--shm-size" to which size of /dev/shm is changed.

- Optional "--shm-size=" was added to the sub-command(run, create,and build).
- The size of /dev/shm in the container can be changed
  when container is made.
- Being able to specify is a numerical value that applies number,
  b, k, m, and g.
- The default value is 64MB, when this option is not set.
- It deals with both native and lxc drivers.

Signed-off-by: NIWA Hideyuki <niwa.hiedyuki@jp.fujitsu.com>
Upstream-commit: 5aeaf2a0c4236711e0981515d8627b30e22a1637
Component: engine
This commit is contained in:
NIWA Hideyuki
2015-11-20 09:24:18 +09:00
parent e1191bf537
commit 4581692a0e
16 changed files with 81 additions and 3 deletions
@@ -211,6 +211,7 @@ type HostConfig struct {
SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux.
Ulimits []*ulimit.Ulimit // List of ulimits to be set in the container
UTSMode UTSMode // UTS namespace to use for the container
ShmSize int64 // Total shm memory usage
// Applicable to Windows
ConsoleSize [2]int // Initial console size
+14
View File
@@ -105,6 +105,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
flVolumeDriver = cmd.String([]string{"-volume-driver"}, "", "Optional volume driver for the container")
flStopSignal = cmd.String([]string{"-stop-signal"}, signal.DefaultStopSignal, fmt.Sprintf("Signal to stop a container, %v by default", signal.DefaultStopSignal))
flIsolation = cmd.String([]string{"-isolation"}, "", "Container isolation level")
flShmSize = cmd.String([]string{"-shm-size"}, "", "Size of /dev/shm, default value is 64MB")
)
cmd.Var(&flAttach, []string{"a", "-attach"}, "Attach to STDIN, STDOUT or STDERR")
@@ -200,6 +201,18 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
return nil, nil, cmd, fmt.Errorf("Invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
}
var parsedShm int64 = 67108864 // initial SHM size is 64MB
if *flShmSize != "" {
var err error
parsedShm, err = units.RAMInBytes(*flShmSize)
if err != nil {
return nil, nil, cmd, fmt.Errorf("--shm-size: invalid SHM size")
}
if parsedShm <= 0 {
return nil, nil, cmd, fmt.Errorf("--shm-size: SHM size must be greater than 0 . You specified: %v ", parsedShm)
}
}
var binds []string
// add any bind targets to the list of container volumes
for bind := range flVolumes.GetMap() {
@@ -381,6 +394,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
CgroupParent: *flCgroupParent,
VolumeDriver: *flVolumeDriver,
Isolation: IsolationLevel(*flIsolation),
ShmSize: parsedShm,
}
// When allocating stdin in attached mode, close stdin at client disconnect
+12
View File
@@ -524,6 +524,18 @@ func TestParseModes(t *testing.T) {
if !hostconfig.UTSMode.Valid() {
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
}
// shm-size ko
if _, _, _, err = parseRun([]string{"--shm-size=a128m", "img", "cmd"}); err == nil || err.Error() != "--shm-size: invalid SHM size" {
t.Fatalf("Expected an error with message '--shm-size: invalid SHM size', got %v", err)
}
// shm-size ok
_, hostconfig, _, err = parseRun([]string{"--shm-size=128m", "img", "cmd"})
if err != nil {
t.Fatal(err)
}
if hostconfig.ShmSize != 134217728 {
t.Fatalf("Expected a valid ShmSize, got %v", hostconfig.ShmSize)
}
}
func TestParseRestartPolicy(t *testing.T) {