{
  "id": "pytorch/dataloader-shared-memory-segfault",
  "signature": "RuntimeError: DataLoader worker (pid 12345) received signal 11 (Segmentation fault). Possible causes: shared memory exhausted or corrupted shared memory files.",
  "signature_zh": "RuntimeError: DataLoader 工作进程（pid 12345）收到信号 11（段错误）。可能原因：共享内存耗尽或共享内存文件损坏。",
  "regex": "RuntimeError: DataLoader worker \\(pid \\d+\\) received signal 11 \\(Segmentation fault\\)",
  "domain": "pytorch",
  "category": "resource_error",
  "subcategory": null,
  "root_cause": "DataLoader workers using multiprocessing with shared memory (shm) run out of /dev/shm space or encounter corrupted shared memory files, causing segfault.",
  "root_cause_type": "generic",
  "root_cause_zh": "DataLoader 工作进程使用多进程和共享内存（shm）时，/dev/shm 空间耗尽或共享内存文件损坏，导致段错误。",
  "versions": [
    {
      "version": "torch>=1.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "torch>=2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Linux kernel 5.x+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Docker containers",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing num_workers to speed up loading",
      "why_fails": "More workers consume more shared memory, exacerbating the exhaustion and making segfaults more frequent.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting multiprocessing_context to 'fork' on Linux",
      "why_fails": "Fork inherits parent's memory space, but shared memory issues remain; 'spawn' is recommended for PyTorch.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Increase /dev/shm size: docker run --shm-size=8g ... or sudo mount -o remount,size=8G /dev/shm",
      "success_rate": 0.85,
      "how": "Increase /dev/shm size: docker run --shm-size=8g ... or sudo mount -o remount,size=8G /dev/shm",
      "condition": "",
      "sources": []
    },
    {
      "action": "Set DataLoader with multiprocessing_context='spawn' and reduce num_workers: DataLoader(dataset, num_workers=2, multiprocessing_context='spawn')",
      "success_rate": 0.75,
      "how": "Set DataLoader with multiprocessing_context='spawn' and reduce num_workers: DataLoader(dataset, num_workers=2, multiprocessing_context='spawn')",
      "condition": "",
      "sources": []
    },
    {
      "action": "Disable shared memory by setting DataLoader with persistent_workers=False and pin_memory=False",
      "success_rate": 0.7,
      "how": "Disable shared memory by setting DataLoader with persistent_workers=False and pin_memory=False",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pytorch.org/docs/stable/data.html#multi-process-data-loading",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}