diff --git a/src/backend/address_space.h b/src/backend/address_space.h index 1b3ce40..15c1ae3 100644 --- a/src/backend/address_space.h +++ b/src/backend/address_space.h @@ -45,8 +45,7 @@ namespace snmalloc * arena_map for use in subsequent amplification. */ template - capptr::Chunk - reserve(typename Pagemap::LocalState* local_state, size_t size) + capptr::Chunk reserve(size_t size) { #ifdef SNMALLOC_TRACING std::cout << "ASM reserve request:" << size << std::endl; @@ -64,7 +63,7 @@ namespace snmalloc { auto base = capptr::Chunk(PAL::template reserve_aligned(size)); - Pagemap::register_range(local_state, address_cast(base), size); + Pagemap::register_range(address_cast(base), size); return base; } } @@ -72,7 +71,7 @@ namespace snmalloc capptr::Chunk res; { FlagLock lock(spin_lock); - res = core.template reserve(local_state, size); + res = core.template reserve(size); if (res == nullptr) { // Allocation failed ask OS for more memory @@ -134,12 +133,12 @@ namespace snmalloc return nullptr; } - Pagemap::register_range(local_state, address_cast(block), block_size); + Pagemap::register_range(address_cast(block), block_size); - core.template add_range(local_state, block, block_size); + core.template add_range(block, block_size); // still holding lock so guaranteed to succeed. - res = core.template reserve(local_state, size); + res = core.template reserve(size); } } @@ -158,8 +157,7 @@ namespace snmalloc * used, by smaller objects. */ template - capptr::Chunk reserve_with_left_over( - typename Pagemap::LocalState* local_state, size_t size) + capptr::Chunk reserve_with_left_over(size_t size) { SNMALLOC_ASSERT(size >= sizeof(void*)); @@ -167,15 +165,14 @@ namespace snmalloc size_t rsize = bits::next_pow2(size); - auto res = reserve(local_state, rsize); + auto res = reserve(rsize); if (res != nullptr) { if (rsize > size) { FlagLock lock(spin_lock); - core.template add_range( - local_state, pointer_offset(res, size), rsize - size); + core.template add_range(pointer_offset(res, size), rsize - size); } if constexpr (committed) @@ -195,13 +192,10 @@ namespace snmalloc * Add a range of memory to the address space. * Divides blocks into power of two sizes with natural alignment */ - void add_range( - typename Pagemap::LocalState* local_state, - capptr::Chunk base, - size_t length) + void add_range(capptr::Chunk base, size_t length) { FlagLock lock(spin_lock); - core.template add_range(local_state, base, length); + core.template add_range(base, length); } }; } // namespace snmalloc diff --git a/src/backend/address_space_core.h b/src/backend/address_space_core.h index df26b39..fa3aa25 100644 --- a/src/backend/address_space_core.h +++ b/src/backend/address_space_core.h @@ -79,7 +79,6 @@ namespace snmalloc * particular size. */ void set_next( - typename Pagemap::LocalState* local_state, size_t align_bits, capptr::Chunk base, capptr::Chunk next) @@ -96,7 +95,7 @@ namespace snmalloc // dealloc() can reject attempts to free such MetaEntry-s due to the // zero sizeclass. MetaEntry t(reinterpret_cast(next.unsafe_ptr()), nullptr); - Pagemap::set_metaentry(local_state, address_cast(base), 1, t); + Pagemap::set_metaentry(address_cast(base), 1, t); return; } @@ -112,15 +111,13 @@ namespace snmalloc * to store the next pointer for the list of unused address space of a * particular size. */ - capptr::Chunk get_next( - typename Pagemap::LocalState* local_state, - size_t align_bits, - capptr::Chunk base) + capptr::Chunk + get_next(size_t align_bits, capptr::Chunk base) { if (align_bits >= MIN_CHUNK_BITS) { - const MetaEntry& t = Pagemap::template get_metaentry( - local_state, address_cast(base)); + const MetaEntry& t = + Pagemap::template get_metaentry(address_cast(base)); return capptr::Chunk( reinterpret_cast(t.get_metaslab_no_remote())); } @@ -132,15 +129,12 @@ namespace snmalloc * Adds a block to `ranges`. */ template - void add_block( - typename Pagemap::LocalState* local_state, - size_t align_bits, - capptr::Chunk base) + void add_block(size_t align_bits, capptr::Chunk base) { check_block(base, align_bits); SNMALLOC_ASSERT(align_bits < 64); - set_next(local_state, align_bits, base, ranges[align_bits]); + set_next(align_bits, base, ranges[align_bits]); ranges[align_bits] = base.template as_static(); } @@ -149,8 +143,7 @@ namespace snmalloc * to satisfy this request. */ template - capptr::Chunk - remove_block(typename Pagemap::LocalState* local_state, size_t align_bits) + capptr::Chunk remove_block(size_t align_bits) { capptr::Chunk first = ranges[align_bits]; if (first == nullptr) @@ -162,8 +155,7 @@ namespace snmalloc } // Look for larger block and split up recursively - capptr::Chunk bigger = - remove_block(local_state, align_bits + 1); + capptr::Chunk bigger = remove_block(align_bits + 1); if (SNMALLOC_UNLIKELY(bigger == nullptr)) return nullptr; @@ -180,7 +172,6 @@ namespace snmalloc auto left_over = pointer_offset(bigger, half_bigger_size); add_block( - local_state, align_bits, Aal::capptr_bound( left_over, half_bigger_size)); @@ -191,7 +182,7 @@ namespace snmalloc } check_block(first, align_bits); - ranges[align_bits] = get_next(local_state, align_bits, first); + ranges[align_bits] = get_next(align_bits, first); return first.as_void(); } @@ -201,10 +192,7 @@ namespace snmalloc * Divides blocks into power of two sizes with natural alignment */ template - void add_range( - typename Pagemap::LocalState* local_state, - capptr::Chunk base, - size_t length) + void add_range(capptr::Chunk base, size_t length) { // For start and end that are not chunk sized, we need to // commit the pages to track the allocations. @@ -235,7 +223,7 @@ namespace snmalloc Aal::capptr_bound(base, align); check_block(b, align_bits); - add_block(local_state, align_bits, b); + add_block(align_bits, b); base = pointer_offset(base, align); length -= align; @@ -268,8 +256,7 @@ namespace snmalloc * arena_map for use in subsequent amplification. */ template - capptr::Chunk - reserve(typename Pagemap::LocalState* local_state, size_t size) + capptr::Chunk reserve(size_t size) { #ifdef SNMALLOC_TRACING std::cout << "ASM Core reserve request:" << size << std::endl; @@ -278,7 +265,7 @@ namespace snmalloc SNMALLOC_ASSERT(bits::is_pow2(size)); SNMALLOC_ASSERT(size >= sizeof(void*)); - return remove_block(local_state, bits::next_pow2_bits(size)); + return remove_block(bits::next_pow2_bits(size)); } /** @@ -289,8 +276,7 @@ namespace snmalloc * used by smaller objects. */ template - capptr::Chunk reserve_with_left_over( - typename Pagemap::LocalState* local_state, size_t size) + capptr::Chunk reserve_with_left_over(size_t size) { SNMALLOC_ASSERT(size >= sizeof(void*)); @@ -298,7 +284,7 @@ namespace snmalloc size_t rsize = bits::next_pow2(size); - auto res = reserve(local_state, rsize); + auto res = reserve(rsize); if (res != nullptr) { @@ -311,7 +297,7 @@ namespace snmalloc size_t residual_size = rsize - size; auto residual = pointer_offset(res, size); res = Aal::capptr_bound(res, size); - add_range(local_state, residual, residual_size); + add_range(residual, residual_size); } } return res; diff --git a/src/backend/backend.h b/src/backend/backend.h index e529ad8..e7cff28 100644 --- a/src/backend/backend.h +++ b/src/backend/backend.h @@ -114,7 +114,7 @@ namespace snmalloc meta->meta_common.chunk = p; MetaEntry t(meta, remote, sizeclass); - Pagemap::set_metaentry(local_state, address_cast(p), size, t); + Pagemap::set_metaentry(address_cast(p), size, t); return {p, meta}; } @@ -146,14 +146,14 @@ namespace snmalloc auto& local = local_state->local_address_space; #endif - p = local.template reserve_with_left_over(local_state, size); + p = local.template reserve_with_left_over(size); if (p != nullptr) { return p; } auto refill_size = LOCAL_CACHE_BLOCK; - auto refill = global.template reserve(local_state, refill_size); + auto refill = global.template reserve(refill_size); if (refill == nullptr) return nullptr; @@ -165,10 +165,10 @@ namespace snmalloc } #endif PAL::template notify_using(refill.unsafe_ptr(), refill_size); - local.template add_range(local_state, refill, refill_size); + local.template add_range(refill, refill_size); // This should succeed - return local.template reserve_with_left_over(local_state, size); + return local.template reserve_with_left_over(size); } #ifdef SNMALLOC_META_PROTECTED @@ -179,7 +179,7 @@ namespace snmalloc size_t rsize = bits::max(OS_PAGE_SIZE, bits::next_pow2(size)); size_t size_request = rsize * 64; - p = global.template reserve(local_state, size_request); + p = global.template reserve(size_request); if (p == nullptr) return nullptr; @@ -195,7 +195,7 @@ namespace snmalloc SNMALLOC_ASSERT(!is_meta); #endif - p = global.template reserve_with_left_over(local_state, size); + p = global.template reserve_with_left_over(size); return p; } @@ -241,8 +241,6 @@ namespace snmalloc public: using Pal = PAL; - class LocalState; - class Pagemap { friend class BackendAllocator; @@ -252,12 +250,6 @@ namespace snmalloc concretePagemap; public: - /** - * Provide a type alias for LocalState so that we can refer to it without - * needing the whole BackendAllocator type at hand. - */ - using LocalState = BackendAllocator::LocalState; - /** * Get the metadata associated with a chunk. * @@ -265,10 +257,8 @@ namespace snmalloc * to access a location that is not backed by a chunk. */ template - SNMALLOC_FAST_PATH static const MetaEntry& - get_metaentry(LocalState* ls, address_t p) + SNMALLOC_FAST_PATH static const MetaEntry& get_metaentry(address_t p) { - UNUSED(ls); return concretePagemap.template get(p); } @@ -279,10 +269,8 @@ namespace snmalloc * to access a location that is not backed by a chunk. */ template - SNMALLOC_FAST_PATH static MetaEntry& - get_metaentry_mut(LocalState* ls, address_t p) + SNMALLOC_FAST_PATH static MetaEntry& get_metaentry_mut(address_t p) { - UNUSED(ls); return concretePagemap.template get_mut(p); } @@ -290,19 +278,16 @@ namespace snmalloc * Set the metadata associated with a chunk. */ SNMALLOC_FAST_PATH - static void - set_metaentry(LocalState* ls, address_t p, size_t size, MetaEntry t) + static void set_metaentry(address_t p, size_t size, MetaEntry t) { - UNUSED(ls); for (address_t a = p; a < p + size; a += MIN_CHUNK_SIZE) { concretePagemap.set(a, t); } } - static void register_range(LocalState* ls, address_t p, size_t sz) + static void register_range(address_t p, size_t sz) { - UNUSED(ls); concretePagemap.register_range(p, sz); } @@ -314,18 +299,16 @@ namespace snmalloc template static SNMALLOC_FAST_PATH std::enable_if_t> - get_bounds(LocalState* local_state) + get_bounds() { static_assert( fixed_range_ == fixed_range, "Don't set SFINAE parameter!"); - UNUSED(local_state); return concretePagemap.get_bounds(); } - static bool is_initialised(LocalState* ls) + static bool is_initialised() { - UNUSED(ls); return concretePagemap.is_initialised(); } }; @@ -372,15 +355,13 @@ namespace snmalloc } template - static std::enable_if_t - init(LocalState* local_state, void* base, size_t length) + static std::enable_if_t init(void* base, size_t length) { static_assert(fixed_range_ == fixed_range, "Don't set SFINAE parameter!"); auto [heap_base, heap_length] = Pagemap::concretePagemap.init(base, length); - address_space.add_range( - local_state, capptr::Chunk(heap_base), heap_length); + address_space.add_range(capptr::Chunk(heap_base), heap_length); } /** diff --git a/src/backend/backend_concept.h b/src/backend/backend_concept.h index e4cbc91..9aac9ff 100644 --- a/src/backend/backend_concept.h +++ b/src/backend/backend_concept.h @@ -18,17 +18,16 @@ namespace snmalloc template concept ConceptBackendMeta = requires( - typename Meta::LocalState* ls, address_t addr, size_t sz, MetaEntry t) { - { Meta::set_metaentry(ls, addr, sz, t) } -> ConceptSame; + { Meta::set_metaentry(addr, sz, t) } -> ConceptSame; - { Meta::template get_metaentry(ls, addr) } + { Meta::template get_metaentry(addr) } -> ConceptSame; - { Meta::template get_metaentry(ls, addr) } + { Meta::template get_metaentry(addr) } -> ConceptSame; }; @@ -41,9 +40,9 @@ namespace snmalloc */ template concept ConceptBackendMeta_Range = - requires(typename Meta::LocalState* ls, address_t addr, size_t sz) + requires(address_t addr, size_t sz) { - { Meta::register_range(ls, addr, sz) } -> ConceptSame; + { Meta::register_range(addr, sz) } -> ConceptSame; }; /** @@ -66,7 +65,8 @@ namespace snmalloc */ template concept ConceptBackendDomestication = - requires(typename Globals::LocalState* ls, + requires( + typename Globals::LocalState* ls, capptr::AllocWild ptr) { { Globals::capptr_domesticate(ls, ptr) } @@ -96,9 +96,6 @@ namespace snmalloc std::is_base_of::value && ConceptPAL && ConceptBackendMetaRange && - ConceptSame< - typename Globals::LocalState, - typename Globals::Pagemap::LocalState> && requires() { typename Globals::LocalState; diff --git a/src/backend/fixedglobalconfig.h b/src/backend/fixedglobalconfig.h index b3290da..a0fe819 100644 --- a/src/backend/fixedglobalconfig.h +++ b/src/backend/fixedglobalconfig.h @@ -49,7 +49,8 @@ namespace snmalloc static void init(typename Backend::LocalState* local_state, void* base, size_t length) { - Backend::init(local_state, base, length); + UNUSED(local_state); + Backend::init(base, length); } /* Verify that a pointer points into the region managed by this config */ @@ -66,7 +67,7 @@ namespace snmalloc UNUSED(ls); auto address = address_cast(p); - auto [base, length] = Backend::Pagemap::get_bounds(nullptr); + auto [base, length] = Backend::Pagemap::get_bounds(); if ((address - base > (length - sz)) || (length < sz)) { return nullptr; diff --git a/src/mem/chunkallocator.h b/src/mem/chunkallocator.h index 9f4de92..3965dbd 100644 --- a/src/mem/chunkallocator.h +++ b/src/mem/chunkallocator.h @@ -234,7 +234,7 @@ namespace snmalloc #endif MetaEntry entry{meta, remote, sizeclass}; SharedStateHandle::Pagemap::set_metaentry( - &local_state, address_cast(slab), slab_size, entry); + address_cast(slab), slab_size, entry); return {slab, meta}; } diff --git a/src/mem/corealloc.h b/src/mem/corealloc.h index 66e6b7b..760ca21 100644 --- a/src/mem/corealloc.h +++ b/src/mem/corealloc.h @@ -486,14 +486,14 @@ namespace snmalloc [local_state](freelist::QueuePtr p) SNMALLOC_FAST_PATH_LAMBDA { return capptr_domesticate(local_state, p); }; - auto cb = [this, local_state, &need_post](freelist::HeadPtr msg) + auto cb = [this, &need_post](freelist::HeadPtr msg) SNMALLOC_FAST_PATH_LAMBDA { #ifdef SNMALLOC_TRACING std::cout << "Handling remote" << std::endl; #endif auto& entry = SharedStateHandle::Pagemap::get_metaentry( - local_state, snmalloc::address_cast(msg)); + snmalloc::address_cast(msg)); handle_dealloc_remote(entry, msg.as_void(), need_post); @@ -675,8 +675,8 @@ namespace snmalloc SNMALLOC_FAST_PATH void dealloc_local_object(CapPtr p) { - auto entry = SharedStateHandle::Pagemap::get_metaentry( - backend_state_ptr(), snmalloc::address_cast(p)); + auto entry = + SharedStateHandle::Pagemap::get_metaentry(snmalloc::address_cast(p)); if (SNMALLOC_LIKELY(dealloc_local_object_fast(entry, p, entropy))) return; @@ -848,7 +848,7 @@ namespace snmalloc bool need_post = true; // Always going to post, so ignore. auto n_tame = p_tame->atomic_read_next(key_global, domesticate); auto& entry = SharedStateHandle::Pagemap::get_metaentry( - backend_state_ptr(), snmalloc::address_cast(p_tame)); + snmalloc::address_cast(p_tame)); handle_dealloc_remote(entry, p_tame.as_void(), need_post); p_tame = n_tame; } diff --git a/src/mem/localalloc.h b/src/mem/localalloc.h index d8e1b13..f9082e2 100644 --- a/src/mem/localalloc.h +++ b/src/mem/localalloc.h @@ -268,8 +268,8 @@ namespace snmalloc std::cout << "Remote dealloc post" << p.unsafe_ptr() << " size " << alloc_size(p.unsafe_ptr()) << std::endl; #endif - MetaEntry entry = SharedStateHandle::Pagemap::get_metaentry( - core_alloc->backend_state_ptr(), address_cast(p)); + MetaEntry entry = + SharedStateHandle::Pagemap::get_metaentry(address_cast(p)); local_cache.remote_dealloc_cache.template dealloc( entry.get_remote()->trunc_id(), p, key_global); post_remote_cache(); @@ -626,8 +626,8 @@ namespace snmalloc capptr::Alloc p_tame = capptr_domesticate( core_alloc->backend_state_ptr(), p_wild); - const MetaEntry& entry = SharedStateHandle::Pagemap::get_metaentry( - core_alloc->backend_state_ptr(), address_cast(p_tame)); + const MetaEntry& entry = + SharedStateHandle::Pagemap::get_metaentry(address_cast(p_tame)); if (SNMALLOC_LIKELY(local_cache.remote_allocator == entry.get_remote())) { # if defined(__CHERI_PURE_CAPABILITY__) && defined(SNMALLOC_CHECK_CLIENT) @@ -716,8 +716,8 @@ namespace snmalloc // To handle this case we require the uninitialised pagemap contain an // entry for the first chunk of memory, that states it represents a // large object, so we can pull the check for null off the fast path. - MetaEntry entry = SharedStateHandle::Pagemap::get_metaentry( - core_alloc->backend_state_ptr(), address_cast(p_raw)); + MetaEntry entry = + SharedStateHandle::Pagemap::get_metaentry(address_cast(p_raw)); return sizeclass_full_to_size(entry.get_sizeclass()); #endif @@ -763,7 +763,7 @@ namespace snmalloc #ifndef SNMALLOC_PASS_THROUGH MetaEntry entry = SharedStateHandle::Pagemap::template get_metaentry( - core_alloc->backend_state_ptr(), address_cast(p)); + address_cast(p)); auto sizeclass = entry.get_sizeclass(); return snmalloc::remaining_bytes(sizeclass, address_cast(p)); @@ -774,8 +774,7 @@ namespace snmalloc bool check_bounds(const void* p, size_t s) { - auto ls = core_alloc->backend_state_ptr(); - if (SNMALLOC_LIKELY(SharedStateHandle::Pagemap::is_initialised(ls))) + if (SNMALLOC_LIKELY(SharedStateHandle::Pagemap::is_initialised())) { return remaining_bytes(p) >= s; } @@ -793,7 +792,7 @@ namespace snmalloc #ifndef SNMALLOC_PASS_THROUGH MetaEntry entry = SharedStateHandle::Pagemap::template get_metaentry( - core_alloc->backend_state_ptr(), address_cast(p)); + address_cast(p)); auto sizeclass = entry.get_sizeclass(); return snmalloc::index_in_object(sizeclass, address_cast(p)); diff --git a/src/mem/remotecache.h b/src/mem/remotecache.h index 2ecb056..cafe158 100644 --- a/src/mem/remotecache.h +++ b/src/mem/remotecache.h @@ -101,8 +101,8 @@ namespace snmalloc if (!list[i].empty()) { auto [first, last] = list[i].extract_segment(key); - MetaEntry entry = SharedStateHandle::Pagemap::get_metaentry( - local_state, address_cast(first)); + MetaEntry entry = + SharedStateHandle::Pagemap::get_metaentry(address_cast(first)); if constexpr (SharedStateHandle::Options.QueueHeadsAreTame) { auto domesticate_nop = [](freelist::QueuePtr p) { @@ -134,8 +134,8 @@ namespace snmalloc // Use the next N bits to spread out remote deallocs in our own // slot. auto r = resend.take(key, domesticate); - MetaEntry entry = SharedStateHandle::Pagemap::get_metaentry( - local_state, address_cast(r)); + MetaEntry entry = + SharedStateHandle::Pagemap::get_metaentry(address_cast(r)); auto i = entry.get_remote()->trunc_id(); size_t slot = get_slot(i, post_round); list[slot].add(r, key);