Skip to content

fix: correct contrib jemalloc builds and C allocation slices - #505

Open
anirekhj wants to merge 2 commits into
dgraph-io:mainfrom
anirekhj:fix-contrib-memory-validation
Open

anirekhj wants to merge 2 commits into
dgraph-io:mainfrom
anirekhj:fix-contrib-memory-validation

Conversation

@anirekhj

@anirekhj anirekhj commented Oct 10, 2026 •

Copy link
Copy Markdown

Description
While testing optional jemalloc configurations, both contrib/demo jemalloc variants fail to compile because nodeSz is undefined. Define it from unsafe.Sizeof(node{}).

Replace the standalone reflect.SliceHeader conversion in contrib/memtest with unsafe.Slice, removing the existing go vet warning without converting a C pointer through uintptr.

Add bounded tests for node allocation/traversal/free, zero-initialized C allocations and byte accounting, and memory-reporting/list cleanup. Tests use small allocations rather than running the default multi-GiB memory-stress workload. The allocator-mode demo test temporarily uses a dedicated allocator and restores the original to support repeated test runs.

Checklist

  • Code compiles correctly and linting passes locally
  • Tests added for new functionality, or regression tests for bug fixes added as applicable

Local compilation and vet passed with go build ./... and go vet ./.... Repository-pinned Trunk 1.25.0 passed with trunk check --ci --no-progress --no-fix --upstream origin/main --print-failures: no issues across the four modified files. This is the repository-configured PR-scoped lint check.

Validation

Go 1.25.0; macOS arm64 default-mode contrib race tests and go vet ./... pass.

Linux arm64 container with jemalloc 5.3.0 built using --with-jemalloc-prefix=je_ --disable-shared --with-pic:

  • go test -count=1 -race ./contrib/...
  • go test -count=1 -race -tags jemalloc ./contrib/...
  • go test -count=1 -race -tags "jemalloc allocator" ./contrib/...
  • go vet ./...

All passed. Also tested in combination with #504: full uncached race suites and full-repository vet pass both with and without the jemalloc build tag. No tests of the original multi-GiB stress workload are claimed.

This cleanup is independent of #504 and can merge separately.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Refactor
    • Updated memory allocation handling while preserving allocation tracking.
  • Tests
    • Added checks for zero-initialized allocations, writable memory, allocation accounting, and cleanup.
    • Added lifecycle coverage for linked-node allocations and memory reporting, including verification that cleanup restores prior allocation counts.

@anirekhj
anirekhj requested a review from a team as a code owner October 10, 2026 02:58
@CLAassistant

CLAassistant commented Oct 10, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 33803471-8a46-4423-be38-64ee007bd8cb




📥 Commits

Reviewing files that changed from the base of the PR and between 04f3117 and 27cca3f.





📒 Files selected for processing (3)
  • contrib/demo/node_test.go
  • contrib/memtest/main_test.go
  • contrib/memtest/nojemalloc.go




🚧 Files skipped from review as they are similar to previous changes (3)
  • contrib/demo/node_test.go
  • contrib/memtest/nojemalloc.go
  • contrib/memtest/main_test.go




Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.






📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes define the demo node size and add a node lifecycle test. They also use unsafe.Slice to construct Calloc’s returned slice and add tests for allocation accounting and memory reporting.

Changes

Node Lifecycle Demo

Layer / File(s) Summary
Node size and lifecycle test
contrib/demo/node.go, contrib/demo/node_test.go
The demo defines nodeSz using unsafe.Sizeof. The test builds and prints a linked list, checks values from -1 through 14, and frees each node.

Calloc and Memory Reporting

Layer / File(s) Summary
Calloc slice construction and accounting checks
contrib/memtest/nojemalloc.go, contrib/memtest/main_test.go
Calloc uses unsafe.Slice instead of reflect.SliceHeader to construct its result. Tests check buffer length, capacity, zero initialization, allocation accounting, and memory reporting.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: amalistari

















Merge Risk: ⚪ Minimal · up to 27cca

This change fixes contrib jemalloc builds and a go vet warning, and adds small tests. No merge-blocking risk is evident from the supplied context.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies both main changes: fixing contrib jemalloc builds and correcting C allocation slice construction.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR







  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@anirekhj
anirekhj force-pushed the fix-contrib-memory-validation branch from 27cca3f to 0574771 Compare October 10, 2026 03:10
@anirekhj anirekhj changed the title Fix contrib jemalloc builds and C allocation slice construction fix: correct contrib jemalloc builds and C allocation slices Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants