From fd727b42f29074290f41142016a7b5157b7bca56 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 19 Jun 2023 17:32:52 -0700 Subject: mem_fb: keep spare pages on a free list Snapshotting made page alloc/free more frequent, and modules/mixer really hammers on snapshots in fade mode... drizzle as well, but mixer snapshots both module outputs per frame. So by keeping these around the reclaimed page snapshots can be held onto at within the fb as spares for quicker allocation. In practice it should just hit a high water mark of a working set for spare pages, once in a steady state, assuming snapshots aren't leaking. Future commits will replicate this change in {drm,sdl}_fb --- src/mem_fb.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/mem_fb.c b/src/mem_fb.c index 2dfa5bb..fc9406b 100644 --- a/src/mem_fb.c +++ b/src/mem_fb.c @@ -11,7 +11,7 @@ typedef struct mem_fb_page_t mem_fb_page_t; struct mem_fb_page_t { - void *unused; + mem_fb_page_t *next_spare; uint32_t buf[]; }; @@ -22,6 +22,7 @@ typedef struct mem_fb_setup_t { typedef struct mem_fb_t { mem_fb_setup_t setup; + mem_fb_page_t *spare_pages; } mem_fb_t; @@ -90,9 +91,15 @@ _err: static void mem_fb_shutdown(til_fb_t *fb, void *context) { mem_fb_t *c = context; + mem_fb_page_t *p; assert(c); + while ((p = c->spare_pages)) { + c->spare_pages = p->next_spare; + free(p); + } + free(c); } @@ -111,11 +118,18 @@ static void mem_fb_release(til_fb_t *fb, void *context) static void * mem_fb_page_alloc(til_fb_t *fb, void *context, til_fb_fragment_t *res_fragment) { mem_fb_t *c = context; - mem_fb_page_t *p; + mem_fb_page_t *p = NULL; - p = calloc(1, sizeof(mem_fb_page_t) + c->setup.width * c->setup.height * sizeof(uint32_t)); - if (!p) - return NULL; + if (c->spare_pages) { + p = c->spare_pages; + c->spare_pages = p->next_spare; + } + + if (!p) { + p = calloc(1, sizeof(mem_fb_page_t) + c->setup.width * c->setup.height * sizeof(uint32_t)); + if (!p) + return NULL; + } *res_fragment = (til_fb_fragment_t){ .buf = p->buf, @@ -132,9 +146,11 @@ static void * mem_fb_page_alloc(til_fb_t *fb, void *context, til_fb_fragment_t * static int mem_fb_page_free(til_fb_t *fb, void *context, void *page) { + mem_fb_t *c = context; mem_fb_page_t *p = page; - free(p); + p->next_spare = c->spare_pages; + c->spare_pages = p; return 0; } -- cgit v1.2.3