memory.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Memory | NebOS Architecture</title>
  7. <meta name="description" content="NebOS memory architecture: fixed low-memory addresses, E820 parsing, bitmap frame allocator with lowmem/highmem zones, identity paging, kmap, MTRR write-combining, user arenas and boot-pack lifetime.">
  8. <link rel="icon" href="favicon.svg" type="image/svg+xml">
  9. <link rel="stylesheet" href="style.css">
  10. </head>
  11. <body>
  12. <a class="skip" href="#main">Skip to content</a>
  13. <header class="site-header">
  14. <a class="brand" href="index.html">
  15. <span class="brand-mark" aria-hidden="true"></span>
  16. <span>NebOS <span class="brand-sub">Architecture</span></span>
  17. </a>
  18. <nav class="site-nav" aria-label="Architecture sections">
  19. <a href="index.html">Overview</a>
  20. <a href="boot.html">Boot</a>
  21. <a href="memory.html" aria-current="page">Memory</a>
  22. <a href="cpu.html">CPU</a>
  23. <a href="drivers.html">Drivers</a>
  24. <a href="filesystems.html">Filesystems</a>
  25. <a href="graphics.html">Graphics</a>
  26. <a href="network.html">Network</a>
  27. <a href="userland.html">Userland</a>
  28. <a href="development.html">Development</a>
  29. </nav>
  30. </header>
  31. <main id="main" class="page">
  32. <div class="page-head">
  33. <p class="kicker">Memory &amp; paging</p>
  34. <h1>A fixed ladder and a 4 KB frame allocator.</h1>
  35. <p class="lede">
  36. NebOS identity-maps the first 1 GB of RAM (lowmem) with 4 MB pages
  37. and hands out 4 KB frames from a bitmap; RAM from 1 GB up to 4 GB
  38. (highmem) backs ring-3 pages and is reached by the kernel through
  39. per-CPU <code>kmap</code> slots. A small set of low-memory addresses is
  40. fixed by the boot path and the ABI; everything else — process stacks,
  41. window canvases, the ring-3 heap and the rootfs copy — is dynamic.
  42. </p>
  43. <div class="meta">
  44. <span class="pill">1 GB lowmem · 4 GB highmem</span>
  45. <span class="pill">4 KB frames</span>
  46. <span class="pill">4 MB PSE pages</span>
  47. <span class="pill">identity map</span>
  48. </div>
  49. </div>
  50. <nav class="toc" aria-label="On this page">
  51. <h2>On this page</h2>
  52. <ul>
  53. <li><a href="#physical">Physical memory</a></li>
  54. <li><a href="#landmarks">Address landmarks</a></li>
  55. <li><a href="#paging">Paging &amp; caching</a></li>
  56. <li><a href="#frame">Frame allocator</a></li>
  57. <li><a href="#heap">kmalloc</a></li>
  58. <li><a href="#user">Ring-3 memory</a></li>
  59. <li><a href="#pack">Rootfs pack lifetime</a></li>
  60. <li><a href="#limits">Limits &amp; leaks</a></li>
  61. <li><a href="#sources">Source map</a></li>
  62. </ul>
  63. </nav>
  64. <section id="physical">
  65. <h2>Physical memory</h2>
  66. <p>
  67. The real-mode stage probes <code>INT 15h</code> E820 and writes the
  68. map to <code>0x1000</code>; the UEFI loader synthesises the same
  69. structure from <code>GetMemoryMap</code>. <span class="file">mm.c</span>
  70. starts with every page marked used, frees the E820 “usable RAM”
  71. ranges, then reserves the regions the kernel already owns.
  72. </p>
  73. <figure class="figure">
  74. <svg viewBox="0 0 920 180" role="img" aria-labelledby="phys-title phys-desc">
  75. <title id="phys-title">Physical memory composition</title>
  76. <desc id="phys-desc">Of the 1 GB addressable window, the low 1 MB and an 8 MB VGA shadow reserve are unavailable, leaving about 1015 MB for the frame allocator.</desc>
  77. <text class="svg-text" x="20" y="28">0x00000000</text>
  78. <text class="svg-text" x="900" y="28" text-anchor="end">0x40000000 · 1 GB</text>
  79. <rect class="svg-box blue" x="40" y="44" width="1.5" height="34" rx="1"/>
  80. <rect class="svg-box accent" x="41.5" y="44" width="6.7" height="34" rx="1"/>
  81. <rect class="svg-box green" x="48.2" y="44" width="851.8" height="34" rx="2"/>
  82. <text class="svg-tiny" x="40" y="100">low 1 MB</text>
  83. <text class="svg-tiny" x="64" y="100">VGA shadow · 8 MB</text>
  84. <text class="svg-tiny" x="477" y="100" text-anchor="middle">frame allocator · ~1015 MB</text>
  85. <line class="svg-line" x1="41" y1="78" x2="41" y2="88"/>
  86. <line class="svg-line" x1="45" y1="78" x2="45" y2="88"/>
  87. <line class="svg-line" x1="490" y1="78" x2="490" y2="88"/>
  88. <text class="svg-tiny" x="40" y="130">boot structures · kernel image · BIOS/UMA · DMA buffers</text>
  89. <text class="svg-tiny" x="40" y="150">The 8 MB reserve protects the shadow buffer; the allocator starts at 0x900000.</text>
  90. </svg>
  91. <figcaption>
  92. <strong>Lowmem ends at 1 GB</strong> (<code>MM_MAX_PHYS</code>,
  93. <code>include/phys.h</code>). The identity map covers
  94. <code>[0, 0x40000000)</code> and ring-3 space starts at
  95. <code>USER_BASE</code> = <code>0x40000000</code>; <code>paging.c</code>
  96. statically asserts the two never overlap. RAM above 1 GB (up to
  97. <code>MM_HIGH_LIMIT</code>, 4 GB) is highmem: tracked by the same
  98. bitmap, never identity-mapped, used only for ring-3 pages. Highmem that the firmware's variable MTRRs leave non-write-back (a BIOS short of MTRRs on a 3–4 GB board) is never handed out: <code>mm_init</code> asks <code>mtrr_mem_type()</code> for every MB of free RAM, withholds such highmem, logs <code>mm: RAM not write-back by MTRR</code>, and <code>meminfo</code> shows the counts. Ring-3 code whose heap sits in uncached RAM runs many times slower (a browser's JavaScript heap, for example). The VGA shadow reserve is conservative: the
  99. actual buffer is smaller, but the gap keeps a future resolution bump
  100. from colliding with allocated pages.
  101. </figcaption>
  102. </figure>
  103. </section>
  104. <section id="landmarks">
  105. <h2>Address landmarks</h2>
  106. <p>
  107. These addresses are part of the boot contract or the kernel ABI.
  108. Changing one requires updating the assembly, linker scripts, headers
  109. and this table together.
  110. </p>
  111. <div class="table-wrap">
  112. <table>
  113. <thead>
  114. <tr><th>Address</th><th>Purpose</th><th>Written by / notes</th></tr>
  115. </thead>
  116. <tbody>
  117. <tr><td><code>0x500</code></td><td>Boot info, 12 dwords</td><td>VESA stage, UEFI loader or kexec; <code>bootinfo.h</code></td></tr>
  118. <tr><td><code>0x600</code></td><td>Boot framebuffer info</td><td>VESA stage or UEFI loader; <code>vga.h</code></td></tr>
  119. <tr><td><code>0x7C00</code></td><td>Boot-sector load address / UEFI handoff stack top</td><td>BIOS and UEFI trampoline</td></tr>
  120. <tr><td><code>0x7E00</code></td><td>Kernel load address and VESA-stage entry</td><td><code>kernel.ld</code></td></tr>
  121. <tr><td><code>0x800</code></td><td>kexec and UEFI trampoline</td><td>Relocated at runtime; below the kernel</td></tr>
  122. <tr><td><code>0x900</code></td><td>kexec/UEFI flat GDT and GDTR</td><td>Built at runtime; below the kernel</td></tr>
  123. <tr><td><code>0x1000</code></td><td>E820 memory map</td><td>VESA stage, UEFI loader or kexec; parsed by <code>mm.c</code></td></tr>
  124. <tr><td><code>0x3000</code></td><td>UHCI frame list</td><td>1024 × 4 bytes, 4 KB aligned</td></tr>
  125. <tr><td><code>0x4000</code></td><td>ISA DMA buffer</td><td>One sector, used by the floppy driver</td></tr>
  126. <tr><td><code>0x6000</code></td><td>AP real/protected-mode trampoline</td><td>SIPI vector <code>0x06</code>; image ends below <code>0x6C00</code></td></tr>
  127. <tr><td><code>0x6C00</code></td><td>AP trampoline real-mode stack top</td><td>Grows down</td></tr>
  128. <tr><td><code>0x6F00</code></td><td>AP startup info block</td><td>CR3, stack top, C entry, CPU index</td></tr>
  129. <tr><td><code>0x60000</code></td><td>Former rootfs staging</td><td>No longer used by the loader; kernel BSS/stack may use it</td></tr>
  130. <tr><td><code>_end</code></td><td>Kernel end</td><td><code>kernel.ld</code> asserts <code>_end ≤ 0x90000</code></td></tr>
  131. <tr><td><code>0x900000</code></td><td>Boot pack (written directly by the legacy stage), then the frame bitmap right after it; dynamic stacks and kexec staging</td><td>The pack is freed after <code>ramfs_init</code> takes its copy; the bitmap stays</td></tr>
  132. <tr><td><code>0x100000</code></td><td>VGA shadow buffer base</td><td><code>VGA_SHADOW_BASE</code>; 8 MB reserved</td></tr>
  133. <tr><td><code>0x40000000</code></td><td>Ring-3 ELF link/load address</td><td><code>USER_BASE</code>, 4 MB window up to <code>0x40400000</code></td></tr>
  134. <tr><td><code>0x4FC00000</code></td><td>kmap window (virtual)</td><td><code>MM_KMAP_VA</code>; supervisor page table shared by every directory, 4 slots per CPU</td></tr>
  135. <tr><td><code>0x50000000</code></td><td>Ring-3 window canvas</td><td><code>USER_WIN_BASE</code>, 4 MB slot</td></tr>
  136. <tr><td><code>0x58000000</code></td><td>WM shadow mapping</td><td><code>WM_SHADOW_VA</code>; ring-3 WM only</td></tr>
  137. <tr><td><code>0x59000000</code></td><td>WM content slots</td><td><code>WM_CONTENT_VA_BASE</code> + index × 4 MB (<code>WM_CONTENT_SLOT</code>)</td></tr>
  138. <tr><td><code>0x60000000</code></td><td>Ring-3 anonymous heap</td><td><code>USER_HEAP_BASE</code>, up to 64 MB</td></tr>
  139. <tr><td><code>0xC0000000</code></td><td>ioremap window (virtual)</td><td><code>IOMAP_BASE</code> to 4 GB: MMIO, firmware tables, LFB; kernel-only, 4 KB pages</td></tr>
  140. </tbody>
  141. </table>
  142. </div>
  143. </section>
  144. <section id="paging">
  145. <h2>Paging &amp; caching</h2>
  146. <p>
  147. <span class="file">paging.c</span> builds an identity map of RAM with
  148. 4 MB pages through <code>CR4.PSE</code>, adds the framebuffer's LFB
  149. range (in lowmem; otherwise through the ioremap window), and enables
  150. <code>CR0.PG</code> and <code>CR0.WP</code>. Before
  151. switching, it clears translation controls a BIOS protected-mode call
  152. can leave behind: <code>CR4.PAE/PGE/LA57/PCIDE/SMEP/SMAP</code> and
  153. <code>EFER.LME</code>.
  154. </p>
  155. <ul>
  156. <li><strong>Identity map.</strong> Physical and virtual addresses are equal below 1 GB (lowmem). Page-directory entries are shared with every process.</li>
  157. <li><strong>kmap window.</strong> The 4 MB slot at <code>MM_KMAP_VA</code> (<code>0x4FC00000</code>, in the unused gap below <code>USER_WIN_BASE</code>) has one supervisor page table that every process directory shares. <code>kmap(phys)</code> returns the identity address for lowmem, and for a highmem frame takes this CPU's next slot (4 per CPU, nesting LIFO) with preemption disabled until <code>kunmap()</code>; only the local TLB entry is flushed, because no other CPU uses that slot. It is not the last lowmem slot, because firmware puts the ACPI tables at the top of RAM, and not the top of the address space, where a VBE LFB may sit.</li>
  158. <li><strong>ioremap window.</strong> Nothing above lowmem is mapped at its physical address. Device registers, ACPI/SMBIOS tables and the LFB go through <code>ioremap(phys, size, type)</code>: lowmem returns its identity address (an MMIO range there gets uncacheable 4 MB pages), everything else gets 4 KB pages in the kernel-only window <code>[0xC0000000, 4 GB)</code> (<code>IOMAP_BASE</code>). Its page tables are allocated on first use and copied into every live process directory (<code>process_sync_kernel_pde</code>); a range already covered by a same-type mapping is reused, and one that runs past the newest mapping grows it in place. MMIO pages are uncached except the pages the LFB's WC MTRR covers, which are cacheable in every alias; <code>IOREMAP_RAM</code> pages are write-back. Drivers keep the physical BAR for logs and use the returned pointer. <code>peek</code>, <code>poke</code> and <code>dbg</code> reach any physical byte through <code>paging_debug_map()</code>.</li>
  159. <li><strong>Kernel stacks mapped everywhere.</strong> Each process gets a page directory cloned from the kernel identity map, so CR3 can switch while still running on the old kernel stack.</li>
  160. <li><strong>LFB is uncacheable by default.</strong> If <code>mtrr_set_wc()</code> successfully covers the framebuffer, the LFB pages are mapped cacheable so the shadow-buffer flush can write-combine.</li>
  161. <li><strong>No process isolation.</strong> There is one address space with per-process page directories only for mappings; a wild ring-0 or ring-3 pointer can reach any mapped physical page.</li>
  162. </ul>
  163. <p>
  164. There is no cross-CPU TLB shootdown. MMIO mappings for another CPU's
  165. running process rely on not-present TLB entries not being cached;
  166. normal process teardown is unaffected because no two processes share
  167. an address space.
  168. </p>
  169. <div class="note">
  170. <p><strong>NVIDIA ION special case.</strong> On the ION the framebuffer is
  171. stolen DRAM and the VBE LFB is a BAR3 window into it. The BIOS leaves a
  172. 512 MB uncacheable MTRR over the PCIe apertures, so <span class="file">nvidia.c</span>
  173. locates the framebuffer in the stolen VRAM and writes through that
  174. alias once a WC MTRR covers the stolen range. Everything else keeps
  175. the uncacheable LFB.</p>
  176. </div>
  177. </section>
  178. <section id="frame">
  179. <h2>Frame allocator</h2>
  180. <p>
  181. <span class="file">mm.c</span> keeps one bit per 4 KB page for the
  182. RAM below 4 GB: the bitmap is sized to the highest E820 RAM
  183. address (32 KB at 1 GB, 96 KB at 3 GB) and is not part of the kernel
  184. image. <code>mm_init</code> places it in the first lowmem E820 RAM run at or above
  185. <code>0x900000</code> that avoids the boot rootfs pack and the LFB, and
  186. marks its own pages used (legacy boots put it right after the pack;
  187. a 16 MB static fallback covers a missing E820 map). The allocators
  188. disable interrupts around the bitmap and hand out the lowest free
  189. frames of a zone: each zone has a first-free word hint that skips its
  190. full low part, single pages are found with <code>bsf</code>, and
  191. <code>mm_alloc_pages(n)</code> steps over full and empty words 32 pages
  192. at a time. Everything the kernel dereferences by physical address
  193. (page tables, DMA buffers, canvases, kernel stacks, <code>kmalloc</code>)
  194. comes from lowmem; ring-3 program, stack and heap frames prefer
  195. highmem. The allocator returns:
  196. </p>
  197. <ul>
  198. <li><code>mm_alloc_page()</code> — one lowmem page (physical address 0 means failure).</li>
  199. <li><code>mm_alloc_user_page()</code> — one frame for a ring-3 mapping: highmem first, lowmem when highmem is exhausted. Touch it only through <code>kmap()</code> or the user mapping (<span class="file">elf.c</span>, the user stack in <span class="file">process.c</span>, the heap in <span class="file">sys_mem.c</span>).</li>
  200. <li><code>mm_alloc_pages(n)</code> — <code>n</code> contiguous lowmem pages.</li>
  201. <li><code>mm_free_page()</code> / <code>mm_free_range()</code> — release a page or a page-aligned boot reservation.</li>
  202. </ul>
  203. <p>
  204. At boot, <code>mm_init</code> reserves the low 1 MB, the 8 MB VGA
  205. shadow region, any LFB that overlaps RAM, the bitmap itself and the
  206. boot-time rootfs pack. The pack reservation is released by
  207. <code>ramfs_init</code> after it copies/inflates the pack into fresh
  208. pages.
  209. </p>
  210. <p>
  211. Fresh pages are <em>not</em> zeroed. Structures whose fields are read
  212. before being written must be cleared explicitly; <code>clear_proc()</code>
  213. in <span class="file">process.c</span> exists because a stale
  214. <code>cr3</code> faulted on real hardware while QEMU's cleared RAM hid
  215. the bug.
  216. </p>
  217. </section>
  218. <section id="heap">
  219. <h2>kmalloc</h2>
  220. <p>
  221. <span class="file">kmalloc.c</span> is a power-of-two heap allocator
  222. on top of the frame allocator. It is intentionally simple: allocation
  223. rounds to a size class, free lists are per class, and large objects
  224. become contiguous page runs. PCBs, command context and
  225. <span class="file">sys_fs.c</span> file loads use it.
  226. </p>
  227. <p>
  228. The kernel heap is separate from userspace. Ring-3 processes get one
  229. anonymous arena through <code>SYS_MEM_ALLOC</code>,
  230. <code>SYS_MEM_GROW</code> and <code>SYS_MEM_FREE</code>;
  231. commands manage it with <code>malloc</code>/<code>free</code>
  232. from <span class="file">libc/malloc.c</span>. The syscalls are the
  233. backend in <span class="file">libc/ucmd_mem.c</span> and are not
  234. called by application code.
  235. </p>
  236. </section>
  237. <section id="user">
  238. <h2>Ring-3 memory</h2>
  239. <p>
  240. A ring-3 ELF is linked at <code>0x40000000</code>. The image and its
  241. 32-page (128 KB) user stack live in a 4 MB window ending at
  242. <code>0x40400000</code>. The kernel window server maps a window's
  243. RGB565 back buffer at <code>0x50000000</code>, and the anonymous heap
  244. starts at <code>0x60000000</code>.
  245. </p>
  246. <figure class="figure">
  247. <div class="bars" role="img" aria-label="Ring-3 arena sizes relative to the 64 MB heap cap: image and stack 4 MB, canvas slot 4 MB, heap up to 64 MB.">
  248. <div class="bar-row">
  249. <span class="bar-label">image + stack</span>
  250. <div class="bar-track"><span class="bar-fill blue" style="--w:6.25%"></span></div>
  251. <span class="bar-value">4 MB</span>
  252. </div>
  253. <div class="bar-row">
  254. <span class="bar-label">canvas slot</span>
  255. <div class="bar-track"><span class="bar-fill" style="--w:6.25%"></span></div>
  256. <span class="bar-value">4 MB</span>
  257. </div>
  258. <div class="bar-row">
  259. <span class="bar-label">anonymous heap</span>
  260. <div class="bar-track"><span class="bar-fill green" style="--w:100%"></span></div>
  261. <span class="bar-value">64 MB</span>
  262. </div>
  263. </div>
  264. <figcaption>
  265. <strong>Three separate rings.</strong> The image/stack window is
  266. fixed at link time; the canvas slot is one 4 MB mapping; the heap is
  267. a growable arena. Bar widths are relative to the 64 MB heap cap
  268. (<code>USER_HEAP_MAX</code> in <span class="file">process.h</span>; the browser's
  269. DOM arenas and QuickJS heap use ~30 MB before images).
  270. </figcaption>
  271. </figure>
  272. <div class="table-wrap">
  273. <table>
  274. <thead>
  275. <tr><th>Range</th><th>Size</th><th>Contents</th></tr>
  276. </thead>
  277. <tbody>
  278. <tr><td><code>0x40000000</code>–<code>0x40400000</code></td><td>4 MB</td><td>ELF segments, user stack top at <code>0x40400000</code> (32 pages / 128 KB, grows down); highmem frames when available</td></tr>
  279. <tr><td><code>0x50000000</code>–<code>0x50400000</code></td><td>4 MB</td><td>One window canvas mapping (RW, per window)</td></tr>
  280. <tr><td><code>0x60000000</code>–<code>0x64000000</code></td><td>up to 64 MB</td><td>Anonymous heap (highmem frames when available, zeroed through <code>kmap</code>); initial allocation zeroed, growth pages are not</td></tr>
  281. </tbody>
  282. </table>
  283. </div>
  284. <p>
  285. Ring-3 commands treat that arena as a real heap:
  286. <span class="file">libc/malloc.c</span> maps 64 KB on
  287. first use, grows in page-rounded steps with 64 KB slack, and uses
  288. boundary-tag blocks with a first-fit free list and immediate
  289. coalescing. <code>heap_reset()</code> discards everything and unmaps
  290. the arena; the browser calls it on navigation, so page-scoped
  291. allocations (body, rules, image bitmaps and decode arenas) go back
  292. to the frame allocator. A single allocation near 64 MB fails because
  293. block headers count against the same cap.
  294. </p>
  295. <p>
  296. Kernel stacks are 4 KB pages from the frame allocator, with an 8-stack
  297. static fallback pool in BSS. The idle/bootstrap context uses the
  298. in-image 8 KB <code>.stack</code> section. The user stack is separate:
  299. 32 pages just below <code>0x40400000</code>.
  300. </p>
  301. </section>
  302. <section id="pack">
  303. <h2>Rootfs pack lifetime</h2>
  304. <ol>
  305. <li>The compressed pack is at most 4 MB (<code>PACK_MAX</code>), so the legacy copy ends below <code>0xD00000</code>, still inside the 16 MB no-E820 fallback; inflated it is about 4.35 MB with the WiFi firmware (the 8 MB <code>RAMFS_MAX_DECOMPRESSED</code> cap applies).</li>
  306. <li>The boot path places the gzip pack in RAM: the legacy stage copies it directly to <code>0x900000</code> with a protected-mode <code>rep movsb</code>, UEFI into a loader-data buffer below 1 GB, kexec in its staging buffer.</li>
  307. <li><code>mm_init</code> reserves <code>[pack_addr, pack_addr + pack_size)</code> so the frame allocator cannot reuse it.</li>
  308. <li><code>ramfs_init</code> takes a private page-allocated copy, validates the <code>NBROOT1</code> header and inflates the pack into it.</li>
  309. <li><code>mm_free_range</code> releases the boot region when it is above the VGA shadow reserve. The private copy lives until <code>ramfs_replace</code> or reboot.</li>
  310. </ol>
  311. <p>
  312. The ramfs holds at most 128 files and 8 MB of decompressed pack. A
  313. larger pack fails to load rather than partially mounting.
  314. </p>
  315. </section>
  316. <section id="limits">
  317. <h2>Limits &amp; leaks</h2>
  318. <ul>
  319. <li><strong>No per-process address spaces.</strong> Paging is identity-mapped; there is no memory protection between processes.</li>
  320. <li><strong>4 GB ceiling, 64 MB per process.</strong> RAM above 4 GB is ignored (it would need PAE). Highmem raises the system total, but one process still has a 64 MB heap and a 4 MB image/stack window; <code>[USER_BASE, IOMAP_BASE)</code> is free for demand paging. A wild kernel pointer between the identity map and the user windows is an instant <code>#PF</code>.</li>
  321. <li><strong>ioremap is append-only.</strong> 1 GB of window, 96 mapping records and no unmap: a driver that remaps repeatedly would exhaust it (<code>ioremap</code> logs <code>window full</code> and returns 0).</li>
  322. <li><strong>Highmem is user-only.</strong> Contiguous kernel buffers and every kernel structure stay in the 1 GB lowmem zone, so a machine with 4 GB can still run out of lowmem first.</li>
  323. <li><strong>Kernel heap fragmentation.</strong> <code>kmalloc</code>'s power-of-two size classes make long-running mixed-size kernel allocation wasteful; ring-3 commands use the separate first-fit libc heap described above.</li>
  324. <li><strong>No TLB shootdown.</strong> Cross-CPU mapping changes rely on not-present entries not being cached.</li>
  325. </ul>
  326. </section>
  327. <section id="sources">
  328. <h2>Source map</h2>
  329. <ul class="filelist">
  330. <li><code>kernel/mm.c</code>, <code>kernel/mm.h</code> — E820 + bitmap allocator</li>
  331. <li><code>include/phys.h</code> — lowmem ceiling, kmap window, highmem limit</li>
  332. <li><code>kernel/kmalloc.c</code>, <code>kernel/kmalloc.h</code> — kernel heap</li>
  333. <li><code>user/lib/libc/malloc.c</code>, <code>user/lib/libc/ucmd_mem.c</code> — ring-3 heap and <code>SYS_MEM_*</code> backend</li>
  334. <li><code>user/lib/libc/string.c</code>, <code>user/lib/libc/stdlib.c</code> — ring-3 libc support</li>
  335. <li><code>kernel/paging.c</code>, <code>kernel/paging.h</code> — identity map, kmap window, ioremap window, debug physical access</li>
  336. <li><code>kernel/mtrr.c</code> — write-combining MTRRs</li>
  337. <li><code>kernel/process.c</code>, <code>kernel/process.h</code> — stacks and user layout</li>
  338. <li><code>kernel/ramfs.c</code> — pack copy / inflate</li>
  339. <li><code>boot/efi/main.c</code> — firmware map conversion</li>
  340. <li><code>kernel/kernel.ld</code> — low-memory image limits</li>
  341. </ul>
  342. </section>
  343. </main>
  344. <footer class="site-footer">
  345. <div class="inner">
  346. <p><strong>NebOS 0.2.0</strong> · Architecture documentation · <a href="index.html">overview</a></p>
  347. <p>Maintain alongside <code>AGENTS.md</code> and the source files listed on each page.</p>
  348. </div>
  349. </footer>
  350. </body>
  351. </html>