mirror of
https://github.com/netbirdio/wireguard-go.git
synced 2026-05-22 17:08:51 -07:00
device: add MaxBatchSizeOverride global for default batch-size control
This commit is contained in:
@@ -307,6 +307,10 @@ func NewDevice(tunDevice tun.Device, bind conn.Bind, logger *Logger) *Device {
|
||||
device.rate.limiter.Init()
|
||||
device.indexTable.Init()
|
||||
|
||||
if MaxBatchSizeOverride > 0 {
|
||||
device.batchSizeOverride.Store(int32(MaxBatchSizeOverride))
|
||||
}
|
||||
|
||||
device.PopulatePools()
|
||||
|
||||
// create queues
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
|
||||
package device
|
||||
|
||||
// MaxBatchSizeOverride, when nonzero, replaces the per-Device batch size used
|
||||
// to size eager buffer allocations in RoutineReceiveIncoming and
|
||||
// RoutineReadFromTUN. Changes affect Devices created after this assignment.
|
||||
// Use SetMaxBatchSizeOverride to change it safely at runtime.
|
||||
var MaxBatchSizeOverride uint32 = 0
|
||||
|
||||
// SetPreallocatedBuffersPerPool sets the cap on the number of buffers held by
|
||||
// each per-Device pool. Zero disables the cap (upstream default on
|
||||
// non-mobile platforms). Changes affect Devices created after this call.
|
||||
@@ -13,6 +19,13 @@ func SetPreallocatedBuffersPerPool(n uint32) {
|
||||
PreallocatedBuffersPerPool = n
|
||||
}
|
||||
|
||||
// SetMaxBatchSizeOverride sets the global batch size override applied to
|
||||
// Devices created after this call. Zero disables the override. Existing
|
||||
// Devices are unaffected; use Device.SetMaxBatchSize for per-instance.
|
||||
func SetMaxBatchSizeOverride(n uint32) {
|
||||
MaxBatchSizeOverride = n
|
||||
}
|
||||
|
||||
// SetPreallocatedBuffersPerPool updates the cap on this Device's pools in
|
||||
// place. Takes effect immediately; goroutines blocked in Get are unblocked if
|
||||
// the cap was raised. Has no effect if the Device was created with
|
||||
|
||||
Reference in New Issue
Block a user