Skip to content

Commit af8455d

Browse files
committed
distri fuse: bump rlimit NOFILE (open files) to 398430 (Linux max)
This will fix the problem once and for all! fixes #53
1 parent dbc30ef commit af8455d

7 files changed

Lines changed: 48 additions & 6 deletions

File tree

cmd/distri/distri.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import (
44
"context"
55
"flag"
66
"fmt"
7+
"io/ioutil"
78
"log"
89
"net/http"
910
"os"
1011
"runtime/pprof"
1112
"runtime/trace"
13+
"strconv"
14+
"strings"
1215
"sync"
1316
"sync/atomic"
1417

1518
"github.com/distr1/distri/cmd/distri/internal/fuse"
19+
"golang.org/x/sys/unix"
1620
"golang.org/x/xerrors"
1721

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

34+
func bumpRlimitNOFILE() error {
35+
// The smaller of the two is the highest which Linux will let us set:
36+
// https://github.com/torvalds/linux/blob/2be7d348fe924f0c5583c6a805bd42cecda93104/kernel/sys.c#L1526-L1541
37+
var fileMax, nrOpen uint64
38+
{
39+
b, err := ioutil.ReadFile("/proc/sys/fs/file-max")
40+
if err != nil {
41+
return err
42+
}
43+
fileMax, err = strconv.ParseUint(strings.TrimSpace(string(b)), 0, 64)
44+
if err != nil {
45+
return err
46+
}
47+
}
48+
{
49+
b, err := ioutil.ReadFile("/proc/sys/fs/nr_open")
50+
if err != nil {
51+
return err
52+
}
53+
nrOpen, err = strconv.ParseUint(strings.TrimSpace(string(b)), 0, 64)
54+
if err != nil {
55+
return err
56+
}
57+
}
58+
max := fileMax
59+
if nrOpen < max {
60+
max = nrOpen
61+
}
62+
set := unix.Rlimit{
63+
Max: max,
64+
Cur: max,
65+
}
66+
return unix.Setrlimit(unix.RLIMIT_NOFILE, &set)
67+
}
68+
3069
var atExit struct {
3170
sync.Mutex
3271
fns []func() error
@@ -96,6 +135,9 @@ func main() {
96135
"scaffold": {scaffold},
97136
"install": {install},
98137
"fuse": {func(args []string) error {
138+
if err := bumpRlimitNOFILE(); err != nil {
139+
log.Printf("Warning: bumping RLIMIT_NOFILE failed: %v", err)
140+
}
99141
join, err := fuse.Mount(args)
100142
if err != nil {
101143
return err

pkgs/base-cloud/build.textproto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source: "empty://"
2-
version: "1-4"
2+
version: "1-5"
33

44
# This is the shortest and fastest way to build an empty package:
55
dep: "bash"

pkgs/base-full/build.textproto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source: "empty://"
2-
version: "3-9"
2+
version: "3-10"
33

44
# This is the shortest and fastest way to build an empty package:
55
dep: "bash"

pkgs/base-x11/build.textproto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source: "empty://"
2-
version: "2-11"
2+
version: "2-12"
33

44
# This is the shortest and fastest way to build an empty package:
55
dep: "bash"

pkgs/base/build.textproto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source: "empty://"
2-
version: "3-9"
2+
version: "3-10"
33

44
# This is the shortest and fastest way to build an empty package:
55
dep: "bash"

pkgs/debugfs/build.textproto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source: "empty://"
2-
version: "1-8"
2+
version: "1-9"
33

44
cherry_pick: "service.patch"
55

pkgs/distri1/build.textproto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source: "distriroot://distri1-1.tar.gz"
22
hash: ""
3-
version: "native-17"
3+
version: "native-18"
44

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

0 commit comments

Comments
 (0)