Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp781814lqp; Sat, 13 Apr 2024 21:56:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+5YKWNvT0spUq6iWMyvcleaOm1xbYKI8px8mEKED3qUZHPeCEDTvHaOeITmm9N42PsjW7jl8JgKGnItIu4eIYp+A0Umw7vGIHElg4Sg== X-Google-Smtp-Source: AGHT+IF5N/Bf0mMkzVUFFcnZ8qcw8plJbu880j3cGm8AsGIwuRyaC6ph1p4CaWijJBIUkCpKuA2g X-Received: by 2002:a05:6358:6996:b0:183:cd9a:b2dd with SMTP id a22-20020a056358699600b00183cd9ab2ddmr7055765rwi.23.1713070569262; Sat, 13 Apr 2024 21:56:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713070569; cv=pass; d=google.com; s=arc-20160816; b=bVODaXmKVfhxZk049UImAvw/F2e/szykhL3bxehllx985gF6CcgyaP4L7/6txCB6Eg rHLBaRobo1iWi+oWp97Bg29xb5p97SKEUnX9egfKoP+qNcqQB+pRatQrkUG+2wjP8/DR Et87n5qH3v4ULX2Dydz2VgFaoZpWvsqS+jMUd8SaC7gP7sH/ibjSuv69NOcS1pLFOS6Q XqrmabHLU1ZmcF3+DfUtCwMXlglorYTQ3b88wQtvhAU6P39U66QJdxEJ/MVKklKozN0X 6T8EM7LWqUOY+JURe9dsYmjfPJm9T8lsTHw9gKV8SiRfw9y2CB836i61CpIOw1lHbT9K FdVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=6sSjcJpVJMu7l0K8sOsNBgOrRR0o2lGErM0v7V0igqw=; fh=GmqYvvjkMqUEXruU6BKKfudHB60wGt5NdIXXeRwHsMA=; b=x28l1jjM/44mqwT5oeuE+oFH5xXxIVWeCs3e//x322wTemyD0VGXGBgHQ+iBJTAC2c Sp4ERZKKQtNsaknCn5zr3/pbQSIjwu6s3mlKg06bfP/1/vWuge50H8iLYbEvJozArA2h gI0fXYmBs3kbqcKBufHeseYx0IGSVzzNnvc/AnZzoS1DBm6wBETGQlICn8Kj6PbP3dmh MmVJTvOZYuLHj8tu6Hiuu/4nTGzAZgpE3F/7PVGAnM/FwUXhqp2kHulJHs1QR28xf/3h /PDSCtOrzLGoXyncZ0pZogNYQ/hu8nRjgJ/2eO6tLZ70TKskq9lUQx5ASwfeH9ggBXkx u+MQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=bd27Pkbs; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-143982-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143982-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u88-20020a17090a51e100b002a07edca226si6027968pjh.76.2024.04.13.21.56.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Apr 2024 21:56:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143982-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=bd27Pkbs; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-143982-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143982-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E3AFC28217D for ; Sun, 14 Apr 2024 04:56:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 506691BC3E; Sun, 14 Apr 2024 04:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="bd27Pkbs" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (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 177CC17588 for ; Sun, 14 Apr 2024 04:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713070559; cv=none; b=WCPpG2aZ6p/ldrLzlQT3VjfHjuIXm4g17TMWugSOGoJv9dmAEjR2BtOs1IqF1eYCSQUwWbka7Q/ChUFfXnm0xsbir749ngkDg0XGS/zU3T1qMeY5aU7LI+RXeJjESAaQspHCMf692xi4fB9AvlSV7Igshd6yqIZDDWSNVkYStGM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713070559; c=relaxed/simple; bh=y2j7KoDsaeJBqN/VpTEyT+mxqBwI9JziatVanbwDF44=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bF1Pf/GfCfbA4ySd3U0NXKR1o90z7GBhR3z5KAC27ppOkLsSWHPyOUv9VWOI3yfBgiGo2IWb0gIn3h/UoHi3XC9Q8P+uCAZaFk4jovaFrYu5h0JeAVNEHBuHV7a7GpBnP1/bJRyEIfhrmGf44XunUX2h+yzKnsWcjxC3jMgITKI= 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=bd27Pkbs; arc=none smtp.client-ip=95.215.58.185 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 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> 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: <20240325-slab-memcg-v2-1-900a458233a6@suse.cz> X-Migadu-Flow: FLOW_OUT 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