From a180f371800d5db486afc12f260c8e2226c28424 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Wed, 17 Jul 2024 17:34:32 +0200 Subject: [PATCH] Use binary prefix for memory limit and swap (#24) * use binary prefix for memory limit and swap * update comment --- config/config.go | 2 +- environment/settings.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 16364be..8480866 100644 --- a/config/config.go +++ b/config/config.go @@ -91,7 +91,7 @@ type ApiConfiguration struct { // servers. DisableRemoteDownload bool `json:"-" yaml:"disable_remote_download"` - // The maximum size for files uploaded through the Panel in MB. + // The maximum size for files uploaded through the Panel in MiB. UploadLimit int64 `default:"100" json:"upload_limit" yaml:"upload_limit"` // A list of IP address of proxies that may send a X-Forwarded-For header to set the true clients IP diff --git a/environment/settings.go b/environment/settings.go index 77d7c3e..596da6f 100644 --- a/environment/settings.go +++ b/environment/settings.go @@ -34,7 +34,7 @@ type Mount struct { // Limits is the build settings for a given server that impact docker container // creation and resource limits for a server instance. type Limits struct { - // The total amount of memory in megabytes that this server is allowed to + // The total amount of memory in mebibytes that this server is allowed to // use on the host system. MemoryLimit int64 `json:"memory_limit"` @@ -50,7 +50,7 @@ type Limits struct { // should be a value between 1 and THREAD_COUNT * 100. CpuLimit int64 `json:"cpu_limit"` - // The amount of disk space in megabytes that a server is allowed to use. + // The amount of disk space in mebibytes that a server is allowed to use. DiskSpace int64 `json:"disk_space"` // Sets which CPU threads can be used by the docker instance. @@ -79,7 +79,7 @@ func (l Limits) MemoryOverheadMultiplier() float64 { } func (l Limits) BoundedMemoryLimit() int64 { - return int64(math.Round(float64(l.MemoryLimit) * l.MemoryOverheadMultiplier() * 1_000_000)) + return int64(math.Round(float64(l.MemoryLimit) * l.MemoryOverheadMultiplier() * 1024 * 1024)) } // ConvertedSwap returns the amount of swap available as a total in bytes. This @@ -90,7 +90,7 @@ func (l Limits) ConvertedSwap() int64 { return -1 } - return (l.Swap * 1_000_000) + l.BoundedMemoryLimit() + return (l.Swap * 1024 * 1024) + l.BoundedMemoryLimit() } // ProcessLimit returns the process limit for a container. This is currently @@ -110,7 +110,7 @@ func (l Limits) AsContainerResources() container.Resources { pids := l.ProcessLimit() resources := container.Resources{ Memory: l.BoundedMemoryLimit(), - MemoryReservation: l.MemoryLimit * 1_000_000, + MemoryReservation: l.MemoryLimit * 1024 * 1024, MemorySwap: l.ConvertedSwap(), BlkioWeight: l.IoWeight, OomKillDisable: boolPtr(!l.OOMKiller),