Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading kernel is very slow #403

Open
m-mueller678 opened this issue Nov 19, 2023 · 8 comments
Open

Loading kernel is very slow #403

m-mueller678 opened this issue Nov 19, 2023 · 8 comments

Comments

@m-mueller678
Copy link

m-mueller678 commented Nov 19, 2023

The bootloader is stuck on 'loading kernel...' (apparently in stage 2) for about 10 seconds. I am using qemu with kvm enabled, booting via bios.

qemu-system-x86_64 -enable-kvm -drive format=raw,file=os.img -serial stdio

I find this surprising, as on 0.9.23 it was practically instantaneous. Is this expected?

@phil-opp
Copy link
Member

I think we automatically stripped debug symbols from the kernel ELF when creating the bootable disk image in v0.9. In the current version, we don't do this anymore as users have more control over the disk image creation now. So I suspect that the reason for the slow loading is that your kernel contains a lot of debug info.

Ideally, our loading code would only load the relevant parts of the ELF file into memory. However, this is currently diffcult since the loading needs to happen in real mode for BIOS booting, which limits the complexity of our loader because of memory size contraints.

So I recommend to strip the kernel executable to speed up the load process. You can do this via cargo by using the strip profile setting (or maybe split-debuginfo to write it to a separate file). Alternatively, you can also invoke the strip executable on your kernel before passing it to the DiskImageBuilder.

Let me know whether stripping the executable helps! If not, there might be some bug in our loading code...

@m-mueller678
Copy link
Author

I switched to UEFI as a workaround, that was much faster. Unfortunately, I don't have the BIOS code at hand anymore.

@m-mueller678
Copy link
Author

m-mueller678 commented Jan 7, 2024

I am now using stripped binaries with BIOS, it is faster than unstripped with BIOS. 1.8s for 750KB, which still seems kind of slow to be honest.

@bjorn3
Copy link
Contributor

bjorn3 commented Jan 7, 2024

Looks like the BIOS code directly uses the BIOS interfaces to load individual sectors using int 13h. This is the most portable (supports SCSI, NVMe, USB, ... Especially USB is hard to implement.), but doesn't allow submitting multiple requests at the same time to mitigate latency. It may be possible to load multiple contiguous sectors at the same time though, which should help a lot when there is no disk fragmentation.

@m-mueller678
Copy link
Author

I think it already tries to load multiple contiguous sectors:
let sectors = u64::min(number_of_sectors, 32) as u16;
I'm not sure why it's limited to 32 though, Wikipedia says some BIOS implementations are limited to at most 127.

@phil-opp
Copy link
Member

I'm not sure why it's limited to 32 though, Wikipedia says some BIOS implementations are limited to at most 127.

I don't remember either. We can try to increase the sector limit to 127 here:

let sectors = u64::min(number_of_sectors, 32) as u16;

I just tried it and it seems to work in QEMU. We should probably test it on some real world systems too though.

I am now using stripped binaries with BIOS, it is faster than unstripped with BIOS. 1.8s for 750KB, which still seems kind of slow to be honest.

How does it compare to v0.9? If I remember correctly, we loaded each sector separately in v0.9, so the kernel load should be faster in v0.11 even with the limit set to 32. There might be some additional fixed overhead in v0.10 because we're now reading things from a FAT partition, which requires some additional load operations.

@m-mueller678
Copy link
Author

I never measured it for 0.9, I remember it being practically instantaneous while following the OS dev tutorial. The first thing I did after is switching to the new bootloader, where I was surprised by the slow boot.

@zefr0x
Copy link

zefr0x commented Feb 7, 2024

The bootloader is stuck on 'loading kernel...' (apparently in stage 2) for about 10 seconds. I am using qemu with kvm enabled, booting via bios.

qemu-system-x86_64 -enable-kvm -drive format=raw,file=os.img -serial stdio

I find this surprising, as on 0.9.23 it was practically instantaneous. Is this expected?

Use qemu-system-x86_64 -machine accel=kvm,type=q35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants