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 D1615C47DD9 for ; Sun, 24 Mar 2024 17:45:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFEEC6B0082; Sun, 24 Mar 2024 13:45:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAEAF6B0083; Sun, 24 Mar 2024 13:45:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94F536B0085; Sun, 24 Mar 2024 13:45:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 825D46B0082 for ; Sun, 24 Mar 2024 13:45:02 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9EF00160542 for ; Sun, 24 Mar 2024 17:45:01 +0000 (UTC) X-FDA: 81932658402.07.D0B0D5A Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf25.hostedemail.com (Postfix) with ESMTP id 75549A0023 for ; Sun, 24 Mar 2024 17:44:58 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=bn5+GvQd; dmarc=none; spf=pass (imf25.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.169 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711302298; 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=oe6GIQzO/C567doEXwsmBSySXlt6oy2RX728KJkYzKg=; b=0DRuM9i0DIokpStSTKXbRDAyUl7S8O7jRB77A6lwyBRu0Ww7Js1sxSdVm3jQMgjl9KlWaF 52um24n1/fbKsCktAuU6YrfQOh9EyEOhJZHo0bStM4VWB4jSFQomKCX+0ev0DYiaFOPEOJ GSZij2ko7p2rcY358hdhZXZLaYEbRRE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=bn5+GvQd; dmarc=none; spf=pass (imf25.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.169 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711302298; a=rsa-sha256; cv=none; b=2JU+iBE1Pg8c1mlQhXithpd0y3cD8FPBcHAj/SMeLEwWjt5ROk2gf9kypGR2lkjnu8FzF1 SDlFmVilekEKb7zJEN9zH3uh09oQ0Qx+di3MouAk15ADHvhj1pYGFkiW9OHf98arQs4IAJ M43i1T3ehfv6hcU36akYOGrFQQpvdBo= Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d485886545so64560481fa.2 for ; Sun, 24 Mar 2024 10:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1711302296; x=1711907096; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=oe6GIQzO/C567doEXwsmBSySXlt6oy2RX728KJkYzKg=; b=bn5+GvQdq8WdwZyzrCIETm505HyzVxjfMofmtK9BdLTeMk6S2hG9amEq/YlXP7Usle P1jCtJkuJw9CuI48tShRWgjTGwYkATIZ14KMfBlRqWwV8wV8ICl3NhZ3OXyBMP4vgFNb 9e8aAmqGx5YYBTRjyV28DH9J8fvaim5cfwIJ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711302296; x=1711907096; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oe6GIQzO/C567doEXwsmBSySXlt6oy2RX728KJkYzKg=; b=L/oQ5yER/Jj4eaGHlYQE7L+KyGEkJhWZ53Ap5R6PIAxOpJVVYO58vBustHGNKaMQBn /MzpD9KD4/dC7X3w60J6Hy96X1uCl29y/j9t98s2qkC2PBJN9R1MiqjOBBe8pyyGVy5v +vwhbLE94pzIBpRsHM1AVtMAbZeayWH2pnMH/sOVOIJgQ0HKZJmIOyJ0klocJw//qTId 0YACO2MFVlRgIg35m9Je3fFzSIJG3IA82KZMTzB1/9DfpEigJzV8cHV4EA5t/1T6YK8M rA7idKYWf8UtTe8raVnlIYBGRsg/aqSpFYMc7Ii+3dncFDFyGMMgdz7tj+LYJ+VkpmBT 4a9g== X-Forwarded-Encrypted: i=1; AJvYcCXA8wtGbDCKfjqhGNRBQpR41wtcIouC8m6CPkOGpUpbUobp7Yil0JekoyFUztJtw0IV4U+tlxTFmRiWT4G9iQPrRoA= X-Gm-Message-State: AOJu0Yxm4LCd1JytqmLvoHvQdvZxnDbEs/1Omk3Jj0r6eone1Wb7ngsu iSAN9/PZOT3EtU3D1PseqV4we08SyOzY45qFP1NlNEUMdwCjEFE0eHpTxlqF1KOQ6V9h6a62TQD oLEbvrw== X-Google-Smtp-Source: AGHT+IH3x2E1+NSfHn0/i2F9/qRu8/y43wUw0m/F7AzjACBmtxwEDgcq61FfaDr+XxkvBbSSsjEz/A== X-Received: by 2002:a2e:b74e:0:b0:2d4:6a34:97bf with SMTP id k14-20020a2eb74e000000b002d46a3497bfmr3470406ljo.49.1711302296447; Sun, 24 Mar 2024 10:44:56 -0700 (PDT) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com. [209.85.167.43]) by smtp.gmail.com with ESMTPSA id t8-20020a2e9c48000000b002d48dcd10a9sm1146554ljj.86.2024.03.24.10.44.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 24 Mar 2024 10:44:56 -0700 (PDT) Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-513e6777af4so6630386e87.2 for ; Sun, 24 Mar 2024 10:44:56 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXvcnF9BRovK+amjQSiGKTjIvUPxprCaDgV/y4Nx+c+o+N9jT6BW4lqNa+8cN6bSqs6HZWUFjejB9sOKsR6Z98xP70= X-Received: by 2002:a19:ca19:0:b0:515:9ce3:daa3 with SMTP id a25-20020a19ca19000000b005159ce3daa3mr3631407lfg.37.1711302295763; Sun, 24 Mar 2024 10:44:55 -0700 (PDT) MIME-Version: 1.0 References: <20240301-slab-memcg-v1-0-359328a46596@suse.cz> <20240301-slab-memcg-v1-4-359328a46596@suse.cz> <20240324022731.GR538574@ZenIV> In-Reply-To: <20240324022731.GR538574@ZenIV> From: Linus Torvalds Date: Sun, 24 Mar 2024 10:44:39 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RFC 4/4] UNFINISHED mm, fs: use kmem_cache_charge() in path_openat() To: Al Viro 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 , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 75549A0023 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: iot7jccn519rx36zipwut7ga7p9dotm1 X-HE-Tag: 1711302298-756585 X-HE-Meta: U2FsdGVkX1+ObRFSEGEjhdU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uEpJ0GMx2SCY7jpcVe70QjpAI7y0ptk7fRVBq4dUqpAUuWNQkDMiyJ8WPLMZ3crEhs0543ldKRx2AFcDBBF6W05rbf+KJSFw7wWMc/wob8kb61pdN9QNrLJwMIU6Y6S3fzW8Wh/SZnq58kwQTkITzqiNbu8HOQsqXe0WMPPmpQrAy/PfEcgKSJn3EyI3b2xkrbrsnoXHUbzS4HM5IBkFr14cciELibk9Ec0v/p0e6l0VO5PzX82mpY8IkcUIse3qm5xKShCjgJqvo2wFcWe99/QiLyqyK3Nuwg/fQZl4Z+V7po/Od/iR7lKuoHx9a4pewynaPZOt2UbKJKq/+G8Ic4kL1MtSTaKAMURwDRQvbHISwT57Di0LVy95dK5fdCLXQa0zTwjLT8Y6ASCIWJmleWErigY56v+1vR/voJRRYd1GDv4giPkAfroIIRTFWKVUhfalET6ij34jn/6U/wHYvphDVbQH9jdFik5vfKnKMFlbt3F20L/KePpIgkajKPvRBLCV+5ITGwbT5m2RhNNUN3ugAUObGSc8qKJ9a3v3yG4w8//ljZSo= 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: [ Al, I hope your email works now ] On Sat, 23 Mar 2024 at 19:27, Al Viro wrote: > > We can have the same file occuring in many slots of many descriptor tables, > obviously. So it would have to be a flag (in ->f_mode?) set by it, for > "someone's already charged for it", or you'll end up with really insane > crap on each fork(), dup(), etc. Nope. That flag already exists in the slab code itself with this patch. The kmem_cache_charge() thing itself just sets the "I'm charged" bit in the slab header, and you're done. Any subsequent fd_install (with dup, or fork or whatever) simply is irrelevant. In fact, dup and fork and friends won't need to worry about this, because they only work on files that have already been installed, so they know the file is already accounted. So it's only the initial open() case that needs to do the kmem_cache_charge() as it does the fd_install. > But there's also MAP_ANON with its setup_shmem_file(), with the resulting > file not going into descriptor tables at all, and that's not a rare thing. Just making alloc_file_pseudo() do a SLAB_ACOUNT should take care of all the normal case. For once, the core allocator is not exposed very much, so we can literally just look at "who does alloc_file*()" and it turns out it's all pretty well abstracted out. So I think it's mainly the three cases of 'alloc_empty_file()' that would be affected and need to check that they actually do the fd_install() (or release it). Everything else should either not account at all (if they know they are doing temporary kernel things), or always account (eg alloc_file_pseudo()). Linus