FS (native)#

A file-system L2 adapter backed by the native C++ LMCacheFSClient wrapped with NativeConnectorL2Adapter. I/O is dispatched through a C++ worker-thread pool with eventfd-driven completions, giving a true I/O queue depth on a single Python thread.

Required fields:

  • base_path: Directory for storing KV cache files.

Optional fields:

  • num_workers (int, default 4, > 0): Number of C++ worker threads inside the connector. With num_read_workers at 0 this is also the read queue depth against the device, since each worker reads one object at a time.

  • relative_tmp_dir (str, default ""): Relative sub-directory for temporary files during writes (atomic rename on completion).

  • use_odirect (bool, default false): Bypass the page cache via O_DIRECT. Required to measure real disk bandwidth. See alignment caveat below.

  • read_ahead_size (int, optional): Trigger filesystem readahead by issuing a warm-up read of this many bytes at open time. This is skipped for reads that use O_DIRECT because direct I/O bypasses the page cache.

  • max_capacity_gb (float, default 0): Maximum L2 capacity in GB for client-side usage tracking. Default 0 disables tracking.

  • num_read_workers (int, default 256): Threads that run lookups and reads, and so the maximum reads in flight. Lookups and reads go straight to these threads, so they do not queue behind writes on the num_workers threads. 0 keeps the legacy path, where both run on the num_workers threads and the read depth equals num_workers, usually far below what an array of several devices needs. Each reader thread holds one file open at a time.

  • read_max_bytes_in_flight (int, default 0): With num_read_workers positive, the bytes kept outstanding against the device. 0 selects 1536 MiB, chosen for its worst case across local and network-latency storage; a single slow device does better with a smaller value. Bytes in flight also never exceed num_read_workers x object size, so num_read_workers must be large enough for the budget to bind. Sizing notes: docs/design/v1/distributed/l2_adapters/fs_native_read_depth.md.

Important

O_DIRECT has two independent alignment requirements:

  1. Length alignment. The transfer length must be a multiple of the filesystem’s block size. With use_odirect: true the adapter automatically transfers each object’s full alignment-padded L1 slot (logical bytes plus padding up to --l1-align-bytes), so this requirement holds even when KV chunk byte sizes are not multiples of the block size; on-disk files are correspondingly padded, and loads must run with the same use_odirect and --l1-align-bytes settings as the stores. Raise --l1-align-bytes to match the block size on filesystems with large blocks (GPFS and similar parallel filesystems often use several MiB).

  2. Memory-buffer alignment. The I/O buffer pointer itself must also be aligned (typically to 4096 bytes on local disks, or to the FS block size on parallel filesystems). This is controlled by --l1-align-bytes (default 4096) – raise it to match the FS block size when running on a filesystem with larger blocks. If the buffer is misaligned, the connector reports a runtime error instead of silently falling back to buffered I/O. This protects real-disk benchmark runs from accidentally measuring the page cache.

If unsure, start with use_odirect: false and confirm correctness before enabling O_DIRECT.

Configuration examples:

# Basic native FS adapter
--l2-adapter '{"type": "fs_native", "base_path": "/data/lmcache/l2"}'

# Many worker threads for a parallel filesystem (e.g. GPFS, Lustre)
--l2-adapter '{"type": "fs_native", "base_path": "/data/lmcache/l2", "num_workers": 32}'

# O_DIRECT for real-disk benchmarking
--l2-adapter '{"type": "fs_native", "base_path": "/data/lmcache/l2", "num_workers": 32, "use_odirect": true}'

Buffer-only mode example. L1 acts as a pure write buffer that absorbs the peak burst of in-flight chunks while the C++ worker pool drains them to disk; nothing is retained in L1 once a store completes:

lmcache server \
    --host 0.0.0.0 --port 5555 \
    --max-workers 32 \
    --l1-size-gb 32 --l1-use-lazy \
    --eviction-policy noop \
    --l2-store-policy skip_l1 \
    --l2-adapter '{"type": "fs_native", "base_path": "/data/lmcache/l2", "num_workers": 32, "use_odirect": true}'