Automatic Expiration

The kernel also provides some infrastructure to allow automatic expiration of mounts. When a mount is not used by any process or the kernel itself, it will be automatically removed from the VFS mount tree if automatic expiration is used. Currently the NFS and AFS network filesystems use this offer. All vfsmount instances of submounts that are supposed to expire automatically must be collected on a linked list that uses vfsmount->mnt_expire to chain the elements together.

It then suffices to periodically apply mark_mounts_for_expiry on the list. The function scans through all entries. A mount is unused if its usage count is 1, that is, if it is only referenced by the parent mount. When such an unused mount is found, mnt_expiry_mark is set. When mark_mounts_for_expiry finds an unused entry with mnt_expiry_mark set on the next list traversal, the mount is removed from the namespace.

Note that the mntput is responsible to clear mnt_expiry_mark. This ensures that a mount that has already been on the expiration list but became used again is not immediately expired when it becomes once more unused. The code flow is as follows:

1. An unused mount is marked for expiry by mark_mounts_for_expiry.

2. After this, the mount comes into use again, so its mnt_count is increased. This prevents mark_mounts_for_expiry from removing the mount from the namespace despite the expiration mark still being set.

3. When the usage count is decreased with mntput, the function will also ensure that the expiration mark is removed. The mark_mounts_for_expiry circle can thus commence as usual.

Continue reading here: Pseudo Filesystems

Was this article helpful?

0 0