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 5CC28E6FE41 for ; Fri, 6 Sep 2024 19:04:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B02976B0085; Fri, 6 Sep 2024 15:04:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A645D6B0088; Fri, 6 Sep 2024 15:04:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DED96B0089; Fri, 6 Sep 2024 15:04:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6E9C96B0085 for ; Fri, 6 Sep 2024 15:04:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E6736120FE0 for ; Fri, 6 Sep 2024 19:04:39 +0000 (UTC) X-FDA: 82535239878.17.4A470E9 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by imf12.hostedemail.com (Postfix) with ESMTP id 040734001A for ; Fri, 6 Sep 2024 19:04:37 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=HuSBnH3k; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725649398; a=rsa-sha256; cv=none; b=wVRH6iCgtQd8YgtVonKEnOOcXsj1YwOwuQPbPxZTdflwuN5V7/TDDi0d9RDrZdHiuybZaT 3wisjEYyS9LYuiBCANhUelDQV7vWP3S9cuBHLIbXojZMNida4mhUdepWy+xcDlb+7nZTnH apQSb04nHR8nsBP8czmGZBveGsZSY7A= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=HuSBnH3k; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.179 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=1725649398; 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=yGhIrh+rQpPnyonW7hAs/7/T5yo5hXID+LB/v3yhQQA=; b=QeYa7dTmSE8iD3NO+TMCTW2eVYahT4EzjAdmVE4wnilLHOeU6U6PsPQQWp8eDJQgPw/F3R NM6qXw0d4pTqOxX35l1uc8ah6trXlsxraTooOeDCwWcZUPeP1cesXjcCI3/fgA5Ft2tLmX nnojZTeefItcyhO8za+Q4AywLI11d4A= Date: Fri, 6 Sep 2024 12:04:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1725649475; 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=yGhIrh+rQpPnyonW7hAs/7/T5yo5hXID+LB/v3yhQQA=; b=HuSBnH3k4p4CRY+caXHgDwk0PA1jBcjQKJJZsfnO1tGxmb1w1xQFavKHbW0iknuQJ1THdd p63X1WHVfhVLaAYVFzrwOTtA4Rr8rh7kjsEjmDKOPBRejuI9e25HjWbQIY/YpiBKO5afSP EmNB3vZlMoLDxc0UMboZCcZ1yfPhOh4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Vlastimil Babka Cc: Yosry Ahmed , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , David Rientjes , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Eric Dumazet , "David S . Miller" , Jakub Kicinski , Paolo Abeni , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , cgroups@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH v4] memcg: add charging of already allocated slab objects Message-ID: References: <20240905173422.1565480-1-shakeel.butt@linux.dev> <572688a7-8719-4f94-a5cd-e726486c757d@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 040734001A X-Stat-Signature: 6eicfzmrhg8qjgw8t3nre8x6dj6qdng1 X-Rspam-User: X-HE-Tag: 1725649477-118475 X-HE-Meta: U2FsdGVkX18BPqakmKFgwJ4mOnwjTf/7YV0froxCI6bTGIZlUcTHIKaiZTdsdEVwlO3wl6KFoszkJYBQEHdO1LbpbstHewStsdXgD2gZbFn7bIG+penZuEyQhmZwutwcooSOOhW3gE25KhP9j9rs4pS+HG/wDp8WZM4IhGYNSVb0KIqniW2J+SfUCUg18uBBd0UTGUqBnz7l8tCHkbErmgKwS/NvY0VMx3Vxi1wJyxALa2XLjsXN17XWuUuf7Tt1cDgTYikcDF5A9+xD1Yr6QWFDjFYb3JbUs18EaiT4+rcu759DTd7qqaS4zJvFGCcn4Byw7Qa4eCAPLi/grdjgp4TCcE4JLqwk5UGX1fyUYmQKPITjCjeCnyrx0qAMEDgopEp3MUeY9qax+z1Y8oYDQ3G4tqiPfyB36Aqk+rS2JYAkQZn2qyOGLCE4skYu/4nbF91jWjySZztvXiaB2yjO6Cob/92d8See7JK1vqoIR4Q1QQoW2YswbftBG5I0Gzj0S7M5PTpTlJzzlgV4k/4VqlFLliFB0jy62gTvyZzfsd3NERr6lZ95i1P2IZjh5WKcTnlTnvjXaZ4gLucwMZwsX0/mbo6JUiPYt6MtsNVpykQ7sJO4fW0je7WUfdlvnCi5zr5AcrkQl7CBQUGCfQW4rXQoAPCUGvb+lEl3VdjKyY5h8t7jWEUh617CHuAN9CmfNhhQiC9Q617pZIZeISO1B6vrRPutaiH68XgQftcmThZiv1i92mI3c5UTBUxKIoPM096ewjoVr8cBb4XBQoRrEFlNm2qdHDDf3ZXXYaanM2vz/MjVQeff/QRv3fy7Rg0/KRjkRYDqCI2+FCwGj85QtdrML9fzetNVxHX+axEEXAKmnL3EAuwlLlGy2PI1IJNgj4F9CkgMchorx1cC2zEiTpD6oCdCc9I+YdN08K/2dP++qNoCRGfSsYJqShpjmfOnif0mdfoGmjb88m5SDDl aRhcMitJ 12j+XkTP0V+1tgNcuowMal0dmVdK9x1T6V4M8LuVAHKAgozVfFjfy3YVSbFV8UrtCJDmfPNC3tILgVF0dg4sFkdNYarhV8H0E1M28ky7eqYrWSh5CjA33dm/5Yp0drdSThlFRcj8ozD9inztZMdjcDWX8WCkwwBswEFyeVK1Ko3CcVSY9qDWadcfF8g== 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 Fri, Sep 06, 2024 at 07:28:56PM GMT, Vlastimil Babka wrote: > On 9/6/24 19:19, Yosry Ahmed wrote: > > [..] > >> I felt it could be improved more, so ended up with this. Thoughts? > >> > >> /** > >> * kmem_cache_charge - memcg charge an already allocated slab memory > >> * @objp: address of the slab object to memcg charge > >> * @gfpflags: describe the allocation context > >> * > >> * kmem_cache_charge allows charging a slab object to the current memcg, > >> * primarily in cases where charging at allocation time might not be possible > >> * because the target memcg is not known (i.e. softirq context) > >> * > >> * The objp should be pointer returned by the slab allocator functions like > >> * kmalloc (with __GFP_ACCOUNT in flags) or kmem_cache_alloc. The memcg charge > > > > Aren't allocations done with kmalloc(__GFP_ACCOUNT) already accounted? > > Why would we need to call kmem_cache_charge() for those? > > AFAIU current_obj_cgroup() returns NULL because we're in the interrupt > context and no remote memcg context has been set. Thus the charging is > skipped. The patch commit log describes such scenario for network receive. > But in case of kmalloc() the allocation must have been still attempted with > __GFP_ACCOUNT so a kmalloc-cg cache is used even if the charging fails. > > If there's another usage for kmem_cache_charge() where the memcg is > available but we don't want to charge immediately on purpose (such as the > Linus' idea for struct file), we might need to find another way to tell > kmalloc() to use the kmalloc-cg cache but not charge immediately... > For the struct file, we already have a dedicated kmem_cache (filp_cachep), so no additional handling would be needed. However in future we might have cases where we want the kmalloc allocations to happen from non-normal kmalloc caches and then we can add mechanism to support such cases.