Skip to content

Commit

Permalink
fix: gc policy for windows to use 10% of disk space
Browse files Browse the repository at this point in the history
Initially we had the GC Policy for Windows use only
2 GB (2e9 bytes) of disk space and this was limiting
for some build scenarios that need more than that,
especially ServerCore images.

This commit makes the policy to use percentages
as it is on Linux. Also going for 10% as it is
on Linux. For instance, after the change, on a
dev machine, the configured space was
74694367232 / (1 << 30) = 69.5 GiB.

fixes #4858 docker/buildx#2411

Signed-off-by: Anthony Nandaa <[email protected]>
  • Loading branch information
profnandaa committed Apr 22, 2024
1 parent bbd262a commit 61399b6
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions cmd/buildkitd/config/gcpolicy_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@

package config

import "golang.org/x/sys/windows"

func DetectDefaultGCCap() DiskSpace {
return DiskSpace{Bytes: defaultCap}
return DiskSpace{Percentage: 10}
}

func (d DiskSpace) AsBytes(root string) int64 {
return d.Bytes
if d.Bytes != 0 {
return d.Bytes
}
if d.Percentage == 0 {
return 0
}

rootUTF16, err := windows.UTF16FromString(root)
if err != nil {
return defaultCap
}
var freeAvailableBytes uint64
var totalBytes uint64
var totalFreeBytes uint64

if err := windows.GetDiskFreeSpaceEx(
&rootUTF16[0],
&freeAvailableBytes,
&totalBytes,
&totalFreeBytes); err != nil {
return defaultCap
}

avail := int64(totalBytes) * d.Percentage / 100
return avail
}

0 comments on commit 61399b6

Please sign in to comment.