RecyclerHeuristic.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Memory
  7. {
  8. #define KILOBYTES * 1024
  9. #define MEGABYTES * 1024 KILOBYTES
  10. #define MEGABYTES_OF_PAGES * 1024 * 1024 / AutoSystemInfo::PageSize;
  11. class RecyclerHeuristic
  12. {
  13. private:
  14. RecyclerHeuristic();
  15. public:
  16. static RecyclerHeuristic Instance;
  17. // Heuristics that depend on hardware or environment (not constant).
  18. uint MaxUncollectedAllocBytes;
  19. size_t UncollectedAllocBytesConcurrentPriorityBoost;
  20. uint MaxPartialUncollectedNewPageCount;
  21. uint MaxUncollectedAllocBytesOnExit;
  22. // If we are getting close to the full GC limit, let's just get out of partial GC mode.
  23. uint MaxUncollectedAllocBytesPartialCollect;
  24. // Defines the PageSegment size for recycler small block page allocator.
  25. uint DefaultMaxAllocPageCount;
  26. // Used for RecyclerPageAllocator and determines how many free pages need to be there to trigger decommit
  27. // (most cases, not all).
  28. uint DefaultMaxFreePageCount;
  29. // Constant heuristic that may be changed by switches
  30. static uint UncollectedAllocBytesCollection();
  31. #if ENABLE_CONCURRENT_GC
  32. static uint MaxBackgroundFinishMarkCount(Js::ConfigFlagsTable&);
  33. static DWORD BackgroundFinishMarkWaitTime(bool, Js::ConfigFlagsTable&);
  34. static size_t MinBackgroundRepeatMarkRescanBytes(Js::ConfigFlagsTable&);
  35. static DWORD FinishConcurrentCollectWaitTime(Js::ConfigFlagsTable&);
  36. static DWORD PriorityBoostTimeout(Js::ConfigFlagsTable&);
  37. #endif
  38. #if ENABLE_PARTIAL_GC && ENABLE_CONCURRENT_GC
  39. static bool PartialConcurrentNextCollection(double ratio, Js::ConfigFlagsTable& flags);
  40. #endif
  41. // Constant heuristics
  42. static const uint IdleUncollectedAllocBytesCollection = 1 MEGABYTES;
  43. static const uint TickCountCollection = 1200; // 1.2 second
  44. static const uint TickCountFinishCollection = 45; // 45 milliseconds
  45. static const uint TickCountDoDispose = 300; // Allow for 300 milliseconds of script before attempting dispose
  46. // This heuristic is currently used for dispose on stack probes
  47. static const uint TickCountIdleCollectRepeatTimer = 500; // This heuristic is for in case the first idle task call back didn't finish the GC
  48. // We schedule another timer task to check the collection progress
  49. void ConfigureBaseFactor(uint baseFactor);
  50. #if ENABLE_CONCURRENT_GC
  51. static const uint MaxBackgroundRepeatMarkCount = 2;
  52. // If we rescan at least 128 pages in the first background repeat mark,
  53. // then trigger a second repeat mark pass.
  54. static const uint BackgroundSecondRepeatMarkThreshold = 128;
  55. #if ENABLE_ALLOCATIONS_DURING_CONCURRENT_SWEEP
  56. // Number of blocks a heap bucket needs to have before allocations during concurrent sweep feature kicks-in.
  57. #if DBG
  58. // We would want the feature to kick-in more frequently in debug builds so we excercise the code.
  59. static const uint AllocDuringConcurrentSweepHeapBlockThreshold = 100;
  60. #else
  61. static const uint AllocDuringConcurrentSweepHeapBlockThreshold = 60000;
  62. #endif
  63. #endif
  64. #endif
  65. private:
  66. #ifndef RECYCLER_HEURISTIC_VERSION
  67. #define RECYCLER_HEURISTIC_VERSION 11
  68. #endif
  69. static const uint DefaultUncollectedAllocBytesCollection = 1 MEGABYTES;
  70. #if ENABLE_CONCURRENT_GC
  71. static const uint TickCountConcurrentPriorityBoost = 5000; // 5 second
  72. static const DWORD DefaultFinishConcurrentCollectWaitTime = 1000; // 1 second
  73. static const uint DefaultMaxBackgroundFinishMarkCount = 1;
  74. static const DWORD DefaultBackgroundFinishMarkWaitTime = 15; // ms
  75. static const size_t DefaultMinBackgroundRepeatMarkRescanBytes = 1 MEGABYTES;
  76. #endif
  77. };
  78. }