Skip to content
Snippets Groups Projects
Commit c549e0e8 authored by Avi Kivity's avatar Avi Kivity
Browse files

mempool: add hysteresis

If we allocate and free just one object in an empty pool, we will
continuously allocate a page, format it for the pool, then free it.

This is wastefull, so allow the pool to keep one empty page.  The page is kept
at the back of the free list, so it won't get fragemented needlessly.
parent a76e1813
No related branches found
No related tags found
No related merge requests found
......@@ -228,23 +228,33 @@ void pool::add_page()
});
}
inline bool pool::have_full_pages()
{
return !_free->empty() && _free->back().nalloc == 0;
}
void pool::free_same_cpu(free_object* obj, unsigned cpu_id)
{
void* object = static_cast<void*>(obj);
trace_pool_free_same_cpu(this, object);
page_header* header = to_header(obj);
if (!--header->nalloc) {
if (!--header->nalloc && have_full_pages()) {
if (header->local_free) {
_free->erase(_free->iterator_to(*header));
}
// FIXME: add hysteresis
sched::preempt_enable();
untracked_free_page(header);
sched::preempt_disable();
} else {
if (!header->local_free) {
_free->push_front(*header);
if (header->nalloc) {
_free->push_front(*header);
} else {
// keep full pages on the back, so they're not fragmented
// early, and so we find them easily in have_full_pages()
_free->push_back(*header);
}
}
obj->next = header->local_free;
header->local_free = obj;
......
......@@ -39,6 +39,7 @@ private:
struct page_header;
struct free_object;
private:
bool have_full_pages();
void add_page();
static page_header* to_header(free_object* object);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment