Source: grub2
Version: 2.14-5
Severity: wishlist
Tags: patch fixed-upstream
Dear Debian folks,
AI disclaimer: Assisted by claude-opus-5.5.
tl;dr: Please backport commit 5f05a74ab [1][2] for much faster reads
from disk.
---
Please consider backporting upstream commit 5f05a74ab ("fs/fshelp:
Coalesce contiguous file blocks") [1][2]. It was committed after the
grub-2.16 tag, so neither 2.14-5 (unstable) nor 2.16-1 (experimental)
has it. It applies to both without changes.
Without it, grub_fshelp_read_file() calls grub_disk_read() once per file
system block, so a file on ext4 reaches the disk driver in 32 KiB pieces
(one disk cache entry each), even when the file is contiguous on disk.
With it, contiguous blocks are merged into one request, up to the
driver’s max_agglomerate (640 KiB for efidisk).
This matters for commands that read a whole file in one grub_file_read()
call: loading the initrd (also through the LoadFile2 protocol), loading
the kernel, chainloader, and every file that a verifier such as the tpm
module reads at open. Commands that read in small chunks, like hashsum
or cmp, do not benefit.
Measurements, QEMU/OVMF with KVM, x86_64-efi, ext4 /boot, 61 MiB initrd
in one extent, `time chainloader $f` (reads the whole file in one call,
then fails at LoadImage), three runs each, in seconds:
disk 2.14-5 2.14-5 + 5f05a74ab
NVMe 0.286 0.276 0.207 0.124 0.062 0.064
virtio-blk 0.260 0.198 0.210 0.113 0.049 0.045
AHCI 1.131 1.237 1.128 0.465 0.346 0.343
With `set debug=efidisk`, stock 2.14-5 issues 1953 reads of 0x40 sectors
(32 KiB) for this file. With the backport it issues 197 reads: 97 of
0x4c0 sectors (608 KiB), 99 of 0x40 sectors and one of 0x2c0 sectors.
Both trees were built from the Debian source package with `./configure
--target=x86_64 --with-platform=efi`; the only difference is 5f05a74ab.
The image embeds this configuration:
serial --unit=0 --speed=115200
terminal_output serial
search --no-floppy --fs-uuid --set=root <UUID of /boot>
set f=/initrd.img-7.3.3+deb14-amd64
time chainloader $f
time chainloader $f
time chainloader $f
reboot
Upstream follow-up cd106688f ("fs: Clamp agglomerated read size") [3][4]
fixes a possible 32-bit overflow in the same computation (Coverity CID
914067, 914068). It does not apply to 2.14 without changes, because it
touches files 2.14 lacks (disk/nvme.c) or has in a different form. For
64-bit targets 5f05a74ab alone is fine; for i386 the cast to grub_size_t
in fshelp.c from cd106688f should come along.
Kind regards,
Paul
[1]: https://gitlab.freedesktop.org/gnu-grub/grub/-/commit/5f05a74ab
[2]: https://gitlab.freedesktop.org/gnu-grub/grub/-/merge_requests/256
[3]: https://gitlab.freedesktop.org/gnu-grub/grub/-/commit/cd106688f
[4]: https://gitlab.freedesktop.org/gnu-grub/grub/-/merge_requests/308