Skip to content

Commit

Permalink
fix: properly use base2 (1024, *bibyte) when calculating memory limits (
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLier authored Jun 29, 2024
1 parent 29e4425 commit 934bf24
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 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 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 @@ -105,7 +105,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: &l.OOMDisabled,
Expand Down

0 comments on commit 934bf24

Please sign in to comment.