aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-03-04 21:28:14 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-04-01 12:25:02 +0200
commit32eb57dd9a19254565a0792ab9b627a3dac319f9 (patch)
treec86314fda1e36f2231f352ec0f372aef7d3d9b0a
parent6b1020ef3e034cbb6e0fa4cd984b181c0dd414ff (diff)
libsquashfs: remove the default block writer alignment feature
The idea of the block align feature was to allow micro-managing that some files are forcefully aligned to 1k/4k ("device block") boundaries, hoping to improve access time at the cost of data density. The feature was not exposed in the tools for a long time and eventuall added to the sort file. Measurement and experimentation showed, that it in fact worsened the read performance on a test system with an old micro SD card as the bottle neck. The feature is removed, and if needed, can be brought back simply by wrapping/sub-classing the default block writer, if need be.. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--bin/gensquashfs/src/sort_by_file.c3
-rw-r--r--bin/gensquashfs/test/sort_file.c4
-rw-r--r--include/sqfs/block.h16
-rw-r--r--include/sqfs/block_writer.h8
-rw-r--r--lib/common/src/writer/init.c3
-rw-r--r--lib/sqfs/src/block_processor/backend.c6
-rw-r--r--lib/sqfs/src/block_writer.c55
7 files changed, 14 insertions, 81 deletions
diff --git a/bin/gensquashfs/src/sort_by_file.c b/bin/gensquashfs/src/sort_by_file.c
index a555718..bc89c39 100644
--- a/bin/gensquashfs/src/sort_by_file.c
+++ b/bin/gensquashfs/src/sort_by_file.c
@@ -159,9 +159,6 @@ static int decode_flags(const char *filename, size_t line_no, bool *do_glob,
} else if (strncmp(line, "dont_fragment", 13) == 0) {
line += 13;
(*flags) |= SQFS_BLK_DONT_FRAGMENT;
- } else if (strncmp(line, "align", 5) == 0) {
- line += 5;
- (*flags) |= SQFS_BLK_ALIGN;
} else if (strncmp(line, "dont_compress", 13) == 0) {
line += 13;
(*flags) |= SQFS_BLK_DONT_COMPRESS;
diff --git a/bin/gensquashfs/test/sort_file.c b/bin/gensquashfs/test/sort_file.c
index 951328e..6c6cce6 100644
--- a/bin/gensquashfs/test/sort_file.c
+++ b/bin/gensquashfs/test/sort_file.c
@@ -42,7 +42,7 @@ static const char *sort_file =
" 50 [glob] /bin/*\n"
"\n"
"# Make this file appear first\n"
-" -10000 [dont_compress,dont_fragment,align] /usr/share/bla.txt";
+" -10000 [dont_compress,dont_fragment] /usr/share/bla.txt";
static const char *initial_order[] = {
"bin/chmod",
@@ -93,7 +93,7 @@ static sqfs_s64 priorities[] = {
};
static int flags[] = {
- SQFS_BLK_DONT_COMPRESS | SQFS_BLK_ALIGN | SQFS_BLK_DONT_FRAGMENT,
+ SQFS_BLK_DONT_COMPRESS | SQFS_BLK_DONT_FRAGMENT,
0,
0,
0,
diff --git a/include/sqfs/block.h b/include/sqfs/block.h
index 30f181c..639fb68 100644
--- a/include/sqfs/block.h
+++ b/include/sqfs/block.h
@@ -72,12 +72,9 @@ typedef enum {
SQFS_BLK_DONT_COMPRESS = 0x0001,
/**
- * @brief Align the block on disk to device block size.
- *
- * If set, the @ref sqfs_block_processor_t will add padding before the
- * first block of the affected file and after the last block.
+ * @brief Don't compute block data checksums.
*/
- SQFS_BLK_ALIGN = 0x0002,
+ SQFS_BLK_DONT_HASH = 0x0002,
/**
* @brief Don't add the tail end of a file to a fragment block.
@@ -105,11 +102,6 @@ typedef enum {
SQFS_BLK_IGNORE_SPARSE = 0x0010,
/**
- * @brief Don't compute block data checksums.
- */
- SQFS_BLK_DONT_HASH = 0x0020,
-
- /**
* @brief Set by the @ref sqfs_block_processor_t if it determines a
* block of a file to be sparse, i.e. only zero bytes.
*/
@@ -148,9 +140,9 @@ typedef enum {
/**
* @brief The combination of all flags that are user settable.
*/
- SQFS_BLK_USER_SETTABLE_FLAGS = 0x003F,
+ SQFS_BLK_USER_SETTABLE_FLAGS = 0x001F,
- SQFS_BLK_FLAGS_ALL = 0xFC3F,
+ SQFS_BLK_FLAGS_ALL = 0xFC1F,
} SQFS_BLK_FLAGS;
#endif /* SQFS_BLOCK_H */
diff --git a/include/sqfs/block_writer.h b/include/sqfs/block_writer.h
index 6376d2e..84e6973 100644
--- a/include/sqfs/block_writer.h
+++ b/include/sqfs/block_writer.h
@@ -52,11 +52,6 @@ struct sqfs_block_writer_t {
* @ref SQFS_BLK_LAST_BLOCK flag is set, it uses those stored locations
* to do block deduplication.
*
- * If the flag @ref SQFS_BLK_ALIGN is set in combination with the
- * @ref SQFS_BLK_FIRST_BLOCK, the file size is padded to a multiple of
- * the device block size before writing. If it is set together with the
- * @ref SQFS_BLK_LAST_BLOCK flag, the padding is added afterwards.
- *
* @param wr A pointer to a block writer.
* @param user An optional user data pointer.
* The @ref sqfs_block_processor_t can be told to pass this
@@ -126,15 +121,12 @@ extern "C" {
* @memberof sqfs_block_writer_t
*
* @param file A pointer to a file object that data should be appended to.
- * @param devblksz The underlying device block size if output data
- * should be aligned.
* @param flags A combination of @ref SQFS_BLOCK_WRITER_FLAGS values. If an
* unknown flag is set, creation will fail.
*
* @return A pointer to a new block writer on success, NULL on failure.
*/
SQFS_API sqfs_block_writer_t *sqfs_block_writer_create(sqfs_file_t *file,
- size_t devblksz,
sqfs_u32 flags);
#ifdef __cplusplus
diff --git a/lib/common/src/writer/init.c b/lib/common/src/writer/init.c
index 497fc6e..fe5fcc5 100644
--- a/lib/common/src/writer/init.c
+++ b/lib/common/src/writer/init.c
@@ -120,8 +120,7 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg)
if (ret > 0)
sqfs->super.flags |= SQFS_FLAG_COMPRESSOR_OPTIONS;
- sqfs->blkwr = sqfs_block_writer_create(sqfs->outfile,
- wrcfg->devblksize, 0);
+ sqfs->blkwr = sqfs_block_writer_create(sqfs->outfile, 0);
if (sqfs->blkwr == NULL) {
perror("creating block writer");
goto fail_uncmp;
diff --git a/lib/sqfs/src/block_processor/backend.c b/lib/sqfs/src/block_processor/backend.c
index b443c9d..acff7f5 100644
--- a/lib/sqfs/src/block_processor/backend.c
+++ b/lib/sqfs/src/block_processor/backend.c
@@ -202,8 +202,7 @@ static int process_completed_fragment(sqfs_block_processor_t *proc,
offset = 0;
proc->frag_block = frag;
proc->frag_block->index = index;
- proc->frag_block->flags &=
- (SQFS_BLK_DONT_COMPRESS | SQFS_BLK_ALIGN);
+ proc->frag_block->flags &= SQFS_BLK_DONT_COMPRESS;
proc->frag_block->flags |= SQFS_BLK_FRAGMENT_BLOCK;
} else {
index = proc->frag_block->index;
@@ -214,8 +213,7 @@ static int process_completed_fragment(sqfs_block_processor_t *proc,
proc->frag_block->size += frag->size;
proc->frag_block->flags |=
- (frag->flags &
- (SQFS_BLK_DONT_COMPRESS | SQFS_BLK_ALIGN));
+ (frag->flags & SQFS_BLK_DONT_COMPRESS);
}
if (proc->frag_tbl != NULL) {
diff --git a/lib/sqfs/src/block_writer.c b/lib/sqfs/src/block_writer.c
index a5135bc..c747079 100644
--- a/lib/sqfs/src/block_writer.c
+++ b/lib/sqfs/src/block_writer.c
@@ -36,7 +36,6 @@ typedef struct {
sqfs_file_t *file;
array_t blocks;
- size_t devblksz;
size_t file_start;
@@ -79,9 +78,6 @@ static int deduplicate_blocks(block_writer_default_t *wr, sqfs_u32 flags, sqfs_u
for (i = 0; i < wr->file_start; ++i) {
for (j = 0; j < count; ++j) {
- if (blocks[i + j].hash == 0)
- break;
-
if (blocks[i + j].hash !=
blocks[wr->file_start + j].hash)
break;
@@ -119,33 +115,6 @@ static int deduplicate_blocks(block_writer_default_t *wr, sqfs_u32 flags, sqfs_u
return wr->file->truncate(wr->file, sz);
}
-static int align_file(block_writer_default_t *wr, sqfs_u32 flags)
-{
- void *padding;
- sqfs_u64 size;
- size_t diff;
- int ret;
-
- if (!(flags & SQFS_BLK_ALIGN))
- return 0;
-
- size = wr->file->get_size(wr->file);
- diff = size % wr->devblksz;
- if (diff == 0)
- return 0;
-
- padding = calloc(1, diff);
- if (padding == 0)
- return SQFS_ERROR_ALLOC;
-
- ret = wr->file->write_at(wr->file, size, padding, diff);
- free(padding);
- if (ret)
- return ret;
-
- return store_block_location(wr, size, 0, 0);
-}
-
static void block_writer_destroy(sqfs_object_t *wr)
{
sqfs_drop(((block_writer_default_t *)wr)->file);
@@ -161,14 +130,8 @@ static int write_data_block(sqfs_block_writer_t *base, void *user,
int err;
(void)user;
- if (flags & (SQFS_BLK_FIRST_BLOCK | SQFS_BLK_FRAGMENT_BLOCK)) {
- err = align_file(wr, flags);
- if (err)
- return err;
-
- if (flags & SQFS_BLK_FIRST_BLOCK)
- wr->file_start = wr->blocks.used;
- }
+ if (flags & SQFS_BLK_FIRST_BLOCK)
+ wr->file_start = wr->blocks.used;
*location = wr->file->get_size(wr->file);
@@ -186,14 +149,8 @@ static int write_data_block(sqfs_block_writer_t *base, void *user,
return err;
}
- if (flags & (SQFS_BLK_LAST_BLOCK | SQFS_BLK_FRAGMENT_BLOCK)) {
- err = align_file(wr, flags);
- if (err)
- return err;
-
- if (flags & SQFS_BLK_LAST_BLOCK)
- return deduplicate_blocks(wr, flags, location);
- }
+ if (flags & SQFS_BLK_LAST_BLOCK)
+ return deduplicate_blocks(wr, flags, location);
return 0;
}
@@ -203,8 +160,7 @@ static sqfs_u64 get_block_count(const sqfs_block_writer_t *wr)
return ((const block_writer_default_t *)wr)->blocks.used;
}
-sqfs_block_writer_t *sqfs_block_writer_create(sqfs_file_t *file,
- size_t devblksz, sqfs_u32 flags)
+sqfs_block_writer_t *sqfs_block_writer_create(sqfs_file_t *file, sqfs_u32 flags)
{
block_writer_default_t *wr;
@@ -226,7 +182,6 @@ sqfs_block_writer_t *sqfs_block_writer_create(sqfs_file_t *file,
((sqfs_block_writer_t *)wr)->get_block_count = get_block_count;
wr->flags = flags;
wr->file = sqfs_grab(file);
- wr->devblksz = devblksz;
if (array_init(&(wr->blocks), sizeof(blk_info_t), INIT_BLOCK_COUNT)) {
sqfs_drop(wr->file);