Lines Matching full:size

67 static void (*rt_malloc_hook)(void *ptr, rt_size_t size);
82 void rt_malloc_sethook(void (*hook)(void *ptr, rt_size_t size)) in rt_malloc_sethook() argument
107 * A slab allocator reserves a ZONE for each chunk size, then lays the
112 * The downside of this slab implementation is in the chunk size
115 * the zone size is adjusted downward on machines with less physical
133 * Alloc Size Chunking Number of zones
179 rt_int32_t z_chunksize; /* chunk size for validation */
187 #define ZALLOC_MIN_ZONE_SIZE (32 * 1024) /* minimum zone size */
188 #define ZALLOC_MAX_ZONE_SIZE (128 * 1024) /* maximum zone size */
216 rt_uint32_t size: 30; /* pages allocated or offset from zone */ member
368 RT_DEBUG_LOG(RT_DEBUG_SLAB, ("heap[0x%x - 0x%x], size 0x%x, 0x%x pages\n", in rt_system_heap_init()
374 /* calculate zone size */ in rt_system_heap_init()
385 RT_DEBUG_LOG(RT_DEBUG_SLAB, ("zone size 0x%x, zone page count 0x%x\n", in rt_system_heap_init()
393 RT_DEBUG_LOG(RT_DEBUG_SLAB, ("memusage 0x%x, size 0x%x\n", in rt_system_heap_init()
398 * Calculate the zone index for the allocation request size and set the
399 * allocation request size to that particular zone's chunk size.
474 * @param size the size of memory to be allocated
478 void *rt_malloc(rt_size_t size) in rt_malloc() argument
485 /* zero size, return RT_NULL */ in rt_malloc()
486 if (size == 0) in rt_malloc()
493 if (size >= zone_limit) in rt_malloc()
495 size = RT_ALIGN(size, RT_MM_PAGE_SIZE); in rt_malloc()
497 chunk = rt_page_alloc(size >> RT_MM_PAGE_BITS); in rt_malloc()
504 kup->size = size >> RT_MM_PAGE_BITS; in rt_malloc()
508 size, in rt_malloc()
509 size >> RT_MM_PAGE_BITS, in rt_malloc()
516 used_mem += size; in rt_malloc()
532 * Note: zoneindex() will panic of size is too large. in rt_malloc()
534 zi = zoneindex(&size); in rt_malloc()
537 RT_DEBUG_LOG(RT_DEBUG_SLAB, ("try to malloc 0x%x on zone: %d\n", size, zi)); in rt_malloc()
559 chunk = (slab_chunk *)(z->z_baseptr + z->z_uindex * size); in rt_malloc()
619 kup->size = off; in rt_malloc()
635 if ((size | (size - 1)) + 1 == (size << 1)) in rt_malloc()
636 off = (off + size - 1) & ~(size - 1); in rt_malloc()
642 z->z_nmax = (zone_size - off) / size; in rt_malloc()
646 z->z_chunksize = size; in rt_malloc()
648 chunk = (slab_chunk *)(z->z_baseptr + z->z_uindex * size); in rt_malloc()
663 RT_OBJECT_HOOK_CALL(rt_malloc_hook, ((char *)chunk, size)); in rt_malloc()
671 * This function will change the size of previously allocated memory block.
674 * @param size the new size of memory block
678 void *rt_realloc(void *ptr, rt_size_t size) in rt_realloc() argument
685 return rt_malloc(size); in rt_realloc()
686 if (size == 0) in rt_realloc()
695 * using the same chunk size we do not have to do anything. in rt_realloc()
702 osize = kup->size << RT_MM_PAGE_BITS; in rt_realloc()
703 if ((nptr = rt_malloc(size)) == RT_NULL) in rt_realloc()
705 rt_memcpy(nptr, ptr, size > osize ? osize : size); in rt_realloc()
713 kup->size * RT_MM_PAGE_SIZE); in rt_realloc()
716 zoneindex(&size); in rt_realloc()
717 if (z->z_chunksize == size) in rt_realloc()
721 * Allocate memory for the new request size. Note that zoneindex has in rt_realloc()
722 * already adjusted the request size to the appropriate chunk size, which in rt_realloc()
725 if ((nptr = rt_malloc(size)) == RT_NULL) in rt_realloc()
728 rt_memcpy(nptr, ptr, size > z->z_chunksize ? z->z_chunksize : size); in rt_realloc()
740 * that are size bytes of memory each and returns a pointer to the allocated
746 * @param size size of the objects to allocate
750 void *rt_calloc(rt_size_t count, rt_size_t size) in rt_calloc() argument
754 /* allocate 'count' objects of size 'size' */ in rt_calloc()
755 p = rt_malloc(count * size); in rt_calloc()
759 rt_memset(p, 0, count * size); in rt_calloc()
799 rt_uint32_t size; in rt_free() local
804 size = kup->size; in rt_free()
805 kup->size = 0; in rt_free()
808 used_mem -= size * RT_MM_PAGE_SIZE; in rt_free()
814 (rt_uint32_t)ptr, size)); in rt_free()
817 rt_page_free(ptr, size); in rt_free()
827 kup->size * RT_MM_PAGE_SIZE); in rt_free()
889 kup->size = 0; in rt_free()