Align pagemap entries to OS_PAGE_SIZE

Guarantee the page map is page aligned.  Fix public API.
This commit is contained in:
Matthew Parkinson 2019-01-18 15:22:08 +00:00
Родитель 62ad70b17e
Коммит a62e77f930
2 изменённых файлов: 29 добавлений и 13 удалений

Просмотреть файл

@ -51,6 +51,13 @@ namespace snmalloc
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:
/**
* Stack of large allocations that have been returned for reuse.
@ -61,7 +68,7 @@ namespace snmalloc
* Primitive allocator for structure that are required before
* the allocator can be running.
***/
void* alloc_chunk(size_t size)
void* alloc_chunk(size_t size, size_t alignment = 64)
{
// Cache line align
size = bits::align_up(size, 64);
@ -70,12 +77,20 @@ namespace snmalloc
{
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)
{
auto r_size = reserve_block();
bump = (size_t)r_size.first;
remaining = r_size.second;
new_block();
}
p = (void*)bump;

Просмотреть файл

@ -86,7 +86,8 @@ namespace snmalloc
value, (PagemapEntry*)LOCKED_ENTRY, std::memory_order_relaxed))
{
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);
}
else
@ -160,6 +161,13 @@ namespace snmalloc
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
* in code that propagates changes to the pagemap elsewhere.
@ -182,13 +190,6 @@ namespace snmalloc
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)
{
bool success;