Reputation: 993
I saw the following comment atop 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.
*/
To me that sounds like it's not "putting" anything, but "dropping" it. I'm aware of the drop_inode
function, which gets called from iput
in some cases, so the usage of the term "put" is even more confusing here.
Upvotes: 10
Views: 1836
Reputation: 3405
iput
is the opposite of iget
which searches for an inode,
allocates memory for it if necessary and returns a reference to the inode to the
caller.
iput
takes this inode "back", i.e. frees the memory if needed.
There is a reference counter system, such that one inode can be used
in parallel by more than one caller and can therefore
be only dropped (i.e. removed from memory) if there is no user of it
anymore (every user has 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)
Upvotes: 3
Reputation: 207
Basically a process has a File Descriptor Table, which includes an file pointer point to the files the process open, the file pointer is actually a pointer point to an item of the Open File Table(which is maintained by kernel). And the Open File Table will have an inode pointer point to the item in I-node Table(also maintained by kernel). The I-node table contains all the information of file(file info and pointer to blocks store file data)
When you open a file, an inode item is added to the I-node table. In order to achieve and free inode faster, the system will maintain an inode cache. When the I-node Table needs a new item, it will use iget() to get an inode from the cache, and when a file is closed, it will return the related inode to the cache using iput().
So the iput() means PUT the inode to the inode cache, and DROPPING means reduce the reference of an inode in the I-node Table. Refer to this page to get more details.
Upvotes: 1
Reputation: 361595
put
is common terminology in kernel code for decrementing an object's reference count. It's the complement of get
, which increases the reference count. You can find it lots of places, not just with inodes.
Reference counts are used to keep shared objects from being destroyed as long as they're in use. Code using an object get
s the object, uses it, then put
s it to release it.
Upvotes: 10