From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.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 4DB8A3909A5 for ; Mon, 2 Mar 2026 22:21:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772490080; cv=none; b=SSidDW2MUM1YjO4iCKxou7/x1y1N3t1IT1xYAZLZFTOvrZSp2g5j6UtBLd3QYiZasZ+C0NpZsKQEpcaz0CDIoO8PDXGXKs4Sc7BLXdmQsrrG0YLE4VEMo93lhrjGBGztMJzUxjCy81FbbHjqTM05WamfioQfBgQD1QtvNgn2bNY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772490080; c=relaxed/simple; bh=cM6Sf+nPkriTMX6iDjxwpKHyStgmQ8eaMordpwlaLOg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RbwIS08UHIQeoG18Sv8vM49lEw6KpvL8WqW5HmAsr+Llm7MKRn2KAh+MP3AZfTr6gL5xVJ1guQvuLCzKj5Pb8qsktgEyPrrEzzb+CddjJpXaaEDn4aKiacuVb9EaoHqdFTDwgfBM6wzN3iE5dxIXzCAbBsADScZ47pF5kd0ZGMs= 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=I5qBYBhf; arc=none smtp.client-ip=95.215.58.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="I5qBYBhf" Date: Mon, 2 Mar 2026 14:20:32 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772490067; 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=kxrIqC4lTYaQ10ka6NqFm5OmD9rPDMHzGSGdgraOMEg=; b=I5qBYBhfBL7RM+n9tcitpC63AArsIB0Echd/QGCuxpghhgcyLn1x1g524QDKNs9PGJjFc5 mzS9QY7M33beBsSO00PAS0Jqf6y3ftwMbTuC3N1bAR3SCC4h2C3+fu1e/dMB+2CyU8yss6 HB0nClNoAyr4j8xbicwiok+mySUNHhI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Johannes Weiner Cc: Andrew Morton , Hao Li , Michal Hocko , Roman Gushchin , Vlastimil Babka , Harry Yoo , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/5] mm: memcg: separate slab stat accounting from objcg charge cache Message-ID: References: <20260302195305.620713-1-hannes@cmpxchg.org> <20260302195305.620713-6-hannes@cmpxchg.org> 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: <20260302195305.620713-6-hannes@cmpxchg.org> X-Migadu-Flow: FLOW_OUT On Mon, Mar 02, 2026 at 02:50:18PM -0500, Johannes Weiner wrote: > Cgroup slab metrics are cached per-cpu the same way as the sub-page > charge cache. However, the intertwined code to manage those dependent > caches right now is quite difficult to follow. > > Specifically, cached slab stat updates occur in consume() if there was > enough charge cache to satisfy the new object. If that fails, whole > pages are reserved, and slab stats are updated when the remainder of > those pages, after subtracting the size of the new slab object, are > put into the charge cache. This already juggles a delicate mix of the > object size, the page charge size, and the remainder to put into the > byte cache. Doing slab accounting in this path as well is fragile, and > has recently caused a bug where the input parameters between the two > caches were mixed up. > > Refactor the consume() and refill() paths into unlocked and locked > variants that only do charge caching. Then let the slab path manage > its own lock section and open-code charging and accounting. > > This makes the slab stat cache subordinate to the charge cache: > __refill_obj_stock() is called first to prepare it; > __account_obj_stock() follows to hitch a ride. > > This results in a minor behavioral change: previously, a mismatching > percpu stock would always be drained for the purpose of setting up > slab account caching, even if there was no byte remainder to put into > the charge cache. Now, the stock is left alone, and slab accounting > takes the uncached path if there is a mismatch. This is exceedingly > rare, and it was probably never worth draining the whole stock just to > cache the slab stat update. > > Signed-off-by: Johannes Weiner Thanks, this looks much better. Acked-by: Shakeel Butt