Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jemalloc): Fix the stats of jemalloc #236

Merged
merged 4 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions contrib/memtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"unsafe"

"github.com/dgraph-io/ristretto/z"
"github.com/dustin/go-humanize"
)

type S struct {
Expand Down Expand Up @@ -109,8 +110,14 @@ func memory() {
counter++
}
}
fmt.Printf("[%d] Current Memory: %05.2f G. Increase? %v\n",
counter, float64(curMem)/float64(1<<30), increase)
var js z.MemStats
z.ReadMemStats(&js)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this in memtest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that this can be something which we can use to verify that the stats are as expected.


fmt.Printf("[%d] Current Memory: %s. Increase? %v, MemStats [Active: %s, Allocated: %s,"+
" Resident: %s, Retained: %s]\n",
counter, humanize.IBytes(uint64(z.NumAllocBytes())), increase,
humanize.IBytes(js.Active), humanize.IBytes(js.Allocated),
humanize.IBytes(js.Resident), humanize.IBytes(js.Retained))
}

func viaLL() {
Expand Down
8 changes: 8 additions & 0 deletions z/calloc_jemalloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ func ReadMemStats(stats *MemStats) {
if stats == nil {
return
}
epoch := 1
sz := unsafe.Sizeof(&epoch)
C.je_mallctl(
(C.CString)("epoch"),
unsafe.Pointer(&epoch),
(*C.size_t)(unsafe.Pointer(&sz)),
unsafe.Pointer(&epoch),
(C.size_t)(unsafe.Sizeof(epoch)))
stats.Allocated = fetchStat("stats.allocated")
stats.Active = fetchStat("stats.active")
stats.Resident = fetchStat("stats.resident")
Expand Down