From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87EDC3E8662 for ; Thu, 19 Mar 2026 17:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773942764; cv=none; b=anbDBCRPzy2xHp8i+tUEztUH6GQgFT1YfDC0tVFiHhQc86LFRR4hgg3oyivqlc4HZMGnq0HoSn8eQcs627dc3Lvrnt9NMRAHvml/9rL8GiUREHVMqiZjo7vaT1SQT5v0RGnxZw/bWwQ4mJ8IpTqz/THKljgWBiJbMotzi3K6Ka8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773942764; c=relaxed/simple; bh=jW2VJc6W+LuIAukjBi/miLpc1obKQw6ZJi0pUsJoJtc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=VxFSzVILwd4ZJaulVXIUcVpyomcvUmwM2RcP3oxxiU8jbDz3Ta9njT2QahDE7VCTohADu+BnUksOxqVrHAojQuwrby/o8aCI+YgVbNh0OHrKlons9HIKQPN9TAnCXMq3lWeLzTFdooqxvNyRKxI9midwrochNP9UsAaCdExId+A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu; spf=pass smtp.mailfrom=ncsu.edu; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b=QMKhYN8s; arc=none smtp.client-ip=209.85.128.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b="QMKhYN8s" Received: by mail-yw1-f170.google.com with SMTP id 00721157ae682-79a5ad7cc52so13859337b3.2 for ; Thu, 19 Mar 2026 10:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1773942758; x=1774547558; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UVSiJZUgoONwaVx1Fz2i9/ymQj1QD9Sf17IvYO0Q/HE=; b=QMKhYN8sGr6lTqr8ATAVgbaVoprC7Egs7VOcHzTFEA5GOY7ne4yxt9a2rc2F1/QxWh KEch8dTqPHi48DekJarqqPSJ0R9DO3uvwKMP1Fb9B3GxMLPhix3Mqo0LobUewJcloETi xSCQ7Q8D4UlbUndTkbCKSDrtXH3N441/Ciq3Yh/z87d9CkHdwIc2T4OVs7bLAA9V7yyt OHN+uNAAVp8WpDBIGipHjgesc6bTFooPUC4ccCa+WY7V8COs5zcygHwZsjlAWV5iR837 dWUzPrawlcLzCHBQoDpH9p8Ho+qnndplUjC8myUib9rWvTiW+dJQPGNldX4A8p0gwGVi Kh6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773942758; x=1774547558; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UVSiJZUgoONwaVx1Fz2i9/ymQj1QD9Sf17IvYO0Q/HE=; b=gBLbnG7ki9lUH3BpE6cia/PeL4HYu0rXtwLmLuaezttnj9TQUAhTiqG3C5QinWjp6W ExhD5zyDdNb5S6PJ2sxPTcBtWk3041LUU5hMsUWY3OkPl/r4HRDd/HuWbXyJKfLFHUkH tEdRPEILs/v6pkzXT7IqHr4U62m8QxV+m0Q30S0wvtN+3Z5zIz3fd2xMWEBHWvuvW+Vm 9dtLeYSq6lvtD8BziznrU045TfipMuJIzT1DEXtIW2j3/d1uwnOoSn04+lNIUzQo8C5p ZW4sXlnk779aHIfGzSVE0mTqZO1Fp3BRr8jllMRZAdSGie3QqFXTtjxKDLHoC7/h+zPK XpqA== X-Forwarded-Encrypted: i=1; AJvYcCVCKzC9XBWdBXLoTyLyx0cOEKdhbgWj4GEs7Gecvt5g5AIzic/W/ir0lXbeaGbOvcMZ6wIZMjqfvyPn5mM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywzbz3wjqaeqVsfhUSviQL56EYzSPjNfJCMHwNH8mceD1zifLbx cMTNTS1LTVfsZjGqiJf7FM0IBpbBlen8v1DtYLpPUqaebjCU6JrIgmmzsIMcvoXiSQ== X-Gm-Gg: ATEYQzyPjJpsb9NyX1q47I8u4qTFYjKQ4i3DEKb49Ohtdl1bXFQfUM60+4BCqnjP+UE 1jwkxYl+eRgW1s2roo2ufWAb7P2RsgvPQO+4co/10bYcTCXpBU2QM1j9kNEq3JBrmT65GvW3M6w POlkBSrucggsmefEX0TcWXIRbgTOCU1im+dMDKOUaHOo94XhJHVBLPuIZHip6RCWDw0+yr5Hr4y 1yQvr8fbAg523bzjS7sSa5+lLca7uNBloE5lbIjjXXpQASmentE3trdgPmlsWs2prLoyFmRxSRq bh+CynWNTO3GvTvGMdiAvkeXLolqLlghC6ajBBJUzBhLfRQ0AwXLh/wVV+LrDB9lFRa0KGsn84C D3UXkjU02y4ZTe9lJD+Z6dwLvduZtGBL1fObCBM9ww5Bn6IRHDrrGJtkBABHi/wC2J/BG4biqnh nVp3AU+Y4lEpt7CaSYvHvIQfJ707YgLzddeMiBmnRnus8wlg4u0NsnDK2q X-Received: by 2002:a05:690c:385:b0:799:2b4c:1d49 with SMTP id 00721157ae682-79a71bde9cfmr79312647b3.36.1773942758061; Thu, 19 Mar 2026 10:52:38 -0700 (PDT) Received: from um773-cachyos.sd.ncsu.edu ([152.7.255.206]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79a905bda3esm784667b3.47.2026.03.19.10.52.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Mar 2026 10:52:37 -0700 (PDT) From: Zecheng Li To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Rik van Riel , Chris Mason , Madadi Vineeth Reddy , Xu Liu , Blake Jones , Josh Don , Nilay Vaish , K Prateek Nayak , Andrew Morton , linux-kernel@vger.kernel.org, Zecheng Li Subject: [PATCH v9 RESEND 0/3] sched/fair: Optimize cfs_rq and sched_entity allocation for better data locality Date: Thu, 19 Mar 2026 13:52:12 -0400 Message-ID: <20260319175235.995183-1-zli94@ncsu.edu> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi all, This patch series improves CFS cache performance by allocating cfs_rq and sched_entity together in the per-cpu allocator. It allows for replacing the pointer arrays in task_group with a per-cpu offset. Note: Resending to correct the recipient email address. v9: - Rebased on latest tip/sched/core (v7.0.0-rc4), fixing minor conflicts from upstream using kzalloc_objs instead of original kcalloc. Tested with selftests/cgroup in QEMU. - Kept Reviewed-by tags from v8, but dropped the Tested-by tags due to major version bump. v8: - Simplified free_fair_sched_group() in patch 1, use direct kfree instead of container_of since cfs_rq is at offset 0 (Prateek) - Moved variable declarations to top of function scope (Prateek) v7: - Removed struct sched_entity_stats, using cfs_tg_state to contain all three structs: cfs_rq, sched_entity, and sched_statistics since they are always allocated together in alloc_fair_sched_group. (Josh) v6: - Rebased on latest tip/sched/core. - Added my personal email as a secondary Signed-off-by. - Note: I no longer have access to zecheng@google.com. I am picking this series up from my personal address. v5: - Rebased on tip/sched/core (Resolved a minor conflict in patch 3) - Friendly ping on the series as it's not receiving any comments v4: https://lore.kernel.org/all/20250903194503.1679687-1-zecheng@google.com/ - Rebased on tip/sched/core - Intel kernel test robot results https://lore.kernel.org/all/202507161052.ed3213f4-lkp@intel.com/ v3: https://lore.kernel.org/all/20250701210230.2985885-1-zecheng@google.com/ - Rebased on top of 6.16-rc4. - Minor wording and comment updates. v2: https://lore.kernel.org/lkml/20250609193834.2556866-1-zecheng@google.com/ - Allocate cfs_rq and sched_entity together for non-root task group instead of embedding sched_entity into cfs_rq to avoid increasing the size of struct rq based on the feedback from Peter Zijlstra. v1: https://lore.kernel.org/lkml/20250604195846.193159-1-zecheng@google.com/ Accessing cfs_rq and sched_entity instances incurs many cache misses. This series of patches aims to reduce these cache misses. A struct cfs_rq instance is per CPU and per task_group. Each task_group instance (and the root runqueue) holds cfs_rq instances per CPU. Additionally, there are corresponding struct sched_entity instances for each cfs_rq instance (except the root). Currently, both cfs_rq and sched_entity instances are allocated in NUMA-local memory using kzalloc_node, and tg->cfs_rq and tg->se are arrays of pointers. Original memory layout: tg->cfs_rq = kcalloc(nr_cpu_ids, sizeof(cfs_rq), GFP_KERNEL); tg->se = kcalloc(nr_cpu_ids, sizeof(se), GFP_KERNEL); +----+ +-----------------+ | tg | ----> | cfs_rq pointers | +----+ +-----------------+ | | | v v v cfs_rq cfs_rq cfs_rq +----+ +--------------------+ | tg | ----> | sched_entity ptrs | +----+ +--------------------+ | | | v v v se se se Layout after Optimization: +--------+ | CPU 0 | | CPU 1 | | CPU 2 | | tg | | percpu | | percpu | | percpu | | | ... ... ... | percpu | -> | cfs_rq | | cfs_rq | | cfs_rq | | offset | | se | | se | | se | +--------+ +--------+ +--------+ +--------+ The optimization includes two parts: 1) Co-allocate cfs_rq and sched_entity for non-root task groups. - This benefits loading the sched_entity for the parent runqueue. Currently it incurs pointer chasing, i.e., cfs_rq->tg->se[cpu]. After co-locating, the sched_entity fields can be loaded with simple offset computations from cfs_rq. 2) Allocate the combined cfs_rq/se struct using percpu allocator. - Accesses to cfs_rq instances in hot paths are mostly iterating through multiple task_groups for the same CPU. Therefore, the new percpu layout can reuse the base pointer, and they are more likely to reside in the CPU cache than the per-task_group pointer arrays. - This optimization also reduces the memory needed for the array of pointers. To measure the impact of the patch series, we construct a tree structure hierarchy of cgroups, with “width” and “depth” parameters controlling the number of children per node and the depth of the tree. Each leaf cgroup runs a schbench workload and gets an 80% quota of the total CPU quota divided by number of leaf cgroups (in other words, the target CPU load is set to 80%) to exercise the throttling functions. Bandwidth control period is set to 10ms. We run the benchmark on Intel and AMD machines; each machine has hundreds of threads. Tests were conducted on 6.15. | Kernel LLC Misses | depth 3 width 10 | depth 5 width 4 | +-------------------+---------------------+---------------------+ | AMD-orig | [2218.98, 2241.89]M | [2599.80, 2645.16]M | | AMD-opt | [1957.62, 1981.55]M | [2380.47, 2431.86]M | | Change | -11.69% | -8.248% | | Intel-orig | [1580.53, 1604.90]M | [2125.37, 2208.68]M | | Intel-opt | [1066.94, 1100.19]M | [1543.77, 1570.83]M | | Change | -31.96% | -28.13% | There's also a 25% improvement on kernel IPC on the AMD system. On Intel, the improvement is 3% despite a greater LLC miss reduction. Other workloads without CPU share limits, while also running in a cgroup hierarchy with O(1000) instances, show no obvious regression: sysbench, hackbench - lower is better; ebizzy - higher is better. workload | base | opt | metric ----------+-----------------------+-----------------------+------------ sysbench | 63.55, [63.04, 64.05] | 64.36, [62.97, 65.75] | avg latency hackbench | 36.95, [35.45, 38.45] | 37.12, [35.81, 38.44] | time ebizzy | 610.7, [569.8, 651.6] | 613.5, [592.1, 635.0] | record/s Zecheng Li (3): sched/fair: Co-locate cfs_rq and sched_entity in cfs_tg_state sched/fair: Remove task_group->se pointer array sched/fair: Allocate cfs_tg_state with percpu allocator kernel/sched/core.c | 40 ++++++++------------- kernel/sched/debug.c | 2 +- kernel/sched/fair.c | 83 ++++++++++++++++---------------------------- kernel/sched/sched.h | 55 ++++++++++++++++++++++++----- kernel/sched/stats.h | 9 +---- 5 files changed, 93 insertions(+), 96 deletions(-) -- 2.53.0