Skip to content

Make alignment calculation consistent#1903

Merged
badrishc merged 5 commits into
mainfrom
badrishc/unify-alignment
Jun 30, 2026
Merged

Make alignment calculation consistent#1903
badrishc merged 5 commits into
mainfrom
badrishc/unify-alignment

Conversation

@badrishc

Copy link
Copy Markdown
Collaborator

No description provided.

badrishc and others added 2 commits June 29, 2026 16:20
…max(logical, physical)

native_device::ProbeDioAlignment computed the sector size as
max(logical_block_size, physical_block_size). On Azure NVMe (Lsv3) sysfs reports
logical=512 / physical=262144 (256 KiB), so the allocator rounded every record
I/O up to 256 KiB — ~100x read amplification for read-heavy larger-than-memory
workloads that saturate disk IOPS.

physical_block_size is a write-RMW optimization hint, not the kernel-required
O_DIRECT alignment. Use the required alignment instead: statx STATX_DIOALIGN
(preferred, Linux 6.1+), falling back to sysfs logical_block_size; never
physical. Windows: BytesPerLogicalSector only. This matches
File::GetDeviceAlignment, so the per-File DIO asserts and sector_size() agree.

Unify all local-disk devices behind one probe so they cannot diverge:
- Add NativeStorageDevice.ProbeSectorSize (Linux -> native probe, else
  Native32.GetDeviceSectorSize; power-of-two floor 512). Route RandomAccess /
  Managed / LocalStorage devices through it and drop their per-type static
  sectorSize cache (which ignored the volume, so multi-volume setups shared one
  stale value).
- Remove dead Native32.GetVolumeSectorSize (also used the wrong
  max(logical, physical) algorithm).

Add a cross-device-type consistency regression test, refresh the stale
HardeningSectorSize comment, and rebuild the checked-in linux-x64 native
binaries (libnative_device.so + libnative_device_libaio.so).

The win-x64 native_device.dll must be rebuilt on Windows (MSVC, see cc/README)
to pick up the Windows-branch change; it could not be regenerated in this Linux
environment. Garnet's Windows path uses the managed LocalStorageDevice (already
logical-only via GetDiskFreeSpace), so it is unaffected by the stale dll.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 30, 2026 00:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Tsavorite’s device-sector-size (direct-I/O alignment) probing so that native and managed local-disk device implementations derive a consistent SectorSize from the same “required DIO alignment” signal (statx STATX_DIOALIGN / logical_block_size, never physical_block_size), and adds a regression test to enforce cross-device consistency.

Changes:

  • Unifies managed local-disk device constructors to use NativeStorageDevice.ProbeSectorSize(...) rather than per-type cached probing.
  • Updates the native probe (ProbeDioAlignment) to return required O_DIRECT alignment only (ignore physical block size to avoid read amplification).
  • Removes unused Windows volume-sector query plumbing from Native32, and adds a Linux-only regression test ensuring device types agree on SectorSize.

Reviewed changes

Copilot reviewed 7 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
libs/storage/Tsavorite/cs/test/test.hlog/DeviceTests.cs Updates alignment rationale comment and adds a Linux-only regression test to ensure sector-size consistency across device types.
libs/storage/Tsavorite/cs/src/core/Utilities/Native32.cs Removes unused Windows GetFileInformationByHandleEx(FileStorageInfo) sector-size query helpers; keeps GetDiskFreeSpace logical sector-size probe.
libs/storage/Tsavorite/cs/src/core/Device/RandomAccessLocalStorageDevice.cs Switches sector-size initialization to the shared NativeStorageDevice.ProbeSectorSize and removes static cached sector-size logic.
libs/storage/Tsavorite/cs/src/core/Device/NativeStorageDevice.cs Adds shared ProbeSectorSize API and factors parent-dir materialization used to stabilize probe path resolution.
libs/storage/Tsavorite/cs/src/core/Device/ManagedLocalStorageDevice.cs Switches sector-size initialization to the shared NativeStorageDevice.ProbeSectorSize and removes static cached sector-size logic.
libs/storage/Tsavorite/cs/src/core/Device/LocalStorageDevice.cs Switches sector-size initialization to the shared NativeStorageDevice.ProbeSectorSize and removes static cached sector-size logic.
libs/storage/Tsavorite/cc/src/device/native_device.h Changes Linux/Windows alignment probing to return required O_DIRECT alignment only (prefer STATX_DIOALIGN, fallback to logical_block_size).

Comment thread libs/storage/Tsavorite/cs/src/core/Device/NativeStorageDevice.cs
badrishc and others added 3 commits June 29, 2026 17:17
Comment-only cleanup: condense the verbose comments from the prior commit to
short, factual notes. No code changes; the native binaries are unaffected
(comments do not change generated code) and are intentionally not rebuilt.

Co-authored-by: Copilot <[email protected]>
… review)

Catch BadImageFormatException/FileLoadException from NativeDevice_ProbeAlignment
so a present-but-wrong-arch/corrupt libnative_device falls back to the managed
probe instead of breaking managed local-disk device construction.

Co-authored-by: Copilot <[email protected]>
@badrishc badrishc merged commit 8fe4309 into main Jun 30, 2026
400 of 401 checks passed
@badrishc badrishc deleted the badrishc/unify-alignment branch June 30, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants