jetson-optimize-memory
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesejetson-optimize-memory
Jetson内存优化
Memory is reserved across four layers ordered by boot chronology
(higher row = earlier in boot, closer to hardware):
| Layer | Content | Key files |
|---|---|---|
| MB1 BCT | firmware carveouts | per-module misc DTS |
| MB2 BCT | firmware loading + AST controls | per-module misc DTS |
| Kernel DTS | reserved-memory and driver binding | per-module DTS |
| SWIOTLB | DMA bounce pool size | |
Critical rules:
- Only the scenarios in Scenario recipes are validated. Refuse any request to disable a carveout/cluster/node not in that table.
- Zeroing a carveout requires both: disabling the cluster's loading controls AND removing the AST that references it.
- Emit explicit overrides for every cluster in the recipe, regardless
of how the source /
#ifdeflooks. Verify the merged binary.#else - GPU SW stack must match the chip: T234 -> nvgpu, T264 and later
-> OpenRM. Follow the shared derived-platform rule in
; stop on mismatches instead of guessing.
target-platform-contract.md - Do not set SWIOTLB to 0 — some peripherals can't use the IOMMU.
内存会按启动时序分为四层进行预留(行数越靠上,启动阶段越早,越接近硬件):
| 层级 | 内容 | 关键文件 |
|---|---|---|
| MB1 BCT | 固件内存划分 | 各模块misc DTS |
| MB2 BCT | 固件加载 + AST控制 | 各模块misc DTS |
| Kernel DTS | 保留内存与驱动绑定 | 各模块DTS |
| SWIOTLB | DMA bounce池大小 | |
关键规则:
- 仅验证场景方案中列出的场景。拒绝任何禁用方案表格之外的内存划分/集群/节点的请求。
- 清空内存划分需同时执行两项操作:禁用集群的加载控制 AND 删除引用它的AST。
- 为方案中的每个集群添加显式覆盖配置,无论源文件中的/
#ifdef结构如何。请验证合并后的二进制文件。#else - GPU软件栈必须与芯片匹配:T234 → nvgpu,T264及之后的芯片 → OpenRM。遵循中的共享派生平台规则;若不匹配则停止操作,不要猜测。
target-platform-contract.md - 请勿将SWIOTLB设置为0 — 部分外设无法使用IOMMU。
Scenario recipes
场景方案
| Keyword | MB1 BCT carveouts | MB2 BCT | Kernel DTS |
|---|---|---|---|
| DCE-family (see chip table) | DCE | |
| RCE/VI/ISP-family | RCE | recommended: VI/ISP/NVCSI → disabled |
| 关键词 | MB1 BCT内存划分 | MB2 BCT | Kernel DTS |
|---|---|---|---|
| DCE系列(见芯片表格) | DCE | |
| RCE/VI/ISP系列 | RCE | 推荐:VI/ISP/NVCSI → 禁用 |
Chip-specific carveouts
芯片专属内存划分
| Scenario | T234 (Orin) | T264 (Thor) |
|---|---|---|
| | |
| | |
Post-boot:→headless.sudo systemctl set-default multi-user.target
| 场景 | T234(Orin) | T264(Thor) |
|---|---|---|
| | |
| | |
启动后操作:场景 →headless。sudo systemctl set-default multi-user.target
MB1 BCT carveout overrides
MB1 BCT内存划分覆盖配置
File:
(e.g. for Orin Nano,
for Thor).
Linux_for_Tegra/bootloader/generic/BCT/tegra<chip>-mb1-bct-misc-<module>.dtstegra234-mb1-bct-misc-p3767-0000.dtstegra264-mb1-bct-misc-p3834-0008-p4071-0000.dtsFor each carveout, add inside the existing node:
carveoutdts
aux_info@<CARVEOUT_NAME> {
pref_base = <0x0 0x0>;
size = <0x0 0x0>;
alignment = <0x0 0x0>;
};文件路径:
(例如,Orin Nano对应,Thor对应)。
Linux_for_Tegra/bootloader/generic/BCT/tegra<chip>-mb1-bct-misc-<module>.dtstegra234-mb1-bct-misc-p3767-0000.dtstegra264-mb1-bct-misc-p3834-0008-p4071-0000.dts针对每个内存划分,在已有的节点内添加:
carveoutdts
aux_info@<CARVEOUT_NAME> {
pref_base = <0x0 0x0>;
size = <0x0 0x0>;
alignment = <0x0 0x0>;
};MB2 BCT cluster + AST overrides
MB2 BCT集群 + AST覆盖配置
File:
(includes ).
Linux_for_Tegra/bootloader/generic/BCT/tegra<chip>-mb2-bct-misc-<module>.dtstegra<chip>-mb2-bct-common.dtsiFor each target cluster:
- Override :
auxp_controls@<index>dtsauxp_controls@<index> { enable_init = <0>; enable_fw_load = <0>; enable_unhalt = <0>; }; /delete-node/ auxp_ast_config@<idx>;
Look up indices in : carries a comment
naming its cluster; has children whose
lines identify the owner.
common.dtsiauxp_controls@Nauxp_ast_config@Nast_regioncarveout = <CARVEOUT_…>;文件路径:
(包含)。
Linux_for_Tegra/bootloader/generic/BCT/tegra<chip>-mb2-bct-misc-<module>.dtstegra<chip>-mb2-bct-common.dtsi针对每个目标集群:
- 覆盖:
auxp_controls@<index>dtsauxp_controls@<index> { enable_init = <0>; enable_fw_load = <0>; enable_unhalt = <0>; }; - 添加
/delete-node/ auxp_ast_config@<idx>;
在中查找索引:带有注释说明其所属集群;的子节点包含行,用于标识所属内存划分。
common.dtsiauxp_controls@Nauxp_ast_config@Nast_regioncarveout = <CARVEOUT_…>;Kernel DT reserved-memory
内核DT保留内存
sh
DTB=Linux_for_Tegra/kernel/dtb/<platform-dtb-name>.dtb
dtc -I dtb -O dts -o /tmp/platform.dts $DTBsh
DTB=Linux_for_Tegra/kernel/dtb/<platform-dtb-name>.dtb
dtc -I dtb -O dts -o /tmp/platform.dts $DTBedit: status = "disabled" on target nodes
编辑:将目标节点的status设置为"disabled"
dtc -I dts -O dtb -o $DTB /tmp/platform.dts
**Display** — disable `display@<addr>`, plus `dce@<addr>` if exposed as
a separate kernel node.
**Camera** — under `host1x@<addr>`, disable whichever of `vi*` / `isp*`
/ `nvcsi` exist on the BSP (only emit present nodes):
Locate the display controller node in the decompiled DTS and disable it.
The node's unit address is chip-specific — find it by `compatible` string
(e.g. `nvidia,tegra234-display`) rather than hard-coding the address.
```dts
host1x@<addr> {
vi0@<addr> { status = "disabled"; };
vi1@<addr> { status = "disabled"; };
isp@<addr> { status = "disabled"; };
isp1@<addr> { status = "disabled"; };
nvcsi@<addr> { status = "disabled"; };
};dtc -I dts -O dtb -o $DTB /tmp/platform.dts
**显示模块** — 禁用`display@<addr>`,若`dce@<addr>`作为独立内核节点暴露则同时禁用。
**摄像头模块** — 在`host1x@<addr>`下,禁用BSP中存在的`vi*` / `isp*` / `nvcsi`节点(仅对已存在的节点进行配置):
在反编译后的DTS中找到显示控制器节点并禁用。节点的单元地址是芯片专属的 — 通过`compatible`字符串(例如`nvidia,tegra234-display`)查找,而非硬编码地址。
```dts
host1x@<addr> {
vi0@<addr> { status = "disabled"; };
vi1@<addr> { status = "disabled"; };
isp@<addr> { status = "disabled"; };
isp1@<addr> { status = "disabled"; };
nvcsi@<addr> { status = "disabled"; };
};SWIOTLB DMA bounce pool
SWIOTLB DMA bounce池
The NVIDIA IOMMU covers peripheral DMA, so SWIOTLB is rarely used.
Edit (never ) in :
CMDLINE_ADDCMDLINELinux_for_Tegra/<module>.conf.commonsh
undefinedNVIDIA IOMMU覆盖了外设DMA,因此SWIOTLB很少被使用。
编辑中的(切勿修改):
Linux_for_Tegra/<module>.conf.commonCMDLINE_ADDCMDLINEsh
undefinedTotal bytes = swiotlb_value × 2048; 4 MiB pool:
总字节数 = swiotlb_value × 2048;4 MiB池配置:
CMDLINE_ADD="... swiotlb=2048"
---CMDLINE_ADD="... swiotlb=2048"
---Override verification (mandatory)
覆盖配置验证(必填)
After every patched MB1/MB2 BCT , reproduce the BSP's compile +
decompile using the same flags from in
:
.dts-D…bct_flags.append(...)bootloader/tegraflash_impl_t<chip>.pysh
gcc -E -nostdinc -x assembler-with-cpp \
-DENABLE_<FLAG_1> -DENABLE_<FLAG_2> \
-I bootloader -I bootloader/generic/BCT \
-o /tmp/cpp.dts <patched-bct.dts>
dtc -q -I dts -O dtb -o /tmp/cpp.dtb /tmp/cpp.dts
dtc -q -I dtb -O dts /tmp/cpp.dtb | lessConfirm in the merged output:
- Each zeroed (or
aux_info@<NAME>post macro expansion) hasaux_info@<id>Uandsize = <0x0 0x0>.pref_base = <0x0 0x0> - Each disabled has all three
auxp_controls@<idx>fieldsenable_*.<0> - Each 'd
/delete-node/is absent.auxp_ast_config@<idx>
在每次修改MB1/MB2 BCT的文件后,使用中的相同参数,重现BSP的编译+反编译流程:
.dtsbootloader/tegraflash_impl_t<chip>.pybct_flags.append(...)-D…sh
gcc -E -nostdinc -x assembler-with-cpp \
-DENABLE_<FLAG_1> -DENABLE_<FLAG_2> \
-I bootloader -I bootloader/generic/BCT \
-o /tmp/cpp.dts <patched-bct.dts>
dtc -q -I dts -O dtb -o /tmp/cpp.dtb /tmp/cpp.dts
dtc -q -I dtb -O dts /tmp/cpp.dtb | less在合并后的输出中确认:
- 每个被清空的(或宏展开后的
aux_info@<NAME>)的aux_info@<id>U且size = <0x0 0x0>。pref_base = <0x0 0x0> - 每个被禁用的的三个
auxp_controls@<idx>字段均为enable_*。<0> - 每个被删除的
/delete-node/不存在。auxp_ast_config@<idx>
Verification (on booted target)
启动后验证
sh
sudo cat /proc/iomem | grep -iE 'nv-reserved|cma|fb|carveout'
ls /proc/device-tree/reserved-memory/
dmesg | grep -iE 'firmware|carveout|bpmp|reserved|fail|error' | head -20
free -m| Scenario | Sysfs | dmesg grep |
|---|---|---|
| Display off | | |
| Camera off | | |
| SWIOTLB shrink | | |
For SWIOTLB: must contain , and
must stay under
during full workload — if exceeded, restore original
and re-flash .
/proc/cmdlineswiotlb=<value>watch -n5 cat /sys/kernel/debug/swiotlb/io_tlb_usedio_tlb_nslabsCMDLINE_ADDkernel-dtbsh
sudo cat /proc/iomem | grep -iE 'nv-reserved|cma|fb|carveout'
ls /proc/device-tree/reserved-memory/
dmesg | grep -iE 'firmware|carveout|bpmp|reserved|fail|error' | head -20
free -m| 场景 | Sysfs验证 | dmesg过滤关键词 |
|---|---|---|
| 显示关闭 | | |
| 摄像头关闭 | | |
| SWIOTLB缩小 | | |
对于SWIOTLB:必须包含,且在全负载运行时必须小于 — 若超出限制,恢复原始并重新刷写。
/proc/cmdlineswiotlb=<value>watch -n5 cat /sys/kernel/debug/swiotlb/io_tlb_usedio_tlb_nslabsCMDLINE_ADDkernel-dtbPurpose
目标
Cut the unused DRAM carveouts that ship enabled in the reference BSP
when a Jetson deployment skips display, camera, or other peripherals,
freeing the freed bytes for the application. Always edits the four
layers in boot order so an early-stage carveout never outranks a
later-stage shrink.
当Jetson部署场景无需显示、摄像头或其他外设时,削减参考BSP中默认启用的未使用DRAM内存划分,释放出的内存可供应用使用。始终按照启动顺序修改四个层级,确保早期阶段的内存划分不会覆盖后期阶段的缩减配置。
Prerequisites
前置条件
- Active target profile resolved per
.
../../context/target-platform-contract.md - BSP image extracted and source tree initialized
(,
/jetson-init-imagecomplete)./jetson-init-source - For headless / no-camera recipes: confirm the workload truly does not need display or camera.
- 已根据确定目标设备配置。
../../context/target-platform-contract.md - BSP镜像已提取且源码树已初始化(、
/jetson-init-image执行完成)。/jetson-init-source - 对于无界面/无摄像头方案:确认工作负载确实不需要显示或摄像头功能。
Limitations
限制
- Only the validated recipes (,
headless,no-camera) are exposed; ad-hoc subsystem disables outside the recipe set are refused.swiotlb - SWIOTLB shrink is bounded by peak in-flight DMA — exceeding the new
requires reverting the change.
io_tlb_nslabs - BPMP-DTB edits land in the overlay tracker only after Customize + Build + Deploy run; this skill does not flash on its own.
- 仅提供已验证的方案(、
headless、no-camera);拒绝方案集之外的临时子系统禁用请求。swiotlb - SWIOTLB的缩小受限于峰值DMA流量 — 若超出新的限制,需恢复修改。
io_tlb_nslabs - BPMP-DTB修改需在执行Customize + Build + Deploy后才会加入覆盖跟踪;本操作不会自行完成刷写。
Troubleshooting
故障排除
- Boot fails after MB1 BCT carveout disable — restore the pristine misc DTS and re-flash; the missing carveout is mandatory for the active SoC.
- exceeds
io_tlb_used— revertio_tlb_nslabsinswiotlb=and re-flash the kernel DTB partition.CMDLINE_ADD - Reclaimed delta smaller than expected — verify the recipe truly
matched the deployment (e.g. display still attached); use the
check in this file to confirm.
dmesg | grep -iE 'firmware|carveout' - Validation shows the disabled subsystem still probing — the change probably did not promote through to
dmesg; re-runbsp_image./jetson-promote-image
- MB1 BCT内存划分禁用后启动失败 — 恢复原始misc DTS并重新刷写;该内存划分对当前SoC是必需的。
- 超出
io_tlb_used— 恢复io_tlb_nslabs中的CMDLINE_ADD配置并重新刷写内核DTB分区。swiotlb= - 回收的内存增量低于预期 — 验证方案是否与部署场景匹配(例如是否仍连接了显示器);使用本文中的命令进行检查确认。
dmesg | grep -iE 'firmware|carveout' - 验证时dmesg显示已禁用的子系统仍在探测 — 修改可能未同步到;重新执行
bsp_image。/jetson-promote-image