﻿# Query file-specific alignment before direct model-file reads

Query supported file-specific direct-I/O alignment and validate buffer, offset and length; accepted reads can still require fallback-path verification.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-storage-direct-io-alignment/
Language: en

A custom model loader switches to direct reads and receives invalid-argument errors on some files. Another filesystem appears to accept the same requests. O_DIRECT alignment is not one universal constant: memory address, file offset and transfer length have applicable file-specific requirements. Inspect supported alignment information and actual behavior before calling either result proof of faster uncached storage access.

## Identify the real file path

Record the open flags, filesystem, file identity and kernel context used by the worker. A raw block-device experiment does not automatically describe a regular file on a layered filesystem. Also establish whether the loader or library requested direct I/O at all. A benchmark configuration cannot change the separate application's file-opening behavior merely because both read the same checkpoint.

## Request supported alignment information

Statx provides documented alignment fields when supported, and its returned mask indicates which requested information was supplied. An absent result must not be interpreted as a valid unconstrained alignment. Preserve the returned mask and values together. Filesystem and kernel support vary, so use a documented fallback qualification when the preferred query cannot establish the requirement for this file.

## Check every request component

Validate buffer address, file offset and segment length against the applicable constraints. A correctly aligned allocation does not fix a misaligned subrange inside that buffer or a short final read request. Current documentation also distinguishes available read-specific alignment information. Keep the actual fields supported by the installed environment rather than substituting a familiar filesystem block-size label for every component.

## Interpret acceptance cautiously

Linux documents that misaligned direct I/O can fail or fall back to buffered behavior depending on the filesystem and context. A successful read therefore does not alone prove the intended path. Preserve errors and relevant observations, and handle short successful reads under the read contract. Do not silently compare a buffered fallback against a verified direct path while describing both with one direct flag.

## Verify the loader's objective

Compare complete correct loading under the intended cache and concurrency conditions after establishing the API path. Direct I/O is a mechanism, not a guarantee of lower readiness time. Keep CPU preparation and device transfer visible. A useful conclusion states supported alignment, observed behavior and fallback policy; it does not promise a universal block size or infer model-serving improvement from one accepted low-level read.

## Primary references

[Linux File-Specific Direct I/O Alignment](https://man7.org/linux/man-pages/man2/statx.2.html).

[Linux Open File Descriptions and Directory Handles](https://man7.org/linux/man-pages/man2/open.2.html).

[Linux read Result and Alignment Errors](https://man7.org/linux/man-pages/man2/read.2.html).

Related reading: [Choose vLLM safetensors loading strategies for local disks and NFS](/journal/vllm-safetensors-load-strategy/); [LLM loading: read-latency tails beyond one SSD speed](/journal/nvme-read-latency-model-load/).
