Skip to content

Commit

Permalink
Add notes for section 12.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-stoakes committed May 9, 2016
1 parent 82863e1 commit b85012c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 12.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,32 @@ ENTRIES_PER_PAGE/2 | |-- - -- - -- - -- - | | --------------- | | -------
* Files created by `shmget()` are named `SYSV<NN>` where `<NN>` is the key that
is passed as a parameter to `shmget()`.

## 12.8 System V IPC

* To avoid spending too long on this, we focus only on [shmget()][shmget] and
[shmat()][shmat] and how they are affected by the VM.

* `shmget()` is implemented via [sys_shmget()][sys_shmget]. It performs sanity
checks, sets up the IPC-related data structures and a new segment via
[newseg()][newseg] which creates the file in `shmfs` with
[shmem_file_setup()][shmem_file_setup] as previously discussed.

* `shmat()` is implemented via [sys_shmat()][sys_shmat]. It does sanity checks,
acquires the appropriate descriptor and hands over to [do_mmap()][do_mmap] to
map the shared region into the process address space.

* `sys_shmat()` is responsible for ensuring that VMAs don't overlap if the
caller erroneously specifies to do so.

* The [struct shmid_kernel][shmid_kernel]`->shm_nattch` counter is maintained by
[shm_vm_ops][shm_vm_ops], a
[struct vm_operations_struct][vm_operations_struct] that registers `open()`
and `close()` callbacks of [shm_open()][shm_open] and [shm_close()][shm_close]
respectively.

* `shm_close()` is also responsible for destroying shared regions if the
`SHM_DEST` flag is specified and the `shm_nattch` counter reaches zero.

[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 @@ -590,3 +616,12 @@ ENTRIES_PER_PAGE/2 | |-- - -- - -- - -- - | | --------------- | | -------

[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

[sys_shmget]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/ipc/shm.c#L229
[newseg]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/ipc/shm.c#L178
[sys_shmat]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/ipc/shm.c#L568
[do_mmap]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/include/linux/mm.h#L557
[shmid_kernel]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/ipc/shm.c#L29
[shm_vm_ops]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/ipc/shm.c#L172
[shm_open]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/ipc/shm.c#L110
[shm_close]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/ipc/shm.c#L139

0 comments on commit b85012c

Please sign in to comment.