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

histogram: add pow2 allocation stats via MIMALLOC_SHOW_HISTOGRAM=1 #529

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

michaeljclark
Copy link
Contributor

I do not intend this pull to be merged, but am surfacing the feature just in case anyone finds it useful. It is a bit easier to read if one is trying to assess allocation sizes with a power of two granularity. It is currently guarded behind #ifdef MI_STAT>1 but #if MI_DEBUG>0 might be more appropriate. It currently adds an atomic_increment to counters in a shared histogram array. It could be changed to use thread-local arrays that are merged at program termination.

@ghost
Copy link

ghost commented Jan 18, 2022

CLA assistant check
All CLA requirements met.

src/stats.c Outdated

void _mi_histogram_log(size_t size)
{
size_t bucket = MI_SIZE_BITS - 1 - mi_clz(size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using mi_bsr? That is,

  if (mi_unlikely(size == 0)) return;
  size_t bucket = mi_bsr(size);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I have made these two changes. I think your suggestion for the zero check is necessary unless we were to add another element to the histogram array which also would eliminate a branch. I do a null check in the caller but didn't consider not null pointers with zero size but I believe it does happen when debug is disabled after looking at this conditional statement in mi_heap_malloc_small:

mimalloc/src/alloc.c

Lines 77 to 81 in 38a0322

#if (MI_PADDING)
if (size == 0) {
size = sizeof(void*);
}
#endif

Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate the feedback from @michaeljclark. Last year, I was exploring mimalloc performance issues using the preliminary work. Thus, my proposed change was the part of the workbench.

@daanx daanx changed the base branch from master to dev February 3, 2022 03:59
@daanx
Copy link
Collaborator

daanx commented Feb 3, 2022

Interesting pr; just based it on top of dev which is easier for me to experiment with. Thanks!

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