Skip to content

Commit 6c02a98

Browse files
committed
fix(disk-check): remove redundant /tmp check in containers
- Simplified disk check to only verify root (/) filesystem - In containers, /tmp is just a subdirectory of / (same disk) - Eliminates duplicate log messages with identical results - Updated tests to verify only root filesystem is checked - Updated documentation to reflect container behavior - Reduces check overhead with single disk_usage() call
1 parent 4b1cf9c commit 6c02a98

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

docs/serverless/worker_fitness_checks.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,15 @@ Memory check passed: 12.00GB available (of 16.00GB total)
255255

256256
### Disk Space
257257

258-
Verifies adequate disk space on root filesystem and /tmp (common for model downloads).
258+
Verifies adequate disk space on root filesystem.
259259

260-
Requires free space to be at least a percentage of total disk size, which automatically scales to different machine sizes.
260+
In containers, the root (/) filesystem is typically the only mount point. The check requires free space to be at least a percentage of total disk size, which automatically scales to different machine sizes.
261261

262262
- **Default**: 10% of total disk must be free
263263
- **Configure**: `RUNPOD_MIN_DISK_PERCENT=15` (or any percentage 0-100)
264264

265265
What it checks:
266266
- Root filesystem (/) free space percentage
267-
- Temporary directory (/tmp) free space percentage
268267
- Automatic scaling based on total disk size
269268

270269
Scaling examples with 10% default:
@@ -274,7 +273,7 @@ Scaling examples with 10% default:
274273

275274
Example log output:
276275
```
277-
Disk space check passed on /: 50.00GB free (50.0% available)
276+
Disk space check passed: 50.00GB free (50.0% available)
278277
```
279278

280279
### Network Connectivity

runpod/serverless/modules/rp_system_fitness.py

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,41 +121,33 @@ def _check_memory_availability() -> None:
121121

122122
def _check_disk_space() -> None:
123123
"""
124-
Check disk space availability on root and /tmp.
124+
Check disk space availability on root filesystem.
125125
126+
In containers, root (/) is typically the only filesystem.
126127
Requires free space to be at least MIN_DISK_PERCENT% of total disk size.
127128
128129
Raises:
129130
RuntimeError: If insufficient disk space
130131
"""
131-
paths_to_check = ["/", "/tmp"]
132+
try:
133+
usage = shutil.disk_usage("/")
134+
total_gb = usage.total / (1024**3)
135+
free_gb = usage.free / (1024**3)
136+
free_percent = 100 * (free_gb / total_gb)
132137

133-
for path in paths_to_check:
134-
try:
135-
usage = shutil.disk_usage(path)
136-
total_gb = usage.total / (1024**3)
137-
free_gb = usage.free / (1024**3)
138-
used_percent = 100 * (1 - free_gb / total_gb)
139-
free_percent = 100 * (free_gb / total_gb)
140-
141-
# Check if free space is below the required percentage
142-
if free_percent < MIN_DISK_PERCENT:
143-
raise RuntimeError(
144-
f"Insufficient disk space on {path}: {free_gb:.2f}GB free "
145-
f"({free_percent:.1f}%), {MIN_DISK_PERCENT}% required"
146-
)
147-
148-
log.info(
149-
f"Disk space check passed on {path}: {free_gb:.2f}GB free "
150-
f"({free_percent:.1f}% available)"
138+
# Check if free space is below the required percentage
139+
if free_percent < MIN_DISK_PERCENT:
140+
raise RuntimeError(
141+
f"Insufficient disk space: {free_gb:.2f}GB free "
142+
f"({free_percent:.1f}%), {MIN_DISK_PERCENT}% required"
151143
)
152-
except FileNotFoundError:
153-
# /tmp may not exist on some systems
154-
if path == "/":
155-
# Root always exists
156-
raise
157-
# Skip /tmp if it doesn't exist
158-
log.debug(f"Path {path} not found, skipping disk check")
144+
145+
log.info(
146+
f"Disk space check passed: {free_gb:.2f}GB free "
147+
f"({free_percent:.1f}% available)"
148+
)
149+
except FileNotFoundError:
150+
raise RuntimeError("Could not check disk space: / filesystem not found")
159151

160152

161153
async def _check_network_connectivity() -> None:

tests/test_serverless/test_modules/test_system_fitness.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def test_insufficient_disk_fails(self, mock_disk_usage):
125125

126126
@patch("runpod.serverless.modules.rp_system_fitness.MIN_DISK_PERCENT", 10.0)
127127
@patch("shutil.disk_usage")
128-
def test_checks_both_root_and_tmp(self, mock_disk_usage):
129-
"""Test that both root and /tmp are checked."""
128+
def test_checks_root_filesystem(self, mock_disk_usage):
129+
"""Test that root filesystem is checked."""
130130
mock_usage = MagicMock()
131131
# 100GB total, 50GB free (50% free) - should pass
132132
mock_usage.total = 100 * 1024**3
@@ -135,10 +135,8 @@ def test_checks_both_root_and_tmp(self, mock_disk_usage):
135135

136136
_check_disk_space()
137137

138-
# Verify both paths were checked
139-
assert mock_disk_usage.call_count >= 2
140-
paths_checked = [call[0][0] for call in mock_disk_usage.call_args_list]
141-
assert "/" in paths_checked
138+
# Verify root filesystem was checked
139+
mock_disk_usage.assert_called_once_with("/")
142140

143141

144142
# ============================================================================

0 commit comments

Comments
 (0)