From 4587a56466f0c55d91ece168f0dc872f81a8196c Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 23 May 2020 05:30:16 +0200 Subject: block processor: recycle blocks to reduce allocation pressure Instead of freeing/allocating blocks all the time in the locked, serial path, use a free list to "recycle" blocks. Once a block is no longer used, throw it onto the free list. If a new block is, needed try to get one from the free list before calling malloc. After a few iterations, the block processor should stop allocating new blocks and only re-use the ones it already has. Signed-off-by: David Oberhollenzer --- lib/sqfs/block_processor/winpthread.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'lib/sqfs/block_processor/winpthread.c') diff --git a/lib/sqfs/block_processor/winpthread.c b/lib/sqfs/block_processor/winpthread.c index 80cbde9..281eb6b 100644 --- a/lib/sqfs/block_processor/winpthread.c +++ b/lib/sqfs/block_processor/winpthread.c @@ -192,6 +192,7 @@ static void block_processor_destroy(sqfs_object_t *obj) free_blk_list(proc->proc_queue); free_blk_list(proc->io_queue); free_blk_list(proc->done); + free_blk_list(proc->base.free_list); free(proc->base.blk_current); free(proc->base.frag_block); free(proc); @@ -390,12 +391,13 @@ static void append_block(thread_pool_processor_t *proc, sqfs_block_t *block) static int handle_io_queue(thread_pool_processor_t *proc, sqfs_block_t *list) { - sqfs_block_t *it = list; + sqfs_block_t *it; int status = 0; - while (status == 0 && it != NULL) { + while (status == 0 && list != NULL) { + it = list; + list = list->next; status = process_completed_block(&proc->base, it); - it = it->next; if (status != 0) { LOCK(&proc->mtx); @@ -413,7 +415,7 @@ int append_to_work_queue(sqfs_block_processor_t *proc, sqfs_block_t *block) { thread_pool_processor_t *thproc = (thread_pool_processor_t *)proc; sqfs_block_t *io_list = NULL, *io_list_last = NULL; - sqfs_block_t *blk, *fragblk, *free_list = NULL; + sqfs_block_t *blk, *fragblk; int status; LOCK(&thproc->mtx); @@ -454,8 +456,6 @@ int append_to_work_queue(sqfs_block_processor_t *proc, sqfs_block_t *block) fragblk = NULL; thproc->status = process_completed_fragment(proc, blk, &fragblk); - blk->next = free_list; - free_list = blk; if (fragblk != NULL) { fragblk->io_seq_num = thproc->io_enq_id++; @@ -472,11 +472,12 @@ int append_to_work_queue(sqfs_block_processor_t *proc, sqfs_block_t *block) UNLOCK(&thproc->mtx); free(block); - if (status == 0) + if (status == 0) { status = handle_io_queue(thproc, io_list); + } else { + free_blk_list(io_list); + } - free_blk_list(io_list); - free_blk_list(free_list); return status; } @@ -504,7 +505,6 @@ int sqfs_block_processor_finish(sqfs_block_processor_t *proc) if (status == 0) status = handle_io_queue(thproc, blk); - free(blk); if (status != 0) { LOCK(&thproc->mtx); -- cgit v1.2.3