kmodule: insert independent modules in parallel (Fixes #3424)#3429
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3429 +/- ##
==========================================
- Coverage 59.40% 59.18% -0.23%
==========================================
Files 637 633 -4
Lines 54089 54079 -10
==========================================
- Hits 32134 32009 -125
- Misses 21955 22070 +115
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
rminnich
left a comment
There was a problem hiding this comment.
This seems like something we need to have.
module loading is used at scale in several places; we'll need to be certain that your changes are harmless or not used in existing code paths. You seem to have gotten a long way there.
I am thinking that if you are updating this package, the VM tests will exercise the code. WDYT?
There was a problem hiding this comment.
Pull Request Overview
This PR introduces parallel kernel module loading capabilities to speed up boot times by loading independent modules concurrently. The change addresses concurrency safety issues in the existing sequential module loading approach.
- Adds a new
ParallelProbeOptionsfunction that loads multiple modules concurrently using goroutines - Introduces thread-safe module loading with
sync.Onceto prevent duplicate loads - Refactors existing
ProbeOptionsto use the new parallel loading infrastructure
Which VM tests are you referring to? I took a look at runvmtest, but at least the default image seems nonmodular, or at the least doesn't bring lib/modules into the image. |
2e3f430 to
ebd737c
Compare
Took a crack at this, which also allows for simplifying the interface by removing |
|
Not super familiar with the review process here - is there some release window this waiting for, some more LGTMs, or does this PR look good-to-go? |
|
A related discussion to this PR is
Which involves knowing (and encoding) these dependencies beforehand - which isn't a significant burden, but is a potential footgun. e.g. if you instead write the below, now you've introduced a race where driver-common will sometimes be loaded with no params One of my colleagues suggested we could instead have some stateful mechanism for desired module parameters, maybe like below to avoid needing to encode the dependencies and simplify the caller code. It does expand the API here a bit, though. |
kernel modules are allowed to run thier initialization code in parallel, and for modules that take a long time (e.g. probing hardware, etc.), we can noticably reduce boot times by loading modules in parallel. We want to avoid calling loadModule() for the same dep multiple times as the kernel will return EEXIST for the duplicate module load (plus the wasted cycles loading a duplicate image). Adds a concurrent-safe parallelProbeDep() loading implementation, and updates ProbeOptions() to load dependency modules in parallel. Probe() and ProbeOptions() themselves remain concurrent-unsafe. Fixes u-root#3424 Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
Export new Prober type holding known module state (depMap) & probing options, and new concurrent-safe Prober.Probe method for loading one module and its dependencies. Fixes u-root#3424 Signed-off-by: Khazhismel Kumykov <khazhy@google.com>
This can be used to speed up boot if there's some modules that take a long time (e.g. probing hardware, etc.).
Probe() et. al. are concurrent unsafe since they create independent depMaps, and may in turn end up calling loadModule for the same module at once. This is wasteful since we'll load the images multiple times, and the init module syscall should return EEXIST if we actually try to load the same module twice.
This PR adds a new call: ParallelProbeOptions - that calls a new concurrent-safe implementation to load modules in parallel.
I would like to expose a concurrent safe API to allow for several goroutines that concurrently load then follow up with additional configuration that depends on those modules.
My first thought for what that could look like would just be promote depMap -> ModuleLoader and export the current parallelProbe().
This PR passes
go test, though admittedly I haven't yet figured out the setup for end to end testing... I've tested a similar change end-to-end on our internal build system and the concept works.