From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 998E7217F33 for ; Thu, 30 Apr 2026 13:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777554214; cv=none; b=H2JwAIhPoxNYZ3XmPTe6JyzmaFcQtQtfRFHSa+76JmWj0mWqqMdyvUHFOacKcHirdlOqIVlQpQU+lHA6cIBJgbY33jGImEcWCPZwkWd/4B509FeiEVnazU9hiniqigGgNakgkJzKMI4IDfNgDY7p86hyr1AwZtOLG4KsXm6E2S8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777554214; c=relaxed/simple; bh=SP7g56WfTYGbNHX/Ba/fvguS2wTsCsIUzDC74LX7oSI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=A6FPQBQik0Iv5/YyjxOYmNDxLR1wRb4mRhqMhDoju2uZ2PjGXxTXyA6Ipu7DK150pRvXbXZHIYL3UIhFXnmByZjWXeYZE0p7yJ3COEHITmMfUQiHy73+NN43b7rBoGygJ8jwTauIdn//MfxLm3Tdde4hE2UlwR9Pj0YP4SL3XN4= 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=d4Y47WcK; arc=none smtp.client-ip=91.218.175.172 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="d4Y47WcK" Date: Thu, 30 Apr 2026 06:03:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777554206; 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=48UFhuUrS/5CKzCRf6cET806F55RZ+asmMEzp5H3pjE=; b=d4Y47WcK8SMHjZKcK3wFwqSykiALyGWunDOn09eKb4GbUzLB16aNBXWrZMhduas8+OIEU+ ZnxP+j7MHVjXm/IM3DX9xWvDzVivMWgdLOawhDgFj8pFGL576eU+SVq1uyB3h5hxe83qnl /uHiv5pWfjQT0+cVFvR/jK/XVLcZU10= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Hui Zhu Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Andrew Morton , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hui Zhu Subject: Re: [PATCH] mm/memcontrol: hoist pstatc_pcpu assignment out of CPU loop Message-ID: References: <20260429084216.186238-1-hui.zhu@linux.dev> 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: <20260429084216.186238-1-hui.zhu@linux.dev> X-Migadu-Flow: FLOW_OUT On Wed, Apr 29, 2026 at 04:42:16PM +0800, Hui Zhu wrote: > From: Hui Zhu > > In mem_cgroup_alloc(), the assignment of pstatc_pcpu is invariant > with respect to the for_each_possible_cpu() loop: both the 'parent' > pointer and 'parent->vmstats_percpu' remain constant throughout all > iterations. > > The original code redundantly re-evaluated the 'if (parent)' > condition and reassigned pstatc_pcpu on every CPU iteration, then > repeated the same ternary check 'parent ? pstatc_pcpu : NULL' when > storing into statc->parent_pcpu. > > Move the single conditional assignment of pstatc_pcpu to before the > loop, resolving both the loop-invariant placement issue and the > duplicated null check. On systems with a large number of possible > CPUs, this eliminates repeated branch evaluation with no functional > change. > > No functional change intended. > > Signed-off-by: Hui Zhu Acked-by: Shakeel Butt