pytorch
resource_error
ai_generated
true
RuntimeError: DataLoader 工作进程(pid 12345)收到信号 11(段错误)。可能原因:共享内存耗尽或共享内存文件损坏。
RuntimeError: DataLoader worker (pid 12345) received signal 11 (Segmentation fault). Possible causes: shared memory exhausted or corrupted shared memory files.
ID: pytorch/dataloader-shared-memory-segfault
78%修复率
82%置信度
1证据数
2023-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| torch>=1.10 | active | — | — | — |
| torch>=2.0 | active | — | — | — |
| Linux kernel 5.x+ | active | — | — | — |
| Docker containers | active | — | — | — |
根因分析
DataLoader 工作进程使用多进程和共享内存(shm)时,/dev/shm 空间耗尽或共享内存文件损坏,导致段错误。
English
DataLoader workers using multiprocessing with shared memory (shm) run out of /dev/shm space or encounter corrupted shared memory files, causing segfault.
官方文档
https://pytorch.org/docs/stable/data.html#multi-process-data-loading解决方案
-
Increase /dev/shm size: docker run --shm-size=8g ... or sudo mount -o remount,size=8G /dev/shm
-
Set DataLoader with multiprocessing_context='spawn' and reduce num_workers: DataLoader(dataset, num_workers=2, multiprocessing_context='spawn')
-
Disable shared memory by setting DataLoader with persistent_workers=False and pin_memory=False
无效尝试
常见但无效的做法:
-
Increasing num_workers to speed up loading
70% 失败
More workers consume more shared memory, exacerbating the exhaustion and making segfaults more frequent.
-
Setting multiprocessing_context to 'fork' on Linux
60% 失败
Fork inherits parent's memory space, but shared memory issues remain; 'spawn' is recommended for PyTorch.