From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7A1A38736D for ; Sat, 28 Feb 2026 14:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772288446; cv=none; b=F6dSGcnUl2uEImIBkottvKrRn6EjHso8EV9lnJBUYP9m3aWNBMbTmIgPLmIzHvPQ/+WNSkspZjwiZLtxvqqbnkfBYSle1epsE7c2EGrxI/nGuU8f/TZWG3VsSU6G2ulMWxkT9ZIu0042FxLGlyR5/TaOKgE1igi+yiPHf8+J2CM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772288446; c=relaxed/simple; bh=7f5+r7ycTP2wUCbYBrRzzA6BhtcZIHqy7pWqX2qOIF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WaBCMYEjLufmhZXzGxnjxrV0kd4V8O1HU4/vb3A0tRvjMlz2UnGqE0T+juQOZ856tj+7iwjZmaUjmVwwWjgLy+ZxhLH2htZLWnIJ10MgPLA+6+9c/1g0G6kRDi2NryhYwcSG49qEUsT5veL4z56Tcyts/me1CTj9FsIAaRDG+oI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=kdNYSrcW; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="kdNYSrcW" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772288441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oaHUxVaobjs+nvwAKL/h30L1BqLPqcHDSgP0kHDwdc8=; b=kdNYSrcWgsufXjWGjib/VZy2Bqp1osTgP3+loYpCfqscJwNdtD8HlbRAcQzfLKQE3q16mx PE7HXXkmhnUgu4h9+jVLjjRtKRB67xXlWuOuk1KmufEOndo3fpYmiPIvPrwImoBx5Bg9CM SUGNO9XzYlFARce+XpR8oDn2vTDJVjI= From: Shakeel Butt To: Tejun Heo Cc: Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Roman Gushchin , Kuniyuki Iwashima , Daniel Sedlak , Meta kernel team , linux-mm@kvack.org, netdev@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Subject: [PATCH 1/3] cgroup: reduce cgroup_file_kn_lock hold time in cgroup_file_notify() Date: Sat, 28 Feb 2026 06:20:16 -0800 Message-ID: <20260228142018.3178529-2-shakeel.butt@linux.dev> In-Reply-To: <20260228142018.3178529-1-shakeel.butt@linux.dev> References: <20260228142018.3178529-1-shakeel.butt@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT cgroup_file_notify() calls kernfs_notify() while holding the global cgroup_file_kn_lock. kernfs_notify() does non-trivial work including wake_up_interruptible() and acquisition of a second global spinlock (kernfs_notify_lock), inflating the hold time. Take a kernfs_get() reference under the lock and call kernfs_notify() after dropping it, following the pattern from cgroup_file_show(). Signed-off-by: Shakeel Butt Reported-by: Jakub Kicinski --- kernel/cgroup/cgroup.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index be1d71dda317..33282c7d71e4 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4687,6 +4687,7 @@ int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts) void cgroup_file_notify(struct cgroup_file *cfile) { unsigned long flags; + struct kernfs_node *kn = NULL; spin_lock_irqsave(&cgroup_file_kn_lock, flags); if (cfile->kn) { @@ -4696,11 +4697,17 @@ void cgroup_file_notify(struct cgroup_file *cfile) if (time_in_range(jiffies, last, next)) { timer_reduce(&cfile->notify_timer, next); } else { - kernfs_notify(cfile->kn); + kn = cfile->kn; + kernfs_get(kn); cfile->notified_at = jiffies; } } spin_unlock_irqrestore(&cgroup_file_kn_lock, flags); + + if (kn) { + kernfs_notify(kn); + kernfs_put(kn); + } } EXPORT_SYMBOL_GPL(cgroup_file_notify); -- 2.47.3