From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 074B1C4345F for ; Sun, 14 Apr 2024 04:56:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 467F86B0083; Sun, 14 Apr 2024 00:56:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F1446B0085; Sun, 14 Apr 2024 00:56:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2918C6B0087; Sun, 14 Apr 2024 00:56:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0B1766B0083 for ; Sun, 14 Apr 2024 00:56:00 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8DF41C0261 for ; Sun, 14 Apr 2024 04:55:59 +0000 (UTC) X-FDA: 82006925238.08.DC90D92 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by imf16.hostedemail.com (Postfix) with ESMTP id A676318000D for ; Sun, 14 Apr 2024 04:55:57 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bd27Pkbs; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713070558; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6sSjcJpVJMu7l0K8sOsNBgOrRR0o2lGErM0v7V0igqw=; b=0k5yn98R+eUD/v2rmM8nskR6u+LQokX+zqRam+P9rQKBBPhF/MvPzumcroYY4G0LJeOaBE mKEFTu8JNDWnZnV5HHwluKz+EpTmMPHoO0xmtlS6pDFDmTESL0YS+Q+8mlnb2rI06h7t+B 0PdNlzIEnWzQUYQYGnonHTQS+RwWPtA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=bd27Pkbs; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.173 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713070558; a=rsa-sha256; cv=none; b=ccNbEg8Y4tD3PaB4sBT+OeFkyXZ1ROMwHHeoyyYOC0KUxZeUXDg8dF3W/LWBC9Q5OvGCMy GP27M+gKTO/2BMpq6JprP1mHjboRlNsvX8BrltQirg+wsAffZSR782lZk29bZfYiw9rOPt UXe7Lhu0mbMVHlsaa1s4Bzh+LFp91Tw= Date: Sat, 13 Apr 2024 21:55:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1713070555; 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=6sSjcJpVJMu7l0K8sOsNBgOrRR0o2lGErM0v7V0igqw=; b=bd27PkbsnoxmQ2TUkrCF3MouPnq9Y+/aw2Dy9bJ+DermcBQP4Qe9rrqilLbDsMOG6YAJF6 7MxBTTcLwXcF1PNaQTmmdQOjDP/deb32P7eYNvy4DDjsOtFMHKIEBY2p8vUOE8OWkSQxXr uSpQR8u66hq1ax5RnUSk8bbZ0VKp3DM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Vlastimil Babka Cc: Linus Torvalds , Josh Poimboeuf , Jeff Layton , Chuck Lever , Kees Cook , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Johannes Weiner , Michal Hocko , Muchun Song , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, Chengming Zhou Subject: Re: [PATCH v2 1/2] mm, slab: move memcg charging to post-alloc hook Message-ID: References: <20240325-slab-memcg-v2-0-900a458233a6@suse.cz> <20240325-slab-memcg-v2-1-900a458233a6@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240325-slab-memcg-v2-1-900a458233a6@suse.cz> X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: prfyhh74xnheorgutmi9p77ec5ydrphu X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A676318000D X-HE-Tag: 1713070557-16348 X-HE-Meta: U2FsdGVkX1/7IIdfJyFEAo4HDEyCiVWHbi/uwt1AhtK1ngv0xxnSpYU06ABA6urcp8dYDlOOTjZIWLh+ZtmjD0cLUQi6fZXFH64ENT4x4VS16teV/KA/l/znWhJdVM52wOkgfk5arKL+9kEegVWLtX5Jjr9O1PDL2tD24IX8XxqCjheEN7uITgT2dfh6rzo+G5PLr2MQ8IE+AWCbBebt9oZKLgrjjS1N8S7t8Pv/eSo6MX20iTbhk5ufanr/pR84LD40O4rYVLfp7MPEtb+aS6F9naiKsyogGXdG6Ay0x2qdcyFYmtradTFwB9oUhqRzv6ANxz/oL0MFbEMaqfvQo2eIuGWpZxNcdJfVV/DfOCjFQyDblROvUa90lzSB5G9eA+E6xjgBqelOqGWVz7aEWu5xEgLdfTSX69v/v7/poFVy3yMGb+5mOICeaCrB0yredXzPE76mcLyDrMBfiHpZN79dqeqqyAhNgGWUhegcGpHF1t79/GBDXgvpDVDUJWQ40mQ4WpPvGaoUvvduC43k3BRgRP8O+l92dG11VLDjnMwPiST9lxgi7b4g0dhBcbEccqqWKTxwmK7BlcqA8C2leUHVp84RhAInvbnhVHEquDaknT9/nGnhqWzcyKEVwvQsUTNLy1Ofh7t/1VmPlnxNRzl4fzCMTAOhc4FJ3oCz5WoiuvsN9KULgrbqYTWIPLWJbQT+WHeJapnYhyqH7PkrK6B85gwDd7ilZPJ3njVnISp9LZxBnIHBXR83aiOBcXKkZLRjtGxMPPt6Btc6O5giW6Z0aDFgpRlemvXzxthTHbfRb0kozczeaDnekaOEDIsExCtkULakQ0tVHwaop9A+RmFojRTyg81bL0yDU7z0PuyLqsbA4HsfQuVafdKFNGlRHHvgUBYNjbMcJZVrEvrZMVjTtLoJj70DGNXPOOFZAbU34s5szZflYZPqr/Amobg2wHyaplsPtjEGPS5RFGC vPfchSY0 13vL2/MflIOaTNfqPg7JdZvS65o9Zs+jxCZHv5plf/FfYPxezSkvIYCaYsUgP4kWI9KCeWS7Amea/3NYCrk15XxojIL3li7fWoNJnie4oalpzttOH5vFXYxMOCvU/8AhjSbi/AXL+AoUW5STXQ0uxs3EXMENroCB9Zcubon0CekbJzt3MDWDBgAZJ1i1OuHQQXugOeIrgJCKN1IuhzyEoNK+F68w0lP6A1V8HW8V/hroQPOT4BLSbDO4tiMge2yruDbP1bjMmIYKXh6h6OZWpX/SGJWkWyAwyrvAjm7UxEUOCXC8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Mar 25, 2024 at 09:20:32AM +0100, Vlastimil Babka wrote: > The MEMCG_KMEM integration with slab currently relies on two hooks > during allocation. memcg_slab_pre_alloc_hook() determines the objcg and > charges it, and memcg_slab_post_alloc_hook() assigns the objcg pointer > to the allocated object(s). > > As Linus pointed out, this is unnecessarily complex. Failing to charge > due to memcg limits should be rare, so we can optimistically allocate > the object(s) and do the charging together with assigning the objcg > pointer in a single post_alloc hook. In the rare case the charging > fails, we can free the object(s) back. > > This simplifies the code (no need to pass around the objcg pointer) and > potentially allows to separate charging from allocation in cases where > it's common that the allocation would be immediately freed, and the > memcg handling overhead could be saved. > > Suggested-by: Linus Torvalds > Link: https://lore.kernel.org/all/CAHk-=whYOOdM7jWy5jdrAm8LxcgCMFyk2bt8fYYvZzM4U-zAQA@mail.gmail.com/ > Reviewed-by: Roman Gushchin > Reviewed-by: Chengming Zhou > Signed-off-by: Vlastimil Babka Acked-by: Shakeel Butt