Skip to content

feat: reject RAM disk growth when system memory runs low - #163

Merged
coldhighsun merged 1 commit into
mainfrom
feature/low-memory-write-guard
Sep 16, 2026
Merged

coldhighsun merged 1 commit into
mainfrom
feature/low-memory-write-guard

Conversation

@coldhighsun

Copy link
Copy Markdown
Owner

Summary

  • Backlog item was originally phrased as "GC.AddMemoryPressure", but RAM disk content is plain managed byte[] chunks the GC already tracks, so that API would misrepresent them as unmanaged memory with no real benefit.
  • Instead: query real system-wide available physical memory and reject a growing Create/Overwrite/SetFileSize/Write with STATUS_INSUFFICIENT_RESOURCES once fewer than 256 MiB would remain after the allocation — independent of the disk's own configured capacity, since a disk can have capacity headroom while the host machine itself is nearly out of RAM.
  • Moved the existing SystemMemoryInfo (Win32 GlobalMemoryStatusEx wrapper) from the App layer into ManagedDrive.Core.Diagnostics so MemoryFileSystem can call it directly; the one existing App call site is unaffected since Core.Diagnostics is already a global using there.
  • Added an optional availableMemoryProvider constructor parameter to MemoryFileSystem for injecting a fake available-memory value in tests.
  • The 256 MiB reserve is a fixed constant this round, not user-configurable.

Test plan

  • dotnet build -c Release — 0 warnings, 0 errors
  • dotnet test tests/ManagedDrive.Tests -c Release --filter "FullyQualifiedName~MemoryFileSystemLowMemoryGuardTests" — 7/7 passed
  • dotnet test tests/ManagedDrive.Tests -c Release — 374/374 passed
  • dotnet format --verify-no-changes --no-restore — clean

File content is plain managed byte[] chunks that the GC already accounts
for, so GC.AddMemoryPressure would misrepresent them as unmanaged memory
without any real benefit. Instead, query real system-wide available
physical memory (via the existing Win32 GlobalMemoryStatusEx wrapper,
moved from the App layer into Core.Diagnostics so MemoryFileSystem can
use it directly) and reject Create/Overwrite/SetFileSize/Write growth
with STATUS_INSUFFICIENT_RESOURCES once fewer than 256 MiB would remain,
independently of the disk's own configured capacity.
@coldhighsun
coldhighsun merged commit 73eb684 into main Sep 16, 2026
3 checks passed
@coldhighsun
coldhighsun deleted the feature/low-memory-write-guard branch September 16, 2026 09:46
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.

1 participant