2019-06-10 01:33:19 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-05-12 14:46:35 -07:00
|
|
|
"os"
|
2019-07-24 07:00:05 -07:00
|
|
|
"runtime/debug"
|
2020-05-12 14:46:35 -07:00
|
|
|
"time"
|
2019-07-24 07:00:05 -07:00
|
|
|
|
2019-06-10 01:33:19 -07:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/home"
|
|
|
|
)
|
|
|
|
|
2019-06-20 04:36:26 -07:00
|
|
|
// version will be set through ldflags, contains current version
|
|
|
|
var version = "undefined"
|
|
|
|
|
|
|
|
// channel can be set via ldflags
|
|
|
|
var channel = "release"
|
|
|
|
|
2020-02-06 10:55:37 -07:00
|
|
|
// GOARM value - set via ldflags
|
2020-01-15 08:58:12 -07:00
|
|
|
var goarm = ""
|
|
|
|
|
2019-06-10 01:33:19 -07:00
|
|
|
func main() {
|
2020-05-12 14:46:35 -07:00
|
|
|
memoryUsage()
|
|
|
|
|
2020-01-15 08:58:12 -07:00
|
|
|
home.Main(version, channel, goarm)
|
2019-06-10 01:33:19 -07:00
|
|
|
}
|
2020-05-12 14:46:35 -07:00
|
|
|
|
|
|
|
// memoryUsage implements a couple of not really beautiful hacks which purpose is to
|
|
|
|
// make OS reclaim the memory freed by AdGuard Home as soon as possible.
|
|
|
|
func memoryUsage() {
|
|
|
|
debug.SetGCPercent(10)
|
|
|
|
|
|
|
|
// madvdontneed: setting madvdontneed=1 will use MADV_DONTNEED
|
|
|
|
// instead of MADV_FREE on Linux when returning memory to the
|
|
|
|
// kernel. This is less efficient, but causes RSS numbers to drop
|
|
|
|
// more quickly.
|
|
|
|
_ = os.Setenv("GODEBUG", "madvdontneed=1")
|
|
|
|
|
|
|
|
// periodically call "debug.FreeOSMemory" so
|
|
|
|
// that the OS could reclaim the free memory
|
|
|
|
go func() {
|
|
|
|
ticker := time.NewTicker(15 * time.Second)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case t := <-ticker.C:
|
|
|
|
t.Second()
|
|
|
|
debug.FreeOSMemory()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|