From e2a12802d529f2e8872c51f7d4feac52c3f6148a Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Thu, 21 Feb 2019 13:32:09 +0000 Subject: [PATCH] Hide the low memory notification PAL code. --- src/mem/largealloc.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index cfc5e14..b2cb998 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -120,6 +120,29 @@ namespace snmalloc lazy_decommit_guard.clear(); } + /** + * Wrapper that is instantiated only if the memory provider supports low + * memory notifications and forwards the call to the memory provider. + */ + template + ALWAYSINLINE uint64_t low_mem_epoch( + std::enable_if_t = 0) + { + return MemoryProviderState::low_memory_epoch(); + } + + /** + * Default implementations that is instantiated when the memory provider + * does not support low memory notifications and always returns 0 for the + * epoch. + */ + template + ALWAYSINLINE uint64_t low_memory_epoch( + std::enable_if_t = 0) + { + return 0; + } + public: /** * Stack of large allocations that have been returned for reuse. @@ -171,6 +194,17 @@ namespace snmalloc return p; } + /** + * Returns the number of low memory notifications that have been received + * (over the lifetime of this process). If the underlying system does not + * support low memory notifications, this will return 0. + */ + ALWAYSINLINE + uint64_t low_memory_epoch() + { + return low_mem_epoch(); + } + ALWAYSINLINE void lazy_decommit_if_needed() { #ifdef TEST_LAZY_DECOMMIT