1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/docs/wiki/Program_Loading Fri Aug 12 16:41:06 2022 +0200
1.3 @@ -0,0 +1,236 @@
1.4 += Program Loading =
1.5 +
1.6 +The provision of [[Paging|paging]] of file content leads to the possibility of
1.7 +demand paging for programs, enabling them to be loaded into memory dynamically
1.8 +and to have only the active portions of those programs resident. To achieve
1.9 +this, programs must be appropriately initialised in new tasks, with a page
1.10 +fault handler configured to provide program file content whenever a region of
1.11 +the program payload is encountered that is not currently resident in memory.
1.12 +
1.13 +== Internal Page Fault Handlers ==
1.14 +
1.15 +When satisfying page faults for a task, one approach involves situating the
1.16 +page fault handler within the task itself, this managing the available memory
1.17 +regions and employing receive windows when requesting memory pages.
1.18 +
1.19 +The general arrangement involving such internal page fault handlers for a
1.20 +program in a task is as follows:
1.21 +
1.22 +######## A graph showing the internal paging mechanism
1.23 +
1.24 +{{{#!graphviz
1.25 +#format svg
1.26 +#transform notugly
1.27 +digraph internal_paging {
1.28 + node [fontsize="12.0",fontname="sans-serif",shape=box];
1.29 + edge [fontsize="12.0",fontname="sans-serif"];
1.30 + rankdir=LR;
1.31 +
1.32 + TaskMemory [shape=record,label="Task Memory |<s> stack | ... |<d> data | ... |<c> code"];
1.33 +
1.34 + subgraph {
1.35 + rank=same;
1.36 +
1.37 + InternalPager;
1.38 + InternalPager_note [shape=note,style=filled,fillcolor=gold,label="Resides in\nsame task and\ndefines scope of\nfault resolution"];
1.39 +
1.40 + InternalPager -> InternalPager_note [dir=none,style=dotted];
1.41 + }
1.42 +
1.43 + subgraph {
1.44 + rank=same;
1.45 +
1.46 + Regions [shape=record,label="Regions |
1.47 + {<s> stack |<sd> stack-dataspace } |
1.48 + {<d> data | <dd> data-dataspace } |
1.49 + {<c> code |<cd> code-dataspace } |..."];
1.50 +
1.51 + ReceiveFlexpage [shape=note,label="Flexpage\n(receive window)"];
1.52 +
1.53 + Flexpage [shape=note];
1.54 + Flexpage_note [shape=note,style=filled,fillcolor=gold,label="Satisfies\nmemory\naccess"];
1.55 +
1.56 + Flexpage -> Flexpage_note [dir=none,style=dotted];
1.57 + }
1.58 +
1.59 + subgraph {
1.60 + rank=same;
1.61 +
1.62 + ResourceD [label="Resource\n(Pager)"];
1.63 + ResourceD_note [shape=note,style=filled,fillcolor=gold,label="Provides access\nto file content"];
1.64 +
1.65 + ResourceD -> ResourceD_note [dir=none,style=dotted];
1.66 + }
1.67 +
1.68 + ProgramFile [shape=record,label="Program File | ... |<d> data |<c> code | ..."];
1.69 +
1.70 + /* Page fault handling. */
1.71 +
1.72 + TaskMemory:d -> InternalPager [label="page fault"];
1.73 +
1.74 + InternalPager -> Regions:d [label="find region"];
1.75 +
1.76 + Regions:dd -> ResourceD [style=dashed];
1.77 +
1.78 + InternalPager -> ReceiveFlexpage [dir=none];
1.79 + ReceiveFlexpage -> ResourceD [label="map"];
1.80 +
1.81 + ResourceD -> ProgramFile:d [style=dashed];
1.82 +
1.83 + ResourceD -> Flexpage [dir=none];
1.84 + Flexpage -> InternalPager;
1.85 +}
1.86 +}}}
1.87 +
1.88 +########
1.89 +
1.90 +== External Page Fault Handlers ==
1.91 +
1.92 +Another approach that may be used to support an internal page fault handler
1.93 +deployed in a task is to employ an external page fault handler in the creating
1.94 +task. When a page fault occurs, the external handler ensures that the
1.95 +appropriate content has been brought into its own memory space. It then
1.96 +returns a flexpage from the handler routine to resolve the fault.
1.97 +
1.98 +######## A graph showing the external paging mechanism
1.99 +
1.100 +{{{#!graphviz
1.101 +#format svg
1.102 +#transform notugly
1.103 +digraph external_paging {
1.104 + node [fontsize="12.0",fontname="sans-serif",shape=box];
1.105 + edge [fontsize="12.0",fontname="sans-serif"];
1.106 + rankdir=LR;
1.107 +
1.108 + TaskMemory [shape=record,label="Task Memory |<s> stack | ... |<d> data | ... |<c> code"];
1.109 +
1.110 + subgraph {
1.111 + rank=same;
1.112 +
1.113 + ExternalPager_note [shape=note,style=filled,fillcolor=gold,label="Resides in\nseparate task"];
1.114 + ExternalPager;
1.115 +
1.116 + ExternalPager_note -> ExternalPager [dir=none,style=dotted];
1.117 +
1.118 + MappedFlexpage [shape=note,label="Flexpage\n(positioned)"];
1.119 + MappedFlexpage_note [shape=note,style=filled,fillcolor=gold,label="Satisfies\nmemory\naccess"];
1.120 +
1.121 + MappedFlexpage -> MappedFlexpage_note [dir=none,style=dotted];
1.122 + }
1.123 +
1.124 + subgraph {
1.125 + rank=same;
1.126 +
1.127 + Regions [shape=record,label="Regions |
1.128 + {<s> stack |<sd> stack-dataspace } |
1.129 + {<d> data | <dd> data-dataspace } |
1.130 + {<c> code |<cd> code-dataspace } |..."];
1.131 +
1.132 + L4Re [shape=ellipse,label="L4Re paging\nfunctionality"];
1.133 + L4Re_note [shape=note,style=filled,fillcolor=gold,label="Supports normal\naccess to file content"];
1.134 +
1.135 + L4Re -> L4Re_note [dir=none,style=dotted];
1.136 +
1.137 + Flexpage [shape=note];
1.138 + }
1.139 +
1.140 + subgraph {
1.141 + rank=same;
1.142 +
1.143 + ResourceD [label="Resource\n(Pager)"];
1.144 + ResourceD_note [shape=note,style=filled,fillcolor=gold,label="Provides access\nto file content"];
1.145 +
1.146 + ResourceD -> ResourceD_note [dir=none,style=dotted];
1.147 + }
1.148 +
1.149 + ProgramFile [shape=record,label="Program File | ... |<d> data |<c> code | ..."];
1.150 +
1.151 + /* Page fault handling. */
1.152 +
1.153 + TaskMemory:d -> ExternalPager [label="page fault"];
1.154 +
1.155 + ExternalPager -> Regions:d [label="find region"];
1.156 +
1.157 + Regions:dd -> ResourceD [style=dashed];
1.158 +
1.159 + ExternalPager -> L4Re;
1.160 + L4Re -> ResourceD [label="map"];
1.161 +
1.162 + ResourceD -> ProgramFile:d [style=dashed];
1.163 +
1.164 + ResourceD -> Flexpage [dir=none];
1.165 + Flexpage -> ExternalPager;
1.166 +
1.167 + ExternalPager -> MappedFlexpage [dir=none];
1.168 + MappedFlexpage -> TaskMemory:d;
1.169 +}
1.170 +}}}
1.171 +
1.172 +########
1.173 +
1.174 +== Configuring Programs ==
1.175 +
1.176 +To provide an internal page fault handler alongside an actual program to be
1.177 +run, the following arrangement is used:
1.178 +
1.179 +######## A graph showing the configuration arrangement
1.180 +
1.181 +{{{#!graphviz
1.182 +#format svg
1.183 +#transform notugly
1.184 +digraph program_configuration {
1.185 + node [fontsize="12.0",fontname="sans-serif",shape=box];
1.186 + edge [fontsize="12.0",fontname="sans-serif"];
1.187 + rankdir=LR;
1.188 +
1.189 + subgraph {
1.190 + rank=min;
1.191 +
1.192 + CreatingTask_note [shape=note,style=filled,fillcolor=gold,label="Responsible for\ncreating the\nnew task"];
1.193 + CreatingTask [label="Creating task"];
1.194 +
1.195 + CreatingTask_note -> CreatingTask [dir=none,style=dotted];
1.196 + }
1.197 +
1.198 + subgraph {
1.199 + rank=max;
1.200 +
1.201 + IPCGate_note [shape=note,style=filled,fillcolor=gold,label="Created for sharing\nbetween the tasks"];
1.202 + IPCGate [shape=octagon,label="IPC gate"];
1.203 +
1.204 + IPCGate_note -> IPCGate [dir=none,style=dotted];
1.205 + }
1.206 +
1.207 + InitCaps [shape=record,label="<head> Initial capabilities | {<s> \"server\" |<c> capability }"];
1.208 +
1.209 + subgraph {
1.210 + rank=same;
1.211 +
1.212 + InternalPager;
1.213 + InternalPager_note [shape=note,style=filled,fillcolor=gold,label="Starts and binds\nto IPC gate"];
1.214 +
1.215 + InternalPager -> InternalPager_note [dir=none,style=dotted];
1.216 +
1.217 + Program;
1.218 + Program_note [shape=note,style=filled,fillcolor=gold,label="Starts and references\npager via IPC gate"];
1.219 +
1.220 + Program -> Program_note [dir=none,style=dotted];
1.221 + }
1.222 +
1.223 + /* Create and transfer IPC gate for binding. */
1.224 +
1.225 + CreatingTask -> IPCGate [label="create"];
1.226 + CreatingTask -> InitCaps:head [label="define"];
1.227 + InitCaps:c -> IPCGate;
1.228 +
1.229 + /* Thread initiation. */
1.230 +
1.231 + CreatingTask -> InternalPager [label="start"];
1.232 + InternalPager -> InitCaps:s [label="bind"];
1.233 +
1.234 + CreatingTask -> Program [label="start"];
1.235 + Program -> IPCGate -> InternalPager [style=dashed];
1.236 +}
1.237 +}}}
1.238 +
1.239 +########