Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7371732rwr; Tue, 2 May 2023 13:44:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ602IUez91qNjbz/TvhczGTHX67+eEKsu5J/5FToLq0ZOl5FeFdcEW/Ug+DCdbC8m+O6SFU X-Received: by 2002:a17:90a:1503:b0:24e:1f14:991e with SMTP id l3-20020a17090a150300b0024e1f14991emr4500673pja.36.1683060280472; Tue, 02 May 2023 13:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683060280; cv=none; d=google.com; s=arc-20160816; b=PKQvxGdN99sIACxjqHIZHKLte5uynKUMlHtzjjXZaAa+rsvMTQwkGHAJ/fZCgZ/XPF ipuDBGfhKDaQWM6w+ekmUjxyRkVm0hDaad3cqIFsUEwfxY/84B8FR8lQBc5qSQ+RiBct SrBZ1HyU+z7CNajkN+uIf/qPm30fD3W4GKIzWAzEqaxLjiZR0sIsFuXme2I7nap3lk1r Ch17Iu3mUmPT+4WYMPkvt6igo4raNsZJB5KdS2IIlk0dvrXFTScefYONEiI5STGzbGt/ TErOrh3s9hAZ0nNHbrpn2Y21ELuOdPGDno7RS+37TbOZDM7sF8+XuNUARiaRBJPJa/YO +xMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=NjplYaLubWQQ5jZtL2++PWvD8pdyHWDOHPxaofdWA4k=; b=bXPCNy/G3y8da7rso5yu9g55yJRMGYkc8p9mi2LVfj3kuEhiFBeKMCac90f6n4qTfN MbVl6FXjtGQt85mfxFZTullDiQl/MHZqkqJ88FEs+aK3ciBbhDf7EjsRYBz1nz1C8Ijl eCnn3xfkh+ryAaGsFr/OwwYRIY09KYb5P4dnQRf9NpajkJ0CjMLBj10UrkAIF/2CqiTb /4yYoQM4w/w5kKidp9EaHYS4tWVXf2Eg+b5Hh205I+eQ/pqBDFwAxkli2M86/P9ndFf7 FVdcmfzLAt/4vTfSh5c/LNhLy7wM0zw+Beefwpd3+BbhCPf74iXBPcCauRc5mR9JmsDD NoUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=nPG1qjOr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a17090acf8d00b00246cad7fab9si11910993pju.180.2023.05.02.13.44.26; Tue, 02 May 2023 13:44:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@tesarici.cz header.s=mail header.b=nPG1qjOr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tesarici.cz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjEBUUu (ORCPT + 99 others); Tue, 2 May 2023 16:20:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbjEBUUs (ORCPT ); Tue, 2 May 2023 16:20:48 -0400 Received: from bee.tesarici.cz (bee.tesarici.cz [IPv6:2a03:3b40:fe:2d4::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 635F310FF; Tue, 2 May 2023 13:20:43 -0700 (PDT) Received: from meshulam.tesarici.cz (nat-97.starnet.cz [178.255.168.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bee.tesarici.cz (Postfix) with ESMTPSA id 6FA1714DA42; Tue, 2 May 2023 22:20:39 +0200 (CEST) Authentication-Results: mail.tesarici.cz; dmarc=fail (p=none dis=none) header.from=tesarici.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tesarici.cz; s=mail; t=1683058840; bh=c6+AjJZEdge9Ayz4MLe/nHAKX7Tv0/ZFK/0DiJPO/9k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nPG1qjOr7v6urxTa/dDsxEUlZEa5MDcMqqkvEnzLRd+gOpEDFo3qmkwegYOYej8ZD QTjGWTTox7AQ163g0WgPoZ5rP6EuCPxbnvCFDJub2qlRJj3nCyaLkJ3lmzrYjeUvoJ I4fMaBworaYA333m1PUKTtEiXnPqJC5rCYzJY9jQ2/pvFI2SR3TudZyUI/BtIkzm4K RDtJZNtPk/NZIgn2bz3E8SWJfhfoXpuuXFbWhWc7sUo1cnDE41kYe6YEm0R6gS9db+ etfaPN6CirTgig9v30TjT9Ua3hv9pvMHL0OJQdrDWCwq0nkICa5BEM3ApRSc5Jx6zl 4Oj1rVA8EEZtw== Date: Tue, 2 May 2023 22:20:38 +0200 From: Petr =?UTF-8?B?VGVzYcWZw61r?= To: Kent Overstreet Cc: Suren Baghdasaryan , akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, ldufour@linux.ibm.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org, Alexander Viro Subject: Re: [PATCH 03/40] fs: Convert alloc_inode_sb() to a macro Message-ID: <20230502222038.57a47a85@meshulam.tesarici.cz> In-Reply-To: References: <20230501165450.15352-1-surenb@google.com> <20230501165450.15352-4-surenb@google.com> <20230502143530.1586e287@meshulam.tesarici.cz> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2 May 2023 15:57:51 -0400 Kent Overstreet wrote: > On Tue, May 02, 2023 at 02:35:30PM +0200, Petr Tesa=C5=99=C3=ADk wrote: > > On Mon, 1 May 2023 09:54:13 -0700 > > Suren Baghdasaryan wrote: > > =20 > > > From: Kent Overstreet > > >=20 > > > We're introducing alloc tagging, which tracks memory allocations by > > > callsite. Converting alloc_inode_sb() to a macro means allocations wi= ll > > > be tracked by its caller, which is a bit more useful. > > >=20 > > > Signed-off-by: Kent Overstreet > > > Signed-off-by: Suren Baghdasaryan > > > Cc: Alexander Viro > > > --- > > > include/linux/fs.h | 6 +----- > > > 1 file changed, 1 insertion(+), 5 deletions(-) > > >=20 > > > diff --git a/include/linux/fs.h b/include/linux/fs.h > > > index 21a981680856..4905ce14db0b 100644 > > > --- a/include/linux/fs.h > > > +++ b/include/linux/fs.h > > > @@ -2699,11 +2699,7 @@ int setattr_should_drop_sgid(struct mnt_idmap = *idmap, > > > * This must be used for allocating filesystems specific inodes to s= et > > > * up the inode reclaim context correctly. > > > */ > > > -static inline void * > > > -alloc_inode_sb(struct super_block *sb, struct kmem_cache *cache, gfp= _t gfp) > > > -{ > > > - return kmem_cache_alloc_lru(cache, &sb->s_inode_lru, gfp); > > > -} > > > +#define alloc_inode_sb(_sb, _cache, _gfp) kmem_cache_alloc_lru(_cach= e, &_sb->s_inode_lru, _gfp) =20 > >=20 > > Honestly, I don't like this change. In general, pre-processor macros > > are ugly and error-prone. =20 >=20 > It's a one line macro, it's fine. It's not the same. A macro effectively adds a keyword, because it gets expanded regardless of context; for example, you can't declare a local variable called alloc_inode_sb, and the compiler errors may be quite confusing at first. See also the discussion about patch 19/40 in this series. > > Besides, it works for you only because __kmem_cache_alloc_lru() is > > declared __always_inline (unless CONFIG_SLUB_TINY is defined, but then > > you probably don't want the tracking either). In any case, it's going > > to be difficult for people to understand why and how this works. =20 >=20 > I think you must be confused. kmem_cache_alloc_lru() is a macro, and we > need that macro to be expanded at the alloc_inode_sb() callsite. It's > got nothing to do with whether or not __kmem_cache_alloc_lru() is inline > or not. Oh no, I am not confused. Look at the definition of kmem_cache_alloc_lru(): void *kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru, gfp_t gfpflags) { return __kmem_cache_alloc_lru(s, lru, gfpflags); } See? No _RET_IP_ here. That's because it's here: static __fastpath_inline void *__kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru, gfp_t gfpflags) { void *ret =3D slab_alloc(s, lru, gfpflags, _RET_IP_, s->object_size); trace_kmem_cache_alloc(_RET_IP_, ret, s, gfpflags, NUMA_NO_NODE); return ret; } Now, if __kmem_cache_alloc_lru() is not inlined, then this _RET_IP_ will be somewhere inside kmem_cache_alloc_lru(), which is not very useful. But what is __fastpath_inline? Well, it depends: #ifndef CONFIG_SLUB_TINY #define __fastpath_inline __always_inline #else #define __fastpath_inline #endif In short, if CONFIG_SLUB_TINY is defined, it's up to the C compiler whether __kmem_cache_alloc_lru() is inlined or not. > > If the actual caller of alloc_inode_sb() is needed, I'd rather add it > > as a parameter and pass down _RET_IP_ explicitly here. =20 >=20 > That approach was considered, but adding an ip parameter to every memory > allocation function would've been far more churn. See my reply to patch 19/40. Rename the original function, but add an __always_inline function with the original signature, and let it take care of _RET_IP_. Petr T