Repository navigation
fix(rtps): QEMU restart case internal-RAM headroom (received frames to PSRAM) + docs - #923
Merged
Merged
Conversation
… first 3 s Diagnostic for the restart case's thin internal-RAM headroom: a RTPSTEST dram marker (byte-addressable internal free / min / largest + task count) after each endpoint is created, every 100 ms for 3 s after the endpoints exist, and the task names at both ends of that window, on every participant (the first and the one after the restart), so their costs can be compared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
|
✅Static analysis result - no issues found! ✅ |
rtps memory footprint (QEMU, esp32)Deltas in parentheses are against main @ 555cdd3 (run 45059047023): a bigger size or a smaller free heap than the baseline's is a cost of this change. librtps.a in the image (bytes,
|
| embedded | host | host_large | |
|---|---|---|---|
| flash code | 162,092 (+20) | 163,454 (+24) | 163,870 (+24) |
| flash data | 1,272 (+0) | 1,272 (+0) | 1,272 (+0) |
| DRAM (.data + .bss) | 126 (+0) | 126 (+0) | 126 (+0) |
| IRAM | 0 (+0) | 0 (+0) | 0 (+0) |
engine objects, sizeof (bytes; the Domain is allocated from the heap at start())
| object | embedded | host | host_large |
|---|---|---|---|
| rtps::Domain (holds every pool below) | 99,208 (+0) | 569,968 (+0) | 3,156,208 (+0) |
| rtps::Participant | 34,304 (+0) | 42,736 (+0) | 52,720 (+0) |
| rtps::StatefulWriter | 2,528 (+0) | 2,960 (+0) | 6,416 (+0) |
| rtps::StatelessWriter | 1,872 (+0) | 2,256 (+0) | 3,792 (+0) |
| rtps::StatefulReader | 1,968 (+0) | 2,008 (+0) | 2,104 (+0) |
| rtps::StatelessReader | 1,960 (+0) | 2,000 (+0) | 2,096 (+0) |
| espp::RtpsParticipant | 608 (+0) | 608 (+0) | 608 (+0) |
embedded: heap by stage (free bytes; a cost is a negative delta)
| stage | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| boot | 220,279 (+0) | 219,552 (+1,384) | 131,072 | 4,191,440 (+0) | ||
| started | 160,171 (+16) | -60,108 | 159,576 (+36) | 73,728 | 4,090,196 (-12) | -101,244 |
| endpoints | 139,375 (-120) | -20,796 | 138,000 (-120) | 69,632 | 4,090,196 (-12) | +0 |
embedded: heap after each host-driven step (free bytes; deltas against the previous row; the pools are preallocated, so a peer costs little heap - the low-water mark shows the transients)
| step | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| baseline | 133,259 (+28) | 132,172 (+1,468) | 69,632 | 4,090,216 (+0) | ||
| +1 remote participant (no match) | 133,135 (+40) | -124 | 131,112 (+5,104) | 69,632 | 4,090,216 (+0) | +0 |
| +1 more remote participant (no match) | 133,127 (+32) | -8 | 131,104 (+5,284) | 69,632 | 4,090,208 (-8) | -8 |
| +1 remote participant with a matched publisher | 133,099 (+40) | -28 | 130,948 (+7,728) | 69,632 | 4,090,208 (-8) | +0 |
| after a service call | 133,091 (+56) | -8 | 130,948 (+32,708) | 69,632 | 4,090,208 (-8) | +0 |
| after an action goal | 131,987 (+0) | -1,104 | 130,320 (+46,652) | 69,632 | 4,090,216 (+0) | +8 |
| after one 30 KB sample | 131,987 (+8) | +0 | 129,960 (+54,028) | 69,632 | 4,060,004 (-12) | -30,212 |
| all peers gone | 131,979 (+0) | -8 | 129,960 (+54,028) | 69,632 | 4,059,996 (-20) | -8 |
host: heap by stage (free bytes; a cost is a negative delta)
| stage | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| boot | 219,047 (+0) | 218,320 (+1,384) | 131,072 | 4,191,440 (+0) | ||
| started | 130,575 (+16) | -88,472 | 129,980 (+36) | 69,632 | 3,617,108 (-12) | -574,332 |
| endpoints | 109,779 (-136) | -20,796 | 108,404 (-136) | 69,632 | 3,617,108 (-12) | +0 |
host_large: the participant did not start on this target - the profile does not fit (panicked while the engine was being built - internal RAM exhausted building the Domain's mutexes (the first error logged: [RtpsTransport/E][3.418]: Failed to create valid UDP socket for port 7401)); its sizeof is in the table above, the boot heap below
host_large: heap by stage (free bytes; a cost is a negative delta)
| stage | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| boot | 219,047 (+0) | 218,320 (+0) | 131,072 | 4,191,440 (+0) | ||
| started | n/a | |||||
| endpoints | n/a |
The QEMU memory suite on 276547d (run); the full numbers are the run's rtps-memory artifact.
…TERNAL 512) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…SRAM) The QEMU restart case showed a participant recreated next to a dozen live ROS 2 peers spending 8-12 KB of internal RAM per endpoint (about 1 KB on an empty domain) until creating the action server's FreeRTOS lock failed and the device aborted. The cost is the engine's payload bytes - history-cache samples, the messages it builds and the datagrams it parses: a few hundred bytes each, below CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL, so malloc() put them in internal RAM, and the new endpoints match every peer at once. Lowering ALWAYSINTERNAL to 512 in the QEMU firmware brought the per-endpoint cost after the restart back to ~1 KB and the post-restart low point from 10 KB to 60 KB, confirming it. PayloadBuffer::bytes and PacketInfo::payload now use rtps::PayloadAllocator, which allocates from PSRAM first (heap_caps_malloc_prefer, internal RAM as the fallback) when CONFIG_RTPS_PAYLOAD_PREFER_PSRAM is set - default on whenever PSRAM is enabled - and is plain operator new elsewhere (host, no PSRAM, option off). Applications get it without changing a global heap setting. The QEMU firmware is back on the default ALWAYSINTERNAL to exercise the engine fix and keeps a per-endpoint internal-RAM marker (the timeline and task-name dumps are removed). README + docs: the option, and a section on internal RAM on a busy domain (RESERVE_INTERNAL, lwIP in PSRAM, which free-size figure to watch). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…rt the payload allocator The payload allocator did not move the restart case's internal-RAM cost (after the restart the endpoints still left 8.7 KB, matrix 11/33): the engine's payloads were not it. The cost is the openeth driver's receive buffers: it mallocs a full frame (~1.5 KB) per packet and lwIP holds it until the engine reads the datagram, up to LWIP_UDP_RECVMBOX_SIZE (64) per socket. Below the 4096 ALWAYSINTERNAL threshold they landed in internal RAM, and a participant recreated next to a dozen live peers gets all of their answers while it creates its endpoints. The ALWAYSINTERNAL=512 experiment moved exactly these. QEMU firmware: ALWAYSINTERNAL 1024, below a frame, so smaller allocations (FreeRTOS objects, small engine state) stay internal. PayloadAllocator and RTPS_PAYLOAD_PREFER_PSRAM are removed (the engine is unchanged). The README's busy-domain section now names the driver's frames and lwIP's queue depth as the cost and what to configure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…derations QEMU board (README, its docs page, the QEMU guide): how the emulated MAC's driver holds received frames - the DMA receive ring (4 x 1600 B internal by default; a burst longer than it is dropped, RX frame dropped (0x14)) and one malloc()ed 1522-byte buffer per frame until the application reads it, queued up to LWIP_UDP_RECVMBOX_SIZE per socket - why that lands in internal RAM with PSRAM (below ALWAYSINTERNAL), how it fails (a task or lock that cannot be created), what to configure, and that IP reassembly is off by default. RTPS (README and docs page): the busy-domain section now explains the mechanism - four sockets plus dedicated ports, every live peer answering each new endpoint at once, worst when joining or recreating on a running domain - with the symptoms, the options, where to measure, and the per-endpoint RTPSTEST dram markers the QEMU firmware logs. The QEMU firmware's RESERVE_INTERNAL comment no longer blames the proxies (discovery uses fixed pools; it was the queued frames). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
finger563
marked this pull request as ready for review
November 23, 2026 00:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #922. After the in-process restart, the QEMU restart case passed with almost no internal RAM to spare: 18 KB free after its endpoints, with a low point of 10 KB. Some runs aborted creating a task or a lock.
Cause
The QEMU Ethernet driver (
esp_eth_mac_openeth.c)malloc()s a 1522-byte buffer for every received frame. lwIP frees it only when the application reads the datagram, and the firmware lets each socket queue up to 64 (CONFIG_LWIP_UDP_RECVMBOX_SIZE). That size is belowCONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL(4096), so the frames sat in internal RAM.A participant recreated next to a dozen live ROS 2 peers gets an answer from every peer to each endpoint it creates. Measured per endpoint, that cost 8-12 KB of internal RAM after the restart, against about 1 KB on first boot. The task count stayed flat. Discovery uses fixed pools, and the engine's own payload buffers were ruled out: moving them to PSRAM changed nothing.
Change
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=1024, below a frame, so received frames go to PSRAM while small allocations (FreeRTOS objects, small engine state) stay internal. The engine is unchanged.RTPSTEST dram <endpoint> free= min= largest= tasks=line after each endpoint, on first boot and after the restart, so a regression shows in the CI device log. The memory suite's stage names are not reused.RESERVE_INTERNALcomment from fix(rtps): the QEMU restart case no longer runs the device out of internal RAM #922 no longer blames discovery proxies.Result (QEMU matrix device log)
Free internal RAM (
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT), after the restart:Matrix 45/0, soak 10/0, memory suite passing.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU