From 4abd54d419c14b985e06b4a818feae4a7eb3ab88 Mon Sep 17 00:00:00 2001 From: Flavio Crisciani Date: Wed, 31 May 2017 16:46:14 -0700 Subject: [PATCH] Set kernel specific config on linux On linux systems bump up gc_thresholds so to lower the probability of running with neighbor table overflow issues Signed-off-by: Flavio Crisciani --- libnetwork/drivers/overlay/ostweaks_linux.go | 30 +++++++++++++++++++ .../drivers/overlay/ostweaks_unsupported.go | 5 ++++ libnetwork/drivers/overlay/overlay.go | 5 +++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 libnetwork/drivers/overlay/ostweaks_linux.go create mode 100644 libnetwork/drivers/overlay/ostweaks_unsupported.go diff --git a/libnetwork/drivers/overlay/ostweaks_linux.go b/libnetwork/drivers/overlay/ostweaks_linux.go new file mode 100644 index 0000000000..85840cf8c4 --- /dev/null +++ b/libnetwork/drivers/overlay/ostweaks_linux.go @@ -0,0 +1,30 @@ +package overlay + +import ( + "io/ioutil" + "path" + "strings" + + "github.com/Sirupsen/logrus" +) + +var sysctlConf = map[string]string{ + "net.ipv4.neigh.default.gc_thresh1": "8192", + "net.ipv4.neigh.default.gc_thresh2": "49152", + "net.ipv4.neigh.default.gc_thresh3": "65536", +} + +// writeSystemProperty writes the value to a path under /proc/sys as determined from the key. +// For e.g. net.ipv4.ip_forward translated to /proc/sys/net/ipv4/ip_forward. +func writeSystemProperty(key, value string) error { + keyPath := strings.Replace(key, ".", "/", -1) + return ioutil.WriteFile(path.Join("/proc/sys", keyPath), []byte(value), 0644) +} + +func applyOStweaks() { + for k, v := range sysctlConf { + if err := writeSystemProperty(k, v); err != nil { + logrus.Errorf("error setting the kernel parameter %s = %s, err: %s", k, v, err) + } + } +} diff --git a/libnetwork/drivers/overlay/ostweaks_unsupported.go b/libnetwork/drivers/overlay/ostweaks_unsupported.go new file mode 100644 index 0000000000..a5e8d91083 --- /dev/null +++ b/libnetwork/drivers/overlay/ostweaks_unsupported.go @@ -0,0 +1,5 @@ +// +build !linux + +package overlay + +func applyOStweaks() {} diff --git a/libnetwork/drivers/overlay/overlay.go b/libnetwork/drivers/overlay/overlay.go index 8a932cf370..dc3e40c6d2 100644 --- a/libnetwork/drivers/overlay/overlay.go +++ b/libnetwork/drivers/overlay/overlay.go @@ -46,7 +46,7 @@ type driver struct { store datastore.DataStore localStore datastore.DataStore vxlanIdm *idm.Idm - once sync.Once + initOS sync.Once joinOnce sync.Once localJoinOnce sync.Once keys []*key @@ -188,6 +188,9 @@ func (d *driver) configure() error { return d.initializeVxlanIdm() } + // Apply OS specific kernel configs if needed + d.initOS.Do(applyOStweaks) + return nil }