Skip to content

Commit

Permalink
Use binary prefix for memory limit and swap (#24)
Browse files Browse the repository at this point in the history
* use binary prefix for memory limit and swap

* update comment
  • Loading branch information
Boy132 authored Jul 17, 2024
1 parent 7d61055 commit a180f37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions environment/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit a180f37

Please sign in to comment.