|WARNING| examples/l3fwd: dynamic NUMA-aware alloc lcore_conf
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Tue Jun 23 06:03:10 CEST 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/165964
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-06-23
# DPDK Patch Review
## Summary
This patch refactors `lcore_conf` from a static global array to a pointer array with NUMA-aware hugepage allocation. Overall the approach is sound, but there is one **critical resource leak** on the error path.
---
## Errors
### Resource Leak on init_lcore_conf() Error Path
**Location:** `main.c:1690-1691`
```c
ret = init_lcore_conf();
if (ret)
rte_exit(EXIT_FAILURE, "Init lcore conf failed!\n");
```
**Problem:** If `init_lcore_conf()` fails partway through (e.g., allocation succeeds for lcore 0 but fails for lcore 1), the function returns `-ENOMEM` immediately without freeing the already-allocated `lcore_conf[]` entries. When `rte_exit()` is called, those allocations leak.
**Why it matters:** This wastes hugepage memory and could cause secondary failures in retry scenarios or test harnesses.
**Fix:** Add cleanup on error:
```c
static int
init_lcore_conf(void)
{
unsigned int lcore_id;
int socketid;
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
if (rte_lcore_is_enabled(lcore_id) == 0)
continue;
socketid = rte_lcore_to_socket_id(lcore_id);
lcore_conf[lcore_id] = rte_zmalloc_socket(NULL, sizeof(struct lcore_conf),
RTE_CACHE_LINE_SIZE, socketid);
if (lcore_conf[lcore_id] == NULL)
goto cleanup;
}
return 0;
cleanup:
for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
if (lcore_conf[lcore_id] != NULL) {
rte_free(lcore_conf[lcore_id]);
lcore_conf[lcore_id] = NULL;
}
}
return -ENOMEM;
}
```
---
## Info
### Missing Release Notes
This is a performance optimization for multi-NUMA deployments. Consider adding a note to `doc/guides/rel_notes/release_XX_XX.rst` under "**examples**" describing the NUMA-aware allocation improvement.
Example:
```rst
* **l3fwd: improved NUMA locality for multi-socket systems.**
Refactored per-lcore configuration to use NUMA-aware hugepage allocation,
eliminating cross-NUMA memory access penalty in multi-port multi-NUMA deployments.
```
---
## Observations (No Action Required)
1. **Pointer array initialization:** The global `lcore_conf` array is implicitly zero-initialized (all pointers NULL), which is safe.
2. **Access pattern change:** All reads now indirect through one pointer dereference (`lcore_conf[lcore_id]->field` instead of `lcore_conf[lcore_id].field`). The performance impact is negligible compared to the NUMA locality gain.
3. **No cleanup on normal exit:** The allocations are not freed at program exit. This is acceptable for short-lived examples where the OS reclaims all memory on process termination.
4. **Consistent naming:** The first parameter to `rte_zmalloc_socket()` is `NULL` (unnamed allocation), which is fine for per-lcore structures.
---
## Verdict
**Must fix:** Add cleanup path in `init_lcore_conf()` to free partial allocations on error.
**Should consider:** Release notes entry for the NUMA optimization.
Otherwise the patch is correct and follows DPDK coding standards.
More information about the test-report
mailing list