Memory allocation speed is slow by memory fragmentation on long-run test.
JunBeom Kim
jbkim at e-coretech.kr
Fri Mar 29 07:19:07 UTC 2019
Dear Sir,
I am still working with my customer using RTEMS based Qt Framework in long
time.
My customer are using memory allocation(malloc, realloc, free) with
frequency about small size(64, 128, 256, 512, 1024 byte, etc).
When RTEMS application is run in long time(for example: 6 hours), malloc()
or realloc() speed is slower due to memory fragmentation.
When I used other RTOS(eg: Nucleus, uC/OS, iTRON, etc) before, there was
almost same issue.
I used partition memory management for resolving this.
Is it correct method ?
My trick for RTEMS is below;
rtems_id pmem_id[PMEM_PARTITION_MAX]; /* array of partition ids */
partition_mem_tbl pmem_tbl[PMEM_PARTITION_MAX];
bool pmem_init_flag;
int pmem_64_total_size = (1024*1024*64);
int pmem_128_total_size = (1024*1024*16);
int pmem_256_total_size = (1024*1024*8);
int pmem_512_total_size = (1024*1024*8);
int pmem_1k_total_size = (1024*1024*8);
int pmem_2k_total_size = (1024*1024*32);
int pmem_3k_total_size = (1024*1024*8);
int pmem_4k_total_size = (1024*1024*8);
int pmem_8k_total_size = (1024*1024*8);
int pmem_16k_total_size = (1024*1024*8);
void pmem_tbl_init(uint32_t index, uint32_t id, uint32_t block_size,
uint32_t total_size, void *addr)
{
pmem_tbl[index].id = id;
pmem_tbl[index].block_size = block_size;
pmem_tbl[index].total_size = total_size;
pmem_tbl[index].total_block = total_size / block_size;
pmem_tbl[index].base_address = (uint32_t)addr;
pmem_tbl[index].end_address = pmem_tbl[index].base_address
+ total_size;
pmem_tbl[index].alloc_count = 0;
pmem_tbl[index].alloc_max = 0;
// printf("block[%05d]:start=0x%08x/end=0x%08x\n", block_size,
// pmem_tbl[index].base_address,
pmem_tbl[index].end_address);
}
void pmem_initialize(bool enable)
{
void *addr;
if (enable == true) {
posix_memalign(&addr, 64,
pmem_64_total_size);
rtems_partition_create(rtems_build_name('P','0','6','4'), addr,
pmem_64_total_size, 64,
RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_64_INDEX]);
pmem_tbl_init(PMEM_64_INDEX,
pmem_id[PMEM_64_INDEX], 64, pmem_64_total_size, addr);
posix_memalign(&addr, 64,
pmem_128_total_size);
rtems_partition_create(rtems_build_name('P','1','2','8'), addr,
pmem_128_total_size,
128, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_128_INDEX]);
pmem_tbl_init(PMEM_128_INDEX,
pmem_id[PMEM_128_INDEX], 128, pmem_128_total_size, addr);
posix_memalign(&addr, 64,
pmem_256_total_size);
rtems_partition_create(rtems_build_name('P','2','5','6'), addr,
pmem_256_total_size,
256, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_256_INDEX]);
pmem_tbl_init(PMEM_256_INDEX,
pmem_id[PMEM_256_INDEX], 256, pmem_256_total_size, addr);
posix_memalign(&addr, 64,
pmem_512_total_size);
rtems_partition_create(rtems_build_name('P','5','1','2'), addr,
pmem_512_total_size,
512, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_512_INDEX]);
pmem_tbl_init(PMEM_512_INDEX,
pmem_id[PMEM_512_INDEX], 512, pmem_512_total_size, addr);
posix_memalign(&addr, 64,
pmem_1k_total_size);
rtems_partition_create(rtems_build_name('P','0','1','K'), addr,
pmem_1k_total_size,
1024, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_1K_INDEX]);
pmem_tbl_init(PMEM_1K_INDEX,
pmem_id[PMEM_1K_INDEX], 1024, pmem_1k_total_size, addr);
posix_memalign(&addr, 64,
pmem_2k_total_size);
rtems_partition_create(rtems_build_name('P','0','2','K'), addr,
pmem_2k_total_size,
1024*2, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_2K_INDEX]);
pmem_tbl_init(PMEM_2K_INDEX,
pmem_id[PMEM_2K_INDEX], 1024*2, pmem_2k_total_size, addr);
posix_memalign(&addr, 64,
pmem_4k_total_size);
rtems_partition_create(rtems_build_name('P','0','4','K'), addr,
pmem_4k_total_size,
1024*4, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_4K_INDEX]);
pmem_tbl_init(PMEM_4K_INDEX,
pmem_id[PMEM_4K_INDEX], 1024*4, pmem_4k_total_size, addr);
posix_memalign(&addr, 64,
pmem_8k_total_size);
rtems_partition_create(rtems_build_name('P','0','8','K'), addr,
pmem_8k_total_size,
1024*8, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_8K_INDEX]);
pmem_tbl_init(PMEM_8K_INDEX,
pmem_id[PMEM_8K_INDEX], 1024*8, pmem_8k_total_size, addr);
posix_memalign(&addr, 64,
pmem_16k_total_size);
rtems_partition_create(rtems_build_name('P','1','6','K'), addr,
pmem_16k_total_size,
1024*16, RTEMS_DEFAULT_ATTRIBUTES, &pmem_id[PMEM_16K_INDEX]);
pmem_tbl_init(PMEM_16K_INDEX,
pmem_id[PMEM_16K_INDEX], 1024*16, pmem_16k_total_size, addr);
pmem_init_flag = true;
}
else {
pmem_tbl[PMEM_16K_INDEX].base_address =
RTEMS_Malloc_Heap->area_end;
pmem_init_flag = false;
}
}
In malloc.c,
void *malloc(
size_t size
)
{
void *return_this;
/*
* Validate the parameters
*/
if ( !size )
return (void *) 0;
if ((size>1024*16) || pmem_init_flag == false) {
return_this =
rtems_heap_allocate_aligned_with_boundary( size, 0, 0 );
if ( !return_this ) {
errno = ENOMEM;
return (void *) 0;
}
return return_this;
}
else {
return_this = pmem_malloc(size);
return return_this;
}
}
Best Regards,
JunBeom Kim
~~~~~~~~~~~~~~~~~~~~~~
President / EmbedCoreTech
Phone: +82-31-396-5584
Fax: +82-504-065-5720
Mobile:+82-10-6425-5720
Email: <mailto:jbkim at e-coretech.kr> jbkim at e-coretech.kr
Web: <http://www.e-coretech.kr> www.e-coretech.kr
~~~~~~~~~~~~~~~~~~~~~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20190329/19862b03/attachment-0001.html>
More information about the users
mailing list