Skip to content

Commit cab71a4

Browse files
author
Denis Aleksandrov
committed
livepatch: Use kallsyms_on_each_match_symbol() to improve performance
JIRA: https://issues.redhat.com/browse/RHEL-85303 Based on the test results of kallsyms_on_each_match_symbol() and kallsyms_on_each_symbol(), the average performance can be improved by more than 1500 times. Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> (cherry picked from commit 9cb3735) Signed-off-by: Denis Aleksandrov <daleksan@redhat.com>
1 parent 5795313 commit cab71a4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

kernel/livepatch/core.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ static int klp_find_callback(void *data, const char *name, unsigned long addr)
146146
return 0;
147147
}
148148

149+
static int klp_match_callback(void *data, unsigned long addr)
150+
{
151+
struct klp_find_arg *args = data;
152+
153+
args->addr = addr;
154+
args->count++;
155+
156+
/*
157+
* Finish the search when the symbol is found for the desired position
158+
* or the position is not defined for a non-unique symbol.
159+
*/
160+
if ((args->pos && (args->count == args->pos)) ||
161+
(!args->pos && (args->count > 1)))
162+
return 1;
163+
164+
return 0;
165+
}
166+
149167
static int klp_find_object_symbol(const char *objname, const char *name,
150168
unsigned long sympos, unsigned long *addr)
151169
{
@@ -159,7 +177,7 @@ static int klp_find_object_symbol(const char *objname, const char *name,
159177
if (objname)
160178
module_kallsyms_on_each_symbol(objname, klp_find_callback, &args);
161179
else
162-
kallsyms_on_each_symbol(klp_find_callback, &args);
180+
kallsyms_on_each_match_symbol(klp_match_callback, name, &args);
163181

164182
/*
165183
* Ensure an address was found. If sympos is 0, ensure symbol is unique;

0 commit comments

Comments
 (0)