Skip to content

Commit 1591d16

Browse files
authored
internal/debug: add debug_setMemoryLimit (#31441)
1 parent 263aef9 commit 1591d16

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

internal/debug/api.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"sync"
3636
"time"
3737

38+
"github.com/ethereum/go-ethereum/common"
3839
"github.com/ethereum/go-ethereum/log"
3940
"github.com/hashicorp/go-bexpr"
4041
)
@@ -237,6 +238,24 @@ func (*HandlerT) SetGCPercent(v int) int {
237238
return debug.SetGCPercent(v)
238239
}
239240

241+
// SetMemoryLimit sets the GOMEMLIMIT for the process. It returns the previous limit.
242+
// Note:
243+
//
244+
// - The input limit is provided as bytes. A negative input does not adjust the limit
245+
//
246+
// - A zero limit or a limit that's lower than the amount of memory used by the Go
247+
// runtime may cause the garbage collector to run nearly continuously. However,
248+
// the application may still make progress.
249+
//
250+
// - Setting the limit too low will cause Geth to become unresponsive.
251+
//
252+
// - Geth also allocates memory off-heap, particularly for fastCache and Pebble,
253+
// which can be non-trivial (a few gigabytes by default).
254+
func (*HandlerT) SetMemoryLimit(limit int64) int64 {
255+
log.Info("Setting memory limit", "size", common.PrettyDuration(limit))
256+
return debug.SetMemoryLimit(limit)
257+
}
258+
240259
func writeProfile(name, file string) error {
241260
p := pprof.Lookup(name)
242261
log.Info("Writing profile records", "count", p.Count(), "type", name, "dump", file)

internal/web3ext/web3ext.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ web3._extend({
269269
call: 'debug_setGCPercent',
270270
params: 1,
271271
}),
272+
new web3._extend.Method({
273+
name: 'setMemoryLimit',
274+
call: 'debug_setMemoryLimit',
275+
params: 1,
276+
}),
272277
new web3._extend.Method({
273278
name: 'memStats',
274279
call: 'debug_memStats',

0 commit comments

Comments
 (0)