2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/docs/wiki/ProgramLoading Thu Jun 30 21:18:22 2022 +0200
2.3 @@ -0,0 +1,236 @@
2.4 += Program Loading =
2.5 +
2.6 +The provision of [[Paging|paging]] of file content leads to the possibility of
2.7 +demand paging for programs, enabling them to be loaded into memory dynamically
2.8 +and to have only the active portions of those programs resident. To achieve
2.9 +this, programs must be appropriately initialised in new tasks, with a page
2.10 +fault handler configured to provide program file content whenever a region of
2.11 +the program payload is encountered that is not currently resident in memory.
2.12 +
2.13 +== Internal Page Fault Handlers ==
2.14 +
2.15 +When satisfying page faults for a task, one approach involves situating the
2.16 +page fault handler within the task itself, this managing the available memory
2.17 +regions and employing receive windows when requesting memory pages.
2.18 +
2.19 +The general arrangement involving such internal page fault handlers for a
2.20 +program in a task is as follows:
2.21 +
2.22 +######## A graph showing the internal paging mechanism
2.23 +
2.24 +{{{#!graphviz
2.25 +#format svg
2.26 +#transform notugly
2.27 +digraph internal_paging {
2.28 + node [fontsize="12.0",fontname="sans-serif",shape=box];
2.29 + edge [fontsize="12.0",fontname="sans-serif"];
2.30 + rankdir=LR;
2.31 +
2.32 + TaskMemory [shape=record,label="Task Memory |<s> stack | ... |<d> data | ... |<c> code"];
2.33 +
2.34 + subgraph {
2.35 + rank=same;
2.36 +
2.37 + InternalPager;
2.38 + InternalPager_note [shape=note,style=filled,fillcolor=gold,label="Resides in\nsame task and\ndefines scope of\nfault resolution"];
2.39 +
2.40 + InternalPager -> InternalPager_note [dir=none,style=dotted];
2.41 + }
2.42 +
2.43 + subgraph {
2.44 + rank=same;
2.45 +
2.46 + Regions [shape=record,label="Regions |
2.47 + {<s> stack |<sd> stack-dataspace } |
2.48 + {<d> data | <dd> data-dataspace } |
2.49 + {<c> code |<cd> code-dataspace } |..."];
2.50 +
2.51 + ReceiveFlexpage [shape=note,label="Flexpage\n(receive window)"];
2.52 +
2.53 + Flexpage [shape=note];
2.54 + Flexpage_note [shape=note,style=filled,fillcolor=gold,label="Satisfies\nmemory\naccess"];
2.55 +
2.56 + Flexpage -> Flexpage_note [dir=none,style=dotted];
2.57 + }
2.58 +
2.59 + subgraph {
2.60 + rank=same;
2.61 +
2.62 + ResourceD [label="Resource\n(Pager)"];
2.63 + ResourceD_note [shape=note,style=filled,fillcolor=gold,label="Provides access\nto file content"];
2.64 +
2.65 + ResourceD -> ResourceD_note [dir=none,style=dotted];
2.66 + }
2.67 +
2.68 + ProgramFile [shape=record,label="Program File | ... |<d> data |<c> code | ..."];
2.69 +
2.70 + /* Page fault handling. */
2.71 +
2.72 + TaskMemory:d -> InternalPager [label="page fault"];
2.73 +
2.74 + InternalPager -> Regions:d [label="find region"];
2.75 +
2.76 + Regions:dd -> ResourceD [style=dashed];
2.77 +
2.78 + InternalPager -> ReceiveFlexpage [dir=none];
2.79 + ReceiveFlexpage -> ResourceD [label="map"];
2.80 +
2.81 + ResourceD -> ProgramFile:d [style=dashed];
2.82 +
2.83 + ResourceD -> Flexpage [dir=none];
2.84 + Flexpage -> InternalPager;
2.85 +}
2.86 +}}}
2.87 +
2.88 +########
2.89 +
2.90 +== External Page Fault Handlers ==
2.91 +
2.92 +Another approach that may be used to support an internal page fault handler
2.93 +deployed in a task is to employ an external page fault handler in the creating
2.94 +task. When a page fault occurs, the external handler ensures that the
2.95 +appropriate content has been brought into its own memory space. It then
2.96 +returns a flexpage from the handler routine to resolve the fault.
2.97 +
2.98 +######## A graph showing the external paging mechanism
2.99 +
2.100 +{{{#!graphviz
2.101 +#format svg
2.102 +#transform notugly
2.103 +digraph external_paging {
2.104 + node [fontsize="12.0",fontname="sans-serif",shape=box];
2.105 + edge [fontsize="12.0",fontname="sans-serif"];
2.106 + rankdir=LR;
2.107 +
2.108 + TaskMemory [shape=record,label="Task Memory |<s> stack | ... |<d> data | ... |<c> code"];
2.109 +
2.110 + subgraph {
2.111 + rank=same;
2.112 +
2.113 + ExternalPager_note [shape=note,style=filled,fillcolor=gold,label="Resides in\nseparate task"];
2.114 + ExternalPager;
2.115 +
2.116 + ExternalPager_note -> ExternalPager [dir=none,style=dotted];
2.117 +
2.118 + MappedFlexpage [shape=note,label="Flexpage\n(positioned)"];
2.119 + MappedFlexpage_note [shape=note,style=filled,fillcolor=gold,label="Satisfies\nmemory\naccess"];
2.120 +
2.121 + MappedFlexpage -> MappedFlexpage_note [dir=none,style=dotted];
2.122 + }
2.123 +
2.124 + subgraph {
2.125 + rank=same;
2.126 +
2.127 + Regions [shape=record,label="Regions |
2.128 + {<s> stack |<sd> stack-dataspace } |
2.129 + {<d> data | <dd> data-dataspace } |
2.130 + {<c> code |<cd> code-dataspace } |..."];
2.131 +
2.132 + L4Re [shape=ellipse,label="L4Re paging\nfunctionality"];
2.133 + L4Re_note [shape=note,style=filled,fillcolor=gold,label="Supports normal\naccess to file content"];
2.134 +
2.135 + L4Re -> L4Re_note [dir=none,style=dotted];
2.136 +
2.137 + Flexpage [shape=note];
2.138 + }
2.139 +
2.140 + subgraph {
2.141 + rank=same;
2.142 +
2.143 + ResourceD [label="Resource\n(Pager)"];
2.144 + ResourceD_note [shape=note,style=filled,fillcolor=gold,label="Provides access\nto file content"];
2.145 +
2.146 + ResourceD -> ResourceD_note [dir=none,style=dotted];
2.147 + }
2.148 +
2.149 + ProgramFile [shape=record,label="Program File | ... |<d> data |<c> code | ..."];
2.150 +
2.151 + /* Page fault handling. */
2.152 +
2.153 + TaskMemory:d -> ExternalPager [label="page fault"];
2.154 +
2.155 + ExternalPager -> Regions:d [label="find region"];
2.156 +
2.157 + Regions:dd -> ResourceD [style=dashed];
2.158 +
2.159 + ExternalPager -> L4Re;
2.160 + L4Re -> ResourceD [label="map"];
2.161 +
2.162 + ResourceD -> ProgramFile:d [style=dashed];
2.163 +
2.164 + ResourceD -> Flexpage [dir=none];
2.165 + Flexpage -> ExternalPager;
2.166 +
2.167 + ExternalPager -> MappedFlexpage [dir=none];
2.168 + MappedFlexpage -> TaskMemory:d;
2.169 +}
2.170 +}}}
2.171 +
2.172 +########
2.173 +
2.174 +== Configuring Programs ==
2.175 +
2.176 +To provide an internal page fault handler alongside an actual program to be
2.177 +run, the following arrangement is used:
2.178 +
2.179 +######## A graph showing the configuration arrangement
2.180 +
2.181 +{{{#!graphviz
2.182 +#format svg
2.183 +#transform notugly
2.184 +digraph program_configuration {
2.185 + node [fontsize="12.0",fontname="sans-serif",shape=box];
2.186 + edge [fontsize="12.0",fontname="sans-serif"];
2.187 + rankdir=LR;
2.188 +
2.189 + subgraph {
2.190 + rank=min;
2.191 +
2.192 + CreatingTask_note [shape=note,style=filled,fillcolor=gold,label="Responsible for\ncreating the\nnew task"];
2.193 + CreatingTask [label="Creating task"];
2.194 +
2.195 + CreatingTask_note -> CreatingTask [dir=none,style=dotted];
2.196 + }
2.197 +
2.198 + subgraph {
2.199 + rank=max;
2.200 +
2.201 + IPCGate_note [shape=note,style=filled,fillcolor=gold,label="Created for sharing\nbetween the tasks"];
2.202 + IPCGate [shape=octagon,label="IPC gate"];
2.203 +
2.204 + IPCGate_note -> IPCGate [dir=none,style=dotted];
2.205 + }
2.206 +
2.207 + InitCaps [shape=record,label="<head> Initial capabilities | {<s> \"server\" |<c> capability }"];
2.208 +
2.209 + subgraph {
2.210 + rank=same;
2.211 +
2.212 + InternalPager;
2.213 + InternalPager_note [shape=note,style=filled,fillcolor=gold,label="Starts and binds\nto IPC gate"];
2.214 +
2.215 + InternalPager -> InternalPager_note [dir=none,style=dotted];
2.216 +
2.217 + Program;
2.218 + Program_note [shape=note,style=filled,fillcolor=gold,label="Starts and references\npager via IPC gate"];
2.219 +
2.220 + Program -> Program_note [dir=none,style=dotted];
2.221 + }
2.222 +
2.223 + /* Create and transfer IPC gate for binding. */
2.224 +
2.225 + CreatingTask -> IPCGate [label="create"];
2.226 + CreatingTask -> InitCaps:head [label="define"];
2.227 + InitCaps:c -> IPCGate;
2.228 +
2.229 + /* Thread initiation. */
2.230 +
2.231 + CreatingTask -> InternalPager [label="start"];
2.232 + InternalPager -> InitCaps:s [label="bind"];
2.233 +
2.234 + CreatingTask -> Program [label="start"];
2.235 + Program -> IPCGate -> InternalPager [style=dashed];
2.236 +}
2.237 +}}}
2.238 +
2.239 +########