GCMemoryInfo.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. namespace System
  5. {
  6. public readonly struct GCMemoryInfo
  7. {
  8. /// <summary>
  9. /// High memory load threshold when the last GC occured
  10. /// </summary>
  11. public long HighMemoryLoadThresholdBytes { get; }
  12. /// <summary>
  13. /// Memory load when the last GC ocurred
  14. /// </summary>
  15. public long MemoryLoadBytes { get; }
  16. /// <summary>
  17. /// Total available memory for the GC to use when the last GC ocurred.
  18. ///
  19. /// If the environment variable COMPlus_GCHeapHardLimit is set,
  20. /// or "Server.GC.HeapHardLimit" is in runtimeconfig.json, this will come from that.
  21. /// If the program is run in a container, this will be an implementation-defined fraction of the container's size.
  22. /// Else, this is the physical memory on the machine that was available for the GC to use when the last GC occurred.
  23. /// </summary>
  24. public long TotalAvailableMemoryBytes { get; }
  25. /// <summary>
  26. /// The total heap size when the last GC ocurred
  27. /// </summary>
  28. public long HeapSizeBytes { get; }
  29. /// <summary>
  30. /// The total fragmentation when the last GC ocurred
  31. ///
  32. /// Let's take the example below:
  33. /// | OBJ_A | OBJ_B | OBJ_C | OBJ_D | OBJ_E |
  34. ///
  35. /// Let's say OBJ_B, OBJ_C and and OBJ_E are garbage and get collected, but the heap does not get compacted, the resulting heap will look like the following:
  36. /// | OBJ_A | F | OBJ_D |
  37. ///
  38. /// The memory between OBJ_A and OBJ_D marked `F` is considered part of the FragmentedBytes, and will be used to allocate new objects. The memory after OBJ_D will not be
  39. /// considered part of the FragmentedBytes, and will also be used to allocate new objects
  40. /// </summary>
  41. public long FragmentedBytes { get; }
  42. internal GCMemoryInfo(long highMemoryLoadThresholdBytes,
  43. long memoryLoadBytes,
  44. long totalAvailableMemoryBytes,
  45. long heapSizeBytes,
  46. long fragmentedBytes)
  47. {
  48. HighMemoryLoadThresholdBytes = highMemoryLoadThresholdBytes;
  49. MemoryLoadBytes = memoryLoadBytes;
  50. TotalAvailableMemoryBytes = totalAvailableMemoryBytes;
  51. HeapSizeBytes = heapSizeBytes;
  52. FragmentedBytes = fragmentedBytes;
  53. }
  54. }
  55. }