[PATCH 1/2] Squashfs: Let the number of fragments cached configurable
From: Qixuan Wu
Date: Wed Oct 18 2017 - 03:46:57 EST
Currently, squashfs fragments' cache size is only determined by
config option CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE. Users have
no way to change the value when they get the binary kernel.
Now make it be configured during booting or inserting module.
Signed-off-by: Qixuan Wu <wuqixuan@xxxxxxxxxx>
Signed-off-by: Chen Jie <chenjie6@xxxxxxxxxx>
---
fs/squashfs/super.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index cf01e15..82f9e46 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -38,6 +38,7 @@
#include <linux/module.h>
#include <linux/magic.h>
#include <linux/xattr.h>
+#include <linux/ctype.h>
#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
@@ -49,6 +50,37 @@
static struct file_system_type squashfs_fs_type;
static const struct super_operations squashfs_super_ops;
+static unsigned int squashfs_frags_cache_size = SQUASHFS_CACHED_FRAGMENTS;
+
+#ifndef MODULE
+static int __init squashfs_frags_cachesize_setup(char *buf)
+{
+ unsigned int arg;
+
+ if (!buf || kstrtouint(buf, 10, &arg) < 0) {
+ pr_err("Bad squashfs fragments' cache size, let it be %d\n",
+ SQUASHFS_CACHED_FRAGMENTS);
+ return 0;
+ }
+
+ if (arg < 3 || arg > 99) {
+ pr_warn("Squashfs fragments' cache size should be in the range "
+ "of [3,99]. Let it be %d\n", SQUASHFS_CACHED_FRAGMENTS);
+ return 0;
+ }
+
+ squashfs_frags_cache_size = arg;
+
+ return 0;
+}
+early_param("squashfs.frags_cache_size", squashfs_frags_cachesize_setup);
+
+#else
+module_param(squashfs_frags_cache_size, uint, 0444);
+MODULE_PARM_DESC(squashfs_frags_cache_size,
+ "Squashfs fragments' cache size, it should be in the range of [3,99]");
+#endif
+
static const struct squashfs_decompressor *supported_squashfs_filesystem(short
major, short minor, short id)
{
@@ -276,8 +308,17 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
if (fragments == 0)
goto check_directory_table;
+ if ((squashfs_frags_cache_size < 3)
+ || (squashfs_frags_cache_size > 99)) {
+ ERROR("Fragments' cache size should be in the range of[3,99]."
+ "Let it be %d\n", SQUASHFS_CACHED_FRAGMENTS);
+ squashfs_frags_cache_size = SQUASHFS_CACHED_FRAGMENTS;
+ }
+
+ TRACE("Fragments' cache size %d\n", squashfs_frags_cache_size);
+
msblk->fragment_cache = squashfs_cache_init("fragment",
- SQUASHFS_CACHED_FRAGMENTS, msblk->block_size);
+ squashfs_frags_cache_size, msblk->block_size);
if (msblk->fragment_cache == NULL) {
err = -ENOMEM;
goto failed_mount;
--
2.7.4