# RuntimeError: DataLoader worker (pid 12345) received signal 11 (Segmentation fault). Possible causes: shared memory exhausted or dataset memory corruption

- **ID:** `pytorch/dataloader-worker-segfault`
- **Domain:** pytorch
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A DataLoader worker process crashed with a segmentation fault, typically due to insufficient shared memory (on Linux, /dev/shm is too small) or a buggy dataset that corrupts memory (e.g., unsafe multiprocessing with non-picklable objects).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| pytorch>=1.13 | active | — | — |
| torchvision>=0.14 | active | — | — |
| cuda>=11.7 | active | — | — |
| python>=3.8 | active | — | — |

## Workarounds

1. **Increase shared memory size: In Docker, add --shm-size=8g; on bare metal, remount /dev/shm with larger size: sudo mount -o remount,size=8G /dev/shm** (90% success)
   ```
   Increase shared memory size: In Docker, add --shm-size=8g; on bare metal, remount /dev/shm with larger size: sudo mount -o remount,size=8G /dev/shm
   ```
2. **Reduce num_workers to 0 or 1 to avoid multiprocessing issues: DataLoader(..., num_workers=0)** (80% success)
   ```
   Reduce num_workers to 0 or 1 to avoid multiprocessing issues: DataLoader(..., num_workers=0)
   ```
3. **Switch multiprocessing context to 'spawn' (instead of 'fork'): torch.multiprocessing.set_start_method('spawn', force=True)** (75% success)
   ```
   Switch multiprocessing context to 'spawn' (instead of 'fork'): torch.multiprocessing.set_start_method('spawn', force=True)
   ```

## Dead Ends

- **Increasing num_workers to speed up data loading** — More workers consume more shared memory, making the segfault more likely. (90% fail)
- **Using pin_memory=True without increasing shared memory** — Pin memory also uses shared memory, exacerbating the exhaustion. (85% fail)
