IdleDecommitPageAllocator.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. namespace Memory
  6. {
  7. enum IdleDecommitSignal
  8. {
  9. IdleDecommitSignal_None,
  10. IdleDecommitSignal_NeedTimer,
  11. IdleDecommitSignal_NeedSignal
  12. };
  13. class IdleDecommitPageAllocator : public PageAllocator
  14. {
  15. public:
  16. IdleDecommitPageAllocator(AllocationPolicyManager * policyManager, PageAllocatorType type,
  17. Js::ConfigFlagsTable& flagTable,
  18. uint maxFreePageCount = 0,
  19. uint maxIdleFreePageCount = DefaultMaxFreePageCount,
  20. bool zeroPages = false,
  21. #if ENABLE_BACKGROUND_PAGE_FREEING
  22. BackgroundPageQueue * backgroundPageQueue = nullptr,
  23. #endif
  24. uint maxAllocPageCount = PageAllocator::DefaultMaxAllocPageCount,
  25. bool enableWriteBarrier = false);
  26. void EnterIdleDecommit();
  27. IdleDecommitSignal LeaveIdleDecommit(bool allowTimer);
  28. void Prime(uint primePageCount);
  29. #ifdef IDLE_DECOMMIT_ENABLED
  30. DWORD IdleDecommit();
  31. void DecommitNow(bool all = true);
  32. #endif
  33. #if DBG
  34. virtual bool IsIdleDecommitPageAllocator() const override { return true; }
  35. virtual bool HasMultiThreadAccess() const override;
  36. void ShutdownIdleDecommit();
  37. #endif
  38. private:
  39. class AutoResetWaitingToEnterIdleDecommitFlag
  40. {
  41. public:
  42. AutoResetWaitingToEnterIdleDecommitFlag(IdleDecommitPageAllocator * pageAllocator)
  43. {
  44. this->pageAllocator = pageAllocator;
  45. pageAllocator->waitingToEnterIdleDecommit = true;
  46. }
  47. ~AutoResetWaitingToEnterIdleDecommitFlag()
  48. {
  49. pageAllocator->waitingToEnterIdleDecommit = false;
  50. }
  51. private:
  52. IdleDecommitPageAllocator * pageAllocator;
  53. };
  54. #ifdef IDLE_DECOMMIT_ENABLED
  55. #if DBG_DUMP
  56. virtual void DumpStats() const override sealed;
  57. size_t idleDecommitCount;
  58. #endif
  59. #endif
  60. uint maxIdleDecommitFreePageCount;
  61. uint maxNonIdleDecommitFreePageCount;
  62. #ifdef IDLE_DECOMMIT_ENABLED
  63. bool hasDecommitTimer;
  64. bool hadDecommitTimer;
  65. DWORD decommitTime;
  66. uint idleDecommitTryEnterWaitFactor;
  67. CriticalSection cs;
  68. static const uint IdleDecommitTimeout = 1000;
  69. #endif
  70. friend class PageAllocatorBase<VirtualAllocWrapper>;
  71. #if ENABLE_NATIVE_CODEGEN
  72. friend class PageAllocatorBase<PreReservedVirtualAllocWrapper>;
  73. #endif
  74. #if IDLE_DECOMMIT_ENABLED && DBG
  75. public:
  76. virtual void UpdateThreadContextHandle(ThreadContextId threadContextHandle) override sealed
  77. {
  78. PageAllocator::UpdateThreadContextHandle(threadContextHandle);
  79. }
  80. virtual void SetDisableThreadAccessCheck() override
  81. {
  82. PageAllocator::SetDisableThreadAccessCheck();
  83. }
  84. virtual void SetEnableThreadAccessCheck() override
  85. {
  86. // Can't re-enable thread access check for idle decommit page allocator
  87. Assert(false);
  88. }
  89. #endif
  90. };
  91. }