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

mimalloc: assertion failed in mi_segment_span_free_coalesce #691

Closed
colesbury opened this issue Jan 30, 2023 · 2 comments
Closed

mimalloc: assertion failed in mi_segment_span_free_coalesce #691

colesbury opened this issue Jan 30, 2023 · 2 comments

Comments

@colesbury
Copy link
Contributor

I'm using mimalloc v2.0.9. I'm getting an assertion error when I do the following:

  1. Allocate a large block of memory from thread 1 (i.e., requiring an MI_SEGMENT_HUGE).
  2. Thread 1 exits, abandoning the segment.
  3. The block of memory is freed from thread 2.
  4. Thread 2 exits
#include <assert.h>
#include <pthread.h>
#include <mimalloc.h>

static char* ptr;

static void* thread1_allocate(void *_unused)
{
  ptr = mi_malloc(22085632);
  return NULL;
}

static void* thread2_free(void *_unused)
{
  assert(ptr);
  mi_free(ptr);
  ptr = NULL;
  return NULL;
}

int main(int argc, char** argv) {
  pthread_t thread1, thread2;

  pthread_create(&thread1, NULL, &thread1_allocate, NULL);
  pthread_join(thread1, NULL); 

  pthread_create(&thread2, NULL, &thread2_free, NULL);
  pthread_join(thread2, NULL); 

  return 0;
}
mimalloc: assertion failed: at "/raid/sgross/mimalloc/src/segment.c":635, mi_segment_span_free_coalesce
  assertion: "segment->used == 1"
Aborted
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Jan 31, 2023
@daanx
Copy link
Collaborator

daanx commented Feb 1, 2023

Thanks Sam! I studied it and the assertion is indeed too strict (so no bug). It is because for v2.0.9 I made huge segments behave more regularly and no longer as abandoned "orphans" such that heap walking works correctly now for huge segments/blocks. To still release memory early for huge block frees we now decommit them directly on free but the block and segment itself is reclaimed later on like regular segments -- this lead to the now failing assertion but it is actually correct behavior now.

colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 1, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 19, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 19, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 19, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 19, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 19, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 19, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 19, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 20, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 20, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 20, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Feb 21, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Mar 6, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Mar 6, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Mar 7, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Apr 15, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Apr 16, 2023
colesbury added a commit to colesbury/nogil-3.12 that referenced this issue Apr 23, 2023
@daanx
Copy link
Collaborator

daanx commented Apr 24, 2023

This should be fixed in the latest releases. There has been some code reshuffling recently -- I hope that does not cause too much trouble for your integration. If so, let me know and I can perhaps help further! :-)

@daanx daanx closed this as completed Apr 24, 2023
DinoV pushed a commit to DinoV/cpython that referenced this issue Sep 14, 2023
DinoV pushed a commit to DinoV/cpython that referenced this issue Sep 20, 2023
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

No branches or pull requests

2 participants