mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Usage.Reduce RPC: Add option to avoid Go garbage collection.
PiperOrigin-RevId: 547942962
This commit is contained in:
committed by
gVisor bot
parent
8ccc217397
commit
eb31c9ed59
@@ -127,9 +127,18 @@ func (u *Usage) Collect(opts *MemoryUsageOpts, out *MemoryUsage) error {
|
||||
|
||||
// UsageReduceOpts contains options to Usage.Reduce().
|
||||
type UsageReduceOpts struct {
|
||||
// If Wait is true, Reduce blocks until all activity initiated by
|
||||
// If Wait is `true`, Reduce blocks until all activity initiated by
|
||||
// Usage.Reduce() has completed.
|
||||
// If Wait is `false`, Go garbage collection is still performed and may
|
||||
// still block for some time, unless `DoNotGC` is `true`.
|
||||
Wait bool `json:"wait"`
|
||||
|
||||
// If DoNotGC is true, Reduce does not explicitly run Go garbage collection.
|
||||
// Garbage collection may block for an indeterminate amount of time.
|
||||
// Note that the runtime Go may still perform routine garbage collection at
|
||||
// any time during program execution, so a routine GC is still possible even
|
||||
// when this option set to `true`.
|
||||
DoNotGC bool `json:"do_not_gc"`
|
||||
}
|
||||
|
||||
// UsageReduceOutput contains output from Usage.Reduce().
|
||||
@@ -142,8 +151,9 @@ func (u *Usage) Reduce(opts *UsageReduceOpts, out *UsageReduceOutput) error {
|
||||
if opts.Wait {
|
||||
mf.WaitForEvictions()
|
||||
}
|
||||
// Also reduce Sentry memory usage by garbage-collecting now.
|
||||
runtime.GC()
|
||||
if !opts.DoNotGC {
|
||||
runtime.GC()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user