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 0E026C48BF6 for ; Mon, 4 Mar 2024 12:47:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 786FB6B007D; Mon, 4 Mar 2024 07:47:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 736EB6B007E; Mon, 4 Mar 2024 07:47:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FDC26B0080; Mon, 4 Mar 2024 07:47:56 -0500 (EST) 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 4B31B6B007D for ; Mon, 4 Mar 2024 07:47:56 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1185E1C0A17 for ; Mon, 4 Mar 2024 12:47:56 +0000 (UTC) X-FDA: 81859333752.08.A0FB5EE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 555E01A001A for ; Mon, 4 Mar 2024 12:47:54 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NVj0626x; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709556474; 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=XhsqS1Rj9I9FKqXDCH4/0gEdWhmcOWYGqNACRBYPbdM=; b=oNwbT0u1bzc6YzTX/+OOQQ0M/6OeEurxGIe51JQzq26y+q5LeVou3VnEpszBKcV6cKm6Du ZAvTlJXABPSBDe5rp5NTg0DSOfJdElDDuWpyIE25kgx0FghuNnkEHCCM39rVl0yxnJEjyD XXnUSlWxUdqa9qmDcevfAfgIG6LuU1I= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NVj0626x; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of brauner@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709556474; a=rsa-sha256; cv=none; b=C7Jf8Yt34Qn7pE1l0cWXjJ8PYaPOK+U9WqNkRZTAKpwShGc5mhA5uZC/bNMCRxGiD6h54x 5WyKvtiFD/LGl7IXqJCzEfDOCGxGnJHAqzCHg8mau0ECXxsjYCl46nqOtXH7qX8S0hJFGC 3EAoBRZjIf67HnHHfzc8tIjCRxIDwDs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 612EB6068F; Mon, 4 Mar 2024 12:47:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D93EC433C7; Mon, 4 Mar 2024 12:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709556473; bh=jLz5ELcfTObaRFcBiCY6jXqzV+/2ipsEzVEnweNaefw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NVj0626xPWKm6oCku+qVbL1lqwYTouqrHQCaH3UFjNpYcgerz8YrBQAxVLMUMDzVu 5A3CY7dLUz10f/4pLRxilXh7LkoOU5E2AhJfEuDr5r0NsZ2QULjgK/AEX/4cVXO15z N/4d3xLgdzIl3Oo5SDDPOMTzc1uRRm7QmCHgibWDu2Wf+49YC0k9fSXY9b/VuLgIO4 LKshwUAICdZjbWyf0jSR2lECh+l3LDWx2FvJrYzJI+ObQIdmxJobd6UUaVCRr5uPjO kfCzAaA7gtshaoPK6wL6Kviuof0JMnw+vaX3Tc7QJ4gco6EsYOO0hhOUVlJsSyOvMN RjXYJoVDPbZMg== Date: Mon, 4 Mar 2024 13:47:44 +0100 From: Christian Brauner To: Linus Torvalds Cc: Vlastimil Babka , 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 , Shakeel Butt , Muchun Song , Alexander Viro , Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH RFC 4/4] UNFINISHED mm, fs: use kmem_cache_charge() in path_openat() Message-ID: <20240304-pendant-implantat-4e19caa87151@brauner> References: <20240301-slab-memcg-v1-0-359328a46596@suse.cz> <20240301-slab-memcg-v1-4-359328a46596@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Stat-Signature: cdwghpnuy47uc63zd4skckj8n938yrtk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 555E01A001A X-HE-Tag: 1709556474-160585 X-HE-Meta: U2FsdGVkX19vxlpSg0p9lcIpD0IFKxHdz2kxnT0pfl87F86oJI/JPvYodNaGEuyVYtsIsnlTe+pJ6PZGLjeP6LA06IwRMEs5IAme0UBDImga1I4EQCuvLh7z/OEwguFzRALO49UoANFRqadNNmYg7d5FxhJ8guKpZgf/+mjyYhLEzgNpwWvO1Ki8gY/v6GDtgno4+Mr3royq6FGrVr7K7D1iD/Zo2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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, Mar 01, 2024 at 09:51:18AM -0800, Linus Torvalds wrote: > On Fri, 1 Mar 2024 at 09:07, Vlastimil Babka wrote: > > > > This is just an example of using the kmem_cache_charge() API. I think > > it's placed in a place that's applicable for Linus's example [1] > > although he mentions do_dentry_open() - I have followed from strace() > > showing openat(2) to path_openat() doing the alloc_empty_file(). > > Thanks. This is not the right patch, but yes, patches 1-3 look very nice to me. > > > The idea is that filp_cachep stops being SLAB_ACCOUNT. Allocations that > > want to be accounted immediately can use GFP_KERNEL_ACCOUNT. I did that > > in alloc_empty_file_noaccount() (despite the contradictory name but the > > noaccount refers to something else, right?) as IIUC it's about > > kernel-internal opens. > > Yeah, the "noaccount" function is about not accounting it towards nr_files. > That said, I don't think it necessarily needs to do the memory > accounting either - it's literally for cases where we're never going > to install the file descriptor in any user space. Exactly. > Your change to use GFP_KERNEL_ACCOUNT isn't exactly wrong, but I don't > think it's really the right thing either, because > > > Why is this unfinished: > > > > - there are other callers of alloc_empty_file() which I didn't adjust so > > they simply became memcg-unaccounted. I haven't investigated for which > > ones it would make also sense to separate the allocation and accounting. > > Maybe alloc_empty_file() would need to get a parameter to control > > this. > > Right. I think the natural and logical way to deal with this is to > just say "we account when we add the file to the fdtable". > IOW, just have fd_install() do it. That's the really natural point, > and also makes it very logical why alloc_empty_file_noaccount() > wouldn't need to do the GFP_KERNEL_ACCOUNT. > > > - I don't know how to properly unwind the accounting failure case. It > > seems like a new case because when we succeed the open, there's no > > further error path at least in path_openat(). > > Yeah, let me think about this part. Becasue fd_install() is the right > point, but that too does not really allow for error handling. > > Yes, we could close things and fail it, but it really is much too late > at this point. It would also mean massaging 100+ callsites. And having a non-subsystems specific failure step between file allocation, fd reservation and fd_install() would be awkward and an invitation for bugs. > What I *think* I'd want for this case is > > (a) allow the accounting to go over by a bit > > (b) make sure there's a cheap way to ask (before) about "did we go > over the limit" > > IOW, the accounting never needed to be byte-accurate to begin with, > and making it fail (cheaply and early) on the next file allocation is > fine. I think that's a good idea.