]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
audit: merge loops in __audit_inode_child()
authorRicardo Robaina <rrobaina@redhat.com>
Fri, 31 Oct 2025 12:33:28 +0000 (09:33 -0300)
committerPaul Moore <paul@paul-moore.com>
Fri, 7 Nov 2025 21:50:42 +0000 (16:50 -0500)
commitc8a3dfe7315945ebcc80ed5be8267920b609649a
treee20b47be482a833730e6a0f9d2f269d3730cd80c
parent77563f3d4704206c8f6626852365591aa4e0b779
audit: merge loops in __audit_inode_child()

Whenever there's audit context, __audit_inode_child() gets called
numerous times, which can lead to high latency in scenarios that
create too many sysfs/debugfs entries at once, for instance, upon
device_add_disk() invocation.

   # uname -r
   6.18.0-rc2+

   # auditctl -a always,exit -F path=/tmp -k foo
   # time insmod loop max_loop=1000
   real 0m46.676s
   user 0m0.000s
   sys 0m46.405s

   # perf record -a insmod loop max_loop=1000
   # perf report --stdio |grep __audit_inode_child
   32.73%  insmod [kernel.kallsyms] [k] __audit_inode_child

__audit_inode_child() searches for both the parent and the child
in two different loops that iterate over the same list. This
process can be optimized by merging these into a single loop,
without changing the function behavior or affecting the code's
readability.

This patch merges the two loops that walk through the list
context->names_list into a single loop. This optimization resulted
in around 51% performance enhancement for the benchmark.

   # uname -r
   6.18.0-rc2-enhancedv3+

   # auditctl -a always,exit -F path=/tmp -k foo
   # time insmod loop max_loop=1000
   real 0m22.899s
   user 0m0.001s
   sys 0m22.652s

Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
kernel/auditsc.c