Re: [PATCH] timers: Clear pending_map on CPU hotplug

From: Thomas Gleixner

Date: Tue Sep 29 2026 - 16:08:49 EST


On Sun, Aug 23 2026 at 19:50, Liang Hao wrote:
> CPU hotplug migration leaves pending_map bits set on the outgoing CPU
> while its wheel vectors are empty. After re-online, a later next_expiry
> recalc can treat those empty buckets as pending and temporarily pull
> next_expiry forward until collect drains the bits.
>
> Clear pending_map under the base lock after migration in
> timers_dead_cpu(), and in timers_prepare_cpu() for a full base reinit.
>
> Signed-off-by: Liang Hao <haohlliang@xxxxxxxxx>
> ---
> kernel/time/timer.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/time/timer.c b/kernel/time/timer.c
> index ae9abf14688e..e550489c73b8 100644
> --- a/kernel/time/timer.c
> +++ b/kernel/time/timer.c
> @@ -44,6 +44,7 @@
> #include <linux/compat.h>
> #include <linux/random.h>
> #include <linux/sysctl.h>
> +#include <linux/bitmap.h>
>
> #include <linux/uaccess.h>
> #include <asm/unistd.h>
> @@ -2509,6 +2510,7 @@ int timers_prepare_cpu(unsigned int cpu)
> base->next_expiry_recalc = false;
> base->timers_pending = false;
> base->is_idle = false;
> + bitmap_zero(base->pending_map, WHEEL_SIZE);
> }
> return 0;
> }
> @@ -2541,6 +2543,7 @@ int timers_dead_cpu(unsigned int cpu)
> for (i = 0; i < WHEEL_SIZE; i++)
> migrate_timer_list(new_base, old_base->vectors + i);
>
> + bitmap_zero(old_base->pending_map, WHEEL_SIZE);

Why do you need to zero the map twice - once when the CPU goes out and
then again when it comes back. That does not make sense.

Thanks

tglx