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 6D8CEC25B78 for ; Tue, 28 May 2024 12:03:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB1EA6B0095; Tue, 28 May 2024 08:03:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E62336B0098; Tue, 28 May 2024 08:03:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D29D26B0099; Tue, 28 May 2024 08:03:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B5E466B0095 for ; Tue, 28 May 2024 08:03:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4AA6D1404AD for ; Tue, 28 May 2024 12:03:32 +0000 (UTC) X-FDA: 82167669864.07.7974BEE Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by imf10.hostedemail.com (Postfix) with ESMTP id 0EE1BC0031 for ; Tue, 28 May 2024 12:03:29 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RwvmVixx; spf=pass (imf10.hostedemail.com: domain of urezki@gmail.com designates 209.85.208.179 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716897810; 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=R8Bcb+tJI9CaJKfaspgOHTiOBQF++jxzyxHUR5Y5tUM=; b=FJxiksOdOzXIB7vSDFfoBvNowUsp9rYUk+qyfGnESroqkNIp5ZGUT5VcFLWy5+uCWgH9Px bVMMLZRAov3mz6HOiqHx8ATR+14ZryTgY6bda+u/tdp9LS1WaURBGyUI+Ujj0nuCe+8QVS 2b8yhxY2ys3JO+duUW9qZmHtmcZazIo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716897810; a=rsa-sha256; cv=none; b=MQSU4tOn8Im2qB4nEoPujXHSMRhTY3k9XsePOPgj3lLQfHdNdE5gLKSO5TdzOgqnSyfctb scj9SpGa8IpgX283EWV9GO60dlmJf58I2u5CA30GUq+7FHuXGp5eqhoXZ0NIHuMK0ouSVI GriPGIgVICCHwkRMliZ+Rf4Vd2KmX0o= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RwvmVixx; spf=pass (imf10.hostedemail.com: domain of urezki@gmail.com designates 209.85.208.179 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2e724bc46c4so7434091fa.2 for ; Tue, 28 May 2024 05:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716897808; x=1717502608; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=R8Bcb+tJI9CaJKfaspgOHTiOBQF++jxzyxHUR5Y5tUM=; b=RwvmVixx51tlBRmjOgFj0VTEuPAzSveR498tdhIsx63r0dxVpNF/t/xx6WiTOIDAIj YAsBlg7zOuHeHUmYFNUMQ8ZjIkA6folHOnrE1ftCyrQaJKtTMW9F0FXbRvQjOQIHgNam ObYOanNjAFYJnMe1iQhEikh/nCgJxeKPcfxNta/bfQAM9iLNi92sDdobSpaO6aRZWUIc D6eSDdsfOOkUrWWPadj6iU1enqhzY82o87da7Wi3e9CkxRZII0o+p2RDs8Of0Vacunnx dbSvmOy8Xe4DNyZ3VcqD0i7yVFMiUDo/G9yBdryo8D9azR9gcPz5HwdiZAhJjY3jKbRU Vmbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716897808; x=1717502608; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=R8Bcb+tJI9CaJKfaspgOHTiOBQF++jxzyxHUR5Y5tUM=; b=coRozgLBL3rkQzm8L8tGzGz5r71WyJfZPtBTHKZquCvByh4UcyxDE6gLyjqcnBq3Gz FpAwSgra2dg/riUqpSNfijuJ24wtpANXw0qi7KxL/99yEFJATFBETyGCKs7kHxqzUr7K ai3ir0bFyax6pOVNXAm7aJGGvd8RlBysPZ3l5Y1eof7NhWUtUfPso81tWARUOYidS32U NGQZY5F65fWUzszKoJYzX7U2Q+q6b8OckTdj5MT6GlGigPG34ZHCP09mLxn1mCyAegUe 0DaAH5OSsCIlQGD9bOQ1JqZXYXvz11E/hiNcL8lKlCuxEBERQFSOIWQwNN0SKloHALLW i68g== X-Forwarded-Encrypted: i=1; AJvYcCWRcDJBaPqx+AHvnEmLZBn56ty8jXml0IzWFVHn5+hMc0nlL/FXBSV57VDbH5h4FPZUBeC2SsjoY1B3rmYbA7XWRAY= X-Gm-Message-State: AOJu0YynPBjJetO6FAhVtUqM9D0YmbnVskOdiCcAxZGIfvYxUfAgCIed hdU87ZMVFvsRrp/3bPa0tdr0JtqRrWcmCtvKLCqN5LeA52Jz8tTg X-Google-Smtp-Source: AGHT+IFhc0q6fLKGmGcPnwrDiqp9b6C3AO8YZ/nh8PZIVQx8SvxLDWHJM0kS61lQx+h1F+g4l+WkQg== X-Received: by 2002:a2e:9101:0:b0:2e8:10ca:2437 with SMTP id 38308e7fff4ca-2e95b2db206mr72027361fa.50.1716897807830; Tue, 28 May 2024 05:03:27 -0700 (PDT) Received: from pc636 (host-95-193-70-101.mobileonline.telia.com. [95.193.70.101]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2e95bcc4a9esm22494371fa.16.2024.05.28.05.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 05:03:27 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Tue, 28 May 2024 14:03:25 +0200 To: Julia Lawall Cc: "Paul E. McKenney" , Vlastimil Babka , "linux-mm@kvack.org" , RCU , cocci@inria.fr Subject: Re: [cocci] patch idea: convert trivial call_rcu users to kfree_rcu Message-ID: References: <68b85796-c674-4691-936a-2051849f4692@suse.cz> <6b7e3ed9-d974-cb3b-6839-a6b7cf5f5a36@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0EE1BC0031 X-Rspam-User: X-Stat-Signature: shsyhi59q7j4b7b8tdadeee8sbjchrpg X-HE-Tag: 1716897809-257003 X-HE-Meta: U2FsdGVkX19hXbsokOsCNKcOEvr4HpGpwsl06fe+nuvCdfl7WBsm0Q/OucIvX861s+iJNAAGJI8/u13MwHmTv52oiOp+7mKSvuZZWX3acGSvtbingPp6Ikh/wrHoAmtqCSUX2O3Dv/F6F1iAmd354Hxlhtr5MuYU8MyFC7SijXY8nECxB81HM8p44aOmps6x54YP62ERK+W/3HnmRwnlehpW28e4WNN0Mtb1Oqd6nkdxODD7+Jb1lb+eXTa33BVFcGNeULfN2hzWomsLKoMutwz6PR3dDgoqPSjUf/XbL6XOLzuaAkAzAcDBDgtxTXJfrNtdiWn2R5J/2ZYNZH2D24SH/pYw6y8Yy4qODvtkc/j7CNJUKM5xKFfzhgL4bUA3qFbWJrwyrBCEb8nr+0cjlGw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nLs9cW0w5083jQMaPNy3yypMTsDDBqP2165wN9w= 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: Hello. > > > On Mon, 27 May 2024, Paul E. McKenney wrote: > > > On Mon, May 27, 2024 at 10:13:40AM +0200, Julia Lawall wrote: > > > > > > > > > On Mon, 27 May 2024, Vlastimil Babka wrote: > > > > > > > Hi, > > > > > > > > one bit from LSF/MM discussions is that there might be call_rcu users with a > > > > callback that only does a kmem_cache_free() to a specific cache. Since SLOB > > > > was removed, it's always ok to use kfree() and thus also kfree_rcu() on > > > > allocations from kmem_cache_alloc() in addition to kmalloc(). Thus, such > > > > call_rcu() users might be simplified to kfree_rcu(). I found some cases > > > > semi-manually, but I'd expect coccinelle could help here so if anyone wants > > > > to take this task, feel free to. > > > > > > Thanks for the suggestion! I will try to look into it. > > > > Thank you both! > > I found the following functions. Do you want some other information, such > as where they are called from? > > Ignore the -s at the beginning of some lines. Those are for emphasis. not > to suggest to remove the code. > > I checked that the functions are only used in calls to call_rcu. > > Without more effort, Coccinelle only looks for functions defined in the > same file. Here are the functions that are passed to call_rcu where the > function is not defined in the same file: > > need definition for audit_free_rule_rcu > need definition for __i915_gem_free_object_rcu > need definition for io_eventfd_ops > need definition for ip_vs_dest_dst_rcu_free > need definition for __put_task_struct_rcu_cb > need definition for radix_tree_node_rcu_free > > They all do something more, although radix_tree_node_rcu_free doesn't do > much more (some memsets). > > julia > > diff -u -p /home/jll/linux/drivers/net/wireguard/allowedips.c /tmp/nothing/drivers/net/wireguard/allowedips.c > --- /home/jll/linux/drivers/net/wireguard/allowedips.c > +++ /tmp/nothing/drivers/net/wireguard/allowedips.c > @@ -50,7 +50,6 @@ static void push_rcu(struct allowedips_n > > static void node_free_rcu(struct rcu_head *rcu) > { > - kmem_cache_free(node_cache, container_of(rcu, struct allowedips_node, rcu)); > } > > static void root_free_rcu(struct rcu_head *rcu) > diff -u -p /home/jll/linux/fs/ecryptfs/dentry.c /tmp/nothing/fs/ecryptfs/dentry.c > --- /home/jll/linux/fs/ecryptfs/dentry.c > +++ /tmp/nothing/fs/ecryptfs/dentry.c > @@ -53,8 +53,6 @@ struct kmem_cache *ecryptfs_dentry_info_ > > static void ecryptfs_dentry_free_rcu(struct rcu_head *head) > { > - kmem_cache_free(ecryptfs_dentry_info_cache, > - container_of(head, struct ecryptfs_dentry_info, rcu)); > } > > /** > diff -u -p /home/jll/linux/kernel/fork.c /tmp/nothing/kernel/fork.c > --- /home/jll/linux/kernel/fork.c > +++ /tmp/nothing/kernel/fork.c > @@ -378,7 +378,6 @@ static struct kmem_cache *thread_stack_c > > static void thread_stack_free_rcu(struct rcu_head *rh) > { > - kmem_cache_free(thread_stack_cache, rh); > } > > static void thread_stack_delayed_free(struct task_struct *tsk) > diff -u -p /home/jll/linux/kernel/workqueue.c /tmp/nothing/kernel/workqueue.c > --- /home/jll/linux/kernel/workqueue.c > +++ /tmp/nothing/kernel/workqueue.c > @@ -5024,8 +5024,6 @@ fail: > > static void rcu_free_pwq(struct rcu_head *rcu) > { > - kmem_cache_free(pwq_cache, > - container_of(rcu, struct pool_workqueue, rcu)); > } > > /* > diff -u -p /home/jll/linux/net/ipv4/inetpeer.c /tmp/nothing/net/ipv4/inetpeer.c > --- /home/jll/linux/net/ipv4/inetpeer.c > +++ /tmp/nothing/net/ipv4/inetpeer.c > @@ -130,7 +130,6 @@ static struct inet_peer *lookup(const st > > static void inetpeer_free_rcu(struct rcu_head *head) > { > - kmem_cache_free(peer_cachep, container_of(head, struct inet_peer, rcu)); > } > > /* perform garbage collect on all items stacked during a lookup */ > diff -u -p /home/jll/linux/net/ipv6/xfrm6_tunnel.c /tmp/nothing/net/ipv6/xfrm6_tunnel.c > --- /home/jll/linux/net/ipv6/xfrm6_tunnel.c > +++ /tmp/nothing/net/ipv6/xfrm6_tunnel.c > @@ -180,8 +180,6 @@ EXPORT_SYMBOL(xfrm6_tunnel_alloc_spi); > > static void x6spi_destroy_rcu(struct rcu_head *head) > { > - kmem_cache_free(xfrm6_tunnel_spi_kmem, > - container_of(head, struct xfrm6_tunnel_spi, rcu_head)); > } > > static void xfrm6_tunnel_free_spi(struct net *net, xfrm_address_t *saddr) > diff -u -p /home/jll/linux/security/security.c /tmp/nothing/security/security.c > --- /home/jll/linux/security/security.c > +++ /tmp/nothing/security/security.c > @@ -1599,7 +1599,6 @@ static void inode_free_by_rcu(struct rcu > /* > * The rcu head is at the start of the inode blob > */ > - kmem_cache_free(lsm_inode_cache, head); > } > > /** > See below some extra functions which can be eliminated. How i found them: find ./ -name "*.c" -o -name "*.h" | xargs grep -rn call_rcu -B 10 | grep kmem_cache_free static void nfsd4_free_file_rcu(struct rcu_head *rcu); static void lima_fence_release(struct dma_fence *fence); void intel_context_free(struct intel_context *ce); static void ipmr_cache_free(struct mfc_cache *c); static inline void alias_free_mem_rcu(struct fib_alias *fa); dsthash_free(struct xt_hashlimit_htable *ht, struct dsthash_ent *ent); void nf_ct_expect_put(struct nf_conntrack_expect *exp); static void node_free(struct net *net, struct fib6_node *fn); static inline void ip6mr_cache_free(struct mfc6_cache *c); static void posix_timer_free(struct k_itimer *tmr); static void thread_stack_delayed_free(struct task_struct *tsk); Those are can be replaced by directly calling of kfree_rcu() instead of call_rcu(). -- Uladzislau Rezki