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

Pull some small things off the bottom of #637 #652

Merged
merged 4 commits into from
Jan 5, 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
28 changes: 17 additions & 11 deletions src/snmalloc/mem/corealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,25 @@ namespace snmalloc
*/
SNMALLOC_FAST_PATH bool has_messages()
{
auto domesticate = [local_state = backend_state_ptr()](
freelist::QueuePtr p) SNMALLOC_FAST_PATH_LAMBDA {
if constexpr (Config::Options.QueueHeadsAreTame)
{
return freelist::HeadPtr::unsafe_from(p.unsafe_ptr());
}
else
{
auto local_state = backend_state_ptr();
auto domesticate_head =
[local_state](freelist::QueuePtr p) SNMALLOC_FAST_PATH_LAMBDA {
if constexpr (Config::Options.QueueHeadsAreTame)
{
UNUSED(local_state);
return freelist::HeadPtr::unsafe_from(p.unsafe_ptr());
}
else
{
return capptr_domesticate<Config>(local_state, p);
}
};
auto domesticate_queue =
[local_state](freelist::QueuePtr p) SNMALLOC_FAST_PATH_LAMBDA {
return capptr_domesticate<Config>(local_state, p);
}
};
};

return !(message_queue().can_dequeue(domesticate));
return message_queue().can_dequeue(domesticate_head, domesticate_queue);
}

/**
Expand Down
17 changes: 7 additions & 10 deletions src/snmalloc/mem/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,19 @@ namespace snmalloc
* Entry stored in the pagemap. See docs/AddressSpace.md for the full
* FrontendMetaEntry lifecycle.
*/
template<typename BackendSlabMetadata>
template<typename SlabMetadataType>
class FrontendMetaEntry : public MetaEntryBase
{
/**
* Ensure that the template parameter is valid.
*/
static_assert(
std::is_convertible_v<BackendSlabMetadata, FrontendSlabMetadata_Trait>,
std::is_convertible_v<SlabMetadataType, FrontendSlabMetadata_Trait>,
"The front end requires that the back end provides slab metadata that is "
"compatible with the front-end's structure");

public:
using SlabMetadata = BackendSlabMetadata;
using SlabMetadata = SlabMetadataType;

constexpr FrontendMetaEntry() = default;

Expand All @@ -612,9 +612,8 @@ namespace snmalloc
* `get_remote_and_sizeclass`.
*/
SNMALLOC_FAST_PATH
FrontendMetaEntry(BackendSlabMetadata* meta, uintptr_t remote_and_sizeclass)
: MetaEntryBase(
unsafe_to_uintptr<BackendSlabMetadata>(meta), remote_and_sizeclass)
FrontendMetaEntry(SlabMetadata* meta, uintptr_t remote_and_sizeclass)
: MetaEntryBase(unsafe_to_uintptr<SlabMetadata>(meta), remote_and_sizeclass)
{
SNMALLOC_ASSERT_MSG(
(REMOTE_BACKEND_MARKER & remote_and_sizeclass) == 0,
Expand Down Expand Up @@ -645,12 +644,10 @@ namespace snmalloc
* guarded by an assert that this chunk is being used as a slab (i.e., has
* an associated owning allocator).
*/
[[nodiscard]] SNMALLOC_FAST_PATH BackendSlabMetadata*
get_slab_metadata() const
[[nodiscard]] SNMALLOC_FAST_PATH SlabMetadata* get_slab_metadata() const
{
SNMALLOC_ASSERT(get_remote() != nullptr);
return unsafe_from_uintptr<BackendSlabMetadata>(
meta & ~META_BOUNDARY_BIT);
return unsafe_from_uintptr<SlabMetadata>(meta & ~META_BOUNDARY_BIT);
}
};

Expand Down
7 changes: 4 additions & 3 deletions src/snmalloc/mem/remoteallocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ namespace snmalloc
return fnt;
}

template<typename Domesticator_head>
inline bool can_dequeue(Domesticator_head domesticate_head)
template<typename Domesticator_head, typename Domesticator_queue>
inline bool can_dequeue(
Domesticator_head domesticate_head, Domesticator_queue domesticate_queue)
{
return domesticate_head(front.load())
->atomic_read_next(key_global, domesticate_head) == nullptr;
->atomic_read_next(key_global, domesticate_queue) != nullptr;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/snmalloc/override/libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ namespace snmalloc::libc
// Guard memcpy as GCC is assuming not nullptr for ptr after the memcpy
// otherwise.
if (SNMALLOC_UNLIKELY(sz != 0))
{
SNMALLOC_ASSUME(ptr != nullptr);
::memcpy(p, ptr, sz);
}
a.dealloc(ptr);
}
else if (SNMALLOC_LIKELY(size == 0))
Expand Down Expand Up @@ -174,4 +177,4 @@ namespace snmalloc::libc
*memptr = p;
return 0;
}
} // namespace snmalloc::libc
} // namespace snmalloc::libc