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 4034119309C for ; Wed, 10 Dec 2025 12:51:43 +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=1765371105; cv=none; b=WS+TAZ/BFNTAoG4xXe56/9W4RldvIioCUT625/o5LeBooHE7cBwMdTAiiNaTPmObQzdPdgpy27D8dtDzOIMBI82w4qpJtYjx/5OUKBYk3Xu0FAkojwmmhG9QdRKWCgFXPBa0BfuNBEr34nRVZz3aOr0n7mnVBueoH0J53QmLWBY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765371105; c=relaxed/simple; bh=elwbYD5FJJQiCTFTVz7oUyiVI7SWObVHc5MqguYegoY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=N5vRViKPoXAWQswynxh90bH6uUtTqJ2AxEBoKjAPpWNyzx51+bvnBvgwnH3a/rf7bwzgkefmdNg8uazg7dxHaqdWvAnr5hvLOQEzRx2gMeOAciTYKV8iZkg0d2XAb063XNKvco2MkBmI2AFMgb54QzZC08wT0HDm1q02N4kaIJE= 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=Wbdwgik6; 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="Wbdwgik6" 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=vccCROViGdmZNtPCFanEn050YomfxQNF+2A/iV0Auvc=; b=Wbdwgik64GiL0IxkNhoOCo367P 2fOp4aqzCgO4szlZtMiAJGhIesbw8WAEtjJtz4FEoEhmJ2m8AQ/03SzNHStTZDd/L8LGu/jsnsrFZ PiA+Fb1bMEU43Fzwt8vg7ggseRd1CQjI9hbK65P//3Z3CtneNpRJ3P8P7jaNOmq4cJe5wblxGVUgz 6XZcaHHxOPFcTVJIB7trfp/uR3V50NkpooTjmaY/piKF9eTE30LRLCYjdd9why0TWDSgJFaA+s1en qfPCiI0mE/9leGBVhOstLNoM9FNSMNg8rP3zZV2ziCiNvhHZKgHqpOmPhSyYhMFq5NpTlwA08T2G2 XROy4Dng==; 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 1vTInV-0000000DJaE-17yn; Wed, 10 Dec 2025 11:55:57 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 39045302EC2; Wed, 10 Dec 2025 13:51:14 +0100 (CET) Date: Wed, 10 Dec 2025 13:51:14 +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: <20251210125114.GS3707891@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; > +} Would it perhaps be easier to stick this thing in rq->sd rather than in rq->nr_pref_llc. That way it automagically switches with the 'new' domain. And then, with a bit of care, a singe load-balance pass should see a consistent view (there should not be reloads of rq->sd -- which will be a bit of an audit I suppose).