# 运行时错误：DataLoader 工作进程（pid 12345）收到信号 11（段错误）。可能原因：共享内存耗尽

- **ID:** `pytorch/dataloader-worker-segfault-shared-memory`
- **领域:** pytorch
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

共享内存（/dev/shm）已满或太小，无法容纳 DataLoader 工作进程传输的数据，通常由于批量大小过大或高分辨率图像。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pytorch>=1.10.0 | active | — | — |
| linux | active | — | — |

## 解决方案

1. ```
   通过重新挂载增加 /dev/shm 的大小。在 Docker 中使用 --shm-size=8g。在裸机上编辑 /etc/fstab 或使用 mount -o remount,size=8G /dev/shm。
   ```
2. ```
   减少批量大小或在 DataLoader 中使用 pin_memory=False，避免将张量复制到固定内存，这使用共享内存。
   ```

## 无效尝试

- **** — This is a workaround that changes behavior, but it doesn't fix the underlying shared memory limit. (40% 失败率)
- **** — Larger batches increase shared memory usage, exacerbating the issue. (90% 失败率)
- **** — Shared memory is recreated at boot, but the limit remains the same; it will fill up again. (70% 失败率)
