Skip to content

Commit 3b7ddab

Browse files
mattwuqmhiramat
authored andcommitted
kprobes: kretprobe events missing on 2-core KVM guest
Default value of maxactive is set as num_possible_cpus() for nonpreemptable systems. For a 2-core system, only 2 kretprobe instances would be allocated in default, then these 2 instances for execve kretprobe are very likely to be used up with a pipelined command. Here's the testcase: a shell script was added to crontab, and the content of the script is: #!/bin/sh do_something_magic `tr -dc a-z < /dev/urandom | head -c 10` cron will trigger a series of program executions (4 times every hour). Then events loss would be noticed normally after 3-4 hours of testings. The issue is caused by a burst of series of execve requests. The best number of kretprobe instances could be different case by case, and should be user's duty to determine, but num_possible_cpus() as the default value is inadequate especially for systems with small number of cpus. This patch enables the logic for preemption as default, thus increases the minimum of maxactive to 10 for nonpreemptable systems. Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: wuqiang <[email protected]> Reviewed-by: Solar Designer <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent 0c76ef3 commit 3b7ddab

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

Documentation/trace/kprobes.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ For example, if the function is non-recursive and is called with a
131131
spinlock held, maxactive = 1 should be enough. If the function is
132132
non-recursive and can never relinquish the CPU (e.g., via a semaphore
133133
or preemption), NR_CPUS should be enough. If maxactive <= 0, it is
134-
set to a default value. If CONFIG_PREEMPT is enabled, the default
135-
is max(10, 2*NR_CPUS). Otherwise, the default is NR_CPUS.
134+
set to a default value: max(10, 2*NR_CPUS).
136135

137136
It's not a disaster if you set maxactive too low; you'll just miss
138137
some probes. In the kretprobe struct, the nmissed field is set to

kernel/kprobes.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,13 +2213,9 @@ int register_kretprobe(struct kretprobe *rp)
22132213
rp->kp.post_handler = NULL;
22142214

22152215
/* Pre-allocate memory for max kretprobe instances */
2216-
if (rp->maxactive <= 0) {
2217-
#ifdef CONFIG_PREEMPTION
2216+
if (rp->maxactive <= 0)
22182217
rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus());
2219-
#else
2220-
rp->maxactive = num_possible_cpus();
2221-
#endif
2222-
}
2218+
22232219
#ifdef CONFIG_KRETPROBE_ON_RETHOOK
22242220
rp->rh = rethook_alloc((void *)rp, kretprobe_rethook_handler);
22252221
if (!rp->rh)

0 commit comments

Comments
 (0)