Skip to content

Commit 962af4c

Browse files
committed
Add Daniel Mack's SquashFS performance improvement
This patch dramatically speeds up SquashFS performance. This has a few caveats: 1. You need to re-flash the MicroSD card/eMMC to get it since it's a U-Boot change. 2. The current fwup.conf for the BBB avoids reading large files (like the Linux kernel from SquashFS) because it was slow. New custom systems based on the BBB can benefit from the simplicity of storing the Linux kernel in the root filesystem and removing the need for a FAT filesystem. This is, unfortunately, a backward incompatible change for nerves_system_bbb so it can't be done here.
1 parent f5f1e19 commit 962af4c

6 files changed

+208
-11
lines changed

uboot/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From ed17dca5c434755e53ac6bc3f8df345c2dc83948 Mon Sep 17 00:00:00 2001
1+
From bcba9c297a169cf301f28f3f5f0b998dbe32b440 Mon Sep 17 00:00:00 2001
22
From: Robert Nelson <[email protected]>
33
Date: Wed, 20 Jun 2018 15:39:57 -0500
44
Subject: [PATCH] am335x_evm: uEnv.txt, bootz, n fixes
@@ -1150,5 +1150,5 @@ index 785fc15..110c426 100644
11501150
"if test ${boot_fdt} = try; then " \
11511151
"bootz; " \
11521152
--
1153-
2.17.1
1153+
2.20.1
11541154

uboot/0002-U-Boot-BeagleBone-Cape-Manager.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From fb91a726cde095e6d54e86ba36efcd29a4a5f5f9 Mon Sep 17 00:00:00 2001
1+
From 00ec2a54f729d1a464afc6a95f6b516e50419293 Mon Sep 17 00:00:00 2001
22
From: Robert Nelson <[email protected]>
33
Date: Tue, 14 Aug 2018 21:00:21 -0500
44
Subject: [PATCH] U-Boot: BeagleBone Cape Manager
@@ -942,5 +942,5 @@ index 110c426..d6bbe3e 100644
942942
"ums 0 ${devtype} 1;\0" \
943943
"envboot=mmc dev ${mmcdev}; " \
944944
--
945-
2.17.1
945+
2.20.1
946946

uboot/0004-Add-MMC-environment-location.patch uboot/0003-Add-MMC-environment-location.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 7065382e1fdde6fdb92597697cae86100e84123c Mon Sep 17 00:00:00 2001
1+
From f58ea82894e83370c5f6e3d3d3e3304ec85f366c Mon Sep 17 00:00:00 2001
22
From: Frank Hunleth <[email protected]>
33
Date: Sun, 3 Jun 2018 11:33:53 -0400
44
Subject: [PATCH] Add MMC environment location
@@ -24,5 +24,5 @@ index e55736e..7c8e836 100644
2424

2525
/* SPI flash. */
2626
--
27-
2.17.1
27+
2.20.1
2828

uboot/0005-Move-cape-detection-to-save-environment.patch uboot/0004-Move-cape-detection-to-safe-environment.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From cd7df1bc7f7d8053b82ad43152cdcaada2a28713 Mon Sep 17 00:00:00 2001
1+
From fb19ca14057ec382df14e06ffcbbede22b6e257d Mon Sep 17 00:00:00 2001
22
From: Frank Hunleth <[email protected]>
33
Date: Wed, 11 Jul 2018 10:40:24 -0400
4-
Subject: [PATCH] Move cape detection to save environment
4+
Subject: [PATCH] Move cape detection to safe environment
55

66
The U-boot environment gets trampled on when restoring it from eMMC.
77
Since proper operation depends on the cape detection's environment
@@ -36,5 +36,5 @@ index e2ee1fc..79c21af 100644
3636

3737
return 0;
3838
--
39-
2.17.1
39+
2.20.1
4040

uboot/0003-fs-add-support-for-SquashFS.patch uboot/0005-fs-add-support-for-SquashFS.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From f0cea4b0726380a29b8a51c21e64fe75900a9cc1 Mon Sep 17 00:00:00 2001
1+
From ba341db1e7c7902e0d324940039840cefaac25cb Mon Sep 17 00:00:00 2001
22
From: Frank Hunleth <[email protected]>
33
Date: Tue, 5 Jun 2018 09:10:14 -0400
44
Subject: [PATCH] fs: add support for SquashFS
@@ -5650,5 +5650,5 @@ index 0000000..be54b10
56505650
+
56515651
+#endif /* __U_BOOT_SQUASHFS_H__ */
56525652
--
5653-
2.17.1
5653+
2.20.1
56545654

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
From d477fae3ec58f56ad7ff789e349887dd1e2cbb0f Mon Sep 17 00:00:00 2001
2+
From: Daniel Mack <[email protected]>
3+
Date: Sun, 15 Mar 2020 22:08:54 +0100
4+
Subject: [PATCH] squashfs: read all blocks in one call to squashfs_devread()
5+
6+
Calling into squashfs_devread() for each block is very slow, so let's
7+
allocate one big buffer to read all the content.
8+
9+
This requires the decompressor wrappers to not free the buffers, as they are
10+
no longer individually allocated. The buffer list is still kept around so
11+
the decompressor API doesn't need to change.
12+
13+
This patch speeds up file reads by more than factor of 10 in my tests.
14+
15+
Signed-off-by: Daniel Mack <[email protected]>
16+
---
17+
fs/squashfs/block.c | 64 +++++++++++++++++++-------------------
18+
fs/squashfs/lzo_wrapper.c | 1 -
19+
fs/squashfs/zlib_wrapper.c | 5 +--
20+
3 files changed, 33 insertions(+), 37 deletions(-)
21+
22+
diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
23+
index 225d4a9..72ae6a9 100644
24+
--- a/fs/squashfs/block.c
25+
+++ b/fs/squashfs/block.c
26+
@@ -90,21 +90,21 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
27+
u64 *next_index, struct squashfs_page_actor *output)
28+
{
29+
struct squashfs_sb_info *msblk = sb->s_fs_info;
30+
- char **buf;
31+
+ char **blocks;
32+
+ char *buf = NULL, *blk_len_buf = NULL;
33+
int offset = index & ((1 << msblk->devblksize_log2) - 1);
34+
u64 cur_index = index >> msblk->devblksize_log2;
35+
int bytes, compressed, b = 0, k = 0, avail;
36+
37+
- buf = calloc(((output->length + msblk->devblksize - 1)
38+
- >> msblk->devblksize_log2) + 1, sizeof(*buf));
39+
- if (buf == NULL)
40+
+ blocks = calloc(((output->length + msblk->devblksize - 1)
41+
+ >> msblk->devblksize_log2) + 1, sizeof(*blocks));
42+
+ if (blocks == NULL)
43+
return -ENOMEM;
44+
45+
if (length) {
46+
/*
47+
* Datablock.
48+
*/
49+
- bytes = -offset;
50+
compressed = SQUASHFS_COMPRESSED_BLOCK(length);
51+
length = SQUASHFS_COMPRESSED_SIZE_BLOCK(length);
52+
if (next_index)
53+
@@ -117,16 +117,14 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
54+
(index + length) > msblk->bytes_used)
55+
goto read_failure;
56+
57+
- for (b = 0; bytes < length; b++, cur_index++) {
58+
- buf[b] = squashfs_devread(msblk,
59+
- cur_index * msblk->devblksize,
60+
- msblk->devblksize);
61+
- if (buf[b] == NULL)
62+
- goto block_release;
63+
+ int readlen = ALIGN(length + offset, msblk->devblksize);
64+
65+
- bytes += msblk->devblksize;
66+
- }
67+
+ buf = squashfs_devread(msblk, cur_index * msblk->devblksize, readlen);
68+
+ if (buf == NULL)
69+
+ goto read_failure;
70+
71+
+ for (bytes = 0; bytes < readlen; bytes += msblk->devblksize, b++)
72+
+ blocks[b] = buf + (b * msblk->devblksize);
73+
} else {
74+
/*
75+
* Metadata block.
76+
@@ -134,12 +132,12 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
77+
if ((index + 2) > msblk->bytes_used)
78+
goto read_failure;
79+
80+
- buf[0] = get_block_length(sb, &cur_index, &offset, &length);
81+
- if (buf[0] == NULL)
82+
+ blk_len_buf = get_block_length(sb, &cur_index, &offset, &length);
83+
+ if (blk_len_buf == NULL)
84+
goto read_failure;
85+
+ blocks[0] = blk_len_buf;
86+
b = 1;
87+
88+
- bytes = msblk->devblksize - offset;
89+
compressed = SQUASHFS_COMPRESSED(length);
90+
length = SQUASHFS_COMPRESSED_SIZE(length);
91+
if (next_index)
92+
@@ -150,20 +148,20 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
93+
94+
if (length < 0 || length > output->length ||
95+
(index + length) > msblk->bytes_used)
96+
- goto block_release;
97+
+ goto read_failure;
98+
99+
- for (; bytes < length; b++) {
100+
- buf[b] = squashfs_devread(msblk,
101+
- ++cur_index * msblk->devblksize,
102+
- msblk->devblksize);
103+
- if (buf[b] == NULL)
104+
- goto block_release;
105+
- bytes += msblk->devblksize;
106+
- }
107+
+ int readlen = ALIGN((length + offset) - msblk->devblksize, msblk->devblksize);
108+
+
109+
+ buf = squashfs_devread(msblk, ++cur_index * msblk->devblksize, readlen);
110+
+ if (buf == NULL)
111+
+ goto read_failure;
112+
+
113+
+ for (bytes = 0; bytes < readlen; bytes += msblk->devblksize, b++)
114+
+ blocks[b] = buf + ((b-1) * msblk->devblksize);
115+
}
116+
117+
if (compressed) {
118+
- length = squashfs_decompress(msblk, buf, b, offset, length,
119+
+ length = squashfs_decompress(msblk, blocks, b, offset, length,
120+
output);
121+
if (length < 0)
122+
goto read_failure;
123+
@@ -184,28 +182,30 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
124+
}
125+
avail = min_t(int, in, PAGE_SIZE -
126+
pg_offset);
127+
- memcpy(data + pg_offset, buf[k] + offset,
128+
+ memcpy(data + pg_offset, blocks[k] + offset,
129+
avail);
130+
in -= avail;
131+
pg_offset += avail;
132+
offset += avail;
133+
}
134+
offset = 0;
135+
- kfree(buf[k]);
136+
}
137+
squashfs_finish_page(output);
138+
}
139+
140+
kfree(buf);
141+
- return length;
142+
+ kfree(blocks);
143+
+ kfree(blk_len_buf);
144+
145+
-block_release:
146+
- for (; k < b; k++)
147+
- kfree(buf[k]);
148+
+ return length;
149+
150+
read_failure:
151+
ERROR("squashfs_read_data failed to read block 0x%llx\n",
152+
(unsigned long long) index);
153+
+
154+
kfree(buf);
155+
+ kfree(blocks);
156+
+ kfree(blk_len_buf);
157+
+
158+
return -EIO;
159+
}
160+
diff --git a/fs/squashfs/lzo_wrapper.c b/fs/squashfs/lzo_wrapper.c
161+
index 9736361..20d7d7b 100644
162+
--- a/fs/squashfs/lzo_wrapper.c
163+
+++ b/fs/squashfs/lzo_wrapper.c
164+
@@ -88,7 +88,6 @@ static int lzo_uncompress(struct squashfs_sb_info *msblk, void *strm,
165+
buff += avail;
166+
bytes -= avail;
167+
offset = 0;
168+
- kfree(bh[i]);
169+
}
170+
171+
res = lzo1x_decompress_safe(stream->input, (size_t)length,
172+
diff --git a/fs/squashfs/zlib_wrapper.c b/fs/squashfs/zlib_wrapper.c
173+
index 7d6ca5f..42ae8cd 100644
174+
--- a/fs/squashfs/zlib_wrapper.c
175+
+++ b/fs/squashfs/zlib_wrapper.c
176+
@@ -93,7 +93,7 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
177+
zlib_err = inflate(stream, Z_SYNC_FLUSH);
178+
179+
if (stream->avail_in == 0 && k < b)
180+
- kfree(bh[k++]);
181+
+ k++;
182+
} while (zlib_err == Z_OK);
183+
184+
squashfs_finish_page(output);
185+
@@ -111,9 +111,6 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
186+
return stream->total_out;
187+
188+
out:
189+
- for (; k < b; k++)
190+
- kfree(bh[k]);
191+
-
192+
return -EIO;
193+
}
194+
195+
--
196+
2.20.1
197+

0 commit comments

Comments
 (0)