squashfs: don't allocate read_page cache if SQUASHFS_FILE_DIRECT configured
authorPhillip Lougher <phillip@squashfs.org.uk>
Sun, 29 Dec 2024 23:37:50 +0000 (23:37 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 25 Jan 2025 06:47:21 +0000 (22:47 -0800)
If Squashfs has been configured to directly read datablocks into the page
cache (SQUASHFS_FILE_DIRECT), then the read_page cache is unnecessary.

This improvement is due to the following two commits, which added the
ability to read datablocks into the page cache when pages were missing,
enabling the fallback which used an intermediate buffer to be removed.

commit f268eedddf359 ("squashfs: extend "page actor" to handle missing pages")
commit 1bb1a07afad97 ("squashfs: don't use intermediate buffer if pages missing")

This reduces the amount of memory used when mounting a filesystem by
block_size * maximum number of threads.

Link: https://lkml.kernel.org/r/20241229233752.54481-3-phillip@squashfs.org.uk
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/squashfs/squashfs.h
fs/squashfs/super.c

index 5a756e6790b5b75705c5c0d8a22fa99463a13b29..2c45b9b938e9a131a2300da5598bfaa1de3a93df 100644 (file)
 
 #define WARNING(s, args...)    pr_warn("SQUASHFS: "s, ## args)
 
+#ifdef CONFIG_SQUASHFS_FILE_CACHE
+#define SQUASHFS_READ_PAGES msblk->max_thread_num
+#else
+#define SQUASHFS_READ_PAGES 0
+#endif
+
 /* block.c */
 extern int squashfs_read_data(struct super_block *, u64, int, u64 *,
                                struct squashfs_page_actor *);
index fedae8dbc5de502da02260d121c28c9ac02791a1..67c55fe32ce88d7bcbb8cd448c11b35141915308 100644 (file)
@@ -323,7 +323,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 
        /* Allocate read_page block */
        msblk->read_page = squashfs_cache_init("data",
-               msblk->max_thread_num, msblk->block_size);
+               SQUASHFS_READ_PAGES, msblk->block_size);
        if (IS_ERR(msblk->read_page)) {
                errorf(fc, "Failed to allocate read_page block");
                err = PTR_ERR(msblk->read_page);