From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 6913A1FE44A for ; Wed, 10 Dec 2025 12:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765370625; cv=none; b=JcDx52UVYqM+8sRfyP6GxkINgbOc/hQYp5Y4Lsrj+ocaC+7yDhRBS+jwrvXnFl6WDqERvYp4BKWyWsD6hpMPSo52cc6MHlTPPUmGuH6+1H+yo5OG6vmkF8/hmlBrXvgq1dtlB+dn8XQUjwWvZ42xCe/RJ6F5qK6ISo5HmP7GMdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765370625; c=relaxed/simple; bh=5ruUJ+a+h8R2Ho98/Q7eaK/ft0DgQ7B99lt6uAHn8Ic=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ArQKvOyJa24dCdfjp8k3kwcZPY3P5oCyKe5rBE2fds0deighXl8EFKHo/q27Klxfn1/8qp26UNZFTW6SrgMwG54tfhRGdMGa/gdYqEbw2xjRnaw+ktKVKzy1E8shUMe6ZcG9HB0KZibgA6t0E0w1L2cSnzQqgtWYuqfoA5ai5gY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=MO6Csgq4; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="MO6Csgq4" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Q2t1VBrlZjLPY1RCBCixS/tEMELbPeBcp3yuUId3/mE=; b=MO6Csgq4qbbzlmzrobIZOw6J/V lMKK4ZCPRuJxYSGXO6dZZiFyv2ggxJyXeiuBJYxWzlOMCFA8HW8QMfgjvr86ws49eaqtFGWDQv4h2 a1fGQD3ufyOlD1E2EzoRqIwBBtpyEMtk7lhKZqKETFb+srUJ1fFU8uANFew2s4jerF2/g89ZbN2AZ 3ta/2Fdhp+NUAAhR4hZDVwWbuLlAQ3Yo0awt+/M5HSK0u65WMYNVuWjZYIX5GegWSEsjED3q4XPRw deNJo07ovpY8OSB4PEtUD0jAv8qsrpOqRHu9oLe6hUpxioN9XsIxB788/gQaGxNDGVeKAbvqM2sZw 0gpp3DFQ==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vTIfb-0000000DJ9s-3C34; Wed, 10 Dec 2025 11:47:48 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 59E96302EC2; Wed, 10 Dec 2025 13:43:03 +0100 (CET) Date: Wed, 10 Dec 2025 13:43:03 +0100 From: Peter Zijlstra To: Tim Chen Cc: Ingo Molnar , K Prateek Nayak , "Gautham R . Shenoy" , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Madadi Vineeth Reddy , Hillf Danton , Shrikanth Hegde , Jianyong Wu , Yangyu Chen , Tingyin Duan , Vern Hao , Vern Hao , Len Brown , Aubrey Li , Zhao Liu , Chen Yu , Chen Yu , Adam Li , Aaron Lu , Tim Chen , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 07/23] sched/cache: Introduce per runqueue task LLC preference counter Message-ID: <20251210124303.GR3707891@noisy.programming.kicks-ass.net> References: <63091f7ca7bb473fbc176af86a87d27a07a6e149.1764801860.git.tim.c.chen@linux.intel.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <63091f7ca7bb473fbc176af86a87d27a07a6e149.1764801860.git.tim.c.chen@linux.intel.com> On Wed, Dec 03, 2025 at 03:07:26PM -0800, Tim Chen wrote: > +static int resize_llc_pref(void) > +{ > + unsigned int *__percpu *tmp_llc_pref; > + int i, ret = 0; > + > + if (new_max_llcs <= max_llcs) > + return 0; > + > + /* > + * Allocate temp percpu pointer for old llc_pref, > + * which will be released after switching to the > + * new buffer. > + */ > + tmp_llc_pref = alloc_percpu_noprof(unsigned int *); > + if (!tmp_llc_pref) > + return -ENOMEM; > + > + for_each_present_cpu(i) > + *per_cpu_ptr(tmp_llc_pref, i) = NULL; > + > + /* > + * Resize the per rq nr_pref_llc buffer and > + * switch to this new buffer. > + */ > + for_each_present_cpu(i) { > + struct rq_flags rf; > + unsigned int *new; > + struct rq *rq; > + > + rq = cpu_rq(i); > + new = alloc_new_pref_llcs(rq->nr_pref_llc, per_cpu_ptr(tmp_llc_pref, i)); > + if (!new) { > + ret = -ENOMEM; > + > + goto release_old; > + } > + > + /* > + * Locking rq ensures that rq->nr_pref_llc values > + * don't change with new task enqueue/dequeue > + * when we repopulate the newly enlarged array. > + */ > + rq_lock_irqsave(rq, &rf); > + populate_new_pref_llcs(rq->nr_pref_llc, new); > + rq->nr_pref_llc = new; > + rq_unlock_irqrestore(rq, &rf); > + } > + > +release_old: > + /* > + * Load balance is done under rcu_lock. > + * Wait for load balance before and during resizing to > + * be done. They may refer to old nr_pref_llc[] > + * that hasn't been resized. > + */ > + synchronize_rcu(); > + for_each_present_cpu(i) > + kfree(*per_cpu_ptr(tmp_llc_pref, i)); > + > + free_percpu(tmp_llc_pref); > + > + /* succeed and update */ > + if (!ret) > + max_llcs = new_max_llcs; > + > + return ret; > +} > @@ -2674,6 +2787,8 @@ build_sched_domains(const struct cpumask *cpu_map, struct sched_domain_attr *att > if (has_cluster) > static_branch_inc_cpuslocked(&sched_cluster_active); > > + resize_llc_pref(); > + > if (rq && sched_debug_verbose) > pr_info("root domain span: %*pbl\n", cpumask_pr_args(cpu_map)); I suspect people will hate on you for that synchronize_rcu() in there. Specifically, we do build_sched_domain() for every CPU brought online, this means booting 512 CPUs now includes 512 sync_rcu()s. Worse, IIRC sync_rcu() is O(n) (or worse -- could be n*ln(n)) in number of CPUs, so the total thing will be O(n^2) (or worse) for bringing CPUs online.