Improved pal_supports
This commit is contained in:
@@ -46,8 +46,7 @@ namespace snmalloc
|
||||
// Use flat map is under a single node.
|
||||
# define SNMALLOC_MAX_FLATPAGEMAP_SIZE PAGEMAP_NODE_SIZE
|
||||
#endif
|
||||
static constexpr bool USE_FLATPAGEMAP =
|
||||
(Pal::pal_features & PalFeatures::LazyCommit) ||
|
||||
static constexpr bool USE_FLATPAGEMAP = pal_supports<LazyCommit>() ||
|
||||
(SNMALLOC_MAX_FLATPAGEMAP_SIZE >=
|
||||
sizeof(FlatPagemap<SUPERSLAB_BITS, uint8_t>));
|
||||
|
||||
@@ -1209,9 +1208,7 @@ namespace snmalloc
|
||||
else if constexpr (decommit_strategy == DecommitSuperLazy)
|
||||
{
|
||||
static_assert(
|
||||
std::remove_reference_t<decltype(
|
||||
large_allocator.memory_provider)>::
|
||||
template pal_supports<LowMemoryNotification>(),
|
||||
pal_supports<LowMemoryNotification, MemoryProvider>(),
|
||||
"A lazy decommit strategy cannot be implemented on platforms "
|
||||
"without low memory notifications");
|
||||
}
|
||||
|
||||
@@ -175,15 +175,6 @@ namespace snmalloc
|
||||
return new (p) T(std::forward<Args...>(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query whether the PAL supports a specific feature.
|
||||
*/
|
||||
template<PalFeatures F>
|
||||
constexpr static bool pal_supports()
|
||||
{
|
||||
return (PAL::pal_features & F) == F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of low memory notifications that have been received
|
||||
* (over the lifetime of this process). If the underlying system does not
|
||||
@@ -192,7 +183,7 @@ namespace snmalloc
|
||||
SNMALLOC_FAST_PATH
|
||||
uint64_t low_memory_epoch()
|
||||
{
|
||||
if constexpr (pal_supports<LowMemoryNotification>())
|
||||
if constexpr (pal_supports<LowMemoryNotification, PAL>())
|
||||
{
|
||||
return PAL::low_memory_epoch();
|
||||
}
|
||||
@@ -205,7 +196,7 @@ namespace snmalloc
|
||||
template<bool committed>
|
||||
void* reserve(size_t* size, size_t align) noexcept
|
||||
{
|
||||
if constexpr (pal_supports<AlignedAllocation>())
|
||||
if constexpr (pal_supports<AlignedAllocation, PAL>())
|
||||
{
|
||||
return PAL::template reserve<committed>(size, align);
|
||||
}
|
||||
|
||||
@@ -50,4 +50,13 @@ namespace snmalloc
|
||||
{
|
||||
Pal::error(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query whether the PAL supports a specific feature.
|
||||
*/
|
||||
template<PalFeatures F, typename PAL = Pal>
|
||||
constexpr static bool pal_supports()
|
||||
{
|
||||
return (PAL::pal_features & F) == F;
|
||||
}
|
||||
} // namespace snmalloc
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace snmalloc
|
||||
AlignedAllocation = (1 << 1),
|
||||
/**
|
||||
* This PAL natively supports lazy commit of pages. This means have large
|
||||
* allocations and not touching them does not up memory usage. This is
|
||||
* exposed in the P
|
||||
* allocations and not touching them does not increase memory usage. This is
|
||||
* exposed in the Pal.
|
||||
*/
|
||||
LazyCommit = (1 << 2),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user