diff --git a/kernel/events/core.c b/kernel/events/core.c index 90b0c9324cbf..d357714fc02e 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5489,6 +5489,12 @@ attach_global_ctx_data(struct kmem_cache *ctx_cache) cd = NULL; } if (!cd) { + /* + * Try to allocate context quickly before + * traversing the whole thread list again. + */ + if (!attach_task_ctx_data(p, ctx_cache, true, GFP_NOWAIT)) + continue; get_task_struct(p); goto alloc; }