From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 ED463421EE6 for ; Wed, 13 May 2026 14:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778682456; cv=none; b=ahDj8qa0/HNy0SRQBoIL5Jmvr2jQ97PkOAeSuZSAieQpQaoDqmWEugzwWwZceTK5G/pdxLuW/3H2QznlR64aLWc/2lD0NiuIY++8cBY+YvDW846xPeylm9mYP3fc4a9mOkmzj1wnqF1ngJkevqFlhXeI92jqhxoh822+qoS1eGQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778682456; c=relaxed/simple; bh=qlljKeyeN1rG4Iou/1YDlXG59mRnd1ahfTrMddNlR5o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tN3VA2DGbKrpA7ItINRYFL0gPDJHY3jGPjHpVPwqQa2TojqssqOjgAfJOM/tOVCRwRSR4tuedvFCOoy/lGM6Nxaxt/x0Sv3tdzJGngrW32MlGFv+qfp/dnqd/ypoYLgjFCE40e2+F0tnV+YlCqwcZuffFdsnb2oTQFD5fvF2/s4= 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=kSK6UKwk; arc=none smtp.client-ip=91.218.175.171 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="kSK6UKwk" Date: Wed, 13 May 2026 07:27:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778682450; 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=OT6KxnKuDG1JfLVVwS36wJ8yrLhF0nn4rcZS0tX7pQM=; b=kSK6UKwkJV4guHYiDnTwdaxVuAQy0iSI+VE0KvC0Z6NJkwMmxZ6zjNSsPG1BsjELGVPtHU YQGGEQ04qJDqNky7sxs1usfZXIDNVbmVO/b7z1G1H1VxySwk/FeVpk1Nv5Wk4hWp3wivo0 9618ELZQyQLdm6EPn9e588IlFeaCEkw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Qi Zheng Cc: kernel test robot , oe-lkp@lists.linux.dev, lkp@intel.com, linux-kernel@vger.kernel.org, Andrew Morton , David Carlier , Allen Pais , Axel Rasmussen , Baoquan He , Chengming Zhou , Chen Ridong , David Hildenbrand , Hamza Mahfooz , Harry Yoo , Hugh Dickins , Imran Khan , Johannes Weiner , Kamalesh Babulal , Lance Yang , Liam Howlett , Lorenzo Stoakes , Michal Hocko , Michal =?utf-8?Q?Koutn=C3=BD?= , Mike Rapoport , Muchun Song , Muchun Song , Nhat Pham , Roman Gushchin , Suren Baghdasaryan , Usama Arif , Vlastimil Babka , Wei Xu , Yosry Ahmed , Yuanchu Xie , Zi Yan , Usama Arif , cgroups@vger.kernel.org, linux-mm@kvack.org Subject: Re: [linus:master] [mm] 01b9da291c: stress-ng.switch.ops_per_sec 67.7% regression Message-ID: References: <202605121641.b6a60cb0-lkp@intel.com> <0e1b8994-944d-4dda-8966-3cd43661796d@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: X-Migadu-Flow: FLOW_OUT On Wed, May 13, 2026 at 06:49:45AM -0700, Shakeel Butt wrote: > On Wed, May 13, 2026 at 10:10:34AM +0800, Qi Zheng wrote: > > > > > > On 5/13/26 12:03 AM, Shakeel Butt wrote: > > > On Tue, May 12, 2026 at 08:56:52PM +0800, kernel test robot wrote: > > > > > > > > > > > > Hello, > > > > > > > > kernel test robot noticed a 67.7% regression of stress-ng.switch.ops_per_sec on: > > > > > > > > > > > > commit: 01b9da291c4969354807b52956f4aae1f41b4924 ("mm: memcontrol: convert objcg to be per-memcg per-node type") > > > > https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git master > > > > > > This is most probably due to shuffling of struct mem_cgroup and struct > > > mem_cgroup_per_node members. > > > > Another possibility is that after objcg was split into per-node, the > > slab accounting fast path is still designed assuming only one current > > objcg per CPU: > > > > struct obj_stock_pcp { > > struct obj_cgroup *cached_objcg; > > }; > > > > So it's may cause the following thrashing: > > > > CPU stock cached = memcg/node0 objcg > > free object tagged = memcg/node1 objcg > > => __refill_obj_stock --> objcg mismatch > > => drain_obj_stock() > > => cache switches to node1 objcg > > > > next local allocation tagged = node0 objcg > > => mismatch again > > => drain_obj_stock() > > Actually I think this is the issue, we have ping pong threads running on > different nodes where though theu are in same cgroup but their current->obcg is > for local node and thus this ping pong is thrashing the per-cpu objcg stock. > > The easier fix would be to compare objcg->memcg instead of just objcg during > draining and caching. In addition we can add support for multiple objcg per-cpu > stock caching. Something like the following: >From d756abe831a905d6fe32bad9a984fc619dafb7e0 Mon Sep 17 00:00:00 2001 From: Shakeel Butt Date: Wed, 13 May 2026 07:24:55 -0700 Subject: [PATCH] mm/memcontrol: skip obj_stock drain when refilled objcg shares memcg Signed-off-by: Shakeel Butt --- mm/memcontrol.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d978e18b9b2d..01ed7a8e18ac 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3318,6 +3318,7 @@ static void __refill_obj_stock(struct obj_cgroup *objcg, unsigned int nr_bytes, bool allow_uncharge) { + struct obj_cgroup *cached; unsigned int nr_pages = 0; if (!stock) { @@ -3327,7 +3328,18 @@ static void __refill_obj_stock(struct obj_cgroup *objcg, goto out; } - if (READ_ONCE(stock->cached_objcg) != objcg) { /* reset if necessary */ + cached = READ_ONCE(stock->cached_objcg); + if (cached != objcg && + (!cached || obj_cgroup_memcg(cached) != obj_cgroup_memcg(objcg))) { drain_obj_stock(stock); obj_cgroup_get(objcg); stock->nr_bytes = atomic_read(&objcg->nr_charged_bytes) -- 2.53.0-Meta