linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Theodore Ts'o <tytso@mit.edu>
To: "Kornievskaia, Olga" <Olga.Kornievskaia@netapp.com>
Cc: Leonid Fedorenchik <leonid.fedorenchik@paragon-software.com>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>
Subject: Re: help with understanding evict inode functionality
Date: Sat, 3 Oct 2015 22:28:02 -0400	[thread overview]
Message-ID: <20151004022802.GB4442@thunk.org> (raw)
In-Reply-To: <788B0E19-4D87-4221-BB69-408E930A0227@netapp.com>

On Fri, Oct 02, 2015 at 02:38:49PM +0000, Kornievskaia, Olga wrote:
> 
> Again a general question to the community about inodes and
> eviction. I was under the general impression that when the file is
> closed the inode sticks around just in case the file is reopened
> again. Then when resources are constrainted some background thread
> evicts unused inodes. Is that understanding correct?

I think you're confused about what evict_inode() does.  The i_count
field tracks how many in-memory references the inode has.  Each iput()
decrements i_count.  Once i_count goes to zero, there are no more open
file descriptors for that inode.

Then there is also i_nlink.  This is the number of directory entries
which point at the inode on disk.  When you unlink() a file, this
drops the i_nlink on the inode.  When i_nlink drops to zero, then the
inode is no longer referenced by any directory entry.  But, this
doesn't mean we can actually release the inode and the blocks
associated with the file --- Unix semantics is that you can have an
open file descriptor on an unlinked file, and when the last fd is
closed, only then does the inode get released.

evict_inode() is what happens when i_nlink *and* i_icount hits zero.
So it is only then that the local disk file system can actually
release the inode and blocks associated with that inode.

So by the time the file system's evict_inode() is called, the inode is
not coming back.  With apologies to Monty Python, the inode is no
more; it has ceased to be.  It's expired and gone to meet its
maker..... It is an ex-inode.  :-)

Hence, there is no point trying to worry about what hapens if the file
is reopened again, since the original inode is *gone*.  You could
create a new file with the same file name, but none of the resources
associated with the old inode need to be preserved for the newly
created file.

Cheers,

						- Ted

P.S.  Things do get a little complicated with non-native Unix file
systems which don't obey Posix semantics, or if you are dealing with a
pre-NFSv4 protocol which quaintly assumes that you can have a
stateless networked file system protocol when a file system is
inherently stateful.  For more information, see:

http://serverfault.com/questions/267601/can-open-files-be-unlinked-on-nfs-mounted-volumes-while-applications-that-still

  reply	other threads:[~2015-10-04  2:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-02 13:57 help with understanding evict inode functionality Leonid Fedorenchik
2015-10-02 14:38 ` Kornievskaia, Olga
2015-10-04  2:28   ` Theodore Ts'o [this message]
2015-10-04  6:01     ` Christoph Hellwig
2015-10-04 22:37       ` Theodore Ts'o
2015-10-15  9:53   ` Jan Kara
  -- strict thread matches above, loose matches on Subject: below --
2015-10-01 22:54 Kornievskaia, Olga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151004022802.GB4442@thunk.org \
    --to=tytso@mit.edu \
    --cc=Olga.Kornievskaia@netapp.com \
    --cc=leonid.fedorenchik@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).