Skip to content

Conversation

@l1tsolaiki
Copy link
Contributor

@l1tsolaiki l1tsolaiki commented May 12, 2022

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Try to use mimalloc allocator

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@l1tsolaiki l1tsolaiki force-pushed the l1tsolaiki-mimalloc branch from 0406326 to 53b8db7 Compare May 12, 2022 16:28
@robot-clickhouse robot-clickhouse added the submodule changed At least one submodule changed in this PR. label May 12, 2022
@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label May 12, 2022
Copy link
Member

@azat azat left a comment

Choose a reason for hiding this comment

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

By the way, what is the purpose of using mimalloc?

Copy link
Member

Choose a reason for hiding this comment

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

Debugging stuff ok, but I guess it will be enough to handle mimalloc first and jemalloc as a fallback

Copy link
Member

Choose a reason for hiding this comment

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

I don't see mimalloc-static anywhere in this cmake rules.

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 am following guide from mimalloc/README.md. Looks like it is defined somewhere inside mimalloc itself.
Furthermore, it is done in the same way in previous attempt to use mimalloc. (#5775)

Copy link
Member

Choose a reason for hiding this comment

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

You don't neither MIMALLOC_LIBRARY, so you don't need this variable. And AFAICS right now you added only header only library, so it does not matter static or shared.

Also note (for the future), that there is module part too, i.e. not headers only. Seems that it is required for overrides - https://github.com/microsoft/mimalloc#static-override

Copy link
Member

Choose a reason for hiding this comment

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

By the way, you have not disabled jemalloc, hence mimalloc is not used in the build

@l1tsolaiki
Copy link
Contributor Author

By the way, what is the purpose of using mimalloc?

There is an issue #34157 for testing different allocators, mimalloc being one of them. So the purpose of this PR is to test its performance.

@robot-clickhouse robot-clickhouse added the pr-performance Pull request with some performance improvements label May 13, 2022
@l1tsolaiki l1tsolaiki force-pushed the l1tsolaiki-mimalloc branch from db4d03f to 95ea5a9 Compare May 13, 2022 16:14
# Note: turn of this warning:
# error: identifier '_mi_option_last' is reserved because it starts with '_' at global scope
)
target_include_directories(_mimalloc SYSTEM BEFORE PUBLIC "${ClickHouse_SOURCE_DIR}/contrib/mimalloc/include")
Copy link
Member

Choose a reason for hiding this comment

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

You forgot MI_MALLOC_OVERRIDE, i.e. target_compile_definitions(_mimalloc PRIVATE -DMI_MALLOC_OVERRIDE), this should fix incorrect allocator usage (and possible SIGSEGV due to this).

Copy link
Member

Choose a reason for hiding this comment

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

But this will not be enough, microsoft/mimalloc#583 is required, I've submitted separate draft PR on top of yours that includes all review changes (I cannot push to your fork) - #37304

Comment on lines +36 to +40
target_compile_options(_mimalloc
PRIVATE
-Wno-reserved-identifier
# Note: turn of this warning:
# error: identifier '_mi_option_last' is reserved because it starts with '_' at global scope
Copy link
Member

Choose a reason for hiding this comment

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

Not important, but this looks better:

Suggested change
target_compile_options(_mimalloc
PRIVATE
-Wno-reserved-identifier
# Note: turn of this warning:
# error: identifier '_mi_option_last' is reserved because it starts with '_' at global scope
target_compile_options(_mimalloc PRIVATE
# Note: turn of this warning:
# error: identifier '_mi_option_last' is reserved because it starts with '_' at global scope
-Wno-reserved-identifier

@l1tsolaiki l1tsolaiki force-pushed the l1tsolaiki-mimalloc branch from 6f786bb to 7ecd82f Compare May 18, 2022 14:36
@alexey-milovidov
Copy link
Member

alexey-milovidov commented Sep 18, 2022

@azat It is using 2.5 times more resident memory according to performance tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-performance Pull request with some performance improvements submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants