Skip to content

[C#] FileMappedResizableDirectMemory over-reserves when reopening a page-aligned file #96

In review

Description

@konard

Problem

FileMappedResizableDirectMemory.cs:59 computes

ReservedCapacity = size > minimumReservedCapacity ? ((size / minimumReservedCapacity) + 1) * minimumReservedCapacity : minimumReservedCapacity;

This always adds one more block, even when size is already a multiple of minimumReservedCapacity. Each reopen grows the file by one page. This is the C# twin of the C++ "TODO: cringe" (#87).

Reproduction (probe P2, experiments/issue-94-csharp-probes)

Reopen an 8192-byte file with the default minimum (4096):

  • actual: UsedCapacity = 8192, ReservedCapacity = 12288, and the file is grown to 12288 bytes;
  • expected (mem-rs FileMapped): capacity rounded up to whole pages, i.e. 8192.

Proposed solution

Use RoundUp(max(size, minimumReservedCapacity), pageSize), for example ((size + page - 1) / page) * page with overflow checks. Do the same in C++ (#87). Add regression tests for sizes 0, 1, page-1, page, page+1 and 2·page.


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

Activity

  1. added
    bug
    csharp
    mem-rs-parity
    on Nov 29, 2026
  2. added theissue type on Nov 29, 2026
  3. added a commit that references this issue on Nov 29, 2026
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

    bugcsharpmem-rs-parity

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions