aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/block_processor/serial.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-05-23 05:30:16 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-05-23 17:21:15 +0200
commit4587a56466f0c55d91ece168f0dc872f81a8196c (patch)
tree1b7648f0b4bca6620387ad5ca0b9003f46aca545 /lib/sqfs/block_processor/serial.c
parent0ffda020899f36e17e74a9cb2019066d753bddc2 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/block_processor/serial.c')
-rw-r--r--lib/sqfs/block_processor/serial.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/sqfs/block_processor/serial.c b/lib/sqfs/block_processor/serial.c
index b797ca0..a9190b1 100644
--- a/lib/sqfs/block_processor/serial.c
+++ b/lib/sqfs/block_processor/serial.c
@@ -16,6 +16,13 @@ typedef struct {
static void block_processor_destroy(sqfs_object_t *obj)
{
sqfs_block_processor_t *proc = (sqfs_block_processor_t *)obj;
+ sqfs_block_t *blk;
+
+ while (proc->free_list != NULL) {
+ blk = proc->free_list;
+ proc->free_list = blk->next;
+ free(blk);
+ }
free(proc->blk_current);
free(proc->frag_block);
@@ -50,34 +57,31 @@ int append_to_work_queue(sqfs_block_processor_t *proc, sqfs_block_t *block)
serial_block_processor_t *sproc = (serial_block_processor_t *)proc;
sqfs_block_t *fragblk = NULL;
- if (sproc->status != 0)
- goto done;
+ if (sproc->status != 0) {
+ free(block);
+ return sproc->status;
+ }
sproc->status = block_processor_do_block(block, proc->cmp,
sproc->scratch,
proc->max_block_size);
if (sproc->status != 0)
- goto done;
+ return sproc->status;
if (block->flags & SQFS_BLK_IS_FRAGMENT) {
sproc->status = process_completed_fragment(proc, block,
&fragblk);
if (fragblk == NULL)
- goto done;
-
- free(block);
- block = fragblk;
+ return sproc->status;
- sproc->status = block_processor_do_block(block, proc->cmp,
+ sproc->status = block_processor_do_block(fragblk, proc->cmp,
sproc->scratch,
proc->max_block_size);
if (sproc->status != 0)
- goto done;
+ return sproc->status;
}
sproc->status = process_completed_block(proc, block);
-done:
- free(block);
return sproc->status;
}
@@ -91,16 +95,17 @@ int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
serial_block_processor_t *sproc = (serial_block_processor_t *)proc;
if (proc->frag_block == NULL || sproc->status != 0)
- goto out;
+ goto fail;
sproc->status = block_processor_do_block(proc->frag_block, proc->cmp,
sproc->scratch,
proc->max_block_size);
if (sproc->status != 0)
- goto out;
+ goto fail;
sproc->status = process_completed_block(proc, proc->frag_block);
-out:
+ return sproc->status;
+fail:
free(proc->frag_block);
proc->frag_block = NULL;
return sproc->status;