kmod: block kmod if we're currently loading the same module

load_module() has an optimization in place to check for
the module being requested to be loaded first before actually
trying to load it. The kernel interface to request modules
however does not take advantge of this and relies on calling
userspace and letting userspace tell us a module is already
loaded.

This was not possible before alias processing support was added
to kernel/module.c, now that it has it we can be sure that the
optimization will be effective even if aliases are used for
request_module() -- for instance when get_fs_type() is used.

Note that we cannot always perform this optimization for
__request_module() since not all calls can wait, we only block
when we can wait.

This reduces the latency for knowing if a module is already loaded
by checking if the module is already loaded prior to considering
processing a module request. This skips a bounce back to userspace
for no good reason. This shaves the amount of time it takes to
run kmod.sh test cases down by ~4 seconds for test 0008 and ~16
seconds on test 0009.

Before
======
time kmod.sh -t 0008
real    0m22.247s
user    0m0.084s
sys     0m11.328s
--------------------
time kmod.sh -t 0009
real    0m58.785s
user    0m0.492s
sys     0m10.852s

After
=====
time kmod.sh -t 0008
real    0m17.170s
user    0m0.112s
sys     0m10.956s
--------------------
time kmod.sh -t 0009
real    0m42.081s
user    0m0.512s
sys     0m10.588s

Debugging with the following for dynamic debug:

GRUB_CMDLINE_LINUX_DEFAULT="dyndbg=\"func module_process_aliases +p; func module_name_match +p; \" "

We get as an example upon boot:

[    1.917759] module crc32c_generic num_aliases: 4
[    1.917760] alias[0] = crypto-crc32c-generic
[    1.917762] alias[1] = crc32c-generic
[    1.917764] alias[2] = crypto-crc32c
[    1.917766] alias[3] = crc32c
[    1.918379] module crc32c_generic alias matched: alias[2] = crypto-crc32c
[    1.918384] module crc32c_generic alias matched: alias[2] = crypto-crc32c

When using:

./kmod.sh -s 0009
[  384.241487] module xfs num_aliases: 1
[  384.241490] alias[0] = fs-xfs
[  384.299074] module xfs alias matched: alias[0] = fs-xfs
[  384.299074] ... the same over and over again ...

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
1 file changed