cmd/geth: wrong memory size sanitizing on OpenBSD (#19793)
This commit is contained in:
parent
d9c75cd10e
commit
dcc4adfcd7
|
@ -21,6 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
godebug "runtime/debug"
|
godebug "runtime/debug"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -256,6 +257,9 @@ func init() {
|
||||||
}
|
}
|
||||||
// Cap the cache allowance and tune the garbage collector
|
// Cap the cache allowance and tune the garbage collector
|
||||||
var mem gosigar.Mem
|
var mem gosigar.Mem
|
||||||
|
// Workaround until OpenBSD support lands into gosigar
|
||||||
|
// Check https://github.com/elastic/gosigar#supported-platforms
|
||||||
|
if runtime.GOOS != "openbsd" {
|
||||||
if err := mem.Get(); err == nil {
|
if err := mem.Get(); err == nil {
|
||||||
allowance := int(mem.Total / 1024 / 1024 / 3)
|
allowance := int(mem.Total / 1024 / 1024 / 3)
|
||||||
if cache := ctx.GlobalInt(utils.CacheFlag.Name); cache > allowance {
|
if cache := ctx.GlobalInt(utils.CacheFlag.Name); cache > allowance {
|
||||||
|
@ -263,6 +267,7 @@ func init() {
|
||||||
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(allowance))
|
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(allowance))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Ensure Go's GC ignores the database cache for trigger percentage
|
// Ensure Go's GC ignores the database cache for trigger percentage
|
||||||
cache := ctx.GlobalInt(utils.CacheFlag.Name)
|
cache := ctx.GlobalInt(utils.CacheFlag.Name)
|
||||||
gogc := math.Max(20, math.Min(100, 100/(float64(cache)/1024)))
|
gogc := math.Max(20, math.Min(100, 100/(float64(cache)/1024)))
|
||||||
|
|
|
@ -70,7 +70,7 @@ func NewSyncBloom(memory uint64, database ethdb.Iteratee) *SyncBloom {
|
||||||
// Create the bloom filter to track known trie nodes
|
// Create the bloom filter to track known trie nodes
|
||||||
bloom, err := bloomfilter.New(memory*1024*1024*8, 3)
|
bloom, err := bloomfilter.New(memory*1024*1024*8, 3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to create bloom: %v", err)) // Can't happen, here for sanity
|
panic(fmt.Sprintf("failed to create bloom: %v", err))
|
||||||
}
|
}
|
||||||
log.Info("Allocated fast sync bloom", "size", common.StorageSize(memory*1024*1024))
|
log.Info("Allocated fast sync bloom", "size", common.StorageSize(memory*1024*1024))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue