Refactor logbuffer_grow

Making a full copy of the logbuffer just to access four members
was not justified. The original idea was to re-use logbuffer_fini,
but, effectively, only buddy_return1_ptr_page() was called.
parent 90c10efd
...@@ -1906,14 +1906,22 @@ logbuffer_fini(struct fellow_logbuffer *lbuf) ...@@ -1906,14 +1906,22 @@ logbuffer_fini(struct fellow_logbuffer *lbuf)
static void static void
logbuffer_grow(struct fellow_logbuffer *lbuf, uint8_t initialbits) logbuffer_grow(struct fellow_logbuffer *lbuf, uint8_t initialbits)
{ {
struct fellow_logbuffer old[1]; struct {
struct fellow_alloc_log_block *arr;
struct buddy_ptr_page alloc; // arr allocation
unsigned n, space;
} old;
size_t sz, b; size_t sz, b;
CHECK_OBJ_NOTNULL(lbuf, FELLOW_LOGBUFFER_MAGIC); CHECK_OBJ_NOTNULL(lbuf, FELLOW_LOGBUFFER_MAGIC);
assert(lbuf->n == lbuf->space); assert(lbuf->n == lbuf->space);
memcpy(old, lbuf, sizeof old);
if (old->alloc.bits == 0) { old.arr = lbuf->arr;
old.alloc = lbuf->alloc;
old.n = lbuf->n;
old.space = lbuf->space;
if (old.alloc.bits == 0) {
AN(initialbits); AN(initialbits);
lbuf->alloc = buddy_alloc1_ptr_page_wait( lbuf->alloc = buddy_alloc1_ptr_page_wait(
lbuf->membuddy, FEP_LOG, lbuf->membuddy, FEP_LOG,
...@@ -1921,7 +1929,7 @@ logbuffer_grow(struct fellow_logbuffer *lbuf, uint8_t initialbits) ...@@ -1921,7 +1929,7 @@ logbuffer_grow(struct fellow_logbuffer *lbuf, uint8_t initialbits)
} else { } else {
AZ(initialbits); AZ(initialbits);
lbuf->alloc = buddy_alloc1_ptr_page_wait( lbuf->alloc = buddy_alloc1_ptr_page_wait(
lbuf->membuddy, FEP_LOG, old->alloc.bits + 1, 0); lbuf->membuddy, FEP_LOG, old.alloc.bits + 1, 0);
} }
MEM(lbuf->membuddy); MEM(lbuf->membuddy);
lbuf->arr = lbuf->alloc.ptr; lbuf->arr = lbuf->alloc.ptr;
...@@ -1933,24 +1941,12 @@ logbuffer_grow(struct fellow_logbuffer *lbuf, uint8_t initialbits) ...@@ -1933,24 +1941,12 @@ logbuffer_grow(struct fellow_logbuffer *lbuf, uint8_t initialbits)
assert(b < UINT_MAX); assert(b < UINT_MAX);
lbuf->space = (unsigned)b; lbuf->space = (unsigned)b;
if (old->space == 0) if (old.space == 0)
return; return;
assert(lbuf->space > old->space); assert(lbuf->space > old.space);
if (old->n > 0) { if (old.n > 0)
memcpy(lbuf->arr, old->arr, old->n * sizeof *lbuf->arr); memcpy(lbuf->arr, old.arr, old.n * sizeof *lbuf->arr);
old->n = 0; buddy_return1_ptr_page(lbuf->membuddy, &old.alloc);
}
memset(&old->head, 0, sizeof old->head);
memset(&old->active, 0, sizeof old->active);
memset(&old->fdil, 0, sizeof old->fdil);
/* XXX we should REALLY rework the logbuffer and ff
* in particular. For now, avoid logbuffer_fini to ALSO
* wait on the copy (old) ...
*/
memset(&old->ff, 0, sizeof old->ff);
old->regions_to_free = NULL;
old->state = LBUF_FINI;
logbuffer_fini(old);
} }
static void static void
......
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