From 69cd1a62b273efdd392f1f130bf3dc57c73ef5d5 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 24 May 2020 15:37:07 +0200 Subject: block processor: promote fragments to fragment blocks Instead of [potentially] allocating a new fragment block, take an existing fragment and promote it to the fragmenet block. This saves as a potential block allocation and a memcpy of the initial data. Also it *definitely* removes block allocation from the backend path of the block processor. Signed-off-by: David Oberhollenzer --- lib/sqfs/block_processor/common.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c index c3363f9..1bccf57 100644 --- a/lib/sqfs/block_processor/common.c +++ b/lib/sqfs/block_processor/common.c @@ -153,6 +153,9 @@ int block_processor_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp, sqfs_inode_set_frag_location(*(it->inode), block->index, offset); } + + /* XXX: the block itself got promoted from a fragment */ + sqfs_inode_set_frag_location(*(block->inode), block->index, 0); } if (is_zero_block(block->data, block->size)) { @@ -223,32 +226,33 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag, if (err) goto fail; - proc->frag_block = get_new_block(proc); - if (proc->frag_block == NULL) { - err = SQFS_ERROR_ALLOC; - goto fail; - } - + offset = 0; + proc->frag_block = frag; proc->frag_block->index = index; - proc->frag_block->flags = SQFS_BLK_FRAGMENT_BLOCK; + proc->frag_block->flags &= SQFS_BLK_DONT_COMPRESS; + proc->frag_block->flags |= SQFS_BLK_FRAGMENT_BLOCK; + proc->frag_block->frag_list = NULL; proc->stats.frag_block_count += 1; + } else { + index = proc->frag_block->index; + offset = proc->frag_block->size; + + frag->next = proc->frag_block->frag_list; + proc->frag_block->frag_list = frag; + + proc->frag_block->size += frag->size; } - err = sqfs_frag_table_add_tail_end(proc->frag_tbl, - proc->frag_block->index, - proc->frag_block->size, + err = sqfs_frag_table_add_tail_end(proc->frag_tbl, index, offset, frag->size, frag->checksum); if (err) - goto fail; - - frag->next = proc->frag_block->frag_list; - proc->frag_block->frag_list = frag; + goto fail_outblk; - proc->frag_block->size += frag->size; proc->stats.actual_frag_count += 1; return 0; fail: release_old_block(proc, frag); +fail_outblk: if (*blk_out != NULL) { release_old_block(proc, *blk_out); *blk_out = NULL; -- cgit v1.2.3