# RuntimeError: DataLoader 工作进程 (pid 12345) 收到信号 9 (SIGKILL)。可能原因：内存不足或达到系统限制。

- **ID:** `pytorch/dataloader-num-workers-memory-leak`
- **领域:** pytorch
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

DataLoader 工作进程数量过多且每个样本内存使用量高，导致系统 OOM killer 终止进程，尤其在使用大数据集或高分辨率图像时。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.10 | active | — | — |
| 1.11 | active | — | — |
| 1.12 | active | — | — |
| 1.13 | active | — | — |
| 2.0 | active | — | — |
| 2.1 | active | — | — |
| 2.2 | active | — | — |
| 2.3 | active | — | — |

## 解决方案

1. ```
   Reduce num_workers to a lower value, e.g., 2 or 4, or set to 0 for single-process loading to eliminate worker memory overhead.
   ```
2. ```
   Use prefetch_factor to limit the number of batches prefetched per worker, reducing peak memory usage.
   ```

## 无效尝试

- **** — Increasing workers exacerbates memory pressure, causing more frequent OOM kills. (70% 失败率)
- **** — This doesn't reduce per-worker memory; it just changes how data is split. (50% 失败率)
