{
  "slug": "readahead",
  "term": "readahead (Linux syscall)",
  "aliases": [
    "readahead(2)"
  ],
  "definition": "The Linux readahead syscall requests advance loading of a file range into the page cache without advancing the open file description's offset.",
  "note": "Ranges are handled in whole pages and stop at end of file. Success returns zero, not a fetched-byte count; errors return -1 and set errno. EBADF reports a descriptor that is invalid or not open for reading, and EINVAL a file type that does not support the call. Subsequent reads benefit only if data arrives in time and remains cached. The call exists since Linux 2.4.13 and glibc 2.3. [readahead-api]\n\nThe call may block while locating blocks through filesystem metadata, including the documented ext2/ext3/ext4 indirect-block case. Background data reads therefore do not establish a hard nonblocking-call guarantee. [readahead-api]\n\nThe backing-device budget is not an absolute ceiling for every read. Linux v6.14 initializes per-open state from it; SEQUENTIAL doubles that state, and large demand requests can use io_pages. [readahead-614] [fadvise-614]\n\nExplicit prefetch is also bounded: force_page_cache_ra limits the requested page count to max(io_pages, ra_pages) before chunking. Success does not certify whole-range residency. [readahead-614]\n\nATA drive read look-ahead is a separate device feature, not this file-to-page-cache syscall. hdparm -A controls that feature; -a controls software filesystem readahead. [hdparm-lookahead]",
  "advantages": [
    {
      "text": "Because the file offset is left unchanged, prefetching does not disturb a reader that shares the open file description.",
      "citationIds": [
        "readahead-api"
      ]
    }
  ],
  "limitations": [
    {
      "text": "This Linux-specific interface is distinct from the general automatic read-ahead policy triggered by ordinary reads.",
      "citationIds": [
        "readahead-api"
      ]
    },
    {
      "text": "On some 32-bit architectures the system call signature differs, and portable callers need _FILE_OFFSET_BITS defined as 64.",
      "citationIds": [
        "readahead-api"
      ]
    }
  ],
  "related": [
    "posix-fadv-willneed",
    "rwf-nowait",
    "page-cache",
    "buffered-io",
    "prefetch-wastage",
    "prefetch-trigger-distance",
    "posix-fadv-random",
    "posix-fadv-sequential",
    "ata-read-look-ahead",
    "informed-prefetching"
  ],
  "citations": [
    {
      "id": "readahead-api",
      "title": "Linux man-pages 6.19: readahead(2), ranges, return values and metadata blocking",
      "url": "https://man7.org/linux/man-pages/man2/readahead.2.html",
      "accessed": "2026-10-23"
    },
    {
      "id": "sysfs-block",
      "title": "Linux 7.3: Documentation/ABI/stable/sysfs-block, read_ahead_kb",
      "url": "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/stable/sysfs-block?h=v7.3",
      "accessed": "2026-10-23"
    },
    {
      "id": "pagemap",
      "title": "Linux 7.3: include/linux/pagemap.h, VM_READAHEAD_PAGES",
      "url": "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/pagemap.h?h=v7.3",
      "accessed": "2026-10-23"
    },
    {
      "id": "readahead-614",
      "title": "Linux v6.14 mm/readahead.c: file_ra_state_init, force_page_cache_ra and ractl_max_pages",
      "url": "https://github.com/torvalds/linux/blob/v6.14/mm/readahead.c",
      "accessed": "2026-11-08"
    },
    {
      "id": "fadvise-614",
      "title": "Linux v6.14 mm/fadvise.c: generic advice and SEQUENTIAL budget",
      "url": "https://github.com/torvalds/linux/blob/v6.14/mm/fadvise.c",
      "accessed": "2026-11-08"
    },
    {
      "id": "hdparm-lookahead",
      "title": "hdparm(8): separate -a software readahead and -A drive read-lookahead controls",
      "url": "https://www.man7.org/linux/man-pages/man8/hdparm.8.html",
      "accessed": "2026-11-14"
    }
  ],
  "status": "shipping",
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-14",
  "provenance": [
    "readahead-api is the Linux man-pages 6.19 readahead(2) page, re-read for page rounding, return values, errors, history and the metadata blocking bug.",
    "sysfs-block is the stable block-device sysfs ABI in Linux 7.3, read for the read_ahead_kb attribute.",
    "pagemap is include/linux/pagemap.h in Linux 7.3, read for the VM_READAHEAD_PAGES default.",
    "The posix-fadv-noreuse entry links here because POSIX_FADV_NOREUSE leaves the readahead window size unchanged while other advice values alter it.",
    "2026-11-08 correction: replaced unconditional device-cap wording and default-size implication with version-pinned budget/dispatch distinctions. Source review, not a kernel benchmark."
  ]
}
