Skip to content

Commit 1cfcaa3

Browse files
committed
fix: move live Statfs to RemainingResources; use *uint64 for min-free config
- TotalResources reverts to static startup value to keep total-remaining arithmetic consistent for BBS metrics - RemainingResources caps reported DiskMB at live partition free space (syscall.Statfs), so schedulers see reduced capacity when disk fills - MinCachePartitionFreeBytes changed to *uint64: nil means use the 5 GB default, 0 explicitly disables the check (previously impossible) ai-assisted=yes TNZ-111552
1 parent 66e26d2 commit 1cfcaa3

14 files changed

Lines changed: 131 additions & 52 deletions

File tree

jobs/rep/spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ properties:
147147
diego.executor.max_cache_size_in_bytes:
148148
description: "maximum size of the cache in bytes - this should leave a healthy overhead for temporary items, etc."
149149
default: 10000000000
150+
diego.executor.min_cache_partition_free_bytes:
151+
description: "Minimum free space in bytes that must remain on the disk where the download cache lives. When actual disk free space falls below this threshold, the cache deletes old downloaded files to recover space. Set to 0 to disable this behavior."
152+
default: 5368709120
150153
diego.executor.use_schedulable_disk_size:
151154
description: "Use total space available to containers reported by Garden. If false the total size of image plugin store minus max_cache_size_in_bytes is used."
152155
default: false

jobs/rep/templates/rep.json.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
raise "additional_memory_allocation_mb cannot be negative"
126126
end
127127

128+
config[:min_cache_partition_free_bytes] = p("diego.executor.min_cache_partition_free_bytes")
129+
128130
if_p("diego.executor.volman.driver_paths") do |value|
129131
config[:volman_driver_paths] = value
130132
end

jobs/rep_windows/spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ properties:
129129
diego.executor.max_cache_size_in_bytes:
130130
description: "maximum size of the cache in bytes - this should leave a healthy overhead for temporary items, etc."
131131
default: 10000000000
132+
diego.executor.min_cache_partition_free_bytes:
133+
description: "EXPERIMENTAL: Additional memory allocated to each container for the envoy proxy. This must not be negative. Currently doesn't work on windows cells but left here for compatability with the linux Rep."
134+
default: 5368709120
132135
diego.executor.use_schedulable_disk_size:
133136
description: "Use total space available to containers reported by Garden. If false the total size of image plugin store minus max_cache_size_in_bytes is used."
134137
default: false

jobs/rep_windows/templates/rep.json.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
raise "additional_memory_allocation_mb cannot be negative"
123123
end
124124

125+
config[:min_cache_partition_free_bytes] = p("diego.executor.min_cache_partition_free_bytes")
126+
125127
if_p("diego.executor.volman.driver_paths") do |value|
126128
config[:volman_driver_paths] = value
127129
end

spec/rep_template_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@
123123
expect(JSON.parse(rendered_template)['sidecar_root_fs']).to eq('cflinuxfs4')
124124
end
125125
end
126+
127+
context 'min_cache_partition_free_bytes' do
128+
it 'defaults to 5368709120 (5GB)' do
129+
expect(JSON.parse(rendered_template)['min_cache_partition_free_bytes']).to eq(5_368_709_120)
130+
end
131+
132+
it 'is configurable' do
133+
deployment_manifest_fragment['diego']['executor']['min_cache_partition_free_bytes'] = 1_073_741_824
134+
expect(JSON.parse(rendered_template)['min_cache_partition_free_bytes']).to eq(1_073_741_824)
135+
end
136+
end
126137
end
127138

128139
describe 'setup_mounted_data_dirs.erb' do

spec/rep_windows_template_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,16 @@
123123
expect(JSON.parse(rendered_template)['sidecar_root_fs']).to eq('cflinuxfs4')
124124
end
125125
end
126+
127+
context 'min_cache_partition_free_bytes' do
128+
it 'defaults to 5368709120 (5GB)' do
129+
expect(JSON.parse(rendered_template)['min_cache_partition_free_bytes']).to eq(5_368_709_120)
130+
end
131+
132+
it 'is configurable' do
133+
deployment_manifest_fragment['diego']['executor']['min_cache_partition_free_bytes'] = 1_073_741_824
134+
expect(JSON.parse(rendered_template)['min_cache_partition_free_bytes']).to eq(1_073_741_824)
135+
end
136+
end
126137
end
127138
end

src/code.cloudfoundry.org/cacheddownloader/file_cache.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"errors"
55
"fmt"
66
"io"
7-
"math"
87
"os"
98
"path/filepath"
109
"sync"
11-
"syscall"
1210
"time"
1311

1412
"code.cloudfoundry.org/archiver/compressor"
@@ -34,14 +32,6 @@ type FileCache struct {
3432
Seq uint64
3533
}
3634

37-
func defaultFreeSpaceOnPartition(path string) int64 {
38-
var stat syscall.Statfs_t
39-
if err := syscall.Statfs(path, &stat); err != nil {
40-
return math.MaxInt64
41-
}
42-
return int64(stat.Bavail) * int64(stat.Bsize)
43-
}
44-
4535
type FileCacheEntry struct {
4636
Size int64
4737
Access time.Time
@@ -201,6 +191,11 @@ func (e *FileCacheEntry) expandedDirectory() (string, error) {
201191
err = os.RemoveAll(e.FilePath)
202192
if err != nil {
203193
fmt.Fprintln(os.Stderr, "Unable to delete the cached file", err)
194+
} else {
195+
// GetDirectory doubled Size before calling here; tar is now gone so halve it
196+
// back to reflect only the .tar.d on disk. Mirrors the symmetric halving in
197+
// decrementFileInUseCount() which fires when the tar is deleted later.
198+
e.Size = e.Size / 2
204199
}
205200
}
206201
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build !windows
2+
3+
package cacheddownloader
4+
5+
import (
6+
"math"
7+
"syscall"
8+
)
9+
10+
func defaultFreeSpaceOnPartition(path string) int64 {
11+
var stat syscall.Statfs_t
12+
if err := syscall.Statfs(path, &stat); err != nil {
13+
return math.MaxInt64
14+
}
15+
return int64(stat.Bavail) * int64(stat.Bsize)
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build windows
2+
3+
package cacheddownloader
4+
5+
import "math"
6+
7+
func defaultFreeSpaceOnPartition(path string) int64 {
8+
return math.MaxInt64
9+
}

src/code.cloudfoundry.org/executor/depot/depot.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,29 @@ func (c *client) DeleteContainer(logger lager.Logger, traceID string, guid strin
219219

220220
func (c *client) RemainingResources(logger lager.Logger) (executor.ExecutorResources, error) {
221221
logger = logger.Session("remaining-resources")
222-
return c.containerStore.RemainingResources(logger), nil
222+
remaining := c.containerStore.RemainingResources(logger)
223+
if c.diskPath != "" {
224+
if liveMB, ok := liveDiskMB(c.diskPath); ok && liveMB < remaining.DiskMB {
225+
remaining.DiskMB = liveMB
226+
}
227+
}
228+
return remaining, nil
223229
}
224230

225231
func (c *client) Ping(logger lager.Logger) error {
226232
return c.gardenClient.Ping()
227233
}
228234

229235
func (c *client) TotalResources(logger lager.Logger) (executor.ExecutorResources, error) {
236+
diskMB := c.totalCapacity.DiskMB
237+
if c.diskPath != "" {
238+
if liveMB, ok := liveDiskMB(c.diskPath); ok {
239+
diskMB = liveMB
240+
}
241+
}
230242
return executor.ExecutorResources{
231243
MemoryMB: c.totalCapacity.MemoryMB,
232-
DiskMB: getDiskMB(c.diskPath, c.totalCapacity.DiskMB),
244+
DiskMB: diskMB,
233245
Containers: c.totalCapacity.Containers,
234246
}, nil
235247
}

0 commit comments

Comments
 (0)