From nobody Tue Dec 16 16:39:11 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 390CD1D88A4 for ; Thu, 11 Dec 2025 05:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765432790; cv=none; b=BS1+U+4NkVf5ZL/+ktRtqsUrQGpAseTT4xRbPcboq6YjDngB7LxNavwQjXLetrbOUjz2/W1VWc2VtzngSC+GgGKU38bRAOfCifs5POiPxtq2FPdEZoeTNTD8Ldnc4zAzHnEfgScPU21i1EpDcJbnhvhWMvqw/1gUqA+pzVEUDoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765432790; c=relaxed/simple; bh=c0EfZFkelY90nHs75ursMSmEmEjjFu/LJxOV+bJinTU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AVZTVQ+Fks3lWYq1WdO7BUgeiRjKXR+/3Gggi9zdjJxyZ6hNIFD7WtMfUJy3jd4XJHR5cAqNeQrbaHbXBG4SqE3i5MO9BIya8PDzU+Zp8Tt6AXol1Gc+gbN5mB1sgZrnekZ3n06cTjYpwncvMxc0x5mt4np78SHgvsPKN9P0dyM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=a78pyt81; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="a78pyt81" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1765432788; x=1796968788; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=c0EfZFkelY90nHs75ursMSmEmEjjFu/LJxOV+bJinTU=; b=a78pyt81dBKR3iYINHIud34lIFMjNeaefprlr4fcS+2uYcEXP8jlWKg5 3jFv3M4zTogVKUCz57Ol+Kx9CtWPJiMLGGGWupKN0yVSIDoGB6rSLygiA Qy4u0E7xCVghf5pFt4YFxsw47KMzzbkDPSrA8ZaUJwDaYRfwPXHY0Mado ntgnOzdUZ4paz+13kuTTmyUpWOK05Ha/fBKcYnPtcJEYEQBdu2GzAe7Cs cs5zClLYVqm29yFIb2p1cJEE1COwm6U5us/VgIeoyjFFYC/8B2F4fYqSa Lw66/LqyrqdbvzZhL/xfesO1SgoI3kXlNEM2uafI3fr2IjBfOJsFHqNSS w==; X-CSE-ConnectionGUID: C4lRVk0DStqPIkZHdlUj2A== X-CSE-MsgGUID: 1ox1lO2cTXOivDJEPX51RQ== X-IronPort-AV: E=McAfee;i="6800,10657,11638"; a="67296027" X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="67296027" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2025 21:59:47 -0800 X-CSE-ConnectionGUID: GqmxsnNCSDWD712nd3FPqw== X-CSE-MsgGUID: rnQ72RH2SRquGWRflkKgAw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.20,265,1758610800"; d="scan'208";a="197001765" Received: from linux-pnp-server-11.sh.intel.com ([10.239.176.178]) by fmviesa008.fm.intel.com with ESMTP; 10 Dec 2025 21:59:44 -0800 From: Wangyang Guo To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Cc: linux-kernel@vger.kernel.org, Wangyang Guo , Benjamin Lei , Tim Chen , Tianyou Li Subject: [PATCH] sched/fair: Avoid false sharing in nohz struct Date: Thu, 11 Dec 2025 13:56:12 +0800 Message-ID: <20251211055612.4071266-1-wangyang.guo@intel.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are two potential false sharing issue in nohz struct: 1. idle_cpus_mask is a read-mostly field, but share the same cacheline with frequently updated nr_cpus. 2. Data followed by nohz still share the same cacheline and has potential false sharing issue. This patch tries to resolve the above two problems by isolating the frequently updated fields in a single cacheline. Reported-by: Benjamin Lei Reviewed-by: Tim Chen Reviewed-by: Tianyou Li Signed-off-by: Wangyang Guo --- kernel/sched/fair.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5b752324270b..bcc2766b7986 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7193,13 +7193,14 @@ static DEFINE_PER_CPU(cpumask_var_t, should_we_bala= nce_tmpmask); #ifdef CONFIG_NO_HZ_COMMON =20 static struct { - cpumask_var_t idle_cpus_mask; - atomic_t nr_cpus; + /* Isolate frequently updated fields in a cacheline to avoid false sharin= g issue. */ + atomic_t nr_cpus ____cacheline_aligned; int has_blocked; /* Idle CPUS has blocked load */ int needs_update; /* Newly idle CPUs need their next_balance collated */ unsigned long next_balance; /* in jiffy units */ unsigned long next_blocked; /* Next update of blocked load in jiffies */ -} nohz ____cacheline_aligned; + cpumask_var_t idle_cpus_mask ____cacheline_aligned; +} nohz; =20 #endif /* CONFIG_NO_HZ_COMMON */ =20 --=20 2.47.3