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 6EED2CA0ECB for ; Fri, 30 Aug 2024 06:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD36B6B0098; Fri, 30 Aug 2024 02:10:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5C5B6B00C2; Fri, 30 Aug 2024 02:10:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD5466B00C3; Fri, 30 Aug 2024 02:10:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9B5A66B0098 for ; Fri, 30 Aug 2024 02:10:43 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 45F3481498 for ; Fri, 30 Aug 2024 06:10:43 +0000 (UTC) X-FDA: 82507887966.20.E011448 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) by imf18.hostedemail.com (Postfix) with ESMTP id 4190F1C001C for ; Fri, 30 Aug 2024 06:10:41 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Wigjlgn+; spf=pass (imf18.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=muchun.song@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=1724998153; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nkHJbeEg0+QEjgdCbTpKvNB45+hmK9J6uhHUFwVHosU=; b=2QDGq4LAZ6QiXGrf7tDeHpQJTU662abB2fRu+MCIVRLCyfWLUA+MByY+Z56Sj6OXdAsEWy of3rUou9wPO9uGP9NsDHlJw0XffetHQJPw1fjGcKPekT034cy3A4zSI7C/JEXKSmF5H/2Z bmh0WL6xSv1m+Kcr66vr+dHjAJV5zb0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724998153; a=rsa-sha256; cv=none; b=ttiurGSP2ka9H08NEO767L05K78mnM6g/o1yTYNwX5bwj9GiEBJRA/cErYGDRzDP0CVhqX AhYiIKD3PdDMqYUh9g8sbBw2DU62c8OGL9lghmvoVtC8Qb9Pa8FRcadm/5U90sAQmH/uMq tcNidx48Gv8FKQuDEoFRYavWQ7NmoPc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Wigjlgn+; spf=pass (imf18.hostedemail.com: domain of muchun.song@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724998239; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nkHJbeEg0+QEjgdCbTpKvNB45+hmK9J6uhHUFwVHosU=; b=Wigjlgn+sIZ3NIO96mtgt0axwGAJBzKGSc1KMvciFjPOCGlYdCNu5D48n351f/f7R7IK5S 4xp05lYeArtrcngFl+gGUYx7YKrPOMOUPi0fGuzMKMRM7eIPyBsxEMxsffQQm5bZ2QJIu3 XSPiLgY/5PlPdxI00yzLKHgZfuUGY2E= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: [PATCH v1] memcg: add charging of already allocated slab objects X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: Date: Fri, 30 Aug 2024 14:09:57 +0800 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 Content-Transfer-Encoding: quoted-printable Message-Id: <6088647D-147A-4704-BBA1-8CEDEDAE2885@linux.dev> References: <20240826232908.4076417-1-shakeel.butt@linux.dev> <97F404E9-C3C2-4BD2-9539-C40237E71B2B@linux.dev> To: Shakeel Butt X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 4190F1C001C X-Stat-Signature: 5tihouhj1kb8wj3dbwd4hnqoryks4daf X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724998241-69826 X-HE-Meta: U2FsdGVkX18NlRIK517eFF2Irv2fstI6h/OiJztopieQPhDqmJfs3kSeVYgfHbv+TkJNOlhKDQDWoS9G82NWZ3D1wT8L2cjQyWHc6fslD7afutbQZQSM4SDfJbUq/xQEkFqf/KPuQuoanLdDDkFOjrKeqKdv/fqSiu0LwDHlPRm6jONN8fk1YiKpZdMWUSdFT+oEfJ5oocMKr9ITS0zSOekgGPA4wty/KBwDxdvsXVyvGgYrIW5eAJisffQVGv1XA3NLW6D6NFuSQ5NQtWeLQS549N6RV+ZaaPWe5U5YxLtiAqecmkdSa/tWJXmgrUmB3VlJsYIjff71nJBfBQQurbTm+pbcAzmPfPPyR25n7mFo34ahkKXbWUlC1eymr8ilN6qDMWkVOrShC18RIra3TQqfgGyS7iWManARfENGmG8SXEg4iHK1mM41rIvgvJoCs7b/6Qqe04dF/1p9Yb4PPS/V/2Z0t7t28i+WyJzX2LJqyY9zONWc66l5YUoDJuzslTLqIXTFLO1fTPnEzhxy2JDEag5XJkfED1DZoQLHrsWqE/EgAjyTW+FYO1okqM/UvH644ldFiGQHrYDOB2WzZyyTwNgxFU+m0IC6lB3LRuMmJvAxg1Tc9EOHXnb9gBF60gCJuJ3s9Afl8/v9jFvFX3/SMI1Cxxk4NvRX64h+aWVVQDyHZ5khn737JolMK0uehVu885HtHCfKYz2taaG6eJwgtjCTjPp2NRXAoaNdH3EMmNFekBGnkurD4boI0JytJCkPwd2ngPZ9HxDaFxNedAoJM+rZHJWYg6PKEFhgUZRX4iShlkmnO7I2n+wWrWpkkh0pOWi+FYUwSxr40BSqRYZfoZaqWscoRobDc781zlAsvoBacSnp5Pi448AZh49ivHvLUbiDyv41TzXK+vc+9AjiMZhHYePY9bTJvNFmWeai9WioCDuvKa2P6mJ1thRV1nqQbZR06VmS15uRBeW h9AIGpY8 FbHyi9zb7RKeMar5IBTkcq0IJ2MPYYuKlCWGKUhW9rIiElgKWD9/ixIaSIalg+Kn1blAwd6RRcKCnkqN/IMhRfhkVl8dgDY8ZotIDB8VH7YEhj6F4crNsSGSLujPNvKljC9iBq8Soh9jYHpVQxg3hGC9yrXdu3VOArK6b7cu95NezhkvO5ONd9uTgSpmndJmEpGy017FQpqbL3l6T84LWDowJsg9lng5TcXGgl3763J1/D+VhncgeARIyGQ== 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 Aug 29, 2024, at 23:49, Shakeel Butt = wrote: >=20 > On Thu, Aug 29, 2024 at 10:36:01AM GMT, Muchun Song wrote: >>=20 >>=20 >>> On Aug 29, 2024, at 03:03, Shakeel Butt = wrote: >>>=20 >>> Hi Muchun, >>>=20 >>> On Wed, Aug 28, 2024 at 10:36:06AM GMT, Muchun Song wrote: >>>>=20 >>>>=20 >>>>> On Aug 28, 2024, at 01:23, Shakeel Butt = wrote: >>>>>=20 >>> [...] >>>>>>=20 >>>>>> 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? >>>>>>=20 >>>>>=20 >>>>> 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. >>>>=20 >>>> Hi Shakeel, >>>>=20 >>>> 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? >>>>=20 >>>=20 >>> 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). >>>=20 >>> 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. >>=20 >> 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. >>=20 >=20 > 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. >=20 > 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. Fine. No problem. Thanks. >=20 > thanks, > Shakeel