Skip to content

Commit

Permalink
Add notes for section 12.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-stoakes committed May 9, 2016
1 parent 4bad9d4 commit 38c03f7
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions 12.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,54 @@ ENTRIES_PER_PAGE/2 | |-- - -- - -- - -- - | | --------------- | | -------
returns 0 for success - because the files only exist in RAM, they don't need
to be synchronised with any disk.

## 12.6 Inode Operations in tmpfs

* The most complex operation that is supported for inodes is truncation and
involves four distinct stages:

1. [shmem_truncate()][shmem_truncate] - truncates a partial page at the end of
the file and continually calls
[shmem_truncate_indirect()][shmem_truncate_indirect] until the file is
truncated to the proper size. Each call to `shmem_truncate_indirect()` will
only process one indirect block at each pass, which is why it may need to be
called multiple times.

2. [shmem_truncate_indirect()][shmem_truncate_indirect] - Deals with both doubly
and triply-indrect blocks. It finds the next indirect block that needs to be
truncated to pass to stage 3, and will contain pointers to pages which will
in turn contain swap vectors.

3. [shmem_truncate_direct()][shmem_truncate_direct] - Selects a range of swap
vectors from a page that need to be truncated and passes that range to
[shmem_swp_free()][shmem_swp_free].

4. [shmem_free_swp()][shmem_free_swp] - Frees entries via
[free_swap_and_cache()][free_swap_and_cache] which frees both the swap entry
and the page containing data.

* The linking and unlinking of files is very simple because most of the work is
performed by the filesystem layer.

* To link a file, the directory inode size is incremented, and `ctime` and
`mtime` of the affected inodes are updated and the number of links to the
inode being linked is incremented. A reference to the new
[struct dentry][dentry] is then created via [dget()][dget] and
[d_instantiate()][d_instantiate].

* To unlink a file the same inode statistics are updated before decrementing the
references to the `struct dentry` only using [dput()][dput] (and subsequently
[iput()][iput]) which will clear up the inode when its reference count hits
zero.

* Creating a directory will use [shmem_mkdir()][shmem_mkdir] which in turn uses
[shmem_mknod()][shmem_mknod] with the `S_IFDIR` flag set, before incrementing
the parent directory [struct inode][inode]'s `i_nlink` counter.

* The function [shmem_rmdir()][shmem_rmdir] will delete a directory, first
making sure it's empty via [shmem_empty()][shmem_empty]. If it is, the
function then decrements the parent directory `struct inode->i_nlink` count
and calls [shmem_unlink()][shmem_unlink] to remove it.

[mmap]:http://man7.org/linux/man-pages/man2/mmap.2.html
[fork]:http://man7.org/linux/man-pages/man2/fork.2.html
[shmget]:http://man7.org/linux/man-pages/man2/shmget.2.html
Expand Down Expand Up @@ -505,3 +553,17 @@ ENTRIES_PER_PAGE/2 | |-- - -- - -- - -- - | | --------------- | | -------
[shmem_file_read]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1088
[shmem_file_write]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L924
[shmem_sync_file]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1446

[shmem_truncate_indirect]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L309
[shmem_truncate_direct]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L265
[shmem_free_swp]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L240
[free_swap_and_cache]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/swapfile.c#L332
[dentry]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/include/linux/dcache.h#L67
[dget]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/include/linux/dcache.h#L244
[d_instantiate]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/fs/dcache.c#L651
[dput]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/include/linux/dcache.h#L268
[iput]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/fs/inode.c#L1027
[shmem_mkdir]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1154
[shmem_rmdir]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1232
[shmem_empty]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1201
[shmem_unlink]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1221

0 comments on commit 38c03f7

Please sign in to comment.