Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2823910imu; Sun, 23 Dec 2018 08:35:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/WLJ8ezHQp/L9PKQGEGdASpCy9zbnNiOxpPyuIJ+M/O/hGPaIqeb0XpAKna4lZkB4v5VH+s X-Received: by 2002:a62:2fc3:: with SMTP id v186mr10289325pfv.82.1545582935153; Sun, 23 Dec 2018 08:35:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545582935; cv=none; d=google.com; s=arc-20160816; b=SOVxhkHgCMT0RFJp6g/+N3iG9FPic3gPSVx+R7RjdUVoCWFpzngzlqHvOq31KT1S5J OeSRncxh8550af+yfC0687bd6N54rCifb5JXKWtx6F9igFOmvy46NkmVgJ5QQZMN+Kr8 SZIypSOwPoQBfU4oQCR71OB+EcH48FFmkpvrKu9wta11z6BXsYDVrll1E4l3zV2LPPBy xnwuWpVvaWmx7RhFDVfkdmYOeaEmCv9YQTjhPhoVedvTxKHMLHGfFbKY+PFmOH51++Ph dtkTAiSG92UJkf4guU0wFmiD8177jxBBdYSwXuJVAxQWA951fdsbpia0UNAkFlZZE6mh d0vQ== 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=DVwl9RFJg65qVvnqrdsI9j4ylSWq2AeoUQpzJMc+7Rs=; b=FFn9EtPxzRUyz/qNt1gyvOheBlmw9okdxMQ/wQ97JBlIA8hnM81uLm3LDKbf4nbqek gMDjyrGR0Wojf124B3yUBt/itb2DuQJri5sYO/FlvKYc61vJhk/2JtICN1g9h7/FebKC tA79Sq9MAkUo8W5jp69WdZmP9TidF7ftj0mGeZyqsj2lMLP2hKQ0/FO+XiXSK2XvUGo1 UFpIcEX67gzh/2wgI/+mUUCMWLPxvCkN4dJi9pZoJU4DfMMogyXVT/b1m6indW/I9cPA EwAzqPjpDXGdq+aJ4OQ4AEj6mm2meezSbgfLZ9CIUNRtvzZDPACXb9hAZ6/EWhjHKdE6 4OGA== 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 j65si4332293pge.444.2018.12.23.08.35.19; Sun, 23 Dec 2018 08:35:35 -0800 (PST) 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 S2404434AbeLWBNt (ORCPT + 99 others); Sat, 22 Dec 2018 20:13:49 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:34568 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387711AbeLWBNt (ORCPT ); Sat, 22 Dec 2018 20:13:49 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1gasKn-0007my-C5; Sun, 23 Dec 2018 01:13:37 +0000 Date: Sun, 23 Dec 2018 01:13:37 +0000 From: Al Viro To: yangerkun Cc: gregkh@linuxfoundation.org, rafael@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] debugfs: remove inc_nlink in debugfs_create_automount Message-ID: <20181223011334.GD2217@ZenIV.linux.org.uk> References: <20181222084536.21305-1-yangerkun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181222084536.21305-1-yangerkun@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 22, 2018 at 04:45:36PM +0800, yangerkun wrote: > Remove inc_nlink in debugfs_create_automount, or this inode will never > be free. Explain, please. What exactly would care about i_nlink in debugfs? It does *NOT* free any kind of backing store on inode eviction, for a good and simple reason - there is no backing store at all. And as for the icache retention, debugfs inodes are * never looked up in icache * never hashed * ... and thus never retained in icache past the final iput() i_nlink serves as a refcount - for on-disk inodes on filesystems that allow hardlinks and need to decide if the on-disk inode needs to follow an in-core one into oblivion. The lifetime of in-core inode is *NOT* controlled by i_nlink. They can very well outlive i_nlink dropping to 0, for starters. Consider e.g. the following: cat >/tmp/a.sh <<'EOF' echo still not freed >/tmp/a (sleep 5 && date && stat - && cat) st_nlink and that came straight from ->i_nlink of the (very much alive) in-core inode. And of course, in-core inodes do get freed just fine without i_nlink reaching zero. It's used for 4 things: 1) deciding whether it makes sense to evict in-core inode as soon as we have no more (in-core) references pinning them (i.e. when ->i_count reaches zero). If there's a chance that somebody will do an icache lookup finding that one, we might want to keep it around until memory pressure kicks it out. And since for something like normal Unix filesystem such icache lookup can happen as long as there are links to the (on-disk) inode left in some directories, default policy is "try to keep it around if i_nlink is positive *AND* it is reachable from icache in the first place". Filesystems might override that, but it's all moot if the in-core inode is *not* reachable from icache in the first place. Which is the case for debugfs and similar beasts. 2) deciding whether we want to free the on-disk inode when an in-core one gets evicted. Note that such freeing can not happen as long as in-core inode is around - unlinking an open file does *not* free it; it's still open and IO on such descriptor works just fine. There the normal rules are "if we are evicting an in-core inode and we know that it has no links left, it's time to free the on-disk counterpart". Up to individual filesystems, not applicable to debugfs for obvious reasons. 3) for the same filesystems, if the link count is maintained in on-disk inode we'll need to update it on unlink et.al. ->i_nlink of in-core inode is handy for keeping track of that. Again, not applicable in debugfs 4) reporting st_nlink to userland on stat/fstat/etc. That *is* applicable in debugfs and, in fact, it is the only use of ->i_nlink there.