alloc and free many small buffers
This commit is contained in:
parent
3e2ee555f8
commit
53369ab564
@ -34,7 +34,7 @@ struct mm_root_node {
|
|||||||
mm_leaf_node_t *leafs[MM_LEAF_COUNT];
|
mm_leaf_node_t *leafs[MM_LEAF_COUNT];
|
||||||
};
|
};
|
||||||
STATIC_ASSERT(sizeof(struct mm_root_node) <= MM_BLOCK_SIZE, "struct mm_root_node too big");
|
STATIC_ASSERT(sizeof(struct mm_root_node) <= MM_BLOCK_SIZE, "struct mm_root_node too big");
|
||||||
|
static size_t number_of_bytes_allocated = 0;
|
||||||
|
|
||||||
errval_t mm_init(struct mm *mm, enum objtype objtype,
|
errval_t mm_init(struct mm *mm, enum objtype objtype,
|
||||||
slab_refill_func_t slab_refill_func,
|
slab_refill_func_t slab_refill_func,
|
||||||
@ -120,6 +120,11 @@ errval_t mm_add(struct mm *mm, struct capref cap)
|
|||||||
errval_t mm_alloc_aligned(struct mm *mm, size_t size, size_t alignment, struct capref *retcap)
|
errval_t mm_alloc_aligned(struct mm *mm, size_t size, size_t alignment, struct capref *retcap)
|
||||||
{
|
{
|
||||||
errval_t err;
|
errval_t err;
|
||||||
|
|
||||||
|
//TODO afeer: remove this after evaluation
|
||||||
|
number_of_bytes_allocated += size;
|
||||||
|
// debug_printf("[mm] number_of_bytes_allocated: %x\n", number_of_bytes_allocated);
|
||||||
|
|
||||||
if ((alignment & (alignment - 1)) != 0) {
|
if ((alignment & (alignment - 1)) != 0) {
|
||||||
return MM_ERR_BAD_ALIGNMENT;
|
return MM_ERR_BAD_ALIGNMENT;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,16 +18,44 @@
|
|||||||
#include <aos/aos.h>
|
#include <aos/aos.h>
|
||||||
#include <aos/paging.h>
|
#include <aos/paging.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
#define NUM_SMALL_BUFFERS 128
|
||||||
{
|
|
||||||
//allocate a 256 byte buffer
|
static void test_large_buffer(void) {
|
||||||
// char * small_buf = malloc(256);
|
|
||||||
// small_buf[0] = 'a';
|
|
||||||
//allocate a 256 MiB buffer
|
//allocate a 256 MiB buffer
|
||||||
|
debug_printf("allocating 256MiB buffer\n");
|
||||||
char * big_buf = malloc(1<<28);
|
char * big_buf = malloc(1<<28);
|
||||||
big_buf[0] = 'a';
|
big_buf[0] = 'a';
|
||||||
for (int i = 0; i < (1 << 16); i += 4096) {
|
|
||||||
debug_printf("%x\n", i);
|
//only write to a small part of the large buffer
|
||||||
|
for (int i = 0; i < (1 << 16); i += (1 << 12)) {
|
||||||
big_buf[i] = 'b';
|
big_buf[i] = 'b';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug_printf("freeing 256MiB buffer\n");
|
||||||
|
free(big_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_many_buffers(void) {
|
||||||
|
|
||||||
|
char* buffers[NUM_SMALL_BUFFERS];
|
||||||
|
|
||||||
|
for (int i = 0; i < NUM_SMALL_BUFFERS; ++i) {
|
||||||
|
buffers[i] = malloc(4 * BASE_PAGE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//free the buffers in a different order
|
||||||
|
for (int i = NUM_SMALL_BUFFERS - 1; i >= NUM_SMALL_BUFFERS / 2; --i) {
|
||||||
|
free(buffers[i]);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < NUM_SMALL_BUFFERS / 2; ++i) {
|
||||||
|
free(buffers[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
test_large_buffer();
|
||||||
|
test_many_buffers();
|
||||||
|
|
||||||
|
debug_printf("i am done!\n");
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user