[PATCH] squashfs: Customize squashfs metadata cache size

From: Yury Khmel
Date: Mon Aug 08 2022 - 16:58:35 EST


It provides customization using module params.
In some use-cases reading metadata may take comparable time reading data
itself. Increasing the cache size in such cases helps to eliminate that
bottleneck and increase the overall performance.

Signed-off-by: Yury Khmel <khmel@xxxxxxxxxx>
---
fs/squashfs/file.c | 4 ++--
fs/squashfs/squashfs_fs.h | 2 +-
fs/squashfs/super.c | 12 +++++++++++-
3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c
index 98e64fec75b7..fc8859741f59 100644
--- a/fs/squashfs/file.c
+++ b/fs/squashfs/file.c
@@ -207,7 +207,7 @@ static long long read_indexes(struct super_block *sb, int n,
* to distribute these over the length of the file, entry[0] maps index x,
* entry[1] maps index x + skip, entry[2] maps index x + 2 * skip, and so on.
* The larger the file, the greater the skip factor. The skip factor is
- * limited to the size of the metadata cache (SQUASHFS_CACHED_BLKS) to ensure
+ * limited to the size of the metadata cache (squashfs_cached_blks) to ensure
* the number of metadata blocks that need to be read fits into the cache.
* If the skip factor is limited in this way then the file will use multiple
* slots.
@@ -216,7 +216,7 @@ static inline int calculate_skip(u64 blocks)
{
u64 skip = blocks / ((SQUASHFS_META_ENTRIES + 1)
* SQUASHFS_META_INDEXES);
- return min((u64) SQUASHFS_CACHED_BLKS - 1, skip + 1);
+ return min((u64) squashfs_cached_blks() - 1, skip + 1);
}


diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
index b3fdc8212c5f..b42aaf51de28 100644
--- a/fs/squashfs/squashfs_fs.h
+++ b/fs/squashfs/squashfs_fs.h
@@ -202,7 +202,7 @@ static inline int squashfs_block_size(__le32 raw)
#define SQUASHFS_XATTR_OFFSET(A) ((unsigned int) ((A) & 0xffff))

/* cached data constants for filesystem */
-#define SQUASHFS_CACHED_BLKS 8
+unsigned int squashfs_cached_blks(void);

/* meta index cache */
#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 32565dafa7f3..939a5eb017c2 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -27,6 +27,7 @@
#include <linux/pagemap.h>
#include <linux/init.h>
#include <linux/module.h>
+#include <linux/moduleparam.h>
#include <linux/magic.h>
#include <linux/xattr.h>

@@ -85,6 +86,15 @@ static int squashfs_parse_param(struct fs_context *fc, struct fs_parameter *para
return 0;
}

+static unsigned int cached_blks = 8;
+module_param(cached_blks, uint, 0644);
+MODULE_PARM_DESC(cached_blks, "Metadata squashfs cache size");
+
+unsigned int squashfs_cached_blks(void)
+{
+ return cached_blks;
+}
+
static const struct squashfs_decompressor *supported_squashfs_filesystem(
struct fs_context *fc,
short major, short minor, short id)
@@ -246,7 +256,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
err = -ENOMEM;

msblk->block_cache = squashfs_cache_init("metadata",
- SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE);
+ squashfs_cached_blks(), SQUASHFS_METADATA_SIZE);
if (msblk->block_cache == NULL)
goto failed_mount;

--
2.37.1.559.g78731f0fdb-goog