diff --git a/build/limits.go b/build/limits.go new file mode 100644 index 000000000..93d56577c --- /dev/null +++ b/build/limits.go @@ -0,0 +1,6 @@ +package build + +var ( + DefaultFDLimit uint64 = 16 << 10 + MinerFDLimit uint64 = 100_000 +) diff --git a/build/openrpc/full.json.gz b/build/openrpc/full.json.gz index 6cae0a383..4892e0901 100644 Binary files a/build/openrpc/full.json.gz and b/build/openrpc/full.json.gz differ diff --git a/build/openrpc/miner.json.gz b/build/openrpc/miner.json.gz index e7d1a32e0..b119be722 100644 Binary files a/build/openrpc/miner.json.gz and b/build/openrpc/miner.json.gz differ diff --git a/build/openrpc/worker.json.gz b/build/openrpc/worker.json.gz index f943040b6..06d91c92a 100644 Binary files a/build/openrpc/worker.json.gz and b/build/openrpc/worker.json.gz differ diff --git a/lib/ulimit/ulimit.go b/lib/ulimit/ulimit.go index 7e80fd223..764cd6874 100644 --- a/lib/ulimit/ulimit.go +++ b/lib/ulimit/ulimit.go @@ -3,11 +3,14 @@ package ulimit // from go-ipfs import ( + "errors" "fmt" "os" "strconv" "syscall" + "github.com/filecoin-project/lotus/build" + logging "github.com/ipfs/go-log/v2" ) @@ -17,7 +20,7 @@ var ( supportsFDManagement = false // getlimit returns the soft and hard limits of file descriptors counts - GetLimit func() (uint64, uint64, error) + getLimit func() (uint64, uint64, error) // set limit sets the soft and hard limits of file descriptors counts setLimit func(uint64, uint64) error ) @@ -25,8 +28,15 @@ var ( // minimum file descriptor limit before we complain const minFds = 2048 -// default max file descriptor limit. -const maxFds = 16 << 10 +var ErrUnsupported = errors.New("unsupported") + +func GetLimit() (uint64, uint64, error) { + if getLimit == nil { + return 0, 0, ErrUnsupported + } + + return getLimit() +} // userMaxFDs returns the value of LOTUS_FD_MAX func userMaxFDs() uint64 { @@ -55,7 +65,7 @@ func ManageFdLimit() (changed bool, newLimit uint64, err error) { return false, 0, nil } - targetLimit := uint64(maxFds) + targetLimit := build.DefaultFDLimit userLimit := userMaxFDs() if userLimit > 0 { targetLimit = userLimit diff --git a/lib/ulimit/ulimit_freebsd.go b/lib/ulimit/ulimit_freebsd.go index aeea77d9d..7e50436f3 100644 --- a/lib/ulimit/ulimit_freebsd.go +++ b/lib/ulimit/ulimit_freebsd.go @@ -11,7 +11,7 @@ import ( func init() { supportsFDManagement = true - GetLimit = freebsdGetLimit + getLimit = freebsdGetLimit setLimit = freebsdSetLimit } diff --git a/lib/ulimit/ulimit_test.go b/lib/ulimit/ulimit_test.go index c99b7fb57..ad27a163a 100644 --- a/lib/ulimit/ulimit_test.go +++ b/lib/ulimit/ulimit_test.go @@ -8,6 +8,8 @@ import ( "strings" "syscall" "testing" + + "github.com/filecoin-project/lotus/build" ) func TestManageFdLimit(t *testing.T) { @@ -16,7 +18,7 @@ func TestManageFdLimit(t *testing.T) { t.Errorf("Cannot manage file descriptors") } - if maxFds != uint64(16<<10) { + if build.DefaultFDLimit != uint64(16<<10) { t.Errorf("Maximum file descriptors default value changed") } } diff --git a/lib/ulimit/ulimit_unix.go b/lib/ulimit/ulimit_unix.go index e015b2b32..a351236dc 100644 --- a/lib/ulimit/ulimit_unix.go +++ b/lib/ulimit/ulimit_unix.go @@ -8,7 +8,7 @@ import ( func init() { supportsFDManagement = true - GetLimit = unixGetLimit + getLimit = unixGetLimit setLimit = unixSetLimit } diff --git a/node/builder.go b/node/builder.go index 58095da8f..887f9046f 100644 --- a/node/builder.go +++ b/node/builder.go @@ -28,6 +28,7 @@ import ( "go.uber.org/fx" "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/stores" @@ -152,7 +153,7 @@ func defaults() []Option { Override(new(journal.Journal), modules.OpenFilesystemJournal), Override(new(*alerting.Alerting), alerting.NewAlertingSystem), - Override(CheckFDLimit, modules.CheckFdLimit(16<<10)), + Override(CheckFDLimit, modules.CheckFdLimit(build.DefaultFDLimit)), Override(new(system.MemoryConstraints), modules.MemoryConstraints), Override(InitMemoryWatchdog, modules.MemoryWatchdog), diff --git a/node/builder_miner.go b/node/builder_miner.go index 4c9d2492a..c8ee5d48c 100644 --- a/node/builder_miner.go +++ b/node/builder_miner.go @@ -15,6 +15,7 @@ import ( storage2 "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/gen/slashfilter" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" @@ -74,7 +75,7 @@ func ConfigStorageMiner(c interface{}) Option { return Options( ConfigCommon(&cfg.Common, enableLibp2pNode), - Override(CheckFDLimit, modules.CheckFdLimit(100_000)), // recommend at least 100k FD limit to miners + Override(CheckFDLimit, modules.CheckFdLimit(build.MinerFDLimit)), // recommend at least 100k FD limit to miners Override(new(api.MinerSubsystems), modules.ExtractEnabledMinerSubsystems(cfg.Subsystems)), Override(new(stores.LocalStorage), From(new(repo.LockedRepo))), diff --git a/node/modules/alerts.go b/node/modules/alerts.go index 89261e231..75be08354 100644 --- a/node/modules/alerts.go +++ b/node/modules/alerts.go @@ -7,13 +7,14 @@ import ( func CheckFdLimit(min uint64) func(al *alerting.Alerting) { return func(al *alerting.Alerting) { - if ulimit.GetLimit == nil { + soft, _, err := ulimit.GetLimit() + + if err == ulimit.ErrUnsupported { + log.Warn("FD limit monitoring not available") return } alert := al.AddAlertType("process", "fd-limit") - - soft, _, err := ulimit.GetLimit() if err != nil { al.Raise(alert, map[string]string{ "message": "failed to get FD limit",