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

move mallocx_align to jemalloc-sys and expose it via the ffi module #27

Merged
merged 1 commit into from
Nov 28, 2017
Merged

Conversation

gnzlbg
Copy link
Owner

@gnzlbg gnzlbg commented Nov 23, 2017

No description provided.

@alexcrichton
Copy link
Collaborator

How come? Ideally this crate is pretty conservative in its API, so why would we expose this?

@gnzlbg
Copy link
Owner Author

gnzlbg commented Nov 24, 2017

This crates exposes the ffi module, and the functions in utils are necessary to use the ffi module properly:

  • mallocx_align is a re-implementation of a C macro that the C interface exposes
  • align_to_flags is what everybody using the C interface needs

@SimonSapin suggested removing MIN_ALIGN completely, so maybe we shouldn't expose those, but at least align_to_flags is a must, otherwise everybody needs to reimplement it, and that would be out-of-sync with @SimonSapin changes already... it is better to provide it here.

@SimonSapin
Copy link
Contributor

MIN_ALIGN and align_to_flags implement a specific, opinionated optimization strategy. The ffi-level interface can definitely be used without them.

mallocx_align could maybe be moved to the jemalloc-sys crate, since it is equivalent to something in the C API.

@SimonSapin
Copy link
Contributor

If the MIN_ALIGN strategy is dropped, calls to align_to_flags would be replaced with calls to mallocx_align.

@gnzlbg
Copy link
Owner Author

gnzlbg commented Nov 24, 2017

@SimonSapin doesn't it still make sense to expose a fn size_align_to_flags(size, align) -> c_int API that does the same that the library internally does? (Be it use MIN_ALIGN or not?)

One might want to compute the "alignment" like jemalloctor does internally, but bitwise-or it with other jemalloc flags. That is actually the main reason I see for using the C-API directly instead of just the Allocator API.


I'll move mallocx_align to the jemalloc-sys crate, and drop the rest here, since that seems to be a non-controversial change. But I think that a size/align to jemalloc flags utility function makes sense not only internally but also in the public API.

@SimonSapin
Copy link
Contributor

One might want to compute the "alignment" like jemalloctor does internally, but bitwise-or it with other jemalloc flags.

That is what mallocx_align does.

@gnzlbg
Copy link
Owner Author

gnzlbg commented Nov 24, 2017 via email

@SimonSapin
Copy link
Contributor

Replicating the exact flag-setting strategy of jemallocator while not using jemallocator is a choice you can make, it is not a "must". And I’m not convinced it’s a good idea: it was buggy (rust-lang/rust#45955) at least since https://github.com/alexcrichton/jemallocator/pull/25, and even now its validity is shaky.

@gnzlbg
Copy link
Owner Author

gnzlbg commented Nov 24, 2017 via email

@gnzlbg gnzlbg changed the title Expose utilities via utils module move mallocx_align to jemalloc-sys and expose it via the ffi module Nov 25, 2017
@gnzlbg
Copy link
Owner Author

gnzlbg commented Nov 25, 2017

So i've just moved mallocx_align to the jemalloc-sys crate, which makes jemallocator re-export it via the FFI module and removed all other changes from this PR.

#35 renames align_to_flags to layout_to_flags, it might make sense or not to expose an API for getting sensible jemalloc flags from a layout, but I'll open an issue for that.

@alexcrichton
Copy link
Collaborator

If this is a macro can it have the same name as C?

@gnzlbg
Copy link
Owner Author

gnzlbg commented Nov 25, 2017 via email

@alexcrichton
Copy link
Collaborator

Ah yeah that's just what I mean about changing the name to MALLOCX_ALIGN to align with the macro in C (so it "looks like" the C interface)

Also no worries on all the PRs! It is a little overwhelming but just takes time to get through.

@gnzlbg
Copy link
Owner Author

gnzlbg commented Nov 28, 2017

@alexcrichton that's a good idea, I've named it all in caps like the C macro.

@alexcrichton
Copy link
Collaborator

Looks great!

@alexcrichton alexcrichton merged commit b95133a into gnzlbg:master Nov 28, 2017
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.

3 participants