add linux OS check and the way mmap limit is read

This commit is contained in:
Maxton Huff 2021-01-27 09:52:13 -06:00
parent 8c36da9eeb
commit 927db378b4
2 changed files with 14 additions and 10 deletions

@ -1 +1 @@
Subproject commit 36f453c1ea3bf86c546a8ad4a88f2a926724d683
Subproject commit 28c2313ecfcd7e083d42d4e409483e968b4c421b

View file

@ -23,16 +23,16 @@ import (
"bytes"
"context"
"crypto/tls"
"encoding/binary"
"io"
"io/ioutil"
"log"
"math/rand"
"net"
"os"
"os/exec"
"os/signal"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
"time"
@ -154,13 +154,17 @@ func (m *Command) Start() (err error) {
return errors.Wrap(err, "setting up server")
}
result, err := exec.Command("sysctl", "vm.max_map_count").Output()
if err != nil {
m.logger.Printf("Tried unsuccessfully to check system mmap limit: %v", err)
} else {
sysMmapLimit := binary.BigEndian.Uint64(result)
if m.Config.MaxMapCount > sysMmapLimit {
m.logger.Printf("WARNING: Config max map limit (%v) is greater than current system limits (%v)", m.Config.MaxMapCount, sysMmapLimit)
if runtime.GOOS == "linux" {
result, err := ioutil.ReadFile("/proc/sys/vm/max_map_count")
if err != nil {
m.logger.Printf("Tried unsuccessfully to check system mmap limit: %v", err)
} else {
sysMmapLimit, err := strconv.ParseUint(strings.TrimSuffix(string(result), "\n"), 10, 64)
if err != nil {
m.logger.Printf("Tried unsuccessfully to check system mmap limit: %v", err)
} else if m.Config.MaxMapCount > sysMmapLimit {
m.logger.Printf("WARNING: Config max map limit (%v) is greater than current system limits (%v)", m.Config.MaxMapCount, sysMmapLimit)
}
}
}