-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/global: add the ability to call setrlimit(2) on startup
Recent versions of Go changed the logic for setting RLIMIT_NOFILE as part of child processes: https://go-review.googlesource.com/c/go/+/476097 This might cause build actions to run into file descriptor limits. Let's solve this by adding the ability to override resource limits in bb_runner's configuration.
- Loading branch information
1 parent
e7766ce
commit 1ba9ed4
Showing
10 changed files
with
428 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:build darwin | ||
// +build darwin | ||
|
||
package global | ||
|
||
import ( | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var resourceLimitNames = map[string]int{ | ||
"AS": unix.RLIMIT_AS, | ||
"CORE": unix.RLIMIT_CORE, | ||
"CPU": unix.RLIMIT_CPU, | ||
"DATA": unix.RLIMIT_DATA, | ||
"FSIZE": unix.RLIMIT_FSIZE, | ||
"MEMLOCK": unix.RLIMIT_MEMLOCK, | ||
"NOFILE": unix.RLIMIT_NOFILE, | ||
"NPROC": unix.RLIMIT_NPROC, | ||
"RSS": unix.RLIMIT_RSS, | ||
"STACK": unix.RLIMIT_STACK, | ||
} | ||
|
||
type resourceLimitValueType = uint64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:build freebsd | ||
// +build freebsd | ||
|
||
package global | ||
|
||
import ( | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var resourceLimitNames = map[string]int{ | ||
"AS": unix.RLIMIT_AS, | ||
"CORE": unix.RLIMIT_CORE, | ||
"CPU": unix.RLIMIT_CPU, | ||
"DATA": unix.RLIMIT_DATA, | ||
"FSIZE": unix.RLIMIT_FSIZE, | ||
"MEMLOCK": unix.RLIMIT_MEMLOCK, | ||
"NOFILE": unix.RLIMIT_NOFILE, | ||
"NPROC": unix.RLIMIT_NPROC, | ||
"RSS": unix.RLIMIT_RSS, | ||
"STACK": unix.RLIMIT_STACK, | ||
} | ||
|
||
type resourceLimitValueType = int64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package global | ||
|
||
import ( | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
var resourceLimitNames = map[string]int{ | ||
"AS": unix.RLIMIT_AS, | ||
"MEMLOCK": unix.RLIMIT_MEMLOCK, | ||
"NOFILE": unix.RLIMIT_NOFILE, | ||
"NPROC": unix.RLIMIT_NPROC, | ||
"RSS": unix.RLIMIT_RSS, | ||
} | ||
|
||
type resourceLimitValueType = uint64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package global | ||
|
||
import ( | ||
"github.com/buildbarn/bb-storage/pkg/proto/configuration/global" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func setResourceLimit(name string, resourceLimit *global.SetResourceLimitConfiguration) error { | ||
return status.Error(codes.Unimplemented, "Resource limits cannot be adjusted on this operating system") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build darwin || freebsd || linux | ||
// +build darwin freebsd linux | ||
|
||
package global | ||
|
||
import ( | ||
"github.com/buildbarn/bb-storage/pkg/proto/configuration/global" | ||
|
||
"golang.org/x/sys/unix" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/types/known/wrapperspb" | ||
) | ||
|
||
func convertResourceLimitValue(limit *wrapperspb.UInt64Value) resourceLimitValueType { | ||
if limit == nil { | ||
// No limit provided. Assume infinity. | ||
return unix.RLIM_INFINITY | ||
} | ||
return resourceLimitValueType(limit.Value) | ||
} | ||
|
||
// setResourceLimit applies a single resource limit that is provided in | ||
// the configuration file against the current process using | ||
// setrlimit(2). | ||
func setResourceLimit(name string, resourceLimit *global.SetResourceLimitConfiguration) error { | ||
resource, ok := resourceLimitNames[name] | ||
if !ok { | ||
return status.Error(codes.InvalidArgument, "Resource name is not supported by this operating system") | ||
} | ||
return unix.Setrlimit(resource, &unix.Rlimit{ | ||
Cur: convertResourceLimitValue(resourceLimit.SoftLimit), | ||
Max: convertResourceLimitValue(resourceLimit.HardLimit), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.