Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4457022yba; Mon, 29 Apr 2019 21:29:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhbn24U/gFK4fHzuLcGqKb1WVyJMdo94cr/IPvTDWlxnTsNrPDdrz9wn4UkRk4AUui7ov1 X-Received: by 2002:a17:902:820a:: with SMTP id x10mr27976932pln.316.1556598560845; Mon, 29 Apr 2019 21:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556598560; cv=none; d=google.com; s=arc-20160816; b=i5q/2vZPxSsDNNTP7KQ0fTy+/qDacSlL8vm41LvIe2PoLVjtLCX+orN0LRyXaNs8ws zqDVx1fAmc+hnWxbdh7okNviT9XxwmXl2xJDYMZrUexBj40KMiZOLXoL3IGX4XcAkxH3 G6xsSkWcNHzcqaErKybnt9J5vEjCerlDRHPMfgvoJPuj80EQaWpQCWkmmOCD824RxCT2 39QZIx68CggSeHImkFGHq2IuhQIWOcvr8szSRieXp9l4pFZ0JXSvSVeZMKNuJc1BU+/m tUzgaft47U+A9kqRZlgnRpfoLgUxJ8l4VMI5KikHeWAmUCACLWWse7zHBHAkOH+ngAig ecdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=KBqM7nJxgDugS79U8qF7l3l5i25hwIvzr2WgXndZ+YE=; b=h91aWtMcSzSqJR0g9rNzA2/MRTRU1uep8C0H/NkBlNWqZlHIDlhJ1Y/j7ZqzRqFpOC 0CnaVvb4e4QuvzRtPYlnh7ldiFfIfxyL9/S4oHTB4o07nPd8KdT106MR6P1bR1N8i8Ss zptonoeinvL6pTzMjvLRIHoSBakfKuY5UHkPCqvMnGiPtQeb86HwlL6M0C48/rwwhA6m Y1cKv4hwn1fjrndaSUx7NFcx1+a9K9LRQV3yh4uLAAVq1sUhkqa6HzP88Gi4pnZa37Kb JeY9Te26oTto9j0YgD0vHqK34mLn0tevUhwZXJWxh+btOnF9cF7ojyT6HaLefZ/S5oik womQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p30si7280898pgl.53.2019.04.29.21.29.04; Mon, 29 Apr 2019 21:29:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726088AbfD3E01 (ORCPT + 99 others); Tue, 30 Apr 2019 00:26:27 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:38532 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbfD3E01 (ORCPT ); Tue, 30 Apr 2019 00:26:27 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92 #3 (Red Hat Linux)) id 1hLKLY-0007Ys-3q; Tue, 30 Apr 2019 04:26:24 +0000 Date: Tue, 30 Apr 2019 05:26:24 +0100 From: Al Viro To: Andreas Dilger Cc: Linus Torvalds , linux-fsdevel , Linux List Kernel Mailing Subject: Re: [RFC][PATCHSET] sorting out RCU-delayed stuff in ->destroy_inode() Message-ID: <20190430042623.GJ23075@ZenIV.linux.org.uk> References: <20190416174900.GT2217@ZenIV.linux.org.uk> <20190430030914.GF23075@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 29, 2019 at 10:18:04PM -0600, Andreas Dilger wrote: > > > > void *i_private; /* fs or device private pointer */ > > + void (*free_inode)(struct inode *); > > It seems like a waste to increase the size of every struct inode just to access > a static pointer. Is this the only place that ->free_inode() is called? Why > not move the ->free_inode() pointer into inode->i_fop->free_inode() so that it > is still directly accessible at this point. i_op, surely? In any case, increasing sizeof(struct inode) is not a problem - if anything, I'd turn ->i_fop into an anon union with that. As in, diff --git a/Documentation/filesystems/porting b/Documentation/filesystems/porting index 9d80f9e0855e..b8d3ddd8b8db 100644 --- a/Documentation/filesystems/porting +++ b/Documentation/filesystems/porting @@ -655,3 +655,11 @@ in your dentry operations instead. * if ->free_inode() is non-NULL, it gets scheduled by call_rcu() * combination of NULL ->destroy_inode and NULL ->free_inode is treated as NULL/free_inode_nonrcu, to preserve the compatibility. + + Note that the callback (be it via ->free_inode() or explicit call_rcu() + in ->destroy_inode()) is *NOT* ordered wrt superblock destruction; + as the matter of fact, the superblock and all associated structures + might be already gone. The filesystem driver is guaranteed to be still + there, but that's it. Freeing memory in the callback is fine; doing + more than that is possible, but requires a lot of care and is best + avoided. diff --git a/fs/inode.c b/fs/inode.c index fb45590d284e..627e1766503a 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -211,8 +211,8 @@ EXPORT_SYMBOL(free_inode_nonrcu); static void i_callback(struct rcu_head *head) { struct inode *inode = container_of(head, struct inode, i_rcu); - if (inode->i_sb->s_op->free_inode) - inode->i_sb->s_op->free_inode(inode); + if (inode->free_inode) + inode->free_inode(inode); else free_inode_nonrcu(inode); } @@ -236,6 +236,7 @@ static struct inode *alloc_inode(struct super_block *sb) if (!ops->free_inode) return NULL; } + inode->free_inode = ops->free_inode; i_callback(&inode->i_rcu); return NULL; } @@ -276,6 +277,7 @@ static void destroy_inode(struct inode *inode) if (!ops->free_inode) return; } + inode->free_inode = ops->free_inode; call_rcu(&inode->i_rcu, i_callback); } diff --git a/include/linux/fs.h b/include/linux/fs.h index 2e9b9f87caca..92732286b748 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -694,7 +694,10 @@ struct inode { #ifdef CONFIG_IMA atomic_t i_readcount; /* struct files open RO */ #endif - const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ + union { + const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ + void (*free_inode)(struct inode *); + }; struct file_lock_context *i_flctx; struct address_space i_data; struct list_head i_devices;