Skip to content

*: force zone.o to link on macOS#15275

Merged
tamird merged 1 commit intocockroachdb:masterfrom
tamird:fix-jemalloc-mac-again
Apr 23, 2017
Merged

*: force zone.o to link on macOS#15275
tamird merged 1 commit intocockroachdb:masterfrom
tamird:fix-jemalloc-mac-again

Conversation

@tamird
Copy link
Copy Markdown
Contributor

@tamird tamird commented Apr 23, 2017

This is the mechanism by which jemalloc hooks into malloc on macOS;
without it, jemalloc is not used.

Closes #15272.

@tamird tamird requested review from benesch and petermattis April 23, 2017 01:20
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@benesch
Copy link
Copy Markdown
Contributor

benesch commented Apr 23, 2017

I wonder why this didn't bite us with c-jemalloc, because Go also builds a static library out of each package, right?

Also, I feel obligated to ask: you verified this actually works, yeah?

// #cgo CPPFLAGS: -DJEMALLOC_NO_DEMANGLE
// #cgo LDFLAGS: -ljemalloc
// #cgo !darwin LDFLAGS: -ljemalloc
// #cgo darwin LDFLAGS: -ljemalloc -u_je_zone_register
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you have to do this in all of the cgo directives? I would think this one would be sufficient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, one is sufficient, but do you think the inconsistency is worth it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Inconsistency doesn't bother me. I would have only made this change to server/status/runtime_jemalloc.go because that is the only one we care about. Also, add a comment explaining what is going on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? The problem here is not a reporting problem; before this change, jemalloc is not being used in our macOS builds, period.

Added a comment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

before this change, jemalloc is not being used in our macOS builds, period.

Do we care other than the stats reporting? Btw, given that this is the second time this has broken, perhaps a small test is in order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hm, this behaviour is specific to macOS, which we don't run CI on. How would we test it?

I think we care, even in the absence of stats reporting, but probably just for consistency with other platforms.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hm, this behaviour is specific to macOS, which we don't run CI on. How would we test it?

Developers run tests on macOS frequently. A test would have caught this very quickly. Also, seems possible for this to break on another platform as well.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PS I don't particularly care how many places you add -u_je_zone_register. The test is the more important bit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a test.

Copy link
Copy Markdown
Contributor Author

@tamird tamird left a comment

Choose a reason for hiding this comment

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

I wonder why this didn't bite us with c-jemalloc, because Go also builds a static library out of each package, right?

It's because cgo mashes all the object files into a single object file called _all.o before creating the static archive; the linker is only able to omit whole files, not single functions, so it is forced to keep everything.

Also, I feel obligated to ask: you verified this actually works, yeah?

Yes.

// #cgo CPPFLAGS: -DJEMALLOC_NO_DEMANGLE
// #cgo LDFLAGS: -ljemalloc
// #cgo !darwin LDFLAGS: -ljemalloc
// #cgo darwin LDFLAGS: -ljemalloc -u_je_zone_register
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, one is sufficient, but do you think the inconsistency is worth it?

}

// Used to force allocation in tests.
func allocateMemory() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not put this in the test file?

Copy link
Copy Markdown
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

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

LGTM

@tamird
Copy link
Copy Markdown
Contributor Author

tamird commented Apr 23, 2017 via email

This is the mechanism by which jemalloc hooks into `malloc` on macOS;
without it, jemalloc is not used.

Closes #15272.
@tamird tamird merged commit f957403 into cockroachdb:master Apr 23, 2017
@tamird tamird deleted the fix-jemalloc-mac-again branch April 23, 2017 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants