diff --git a/12.md b/12.md index 0fe609c..410b75e 100644 --- a/12.md +++ b/12.md @@ -496,6 +496,26 @@ ENTRIES_PER_PAGE/2 | |-- - -- - -- - -- - | | --------------- | | ------- function then decrements the parent directory `struct inode->i_nlink` count and calls [shmem_unlink()][shmem_unlink] to remove it. +## 12.7 Setting Up Shared Regions + +* A shared region is backed by a file created in `shm`. + +* There are two cases where a new file will be created - during the setup of a + shared region via (userland) [shmget()][shmget] or when an anonymous region is + set up via (userland) [mmap()][mmap] with the `MAP_SHARED` flag specified. + +* Both approaches ultimately use [shmem_file_setup()][shmem_file_setup] to + create a file, which simply creates a new [struct dentry][dentry] and + [struct inode][inode], fills in the relevant details and instantiates them. + +* Because the file system is internal, the names of the files created do _not_ + have to be unique as the files are always located by inode, not name. As a + result, [shmem_zero_setup()][shmem_zero_setup] always creates a file + `"dev/zero"` which is how it shows up in `/proc//maps`. + +* Files created by `shmget()` are named `SYSV` where `` is the key that + is passed as a parameter to `shmget()`. + [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 @@ -567,3 +587,6 @@ ENTRIES_PER_PAGE/2 | |-- - -- - -- - -- - | | --------------- | | ------- [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 + +[shmem_file_setup]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1607 +[shmem_zero_setup]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/shmem.c#L1664