device: add MaxBatchSizeOverride global for default batch-size control

This commit is contained in:
Viktor Liu
2026-04-22 12:05:03 +02:00
parent 9ece9cee1e
commit 6906fefa2a
2 changed files with 17 additions and 0 deletions
+4
View File
@@ -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
+13
View File
@@ -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