Re: 6c5c1d0bf00: MDEV-35469 Heap tables are calling mallocs to often
![](https://secure.gravatar.com/avatar/39b623a1559cf9c69ac3d9d4fb44e7fe.jpg?s=120&d=mm&r=g)
Hi, Monty, On Dec 21, Michael Widenius wrote:
revision-id: 6c5c1d0bf00 (mariadb-10.6.20-57-g6c5c1d0bf00) parent(s): 671f80c7388 author: Michael Widenius committer: Michael Widenius timestamp: 2024-12-17 10:45:25 +0200 message:
MDEV-35469 Heap tables are calling mallocs to often
Heap tables are allocated blocks to store rows according to my_default_record_cache (mapped to the server global variable read_buffer_size). This causes performance issues when the record length is big (> 1000 bytes) and the my_default_record_cache is small.
Changed to instead split the default heap allocation to 1/16 of the allowed space and not use my_default_record_cache anymore when creating the heap. The allocation is also aligned to be just under a power of 2.
For some test that I have been running, which was using record length=633, the speed of the query doubled thanks to this change.
Other things: - Fixed calculation of max_records passed to hp_create() to take into account padding between records.
diff --git a/storage/heap/hp_create.c b/storage/heap/hp_create.c index c07a1e968c4..fcfcf607822 100644 --- a/storage/heap/hp_create.c +++ b/storage/heap/hp_create.c ... + of the block. + */ + records_in_block= + (my_round_up_to_next_power((uint32) + (records_in_block * recbuffer + + sizeof(HP_PTRS) + MALLOC_OVERHEAD)/2) / + recbuffer);
Strictly speaking, it should be (my_round_up_to_next_power(records_in_block * recbuffer + extra) - extra ) / recbuffer And why /2 ? Regards, Sergei Chief Architect, MariaDB Server and security@mariadb.org
![](https://secure.gravatar.com/avatar/68cce0b6e372c2c66f4d66c6356102af.jpg?s=120&d=mm&r=g)
Hi! On Sat, Dec 21, 2024 at 8:16 PM Sergei Golubchik <serg@mariadb.org> wrote:
Hi, Monty,
MDEV-35469 Heap tables are calling mallocs to often
+ records_in_block= + (my_round_up_to_next_power((uint32) + (records_in_block * recbuffer + + sizeof(HP_PTRS) + MALLOC_OVERHEAD)/2) / + recbuffer);
Strictly speaking, it should be
(my_round_up_to_next_power(records_in_block * recbuffer + extra) - extra ) / recbuffer
Good catch. Fixing.
And why /2 ?
I don't want to allocate more memory than the user has given to heap. The /2 changes 'my_round_up_to_next_power' to 'my_round_up_to_previous_power()' I will add a comment to make this clear. I have also done some other minor adjustments to this patch to ensure that we also take properly into account the memory allocated by indexes when calculating the max number of rows. I will show you the final patch shortly. Regards, Monty
participants (2)
-
Michael Widenius
-
Sergei Golubchik