metall icon indicating copy to clipboard operation
metall copied to clipboard

Assertion triggered on small allocations with custom chunk size

Open liss-h opened this issue 1 year ago • 4 comments

Hi, we've ran into a problem an wanted some guidance. So, the metall manager has this k_chunk_size template parameter which is set to 1 << 21 by default.

If we set it to e.g. 1 << 28 metall fails to allocate small objects (as far as I can tell everything below 2*sizeof(void *)). The following assertion is triggered inside metall:

multilayer_bitset.hpp:481: std::size_t metall::kernel::multilayer_bitset::num_all_blocks(std::size_t) const: Assertion `idx < mlbs::k_num_layers_table.size()' failed.

So I'm basically just here to ask if this is expected behaviour or if this is a bug (an explaination of what the parameter does exactly would also be appreciated) 😅

liss-h avatar Aug 07 '24 08:08 liss-h

Sorry forgot to mention: allocation is done through

auto *x = manager.construct<unsigned char>("test")[sizeof(void *)]();

liss-h avatar Aug 07 '24 08:08 liss-h

The error is an expected one due to the limitation of the current implementation.

A chunk holds multiple slots (allocation space) of the same allocation size. Metall uses a multi-layer bitset to track used/unused slots within a chunk.

The i-th element in k_num_layers_table holds the number of required bitset layers to manage 2^i slots. Currently, the table supports up to 2^24 slots for now.

Since Metall's smallest allocation size is 8 bytes, the maximum chunk size Metall could support is 2^27 (8 x 2^24) bytes.

Is there a situation where you want to use a large chunk size?

KIwabuchi avatar Aug 11 '24 21:08 KIwabuchi

We were basically trying to see if there is any performance benefit to choosing a greater chunk size. But apart from that/if you think it makes no difference we don't have any reason to choose a larger chunk size

liss-h avatar Aug 14 '24 12:08 liss-h

Were you able to get a notable performance improvement by using a large chunk size?

Unfortunately, there is no simple relationship between the chunk size and Metall's performance. I always use the default chunk size.

KIwabuchi avatar Aug 14 '24 15:08 KIwabuchi

No, we were not able to improve the performance by increase the chuck size.

bigerl avatar Aug 15 '24 10:08 bigerl

Is supporting up to 2^27 chunk size still okay for you?

KIwabuchi avatar Aug 15 '24 17:08 KIwabuchi