Skip to content
Permalink
Browse files
distri fuse: bump rlimit NOFILE (open files) to 398430 (Linux max)
This will fix the problem once and for all!

fixes #53
  • Loading branch information
stapelberg committed Nov 26, 2019
1 parent dbc30ef commit af8455d3b396a2d97a07dc05ddcf6ec0439ae062
Showing 7 changed files with 48 additions and 6 deletions.
@@ -4,15 +4,19 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"runtime/pprof"
"runtime/trace"
"strconv"
"strings"
"sync"
"sync/atomic"

"github.com/distr1/distri/cmd/distri/internal/fuse"
"golang.org/x/sys/unix"
"golang.org/x/xerrors"

_ "github.com/distr1/distri/internal/oninterrupt"
@@ -27,6 +31,41 @@ var (
httpListen = flag.String("listen", "", "host:port to listen on for HTTP")
)

func bumpRlimitNOFILE() error {
// The smaller of the two is the highest which Linux will let us set:
// https://github.com/torvalds/linux/blob/2be7d348fe924f0c5583c6a805bd42cecda93104/kernel/sys.c#L1526-L1541
var fileMax, nrOpen uint64
{
b, err := ioutil.ReadFile("/proc/sys/fs/file-max")
if err != nil {
return err
}
fileMax, err = strconv.ParseUint(strings.TrimSpace(string(b)), 0, 64)
if err != nil {
return err
}
}
{
b, err := ioutil.ReadFile("/proc/sys/fs/nr_open")
if err != nil {
return err
}
nrOpen, err = strconv.ParseUint(strings.TrimSpace(string(b)), 0, 64)
if err != nil {
return err
}
}
max := fileMax
if nrOpen < max {
max = nrOpen
}
set := unix.Rlimit{
Max: max,
Cur: max,
}
return unix.Setrlimit(unix.RLIMIT_NOFILE, &set)
}

var atExit struct {
sync.Mutex
fns []func() error
@@ -96,6 +135,9 @@ func main() {
"scaffold": {scaffold},
"install": {install},
"fuse": {func(args []string) error {
if err := bumpRlimitNOFILE(); err != nil {
log.Printf("Warning: bumping RLIMIT_NOFILE failed: %v", err)
}
join, err := fuse.Mount(args)
if err != nil {
return err
@@ -1,5 +1,5 @@
source: "empty://"
version: "1-4"
version: "1-5"

# This is the shortest and fastest way to build an empty package:
dep: "bash"
@@ -1,5 +1,5 @@
source: "empty://"
version: "3-9"
version: "3-10"

# This is the shortest and fastest way to build an empty package:
dep: "bash"
@@ -1,5 +1,5 @@
source: "empty://"
version: "2-11"
version: "2-12"

# This is the shortest and fastest way to build an empty package:
dep: "bash"
@@ -1,5 +1,5 @@
source: "empty://"
version: "3-9"
version: "3-10"

# This is the shortest and fastest way to build an empty package:
dep: "bash"
@@ -1,5 +1,5 @@
source: "empty://"
version: "1-8"
version: "1-9"

cherry_pick: "service.patch"

@@ -1,6 +1,6 @@
source: "distriroot://distri1-1.tar.gz"
hash: ""
version: "native-17"
version: "native-18"

gobuilder: <
install: "./cmd/distri"

0 comments on commit af8455d

Please sign in to comment.