From: Maria Matejka Date: Wed, 22 Feb 2023 13:45:20 +0000 (+0100) Subject: Linpool flush drops all the allocated pages but one X-Git-Tag: v3.0-alpha1~9^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6c058ae40cf33d6d36c0159d0c40c9925c8e60d8;p=thirdparty%2Fbird.git Linpool flush drops all the allocated pages but one When a linpool is used to allocate a one-off big load of memory, it makes no sense to keep that amount of memory for future use inside the linpool. Contrary to previous implementations where the memory was directly free()d, we now use the page allocator which has an internal cache which keeps the released pages for us and subsequent allocations simply get these released pages back. And even if the page cleanup routine kicks in inbetween, the pages get only madvise()d, not munmap()ed so performance aspects are negligible. This may fix some memory usage peaks in extreme cases. --- diff --git a/lib/mempool.c b/lib/mempool.c index 325b1ecfc..7c306e991 100644 --- a/lib/mempool.c +++ b/lib/mempool.c @@ -187,11 +187,18 @@ lp_flush(linpool *m) { struct lp_chunk *c; - /* Move ptr to the first chunk and free all large chunks */ + /* Move ptr to the first chunk and free all other chunks */ m->current = c = m->first; m->ptr = c ? c->data : NULL; m->end = c ? c->data + LP_DATA_SIZE : NULL; + while (c && c->next) + { + struct lp_chunk *d = c->next; + c->next = d->next; + free_page(d); + } + while (c = m->first_large) { m->first_large = c->next;