Skip to content

Commit

Permalink
Merge pull request #1789 from fcrisciani/sysctl_gc_thresh
Browse files Browse the repository at this point in the history
Set kernel specific config on linux
  • Loading branch information
Santhosh Manohar committed Jun 3, 2017
2 parents 2e99f06 + b23cdc3 commit 7c8bcae
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
30 changes: 30 additions & 0 deletions drivers/overlay/ostweaks_linux.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
5 changes: 5 additions & 0 deletions drivers/overlay/ostweaks_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build !linux

package overlay

func applyOStweaks() {}
5 changes: 4 additions & 1 deletion drivers/overlay/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 7c8bcae

Please sign in to comment.