Skip to content

Commit

Permalink
Improve diagrams in Chapter 3
Browse files Browse the repository at this point in the history
- Stack and heap are in same memory area
- Improve minor alignments of diagrams
  • Loading branch information
hirotnk committed May 10, 2020
1 parent 2110812 commit 84e8498
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions chapters/processes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ heap and the stack are actually just one memory area:

[[erlang_process_memory_2]]
.Erlang Process Memory : Heap + Stack
[ditaa]
[ditaa, separation=false]
----
+-------+ +-------+
| PCB | | Stack |
Expand Down Expand Up @@ -805,7 +805,7 @@ our original picture of a process as four memory areas:

[[erlang_process_memory_3]]
.Erlang Process Memory : GC
[ditaa]
[ditaa, separation=false]
----
+-------+ +-------+
Expand Down Expand Up @@ -906,7 +906,7 @@ mailboxes) and a varying number of heap fragments (`m-bufs`):

[[erlang_process_memory_4]]
.Erlang Process Memory : Messages
[ditaa]
[ditaa, separation=false]
----
+-------+ +-------+
Expand All @@ -915,11 +915,11 @@ mailboxes) and a varying number of heap fragments (`m-bufs`):
| free |
+-------+ +-------+ +-------+ +-------+
| M-box | | M-box | | Heap | | Old |
| intern| | inbox | | | | Heap |
| intern| | inq | | | | Heap |
+-------+ +-------+ +-------+ +-------+
+-------+ +-------+ +-------+ +-------+
| m-buf | | m-buf | | m-buf | | m-buf |
| mbuf | | mbuf | | mbuf | | mbuf |
+-------+ +-------+ +-------+ +-------+
Expand Down Expand Up @@ -1028,14 +1028,15 @@ consider messages sent between Erlang nodes. Imagine two processes

[[erlang_message_passing_1]]
.Erlang Message Passing Step 1
[ditaa]
[ditaa, separation=false]
----
P 1
+---------------------------------+
| +-------+ +-------+ +-------+ |
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | [Msg] | | intern| |
Expand All @@ -1052,6 +1053,7 @@ consider messages sent between Erlang nodes. Imagine two processes
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | | | intern| |
Expand All @@ -1076,14 +1078,15 @@ on the heap:

[[erlang_message_passing_2]]
.Erlang Message Passing Step 2
[ditaa]
[ditaa, separation=false]
----
P 1
+---------------------------------+
| +-------+ +-------+ +-------+ |
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | [Msg] | | intern| |
Expand All @@ -1100,19 +1103,20 @@ on the heap:
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | | | intern| |
| | | | [Msg] | | | |
| | | | ^ | | first | |
| +-------+ +-|-----+ +---|---+ |
| | v |
| | +-------+ |
| | |next:[]| |
| | | m: * | |
| | +----|--+ |
| | | |
| +-------------+ |
| | inq | | [Msg] | | intern| |
| | | | | | | |
| | | | ^ | | first | |
| +-------+ +--|----+ +---|---+ |
| | v |
| | +-------+ |
| | |next []| |
| | | m * | |
| | +----|--+ |
| | | |
| +------------+ |
+---------------------------------+
Expand All @@ -1124,14 +1128,15 @@ will end up in an `m-buf` but linked from the internal mailbox:

[[erlang_message_passing_3]]
.Erlang Message Passing Step 3
[ditaa]
[ditaa, separation=false]
----
P 1
+---------------------------------+
| +-------+ +-------+ +-------+ |
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | [Msg] | | intern| |
Expand All @@ -1148,16 +1153,17 @@ will end up in an `m-buf` but linked from the internal mailbox:
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | | | intern| |
| | | | | | | |
| | | | | | first | |
| +-------+ +-------+ +---|---+ |
| m-buf v |
| mbuf v |
| +-------+ +-------+ |
| +->| [Msg] | |next:[]| |
| | | | | m: * | |
| +->| [Msg] | |next []| |
| | | | | m * | |
| | +-------+ +----|--+ |
| | | |
| +------------------+ |
Expand All @@ -1174,14 +1180,15 @@ will end up in an `m-buf` and linked from the external mailbox:

[[erlang_message_passing_4]]
.Erlang Message Passing Step 4
[ditaa]
[ditaa, separation=false]
----
P 1
+---------------------------------+
| +-------+ +-------+ +-------+ |
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | [Msg] | | intern| |
Expand All @@ -1198,22 +1205,21 @@ will end up in an `m-buf` and linked from the external mailbox:
| | PCB | | Stack | | Old | |
| +-------+ +-------+ | Heap | |
| | free | +-------+ |
| | | |
| +-------+ +-------+ +-------+ |
| | M-box | | Heap | | M-box | |
| | inq | | | | intern| |
| | | | | | | |
| | first | | | | first | |
| +---|---+ +-------+ +-------+ |
| v m-buf |
| +-------+ +-------+ |
| |next:[]| | | |
| | m:*--->| [Msg] | |
| +-------+ +-------+ |
| |
| |
| v mbuf |
| +--------+ +-----+ |
| |next [] | | | |
| | | | | |
| | m *------>|[Msg]| |
| | | | | |
| +--------+ +-----+ |
+---------------------------------+
----

After a GC the message will still be in the `m-buf`. Not until
Expand Down Expand Up @@ -1277,7 +1283,7 @@ memory area, PD, the process dictionary:

[[erlang_process_memory_5]]
.Erlang Process Memory : Process Dictionary
[ditaa]
[ditaa, separation=false]
----
+-------+ +-------+ +-------+
Expand All @@ -1290,7 +1296,7 @@ memory area, PD, the process dictionary:
+-------+ +-------+ +-------+ +-------+
+-------+ +-------+ +-------+ +-------+
| m-buf | | m-buf | | m-buf | | m-buf |
| mbuf | | mbuf | | mbuf | | mbuf |
+-------+ +-------+ +-------+ +-------+
Expand Down

0 comments on commit 84e8498

Please sign in to comment.