Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide option to CMake for Page Size #664

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ endif()
set(SNMALLOC_MIN_ALLOC_SIZE "" CACHE STRING "Minimum allocation bytes (power of 2)")
set(SNMALLOC_MIN_ALLOC_STEP_SIZE "" CACHE STRING "Minimum allocation step (power of 2)")

set(SNMALLOC_PAGESIZE "" CACHE STRING "Page size in bytes")

set(SNMALLOC_DEALLOC_BATCH_RING_ASSOC "" CACHE STRING "Associativity of deallocation batch cache; 0 to disable")
set(SNMALLOC_DEALLOC_BATCH_RING_SET_BITS "" CACHE STRING "Logarithm of number of deallocation batch cache associativity sets")

Expand Down Expand Up @@ -257,6 +259,8 @@ add_as_define_value(SNMALLOC_MIN_ALLOC_STEP_SIZE)
add_as_define_value(SNMALLOC_DEALLOC_BATCH_RING_ASSOC)
add_as_define_value(SNMALLOC_DEALLOC_BATCH_RING_SET_BITS)

add_as_define_value(SNMALLOC_PAGESIZE)

target_compile_definitions(snmalloc INTERFACE $<$<BOOL:CONST_QUALIFIED_MALLOC_USABLE_SIZE>:MALLOC_USABLE_SIZE_QUALIFIER=const>)

# In debug and CI builds, link the backtrace library so that we can get stack
Expand Down
10 changes: 9 additions & 1 deletion src/snmalloc/pal/pal_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#endif
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
Expand Down Expand Up @@ -129,8 +130,15 @@ namespace snmalloc
| Entropy
#endif
;

#ifdef SNMALLOC_PAGESIZE
static_assert(
bits::is_pow2(SNMALLOC_PAGESIZE), "Page size must be a power of 2");
static constexpr size_t page_size = SNMALLOC_PAGESIZE;
#elif defined(PAGESIZE)
static constexpr size_t page_size = max(Aal::smallest_page_size, PAGESIZE);
#else
static constexpr size_t page_size = Aal::smallest_page_size;
#endif

/**
* Address bits are potentially mediated by some POSIX OSes, but generally
Expand Down
Loading