# 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`
- **Domain:** pytorch
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

DataLoader workers using multiprocessing with shared memory (shm) run out of /dev/shm space or encounter corrupted shared memory files, causing segfault.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| torch>=1.10 | active | — | — |
| torch>=2.0 | active | — | — |
| Linux kernel 5.x+ | active | — | — |
| Docker containers | active | — | — |

## Workarounds

1. **Increase /dev/shm size: docker run --shm-size=8g ... or sudo mount -o remount,size=8G /dev/shm** (85% success)
   ```
   Increase /dev/shm size: docker run --shm-size=8g ... or sudo mount -o remount,size=8G /dev/shm
   ```
2. **Set DataLoader with multiprocessing_context='spawn' and reduce num_workers: DataLoader(dataset, num_workers=2, multiprocessing_context='spawn')** (75% success)
   ```
   Set DataLoader with multiprocessing_context='spawn' and reduce num_workers: DataLoader(dataset, num_workers=2, multiprocessing_context='spawn')
   ```
3. **Disable shared memory by setting DataLoader with persistent_workers=False and pin_memory=False** (70% success)
   ```
   Disable shared memory by setting DataLoader with persistent_workers=False and pin_memory=False
   ```

## Dead Ends

- **Increasing num_workers to speed up loading** — More workers consume more shared memory, exacerbating the exhaustion and making segfaults more frequent. (70% fail)
- **Setting multiprocessing_context to 'fork' on Linux** — Fork inherits parent's memory space, but shared memory issues remain; 'spawn' is recommended for PyTorch. (60% fail)
