forked from forks/go-ethereum
internal/debug: add debug_setMemoryLimit (#31441)
This commit is contained in:
parent
263aef9cc4
commit
1591d165c4
2 changed files with 24 additions and 0 deletions
|
|
@ -35,6 +35,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/hashicorp/go-bexpr"
|
||||
)
|
||||
|
|
@ -237,6 +238,24 @@ func (*HandlerT) SetGCPercent(v int) int {
|
|||
return debug.SetGCPercent(v)
|
||||
}
|
||||
|
||||
// SetMemoryLimit sets the GOMEMLIMIT for the process. It returns the previous limit.
|
||||
// Note:
|
||||
//
|
||||
// - The input limit is provided as bytes. A negative input does not adjust the limit
|
||||
//
|
||||
// - A zero limit or a limit that's lower than the amount of memory used by the Go
|
||||
// runtime may cause the garbage collector to run nearly continuously. However,
|
||||
// the application may still make progress.
|
||||
//
|
||||
// - Setting the limit too low will cause Geth to become unresponsive.
|
||||
//
|
||||
// - Geth also allocates memory off-heap, particularly for fastCache and Pebble,
|
||||
// which can be non-trivial (a few gigabytes by default).
|
||||
func (*HandlerT) SetMemoryLimit(limit int64) int64 {
|
||||
log.Info("Setting memory limit", "size", common.PrettyDuration(limit))
|
||||
return debug.SetMemoryLimit(limit)
|
||||
}
|
||||
|
||||
func writeProfile(name, file string) error {
|
||||
p := pprof.Lookup(name)
|
||||
log.Info("Writing profile records", "count", p.Count(), "type", name, "dump", file)
|
||||
|
|
|
|||
|
|
@ -269,6 +269,11 @@ web3._extend({
|
|||
call: 'debug_setGCPercent',
|
||||
params: 1,
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'setMemoryLimit',
|
||||
call: 'debug_setMemoryLimit',
|
||||
params: 1,
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'memStats',
|
||||
call: 'debug_memStats',
|
||||
|
|
|
|||
Loading…
Reference in a new issue