-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.mm
65 lines (59 loc) · 3.01 KB
/
README.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
FIXME: move this somewhere else
1. MM area map
mm_private.area
|
|
`->.---------------------.
| | \
| struct mm_shared | } sizeof (struct mm_shared)
| | /
+---------------------+
| | \
| static data | } mm_private.static_size
| | /
+---------------------+ ------------------
| .-----------------. | - \
| | struct mm_chunk | | \ |
| +-----------------+ | } mm_chunk.size |
| | chunk data | | / |
| '-----------------' | - |
| ............... | |
| | } mm_private.dynamic_size
| .-----------------. | |
| | struct mm_chunk | | |
| +-----------------+ | |
| | chunk data | | |
| '-----------------' | |
| ............... | |
| | /
'---------------------' ------------------
All mm_ptr_t are relative to the start of the whole structure (which is
mapped at mm_private.area in the process virtual memory).
.--------------------------------------------------------------------.
| |
| .------------------. .------------------. .------------------. |
| | struct mm_shared | | struct mm_chunk | | struct mm_chunk | |
| | ..... | | ..... | | ..... | |
| | | | | | | |
-+--->.---+---.<-. | .-+--->.---+---.<-. | .-+--->.---+---.<-. | |
| lh | p | n |--+--+-' | lh | p | n |--+--+-' | lh | p | n |--+--+-'
| '---+---' | | | '---+---' | | | '---+---' | |
| |.... --+---+------'.... --+----------'..... | |
'------+-----------' '------------------' '---------------+--'
| |
'------------------------------------------------------'
2. Good mm practices
* use mm_create() durig the init phase of your code and make it globally
accessible (i.e. global variable) so you can easily call mm_
primitives;
* always lock the mm handle before using (even reading) mm shared data;
otherwise things can change while you look at them;
* mm_lock() also ensures that the whole shm area is mapped into your
process virtual memory (the shm area can be enlarged by other
processes between the time you open it with mm_create() and access it);
* if mm_alloc is involved in your critical region, never rely on process
addresses (pointers) and always use mm pointers; although you access
the shm data from within a critical region (with the mm handle locked),
mm_alloc can extend the shm area and thus remap the shm area in your
process virtual memory; old pointer values will then point to
unallocated pages