Skip to content

Commit 45efa94

Browse files
committed
board/common: speed up mounting and boot
Reduce /var image size to 128M (resized at first boot anyway) and tune mke2fs options for faster mounting. Set ext4 'uninit_bg' feature and use '-m 0 -i 4096' extraargs in genimage to optimize filesystem creation and reduce overhead. The genimage tool has several tweaks enabled by default already, the 'uninit_bg' feature speeds up the time to check the file system. Disable periodic fsck with tune2fs at boot while keeping safety checks intact. Adjust mount options in fstab to reduce journal syncs and improve boot time. Fix severe performance regression in find_partition_by_label() that was calling sgdisk on every block device including virtual devices (ram, loop, dm-mapper). This caused boot delays of up to 24 seconds on systems with many block devices. Now skip virtual devices that don't have GPT tables, reducing the delay to ~2 seconds. Also clean up is_mmc() function to use cached result. Signed-off-by: Joachim Wiberg <[email protected]>
1 parent b9e53e5 commit 45efa94

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

board/aarch64/bananapi-bpi-r3/genimage.cfg.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ image cfg.ext4 {
44
size = 128M
55
ext4 {
66
label = "cfg"
7+
use-mke2fs = true
8+
features = "uninit_bg"
9+
extraargs = "-m 0 -i 4096"
710
}
811
}
912

13+
# The /var partition will be expanded automatically at first boot
14+
# to use the full size of the SD-card or eMMC media.
1015
image var.ext4 {
1116
empty = true
1217
temporary = true
13-
size = 1G
18+
size = 128M
1419
ext4 {
1520
label = "var"
1621
use-mke2fs = true
22+
features = "uninit_bg"
23+
extraargs = "-m 0 -i 4096"
1724
}
1825
}
1926

board/aarch64/friendlyarm-nanopi-r2s/genimage.cfg.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ image cfg.ext4 {
55

66
ext4 {
77
label = "cfg"
8+
use-mke2fs = true
9+
features = "uninit_bg"
10+
extraargs = "-m 0 -i 4096"
811
}
912
}
1013

14+
# The /var partition will be expanded automatically at first boot
15+
# to use the full size of the SD-card or eMMC media.
1116
image var.ext4 {
1217
empty = true
1318
temporary = true
14-
size = 512M
19+
size = 128M
1520

1621
ext4 {
1722
label = "var"
18-
use-mke2fs = true
23+
use-mke2fs = true
24+
features = "uninit_bg"
25+
extraargs = "-m 0 -i 4096"
1926
}
2027
}
2128

board/aarch64/raspberrypi-rpi64/genimage.cfg.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ image cfg.ext4 {
1515

1616
ext4 {
1717
label = "cfg"
18+
use-mke2fs = true
19+
features = "uninit_bg"
20+
extraargs = "-m 0 -i 4096"
1821
}
1922
}
2023

24+
# The /var partition will be expanded automatically at first boot
25+
# to use the full size of the SD-card or eMMC media.
2126
image var.ext4 {
2227
empty = true
2328
temporary = true
24-
size = 512M
29+
size = 128M
2530

2631
ext4 {
2732
label = "var"
28-
use-mke2fs = true
33+
use-mke2fs = true
34+
features = "uninit_bg"
35+
extraargs = "-m 0 -i 4096"
2936
}
3037
}
3138

board/common/mkaux.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ image aux.ext4 {
1111
ext4 {
1212
label = "aux"
1313
use-mke2fs = true
14-
features = "^metadata_csum,^metadata_csum_seed"
14+
features = "^metadata_csum,^metadata_csum_seed,uninit_bg"
15+
extraargs = "-m 0 -i 4096"
1516
}
1617
}
1718

board/common/rootfs/etc/fstab

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ cfgfs /config configfs nofail,noauto 0 0
1515
# The chosen backing storage for the overlays placed on /cfg, /etc,
1616
# /home, /root, and /var, are determined dynamically by /usr/libexec/infix/mnt
1717
# depending on the available devices.
18-
mnttmp /mnt/tmp tmpfs defaults 0 0
19-
LABEL=aux /mnt/aux auto noatime,nodiratime,noauto 0 0
20-
LABEL=var /mnt/var auto noatime,nodiratime,noauto 0 0
21-
LABEL=cfg /mnt/cfg auto noatime,nodiratime,noauto 0 0
22-
hostfs /mnt/host 9p cache=none,msize=16384,noauto 0 0
23-
/usr/libexec/infix/mnt# /cfg helper none 0 0
18+
mnttmp /mnt/tmp tmpfs defaults 0 0
19+
LABEL=aux /mnt/aux auto noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
20+
LABEL=var /mnt/var auto noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
21+
LABEL=cfg /mnt/cfg auto noatime,nodiratime,noauto,commit=30,errors=remount-ro 0 0
22+
hostfs /mnt/host 9p cache=none,msize=16384,noauto 0 0
23+
/usr/libexec/infix/mnt# /cfg helper none 0 0

board/common/rootfs/usr/libexec/infix/mnt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set -e
1919

2020
nm=$(basename "$0")
2121
err=0
22+
mmc=""
2223
opt="-k"
2324

2425
# External button or bootloader changed kernel command line
@@ -53,17 +54,22 @@ factory_reset()
5354

5455
is_mmc()
5556
{
57+
[ -n "$mmc" ] && return $mmc
58+
5659
# Check if primary or secondary partition (our rootfs) is on MMC
5760
for label in primary secondary; do
5861
devname=$(find_partition_by_label "$label" 2>/dev/null)
5962
if [ -n "$devname" ]; then
6063
case "$devname" in
6164
mmcblk*)
65+
mmc=0
6266
return 0
6367
;;
6468
esac
6569
fi
6670
done
71+
72+
mmc=1
6773
return 1
6874
}
6975

@@ -89,8 +95,15 @@ find_partition_by_label()
8995

9096
for diskpath in /sys/class/block/*; do
9197
devname=$(basename "$diskpath")
98+
99+
# Skip partitions, only check whole disks
92100
[ -f "$diskpath/partition" ] && continue
93101

102+
# Skip ram, loop, and other virtual devices
103+
case "$devname" in
104+
ram*|loop*|nullb*|dm-*) continue ;;
105+
esac
106+
94107
disk="/dev/$devname"
95108
result=$(sgdisk -p "$disk" 2>/dev/null | awk -v label="$label" -v devname="$devname" '
96109
/^ *[0-9]/ {
@@ -275,6 +288,9 @@ mount_rw()
275288
fi
276289

277290
# TODO: Also look for UBI partitions
291+
292+
#
293+
tune2fs -c 0 -i 0 LABEL="$1" 2>/dev/null
278294
mount LABEL="$1" 2>/dev/null && return 0
279295

280296
return 1

0 commit comments

Comments
 (0)