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 BDCDFC83F2D for ; Thu, 29 Aug 2024 15:49:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33D696B008C; Thu, 29 Aug 2024 11:49:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EDF46B0092; Thu, 29 Aug 2024 11:49:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DC306B0093; Thu, 29 Aug 2024 11:49:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 001BC6B008C for ; Thu, 29 Aug 2024 11:49:40 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 870FA1A0626 for ; Thu, 29 Aug 2024 15:49:40 +0000 (UTC) X-FDA: 82505718120.28.745F79D Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) by imf14.hostedemail.com (Postfix) with ESMTP id 991D8100003 for ; Thu, 29 Aug 2024 15:49:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=FG2DPyp9; spf=pass (imf14.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.170 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724946534; a=rsa-sha256; cv=none; b=g6NL+UUton3dp2OwNVZmlMXCrfFxutnKJ00DHzSvD6MnwR39qxwXqIB2b87XYEBA/kDq1V Dt6OugSvC+2asvjFkYEly77Q/Lr7R3de2cKLp/a/bGXZWVz/Q9LrfNfRxE38l9C0yo/4iN U+xkcS0CO9K3VzIdL+07jtjjBV3nNrU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=FG2DPyp9; spf=pass (imf14.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.170 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724946534; 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=JSVZiXj9uWNsdq1CBv+qiytgVutH4w3/0Njr6e1mFG0=; b=nemUREFsr15Z0tXkByX2s+nM5kp+HREfkv4+Q0eX/r8A3TIEX4V6mCHvRupgoifKvLlgjL 8qX6WRkc1HPi3PI8Jg2aCcgyBJ93KS2Y55XDoRRCHJQFrkMTFC8Qe0HDreu3bLo9LY5LwS 3FHp/V/UVp8m922Xco2bMK2mCRpaRug= Date: Thu, 29 Aug 2024 08:49:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724946576; 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=JSVZiXj9uWNsdq1CBv+qiytgVutH4w3/0Njr6e1mFG0=; b=FG2DPyp9orc0RU6IR4u4nURavRjF22n5a/J740GoG1zfzgAUlDCqamGIA3VjPaCLdQNchZ xUTHqVPrMvi0y8SG8PzZA+xJgXeUlQBZ6zsxocob5xVk45+e2C8dy4wYQY5Xrss549CaNW ZunWROmbBtjp53RvCLZV9owEL4jM97Y= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Muchun Song Cc: Roman Gushchin , Andrew Morton , Johannes Weiner , Michal Hocko , Vlastimil Babka , David Rientjes , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Eric Dumazet , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Linux Memory Management List , LKML , Meta kernel team , cgroups@vger.kernel.org, netdev Subject: Re: [PATCH v1] memcg: add charging of already allocated slab objects Message-ID: References: <20240826232908.4076417-1-shakeel.butt@linux.dev> <97F404E9-C3C2-4BD2-9539-C40237E71B2B@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <97F404E9-C3C2-4BD2-9539-C40237E71B2B@linux.dev> X-Migadu-Flow: FLOW_OUT X-Stat-Signature: w8yjy5mbxe7cmus9nifpseq4dh8k3ezs X-Rspamd-Queue-Id: 991D8100003 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724946578-32443 X-HE-Meta: U2FsdGVkX19VssnjiKMgifXxK5KvJZdIwYBRbFz1hLJi9MDx25D+8AW+2LF9mi1KmNxYu/TwCMHn+2i3L3zuiumRNoC+RcI5YTNsYBKuZrT9e0IJLAGUqtV93Mo7qNALOU7iBOCHR5i1oHsBuY1hTArbFIZ2dNuCcK4atDCAqWf41MkiYmsSM53yp2yK6PmIR4Oxv4Q6bkQyyERIu8sWJf4aH3Ijrn9IE98WHscJJJDSk6WaP8/uxi3cXn9CmVLU6rvW8H0tWv9FclDxtrnUeJhZ1Zn7ufoOT7fDnMECNtpr8iBwmfULUiqAvGF8nxMKayye8j57dQsK2uROxz8189+QRv0afJeYwYP76aOnZ7KmpPSranyFGYzyriOcoJ5VvYGNdADKfo/Cj5GvPzS9IWxdMjNb18RSoYaBUjeVvy6b0nOzTxEaZ6n6NYwYuRFFmAAbw+0Q++ZjVrGNipmOWqLvXaEdo+KXOfH83MW2ufvJ7T/7DxNXalpAdWSRXizbDt+r87CfaRgTKPiblZV88il02aOO3XuvA/pzJXYr4G6czKdAFCPsoA/cKnMEf1b8/Um5TjfpvmGUPf1ppTlTTQS0mfUWsQNqPcW3lyoSJr46iRyAqGFdlOfmYkLac62FW48qv06hbGSqjshp7NgNbF4P6+EvuImfwmWTixuxe9wl2LSdkqnS0d6s1LE/1UnuV+X4Xhi6RmQSLF3T/5oQCM4MyqSR5nd/Ad/UCJC4VPI6/Kb/n5uySTTLLMlg7q2yCZcvlhaVL8RHqrOYUX/rfcFYDlJb1P6LuseGiKrv0Vj6INq1femdXd6xeOWVdNf8f6xY58CXykCCoArqxq8+1nihm0G0h3PDY2eCJlB7CNWk7Bzsur5lMRFwWRDWe1jkthuM0mRpmFekqY2xV58Genj8RMYxrajdba7022hNSBOSI1mirILfiROC0+e6Imx8YnrFsy0T80X7P1UACHM DkMlEz5Z 71l9/zIBF1UCt0e66cHeCKY9xLPpB3VvB8sHT2B4J29GRNoKSaIxo9Y5cpzXaPDTdt0Puhpgy1xXFLPUdYtGrQP9Y7pFdPEhINXBWrOu7JlwnhNdnXP1Wqq0YAn4F2H+dnyMlBVViMd85lPCyoCbpBETeiKcpuWafG5zXThASkiu3n7g2fUCuPGrnOsejm/6cHk9RjnEAQAveoQP//fxckS2o8qbtF4UTy4hn 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 Thu, Aug 29, 2024 at 10:36:01AM GMT, Muchun Song wrote: > > > > On Aug 29, 2024, at 03:03, Shakeel Butt wrote: > > > > Hi Muchun, > > > > On Wed, Aug 28, 2024 at 10:36:06AM GMT, Muchun Song wrote: > >> > >> > >>> On Aug 28, 2024, at 01:23, Shakeel Butt wrote: > >>> > > [...] > >>>> > >>>> Does it handle the case of a too-big-to-be-a-slab-object allocation? > >>>> I think it's better to handle it properly. Also, why return false here? > >>>> > >>> > >>> Yes I will fix the too-big-to-be-a-slab-object allocations. I presume I > >>> should just follow the kfree() hanlding on !folio_test_slab() i.e. that > >>> the given object is the large or too-big-to-be-a-slab-object. > >> > >> Hi Shakeel, > >> > >> If we decide to do this, I suppose you will use memcg_kmem_charge_page > >> to charge big-object. To be consistent, I suggest renaming kmem_cache_charge > >> to memcg_kmem_charge to handle both slab object and big-object. And I saw > >> all the functions related to object charging is moved to memcontrol.c (e.g. > >> __memcg_slab_post_alloc_hook), so maybe we should also do this for > >> memcg_kmem_charge? > >> > > > > If I understand you correctly, you are suggesting to handle the general > > kmem charging and slab's large kmalloc (size > KMALLOC_MAX_CACHE_SIZE) > > together with memcg_kmem_charge(). However that is not possible due to > > slab path updating NR_SLAB_UNRECLAIMABLE_B stats while no updates for > > this stat in the general kmem charging path (__memcg_kmem_charge_page in > > page allocation code path). > > > > Also this general kmem charging path is used by many other users like > > vmalloc, kernel stack and thus we can not just plainly stuck updates to > > NR_SLAB_UNRECLAIMABLE_B in that path. > > Sorry, maybe I am not clear . To make sure we are on the same page, let > me clarify my thought. In your v2, I thought if we can rename > kmem_cache_charge() to memcg_kmem_charge() since kmem_cache_charge() > already has handled both big-slab-object (size > KMALLOC_MAX_CACHE_SIZE) > and small-slab-object cases. You know, we have a function of > memcg_kmem_charge_page() which could be used for charging big-slab-object > but not small-slab-object. So I thought maybe memcg_kmem_charge() is a > good name for it to handle both cases. And if we do this, how about moving > this new function to memcontrol.c since all memcg charging functions are > moved to memcontrol.c instead of slub.c. > Oh you want the core function to be in memcontrol.c. I don't have any strong opinion where the code should exist but I do want the interface to still be kmem_cache_charge() because that is what we are providing to the users which charging slab objects. Yes some of those might be big-slab-objects but that is transparent to the users. Anyways, for now I will go with my current approach but on the followup will explore and discuss with you on which code should exist in which file. I hope that is acceptable to you. thanks, Shakeel