summaryrefslogtreecommitdiff
path: root/src/mem_fb.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-06-19 17:32:52 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-06-19 17:48:47 -0700
commitfd727b42f29074290f41142016a7b5157b7bca56 (patch)
tree3c7d36af2fe1d09e1d7fb7647b03ce4555768d09 /src/mem_fb.c
parenta2f7397d289a21d1077c205e1d3c2beee7b39ac4 (diff)
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
Diffstat (limited to 'src/mem_fb.c')
-rw-r--r--src/mem_fb.c28
1 files 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;
}
© All Rights Reserved