feat: reject RAM disk growth when system memory runs low - #163
Merged
Merged
Conversation
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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
byte[]chunks the GC already tracks, so that API would misrepresent them as unmanaged memory with no real benefit.Create/Overwrite/SetFileSize/WritewithSTATUS_INSUFFICIENT_RESOURCESonce 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.SystemMemoryInfo(Win32GlobalMemoryStatusExwrapper) from the App layer intoManagedDrive.Core.DiagnosticssoMemoryFileSystemcan call it directly; the one existing App call site is unaffected sinceCore.Diagnosticsis already a global using there.availableMemoryProviderconstructor parameter toMemoryFileSystemfor injecting a fake available-memory value in tests.Test plan
dotnet build -c Release— 0 warnings, 0 errorsdotnet test tests/ManagedDrive.Tests -c Release --filter "FullyQualifiedName~MemoryFileSystemLowMemoryGuardTests"— 7/7 passeddotnet test tests/ManagedDrive.Tests -c Release— 374/374 passeddotnet format --verify-no-changes --no-restore— clean