Optimize segment memory allocation further

If the page from the segmem pool is too big, do not just trim it, but
rather trade it for a smaller page if that is sufficient.

Ref #60
parent 0dd59f23
......@@ -4971,21 +4971,36 @@ static size_t fellow_busy_seg_memalloc(struct fellow_busy *fbo,
fbo_segmem_get(fbo->segmem, fbo->fc->tune));
AN(mem.ptr);
sz = (size_t)1 << mem.bits;
if (sz >= fds->seg.size) {
fcs->alloc.ptr = mem.ptr;
fcs->alloc.size = sz;
buddy_trim1_ptr_extent(fbo->fc->membuddy, &fcs->alloc,
fds->seg.size);
/*
* if the fbo_segmem pool gave us too large/small a page,
* trade it in for a new allocation
*/
if (log2up(fds->seg.size) < mem.bits ||
(cram == 0 && sz < fds->seg.size)) {
struct buddy_reqs *reqs =
BUDDY_REQS_STK(fbo->fc->membuddy, 1);
BUDDY_REQS_PRI(reqs, FEP_SPCPRI);
AN(buddy_req_extent(reqs, fds->seg.size, 0));
buddy_return1_ptr_page(fbo->fc->membuddy, &mem);
AN(buddy_alloc_wait(reqs));
fcs->alloc = buddy_get_ptr_extent(reqs, 0);
buddy_alloc_wait_done(reqs);
}
else {
buddy_return1_ptr_page(fbo->fc->membuddy, &mem);
fcs->alloc = buddy_alloc1_ptr_extent_wait(fbo->fc->membuddy,
FEP_SPCPRI, fds->seg.size, cram);
fcs->alloc.ptr = mem.ptr;
fcs->alloc.size = sz;
}
if (fcs->alloc.ptr == NULL)
return (0);
if (fds->seg.size < fcs->alloc.size) {
buddy_trim1_ptr_extent(fbo->fc->membuddy, &fcs->alloc,
fds->seg.size);
}
// cram needs to be chosen correctly
assert(fcs->alloc.size >= MIN_FELLOW_BLOCK);
assert((fcs->alloc.size & FELLOW_BLOCK_ALIGN) == 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment