Align pagemap entries to OS_PAGE_SIZE
Guarantee the page map is page aligned. Fix public API.
This commit is contained in:
@@ -51,6 +51,13 @@ namespace snmalloc
|
|||||||
return std::make_pair(r, size);
|
return std::make_pair(r, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void new_block()
|
||||||
|
{
|
||||||
|
auto r_size = reserve_block();
|
||||||
|
bump = (size_t)r_size.first;
|
||||||
|
remaining = r_size.second;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Stack of large allocations that have been returned for reuse.
|
* Stack of large allocations that have been returned for reuse.
|
||||||
@@ -61,7 +68,7 @@ namespace snmalloc
|
|||||||
* Primitive allocator for structure that are required before
|
* Primitive allocator for structure that are required before
|
||||||
* the allocator can be running.
|
* the allocator can be running.
|
||||||
***/
|
***/
|
||||||
void* alloc_chunk(size_t size)
|
void* alloc_chunk(size_t size, size_t alignment = 64)
|
||||||
{
|
{
|
||||||
// Cache line align
|
// Cache line align
|
||||||
size = bits::align_up(size, 64);
|
size = bits::align_up(size, 64);
|
||||||
@@ -70,12 +77,20 @@ namespace snmalloc
|
|||||||
{
|
{
|
||||||
FlagLock f(lock);
|
FlagLock f(lock);
|
||||||
|
|
||||||
|
auto aligned_bump = bits::align_up(bump, alignment);
|
||||||
|
if ((aligned_bump - bump) < size)
|
||||||
|
{
|
||||||
|
new_block();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
remaining -= aligned_bump - bump;
|
||||||
|
bump = aligned_bump;
|
||||||
|
}
|
||||||
|
|
||||||
if (remaining < size)
|
if (remaining < size)
|
||||||
{
|
{
|
||||||
auto r_size = reserve_block();
|
new_block();
|
||||||
|
|
||||||
bump = (size_t)r_size.first;
|
|
||||||
remaining = r_size.second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p = (void*)bump;
|
p = (void*)bump;
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ namespace snmalloc
|
|||||||
value, (PagemapEntry*)LOCKED_ENTRY, std::memory_order_relaxed))
|
value, (PagemapEntry*)LOCKED_ENTRY, std::memory_order_relaxed))
|
||||||
{
|
{
|
||||||
auto& v = default_memory_provider;
|
auto& v = default_memory_provider;
|
||||||
value = (PagemapEntry*)v.alloc_chunk(PAGEMAP_NODE_SIZE);
|
value =
|
||||||
|
(PagemapEntry*)v.alloc_chunk(PAGEMAP_NODE_SIZE, OS_PAGE_SIZE);
|
||||||
e->store(value, std::memory_order_release);
|
e->store(value, std::memory_order_release);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -160,6 +161,13 @@ namespace snmalloc
|
|||||||
return &(leaf_ix.first->values[leaf_ix.second]);
|
return &(leaf_ix.first->values[leaf_ix.second]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::atomic<T>* get_ptr(void* p)
|
||||||
|
{
|
||||||
|
bool success;
|
||||||
|
return get_addr<true>(p, success);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
/**
|
/**
|
||||||
* Returns the index of a pagemap entry within a given page. This is used
|
* Returns the index of a pagemap entry within a given page. This is used
|
||||||
* in code that propagates changes to the pagemap elsewhere.
|
* in code that propagates changes to the pagemap elsewhere.
|
||||||
@@ -182,13 +190,6 @@ namespace snmalloc
|
|||||||
reinterpret_cast<uintptr_t>(get_addr<true>(p, success)));
|
reinterpret_cast<uintptr_t>(get_addr<true>(p, success)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::atomic<T>* get_ptr(void* p)
|
|
||||||
{
|
|
||||||
bool success;
|
|
||||||
return get_addr<true>(p, success);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
T get(void* p)
|
T get(void* p)
|
||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
|||||||
Reference in New Issue
Block a user