Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: Remove Go <= 1.18 memory limits #3483

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions dcrd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,25 @@ func dcrdMain() error {

// Block and transaction processing can cause bursty allocations. This
// limits the garbage collector from excessively overallocating during
// bursts. It does this by tweaking the target GC percent and soft memory
// limit depending on the version of the Go runtime.
// bursts. It does this by tweaking the soft memory limit.
//
// Starting with Go 1.19, a soft upper memory limit is imposed that leaves
// plenty of headroom for the minimum recommended value and the target GC
// percentage is left at the default value to significantly reduce the
// number of GC cycles thereby reducing the amount of CPU time spent doing
// garbage collection.
// A soft upper memory limit is imposed that leaves plenty of headroom
// for the minimum recommended value and the target GC percentage is
// left at the default value to significantly reduce the number of GC
// cycles thereby reducing the amount of CPU time spent doing garbage
// collection.
//
// For versions of Go prior to 1.19, the ability to set a soft upper memory
// limit was not available, so the GC percentage is lowered instead which
// has the effect of preventing overallocations at the expense of more
// frequent GC cycles.
//
// These values were arrived at with the help of profiling live usage.
if limits.SupportsMemoryLimit {
// Enforce a soft memory limit for a base amount along with any extra
// utxo cache over and above the default max cache size.
const memLimitBase = (15 * (1 << 30)) / 10 // 1.5 GiB
softMemLimit := int64(memLimitBase)
if cfg.UtxoCacheMaxSize > defaultUtxoCacheMaxSize {
extra := int64(cfg.UtxoCacheMaxSize) - defaultUtxoCacheMaxSize
softMemLimit += extra * (1 << 20)
}
limits.SetMemoryLimit(softMemLimit)
dcrdLog.Infof("Soft memory limit: %s", humanizeBytes(softMemLimit))
} else {
debug.SetGCPercent(20)
// A limit of 1.5 GiB is used as a baseline, with an increase to the
// limit when the UTXO cache max size has been increased over the
// default.
const memLimitBase = (15 * (1 << 30)) / 10 // 1.5 GiB
softMemLimit := int64(memLimitBase)
if cfg.UtxoCacheMaxSize > defaultUtxoCacheMaxSize {
extra := int64(cfg.UtxoCacheMaxSize) - defaultUtxoCacheMaxSize
softMemLimit += extra * (1 << 20)
}
debug.SetMemoryLimit(softMemLimit)
dcrdLog.Infof("Soft memory limit: %s", humanizeBytes(softMemLimit))

// Enable http profile server if requested. Note that since the server may
// be started now or dynamically started and stopped later, the stop call is
Expand Down
19 changes: 0 additions & 19 deletions internal/limits/memlimit.go

This file was deleted.

16 changes: 0 additions & 16 deletions internal/limits/memlimit_old.go

This file was deleted.