From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 19F4129B78F; Tue, 31 Mar 2026 08:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774945009; cv=none; b=JH/GoaMYJIP9wvTTtly764HgLrWVGhZs+0vkjXPhpUzjNF8YNjQvX9FMiGWZewxI6QScgc9zuJPduoCxOf48SjvZAMiC8nV/LCr4J3rNnuRoVJwL0w3Z7UddN0w/M3c34ZCdQXFFW6vFpcicboof2VtRtK5QI51/PlB89EfDLsw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774945009; c=relaxed/simple; bh=1/b91mgi/U3fwN0ggRiOwK1YDEmQTiNMQAZyJI8BbOg=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=swbK8Z2EVWz3TrPf5MHU5rGquaMHAjoQau6k0sEwWTItMDqxCSpm4Ld+5gYHnzYnNiLawCszr3h35+au7Eu/Rlayd2Di+UJymsacuRJEVpgcbRp6pmo8LQvJ9kXmf3gFIMkjxmjnteFtgaiXer9rbj9z+Cr6Dg0nFQsO0jUDBRI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=A3HizW0j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="A3HizW0j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B5BDC19423; Tue, 31 Mar 2026 08:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1774945008; bh=1/b91mgi/U3fwN0ggRiOwK1YDEmQTiNMQAZyJI8BbOg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=A3HizW0jQdmUOC+s+7wKXIR69YrouWazRCDICG1ShMemTG6O4228pnr3GD/ExeZ0H YiuTIuS8c5bhc3h429eM5O4XjVloyaxn8D7G7WNwDk4LtfrjwcFLCOzPgxbtdOZlaO hHD0byUs6L0pwQ3/yf5DynWJsovHJUw9rKr/I/+U= Date: Tue, 31 Mar 2026 01:16:47 -0700 From: Andrew Morton To: Hui Zhu Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, teawater Subject: Re: [PATCH mm-unstable v2] mm/memcontrol: batch memcg charging in __memcg_slab_post_alloc_hook Message-Id: <20260331011647.79bdd9b9b6efb99bcbac8d77@linux-foundation.org> In-Reply-To: <20260320020745.833792-1-hui.zhu@linux.dev> References: <20260320020745.833792-1-hui.zhu@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 20 Mar 2026 10:07:45 +0800 Hui Zhu wrote: > When kmem_cache_alloc_bulk() allocates multiple objects, the post-alloc > hook __memcg_slab_post_alloc_hook() previously charged memcg one object > at a time, even though consecutive objects may reside on slabs backed by > the same pgdat node. > > Batch the memcg charging by scanning ahead from the current position to > find a contiguous run of objects whose slabs share the same pgdat, then > issue a single __obj_cgroup_charge() / __consume_obj_stock() call for > the entire run. The per-object obj_ext assignment loop is preserved as-is > since it cannot be further collapsed. > > This implements the TODO comment left in commit bc730030f956 ("memcg: > combine slab obj stock charging and accounting"). > > The existing error-recovery contract is unchanged: if size == 1 then > memcg_alloc_abort_single() will free the sole object, and for larger > bulk allocations kmem_cache_free_bulk() will uncharge any objects that > were already charged before the failure. > > Benchmark using kmem_cache_alloc_bulk() with SLAB_ACCOUNT > (iters=100000): > > bulk=32 before: 215 ns/object after: 174 ns/object (-19%) > bulk=1 before: 344 ns/object after: 335 ns/object ( ~) > > No measurable regression for bulk=1, as expected. I noticed that the AI review of your v1 patch reported a few potential issues: https://sashiko.dev/#/patchset/20260316084839.1342163-1-hui.zhu@linux.dev Can you please take a look, see if any of this is valid for v2? Unfortunately the bot wasn't able to check v2 because it couldn't get the patch to apply. I've checked that this patch does apply cleanly to current mm-stable, which is on the bot's try-to-apply list. So if you wish to get checking of the latest patch, please send us a v3 and that will trigger a retry.