From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.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 D5FE01A5B90 for ; Sun, 5 Jul 2026 21:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783285646; cv=none; b=APOIrCzoU48GizppK1FuwlTQOmDhW+lE6tEdWG0M7JoneQSrtv3TuKJj+/ydiAoLUYUJhA/J3CgwBY13i5sUq9jzvQwdhRMgnurNINEfqokBy1BracgNq3mqLJqFi21yFB4cZx/v8iBhjWIxTwjlIbhGN02hqkaF1HPagefVvms= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783285646; c=relaxed/simple; bh=AMxT6khGPhi+9INrwlh2F+hdfcMFS/ST1qF/A+1Isfg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jQgERKiWqqg5gY6kfceJ/ZshUSvzMjrEZ0mJQGDezD83qZllpWBwwZmYtZ+kzDq/8EizLeohu52CKXM1UBcPGQqI4tr2bPQn6yvfR5ozoVPG6u0b6XyIIQFCyT1rOMoU4BP1oWXriI/NAt/7wtURFMLg0Un5MnrnAnaJ4pzEj+w= 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=L673hFvH; arc=none smtp.client-ip=91.218.175.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="L673hFvH" Date: Sun, 5 Jul 2026 23:07:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783285639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HyCCaEPRCSMvm0SDm0xpK9osL4zwQAIFjRbCtKFsfw8=; b=L673hFvH1iQE115w7jDaNLNsxfmQWC+v6dqxw13OuRhlBIexlfAVq8DRB866wiD9jKEZgp CHqNu8QOi0rzEOTrxhOrGC0S7368WCAnrnv+Wk5XIZVYkaL8OuCgBBgOqpBj8bo70zfmrq vV3BnOXTXhzjuv8tRb6fCIGVxnSSLyI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: David Laight Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND] sched/mmcid: Use clamp() to simplify mm_cid_calc_pcpu_thrs() Message-ID: References: <20260705172054.339425-2-thorsten.blum@linux.dev> <20260705200723.66564929@pumpkin> 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: <20260705200723.66564929@pumpkin> X-Migadu-Flow: FLOW_OUT On Sun, Jul 05, 2026 at 08:07:23PM +0100, David Laight wrote: > On Sun, 5 Jul 2026 19:20:54 +0200 > Thorsten Blum wrote: > > > Use clamp() to simplify the code and improve its readability. > > > > Signed-off-by: Thorsten Blum > > --- > > kernel/sched/core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 8b791e9e9f67..31739bd43176 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -10785,7 +10785,7 @@ static inline unsigned int mm_cid_calc_pcpu_thrs(struct mm_mm_cid *mc) > > > > opt_cids = min(mc->nr_cpus_allowed, mc->users); > > /* Has to be at least 1 because 0 indicates PCPU mode off */ > > - return max(min(opt_cids - opt_cids / 4, num_possible_cpus() / 2), 1); > > + return clamp(opt_cids - opt_cids / 4, 1, num_possible_cpus() / 2); > > Nack, it isn't the same. > clamp() requires that lo <= hi but I suspect num_possible_cpus() > can be zero. num_possible_cpus() probably shouldn't be 0, but you're right anyway, and that's the case I didn't consider: num_possible_cpus() / 2 == 0 when num_possible_cpus() is 1. Let's drop this patch, and thanks for the feedback.