Question about the spare chunk

cee1 fykcee1 at
Wed Dec 3 06:17:30 PST 2014

Hi, all

I'm learning the code of jemalloc 3.6.0, I find in arena_run_dalloc()
if (size == arena_maxclass)
    arena_chunk_dealloc(arena, chunk);

And in arena_chunk_dealloc():
if (arena->spare != NULL) {
    arena_chunk_t *spare = arena->spare;

    arena->spare = chunk;

    chunk_dealloc((void *)spare, chunksize, true);


Here the old spare chunk is replaced by the new one and dealloced.

The deallocating process is done without the lock protection. In this
lockless period, is it possible another arena_chunk_dealloc running in
another thread replaces and deallocates ** our new spare chunk ** ?
Which is still in the chunks_dirty tree and will be accessed by the
purge process later.


- cee1

More information about the jemalloc-discuss mailing list