Squashfs: don't allocate fragment caches more than fragments
authorpangliyuan <pangliyuan1@huawei.com>
Tue, 10 Dec 2024 09:08:42 +0000 (17:08 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 13 Jan 2025 04:21:08 +0000 (20:21 -0800)
Sometimes the actual number of fragments in image is between
0 and SQUASHFS_CACHED_FRAGMENTS, which cause additional
fragment caches to be allocated.

Sets the number of fragment caches to the minimum of fragments
and SQUASHFS_CACHED_FRAGMENTS.

Link: https://lkml.kernel.org/r/20241210090842.160853-1-pangliyuan1@huawei.com
Signed-off-by: pangliyuan <pangliyuan1@huawei.com>
Reviewed-by: Phillip Lougher <phillip@squashfs.org.uk>
Cc: <wangfangpeng1@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/squashfs/super.c

index 22e812808e5cf91802e2c95495207b6dd2348c10..269c6d61bc297fe63e7457f15efa1b51686f81fd 100644 (file)
@@ -405,7 +405,7 @@ handle_fragments:
                goto check_directory_table;
 
        msblk->fragment_cache = squashfs_cache_init("fragment",
-               SQUASHFS_CACHED_FRAGMENTS, msblk->block_size);
+               min(SQUASHFS_CACHED_FRAGMENTS, fragments), msblk->block_size);
        if (msblk->fragment_cache == NULL) {
                err = -ENOMEM;
                goto failed_mount;