Skip to content

[C#] Grow file-mapped memory sparsely (Windows FSCTL_SET_SPARSE, Unix ftruncate holes) #103

Backlog

Description

@konard

Problem

Growing a FileMappedResizableDirectMemory reserves real disk space for zero pages on NTFS. mem-rs keeps zeroed growth sparse on Unix and on Windows file systems that support sparse ranges (linksplatform/mem-rs#39, linksplatform/mem-rs#43). This matters for doublets stores that reserve large capacities up front.

Proposed solution

  • Unix: extend with ftruncate / RandomAccess.SetLength, which creates holes. Never write zeroes explicitly; mapping a new region already reads as zero.
  • Windows: once per file, DeviceIoControl(FSCTL_SET_SPARSE) (P/Invoke), guarded by GetVolumeInformation → FILE_SUPPORTS_SPARSE_FILES; then SetLength.
  • Avoid MemoryBlock.Zero over freshly mapped regions.
  • Tests check allocated size (stat.st_blocks, GetCompressedFileSize) on CI runners that support it.

References:


Part of #94 (catch up with mem-rs). Analysis and evidence: case study.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    csharpenhancementmem-rs-parity

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions