Reduce shared RAM usage without lowering firmware capacities
Specialize repeater ACL session state, compact recent and flood records, stream Merkle proofs, and release cold OTA buffers safely. Preserve saved formats, stack sizes, table capacities, and OTA source limits. Account for lazy buffers when active and add compatibility, ARM alignment, allocation failure, and queued-response tests. Validated six representative board/role builds, 1736 native test cases, sanitizer fixtures, and strict documentation. Document the preexisting Wio-E5 Mini flash overflow separately.
This commit is contained in:
1 parent
76ddc06e56
commit
4b3e419eb0
30 files changed
+1783
-150
No files matched your search
@@ -2474,7 +2474,9 @@ void MyMesh::formatRecentRepeatersReply(char *reply, int page,
|
||||
if (info == NULL) break;
|
||||
char prefix[MAX_ROUTE_HASH_BYTES * 2 + 1];
|
||||
char snr[12];
|
||||
mesh::Utils::toHex(prefix, info->prefix, info->prefix_len);
|
||||
alignas(uint32_t) uint8_t recorded_prefix[MAX_ROUTE_HASH_BYTES];
|
||||
SimpleMeshTables::copyRecentRepeaterPrefix(recorded_prefix, *info);
|
||||
mesh::Utils::toHex(prefix, recorded_prefix, info->prefix_len);
|
||||
prefix[info->prefix_len * 2] = 0;
|
||||
formatLocalSnrX4(snr, sizeof(snr), info->snr_x4);
|
||||
if (is_search) {
|
||||
@@ -2506,7 +2508,9 @@ void MyMesh::printRecentRepeatersSerial() {
|
||||
const auto* info = tables ? tables->getRecentRepeaterBySortedIdx(row++) : nullptr;
|
||||
if (!info) return 0;
|
||||
char prefix[MAX_ROUTE_HASH_BYTES * 2 + 1], snr[12];
|
||||
mesh::Utils::toHex(prefix, info->prefix, info->prefix_len);
|
||||
alignas(uint32_t) uint8_t recorded_prefix[MAX_ROUTE_HASH_BYTES];
|
||||
SimpleMeshTables::copyRecentRepeaterPrefix(recorded_prefix, *info);
|
||||
mesh::Utils::toHex(prefix, recorded_prefix, info->prefix_len);
|
||||
formatLocalSnrX4(snr, sizeof(snr), info->snr_x4);
|
||||
return snprintf(out, capacity, "%s,%s%s\r\n", prefix, snr[0] == '-' ? "" : " ", snr);
|
||||
}, this, "Recent repeaters:\r\n");
|
||||
@@ -2542,7 +2546,9 @@ void MyMesh::printRecentRepeatersSerial() {
|
||||
if (info == NULL) break;
|
||||
char prefix[MAX_ROUTE_HASH_BYTES * 2 + 1];
|
||||
char snr[12];
|
||||
mesh::Utils::toHex(prefix, info->prefix, info->prefix_len);
|
||||
alignas(uint32_t) uint8_t recorded_prefix[MAX_ROUTE_HASH_BYTES];
|
||||
SimpleMeshTables::copyRecentRepeaterPrefix(recorded_prefix, *info);
|
||||
mesh::Utils::toHex(prefix, recorded_prefix, info->prefix_len);
|
||||
prefix[info->prefix_len * 2] = 0;
|
||||
formatLocalSnrX4(snr, sizeof(snr), info->snr_x4);
|
||||
mesh::usbConsolePort().printf("%s,%s%s\n", prefix, snr[0] == '-' ? "" : " ", snr);
|
||||
@@ -5329,13 +5335,15 @@ void MyMesh::servicePendingSerialOutput() {
|
||||
}
|
||||
char prefix[MAX_ROUTE_HASH_BYTES * 2 + 1];
|
||||
char snr[12];
|
||||
mesh::Utils::toHex(prefix, info->prefix, info->prefix_len);
|
||||
alignas(uint32_t) uint8_t recorded_prefix[MAX_ROUTE_HASH_BYTES];
|
||||
SimpleMeshTables::copyRecentRepeaterPrefix(recorded_prefix, *info);
|
||||
mesh::Utils::toHex(prefix, recorded_prefix, info->prefix_len);
|
||||
formatLocalSnrX4(snr, sizeof(snr), info->snr_x4);
|
||||
length = snprintf(record, sizeof(record), "%s,%s%s\n", prefix,
|
||||
snr[0] == '-' ? "" : " ", snr);
|
||||
// Snapshot the row before a short write. Its next pass must retry only
|
||||
// the retained suffix, even if the live recent-repeater table changes.
|
||||
serial_recent_cursor = *info;
|
||||
SimpleMeshTables::copyRecentRepeaterInfo(serial_recent_cursor, *info);
|
||||
serial_recent_cursor_index = next_index;
|
||||
serial_recent_has_cursor = true;
|
||||
} else {
|
||||
@@ -8291,9 +8299,7 @@ void MyMesh::setFloodPacketFilter(const char* args, char* reply,
|
||||
if (i == flood_channel_data_rule_slot) continue;
|
||||
const auto& entry = flood_packet_filters[i];
|
||||
if (entry.active
|
||||
&& memcmp(&entry, &candidate,
|
||||
offsetof(FloodPacketFilterEntry,
|
||||
rate_window_started)) == 0) {
|
||||
&& FloodFilterPolicy::sameRuleConfiguration(entry, candidate)) {
|
||||
slot = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -408,18 +408,27 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
|
||||
uint32_t last_heard_millis;
|
||||
};
|
||||
struct FloodPacketFilterEntry {
|
||||
#if MESH_ENABLE_FLOOD_RULE_ENGINE
|
||||
// Keep multibyte counters naturally aligned. These seven independent
|
||||
// flags share a byte; their bit order is never persisted (FPF7 serializes
|
||||
// each field explicitly). active/retry remain addressable for the stored
|
||||
// rule decoders. Rule mutations run on the mesh loop.
|
||||
uint32_t rate_window_started;
|
||||
uint16_t rate_per_minute;
|
||||
uint16_t rate_window_count;
|
||||
bool suspend_on_temp_radio : 1;
|
||||
bool match_blacklisted_path : 1;
|
||||
bool scope_uses_slow_timing : 1;
|
||||
bool drop_on_match : 1;
|
||||
bool rate_limit_enabled : 1;
|
||||
bool stop_on_match : 1;
|
||||
bool rate_window_active : 1;
|
||||
bool active;
|
||||
bool retry_on_match;
|
||||
uint8_t payload_type;
|
||||
uint8_t min_hops;
|
||||
uint8_t max_hops;
|
||||
bool suspend_on_temp_radio;
|
||||
char scope_name[FLOOD_PACKET_FILTER_SCOPE_NAME_LEN];
|
||||
bool match_blacklisted_path;
|
||||
#if !MESH_ENABLE_FLOOD_RULE_ENGINE
|
||||
bool scope_requires_region_match;
|
||||
#endif
|
||||
bool scope_uses_slow_timing;
|
||||
#if MESH_ENABLE_FLOOD_RULE_ENGINE
|
||||
uint8_t incoming_scope_kind;
|
||||
char incoming_scope_name[FLOOD_PACKET_FILTER_SCOPE_NAME_LEN];
|
||||
uint8_t channel_key_len;
|
||||
@@ -430,16 +439,18 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
|
||||
uint8_t path_hops;
|
||||
uint8_t path[FLOOD_PACKET_FILTER_PATH_PREFIX_BYTES_MAX];
|
||||
char target_region_name[FLOOD_PACKET_FILTER_SCOPE_NAME_LEN];
|
||||
bool drop_on_match;
|
||||
bool rate_limit_enabled;
|
||||
uint16_t rate_per_minute;
|
||||
uint8_t priority;
|
||||
bool stop_on_match;
|
||||
bool retry_on_match;
|
||||
uint8_t transport_modes;
|
||||
uint32_t rate_window_started;
|
||||
uint16_t rate_window_count;
|
||||
bool rate_window_active;
|
||||
#else
|
||||
bool active;
|
||||
uint8_t payload_type;
|
||||
uint8_t min_hops;
|
||||
uint8_t max_hops;
|
||||
bool suspend_on_temp_radio;
|
||||
char scope_name[FLOOD_PACKET_FILTER_SCOPE_NAME_LEN];
|
||||
bool match_blacklisted_path;
|
||||
bool scope_requires_region_match;
|
||||
bool scope_uses_slow_timing;
|
||||
#endif
|
||||
};
|
||||
struct FloodChannelScopeEntry {
|
||||
@@ -483,7 +494,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
|
||||
};
|
||||
mutable FloodRetryBridgeState flood_retry_bridge_states[TOTAL_FLOOD_RETRY_SLOTS];
|
||||
FloodRetryBridgeReachability flood_retry_bridge_reachability[FLOOD_RETRY_BRIDGE_BUCKETS + 1];
|
||||
static_assert(sizeof(FloodPacketFilterEntry) <= (MESH_ENABLE_FLOOD_RULE_ENGINE ? 200 : 40),
|
||||
static_assert(sizeof(FloodPacketFilterEntry) <= (MESH_ENABLE_FLOOD_RULE_ENGINE ? 192 : 40),
|
||||
"Update the flood-table runtime RAM budget in check_firmware_ram.py");
|
||||
// The rule table is the single largest member of this object. It is heap
|
||||
// allocated in the constructor (before setup(), while the heap is still
|
||||
|
||||
@@ -52,6 +52,8 @@ extern "C" bool btInUse() { return false; }
|
||||
|
||||
StdRNG fast_rng;
|
||||
#if MAX_RECENT_REPEATERS > 0
|
||||
// Compact rows retain the complete prefix/SNR/32-bit age at every capacity.
|
||||
// All accesses are owned by this loop, including deferred network commands.
|
||||
#if defined(ESP32)
|
||||
// Classic ESP32 has a much smaller link-time DRAM window than its runtime heap
|
||||
// map. Allocate this large, fixed-capacity history at startup so enabling WiFi
|
||||
|
||||
@@ -1732,8 +1732,7 @@ void FloodRuleEngine::set(const char* args, char* reply,
|
||||
if (slot < 0) {
|
||||
for (int i = 0; i < RULE_SLOTS; i++) {
|
||||
if (_entries[i].active
|
||||
&& memcmp(&_entries[i], &candidate,
|
||||
offsetof(Entry, rate_window_started)) == 0) {
|
||||
&& FloodFilterPolicy::sameRuleConfiguration(_entries[i], candidate)) {
|
||||
slot = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,14 +42,25 @@ public:
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
// Native alignment for counters; explicit FPF7 serialization does not
|
||||
// expose the in-memory flag bit order. Keep active/retry addressable for
|
||||
// the stored rule decoders, and mutate rules only on the mesh loop.
|
||||
uint32_t rate_window_started;
|
||||
uint16_t rate_per_minute;
|
||||
uint16_t rate_window_count;
|
||||
bool suspend_on_temp_radio : 1;
|
||||
bool match_blacklisted_path : 1;
|
||||
bool scope_uses_slow_timing : 1;
|
||||
bool drop_on_match : 1;
|
||||
bool rate_limit_enabled : 1;
|
||||
bool stop_on_match : 1;
|
||||
bool rate_window_active : 1;
|
||||
bool active;
|
||||
bool retry_on_match;
|
||||
uint8_t payload_type;
|
||||
uint8_t min_hops;
|
||||
uint8_t max_hops;
|
||||
bool suspend_on_temp_radio;
|
||||
char scope_name[NAME_LEN];
|
||||
bool match_blacklisted_path;
|
||||
bool scope_uses_slow_timing;
|
||||
uint8_t incoming_scope_kind;
|
||||
char incoming_scope_name[NAME_LEN];
|
||||
uint8_t channel_key_len;
|
||||
@@ -60,24 +71,16 @@ private:
|
||||
uint8_t path_hops;
|
||||
uint8_t path[PATH_PREFIX_BYTES_MAX];
|
||||
char target_region_name[NAME_LEN];
|
||||
bool drop_on_match;
|
||||
bool rate_limit_enabled;
|
||||
uint16_t rate_per_minute;
|
||||
uint8_t priority;
|
||||
bool stop_on_match;
|
||||
bool retry_on_match;
|
||||
uint8_t transport_modes;
|
||||
uint32_t rate_window_started;
|
||||
uint16_t rate_window_count;
|
||||
bool rate_window_active;
|
||||
};
|
||||
|
||||
// This table is 6,200 bytes. Keep it in the constructor-time heap rather
|
||||
// This table is at most 5,952 bytes. Keep it in the constructor-time heap rather
|
||||
// than inside the global MyMesh object: classic ESP32 has a small static
|
||||
// DRAM window but substantially more internal heap at this point in boot.
|
||||
// Allocation is deliberately all-or-nothing. A node must never fall back
|
||||
// to silently running without its configured flood rules.
|
||||
static_assert(sizeof(Entry) == 200,
|
||||
static_assert(sizeof(Entry) <= 192,
|
||||
"Update the flood-rule runtime RAM budget in check_firmware_ram.py");
|
||||
FILESYSTEM* _fs;
|
||||
RegionMap* _regions;
|
||||
|
||||
Reference in new issue
Block a user