Description
When adding resource monitoring with services.AddResourceMonitoring(), the application fails to start with the following error message on WSL (Ubuntu 24.04):
System.InvalidOperationException: 'The total memory usage read from '/sys/fs/cgroup/memory.current' is lesser than inactive memory read from '/sys/fs/cgroup/memory.stat'.'
Debugging the method LinuxUtilizationParserCgroupV2.GetMemoryUsageInBytes, revealed that the memory usage is not read from /sys/fs/cgroup/memory.current (which does not exist) but from sys/fs/cgroup/user.slice/memory.current and /sys/fs/cgroup/system.slice/memory.current.
The calculated total memory usage is then a large negative number, which seems to be odd.
Example:
inactive memory: 492773376
memory usage: 140439552
140439552 - 492773376 = -352333824
Reproduction Steps
Start a .NET application which uses Microsoft.Extensions.Diagnostics.ResourceMonitoring on WSL (maybe only with Ubuntu 24.04?).
Expected behavior
- No exception to be thrown.
- The exception message should show the correct path/file name of the actually read
memory.current files.
Actual behavior
An InvalidOperationException is thrown and the exception message is displaying the wrong path of the actually read memory.current files.
Regression?
No response
Known Workarounds
No.
Configuration
WSL version: 2.7.12.0 with .NET SDK 10.0.111
Running on Windows 11 (25H2 (OS Build 26200.9106)
Other information
No response
Description
When adding resource monitoring with
services.AddResourceMonitoring(), the application fails to start with the following error message on WSL (Ubuntu 24.04):Debugging the method
LinuxUtilizationParserCgroupV2.GetMemoryUsageInBytes, revealed that the memory usage is not read from/sys/fs/cgroup/memory.current(which does not exist) but fromsys/fs/cgroup/user.slice/memory.currentand/sys/fs/cgroup/system.slice/memory.current.The calculated total memory usage is then a large negative number, which seems to be odd.
Example:
inactive memory: 492773376
memory usage: 140439552
140439552 - 492773376 = -352333824
Reproduction Steps
Start a .NET application which uses
Microsoft.Extensions.Diagnostics.ResourceMonitoringon WSL (maybe only with Ubuntu 24.04?).Expected behavior
memory.currentfiles.Actual behavior
An
InvalidOperationExceptionis thrown and the exception message is displaying the wrong path of the actually readmemory.currentfiles.Regression?
No response
Known Workarounds
No.
Configuration
WSL version: 2.7.12.0 with .NET SDK 10.0.111
Running on Windows 11 (25H2 (OS Build 26200.9106)
Other information
No response