tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit a3e7e9bda24ff7eff55c87a2b49b3c7442151a76
parent 95e8ffa97e413c19c7257c9e6dc9511e98347b68
Author: Micah Elizabeth Scott <beth@torproject.org>
Date:   Fri, 25 Aug 2023 10:51:40 -0700

equix: Disable huge page support by default

Equi-X supports optionally allocating its solver memory using huge
pages, to reduce the virtual memory subsystem overhead required to make
the entire solver buffer live.

Tor doesn't use this feature, since it seems to have no noticeable
performance benefit at this time, but we still included code for it at
compile time. To improve portability, this patch disables huge page
support by default and enables it only in the cmake build system used
for equix benchmarks.

With this patch equix-bench still supports huge pages. Verified using
strace that we're making the hugepage allocation.

There's no fallback for huge pages, so Equi-X initialization will fail
if they are requested and we don't support them for any runtime or
compile-time reason.

Addresses #40843 (NetBSD) but also prevents future porting issues
related to huge pages.

Diffstat:
Msrc/ext/equix/CMakeLists.txt | 1+
Msrc/ext/equix/hashx/src/virtual_memory.c | 2++
Msrc/ext/equix/hashx/src/virtual_memory.h | 5++++-
Msrc/ext/equix/src/context.c | 4++++
4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/ext/equix/CMakeLists.txt b/src/ext/equix/CMakeLists.txt @@ -11,6 +11,7 @@ set(EQUIX_VERSION_STR "${EQUIX_VERSION}.${EQUIX_VERSION_MINOR}.${EQUIX_VERSION_P project(equix) add_definitions(-DHASHX_SIZE=8) +add_definitions(-DEQUIX_SUPPORT_HUGEPAGES) add_subdirectory("hashx") diff --git a/src/ext/equix/hashx/src/virtual_memory.c b/src/ext/equix/hashx/src/virtual_memory.c @@ -90,6 +90,7 @@ bool hashx_vm_rx(void* ptr, size_t bytes) { return page_protect(ptr, bytes, PAGE_EXECUTE_READ); } +#ifdef EQUIX_SUPPORT_HUGEPAGES void* hashx_vm_alloc_huge(size_t bytes) { void* mem; #ifdef HASHX_WIN @@ -124,6 +125,7 @@ void* hashx_vm_alloc_huge(size_t bytes) { #endif return mem; } +#endif /* EQUIX_SUPPORT_HUGEPAGES */ void hashx_vm_free(void* ptr, size_t bytes) { if (!ptr) { diff --git a/src/ext/equix/hashx/src/virtual_memory.h b/src/ext/equix/hashx/src/virtual_memory.h @@ -14,7 +14,10 @@ HASHX_PRIVATE void* hashx_vm_alloc(size_t size); HASHX_PRIVATE bool hashx_vm_rw(void* ptr, size_t size); HASHX_PRIVATE bool hashx_vm_rx(void* ptr, size_t size); -HASHX_PRIVATE void* hashx_vm_alloc_huge(size_t size); HASHX_PRIVATE void hashx_vm_free(void* ptr, size_t size); +#ifdef EQUIX_SUPPORT_HUGEPAGES +HASHX_PRIVATE void* hashx_vm_alloc_huge(size_t size); +#endif + #endif diff --git a/src/ext/equix/src/context.c b/src/ext/equix/src/context.c @@ -27,7 +27,11 @@ equix_ctx* equix_alloc(equix_ctx_flags flags) { if (flags & EQUIX_CTX_SOLVE) { if (flags & EQUIX_CTX_HUGEPAGES) { +#ifdef EQUIX_SUPPORT_HUGEPAGES ctx->heap = hashx_vm_alloc_huge(sizeof(solver_heap)); +#else + ctx->heap = NULL; +#endif } else { ctx->heap = malloc(sizeof(solver_heap));