Linux Kernel - What does it mean to put an inode?

I saw the following comment on top of the iput function:

 /** * iput - put an inode * @inode: inode to put * * Puts an inode, dropping its usage count. If the inode use count hits * zero, the inode is then freed and may also be destroyed. * * Consequently, iput() can sleep. */ 

It seems to me that this does not β€œlay” something, but β€œdiscards” it. I know the drop_inode function, which in some cases is called from iput , so using the term "put" here is even more confusing.

+7
linux linux-kernel kernel inode
source share
3 answers

put is a general terminology in kernel code to reduce the number of references to objects. This is an add-on to get that increments the reference count. You can find many places, not just with inodes.

The number of links is used to prevent the destruction of shared objects as long as they are used. The code, using the get object of the object, uses it, then put it to release it.

+6
source share

iput is the opposite of iget , which looks for the index index, allocates memory for it if necessary, and returns a reference to the index to the caller.

iput takes this index backward, i.e. frees memory if necessary.

There is a reference counting system, so that you can use one index in parallel to more than one subscriber and, therefore, can be omitted (that is, deleted from memory) if there is no user (each user called iput ).

 /** * iget_locked - obtain an inode from a mounted file system * @sb: super block of file system * @ino: inode number to get * * Search for the inode specified by @ino in the inode cache and if present * return it with an increased reference count. This is for file systems * where the inode number is sufficient for unique identification of an inode. * * If the inode is not in cache, allocate a new inode and return it locked, * hashed, and with the I_NEW flag set. The file system gets to fill it in * before unlocking it via unlock_new_inode(). */ struct inode *iget_locked(struct super_block *sb, unsigned long ino) 
+3
source share

Basically, a process has a file descriptor table that contains a pointer to a file that points to open processes, the file pointer is actually a pointer to an element of the open file table (which is supported by the kernel). And in the Open File Table, the inode pointer point to the element in the I-node table (also supported by the kernel) will be indicated. The I-node table contains all the information about the file (file information and a pointer to lock the data of the storage file)

When you open the file, an inode element is added to the I-node table. To make inode faster and cheaper, the system will support the inode cache. When the I-node table needs a new element, it will use iget () to get the inode from the cache, and when the file is closed, it will return the corresponding index code to the cache using iput ().

Thus, iput () means PUT inode to the inode cache, and DROPPING means reducing the reference to the inode index in the I-node table. See this page for more details.

+1
source share

All Articles