/* * A simple test that tries to allocate a small memory region. * Expect to allocate an aligned region near the end of the available memory.
*/ staticint alloc_top_down_simple_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL;
phys_addr_t size = SZ_2;
phys_addr_t expected_start;
/* * A test that tries to allocate memory next to a reserved region that starts at * the misaligned address. Expect to create two separate entries, with the new * entry aligned to the provided alignment: * * + * | +--------+ +--------| * | | rgn2 | | rgn1 | * +------------+--------+---------+--------+ * ^ * | * Aligned address boundary * * The allocation direction is top-down and region arrays are sorted from lower * to higher addresses, so the new region will be the first entry in * memory.reserved array. The previously reserved region does not get modified. * Region counter and total size get updated.
*/ staticint alloc_top_down_disjoint_check(void)
{ /* After allocation, this will point to the "old" region */ struct memblock_region *rgn1 = &memblock.reserved.regions[1]; struct memblock_region *rgn2 = &memblock.reserved.regions[0]; struct region r1; void *allocated_ptr = NULL;
phys_addr_t r2_size = SZ_16; /* Use custom alignment */
phys_addr_t alignment = SMP_CACHE_BYTES * 2;
phys_addr_t total_size;
phys_addr_t expected_start;
/* * A test that tries to allocate memory when there is enough space at the end * of the previously reserved block (i.e. first fit): * * | +--------+--------------| * | | r1 | r2 | * +--------------+--------+--------------+ * * Expect a merge of both regions. Only the region size gets updated.
*/ staticint alloc_top_down_before_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL; /* * The first region ends at the aligned address to test region merging
*/
phys_addr_t r1_size = SMP_CACHE_BYTES;
phys_addr_t r2_size = SZ_512;
phys_addr_t total_size = r1_size + r2_size;
/* * A test that tries to allocate memory when there is not enough space at the * end of the previously reserved block (i.e. second fit): * * | +-----------+------+ | * | | r2 | r1 | | * +------------+-----------+------+-----+ * * Expect a merge of both regions. Both the base address and size of the region * get updated.
*/ staticint alloc_top_down_after_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; struct region r1; void *allocated_ptr = NULL;
phys_addr_t r2_size = SZ_512;
phys_addr_t total_size;
PREFIX_PUSH();
setup_memblock();
/* * The first region starts at the aligned address to test region merging
*/
r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES;
r1.size = SZ_8;
/* * A test that tries to allocate memory when there are two reserved regions with * a gap too small to fit the new region: * * | +--------+----------+ +------| * | | r3 | r2 | | r1 | * +-------+--------+----------+---+------+ * * Expect to allocate a region before the one that starts at the lower address, * and merge them into one. The region counter and total size fields get * updated.
*/ staticint alloc_top_down_second_fit_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; struct region r1, r2; void *allocated_ptr = NULL;
phys_addr_t r3_size = SZ_1K;
phys_addr_t total_size;
/* * A test that tries to allocate memory when there are two reserved regions with * a gap big enough to accommodate the new region: * * | +--------+--------+--------+ | * | | r2 | r3 | r1 | | * +-----+--------+--------+--------+-----+ * * Expect to merge all of them, creating one big entry in memblock.reserved * array. The region counter and total size fields get updated.
*/ staticint alloc_in_between_generic_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; struct region r1, r2; void *allocated_ptr = NULL;
phys_addr_t gap_size = SMP_CACHE_BYTES;
phys_addr_t r3_size = SZ_64; /* * Calculate regions size so there's just enough space for the new entry
*/
phys_addr_t rgn_size = (MEM_SIZE - (2 * gap_size + r3_size)) / 2;
phys_addr_t total_size;
/* * A test that tries to allocate memory when the memory is filled with reserved * regions with memory gaps too small to fit the new region: * * +-------+ * | new | * +--+----+ * | +-----+ +-----+ +-----+ | * | | res | | res | | res | | * +----+-----+----+-----+----+-----+----+ * * Expect no allocation to happen.
*/ staticint alloc_small_gaps_generic_check(void)
{ void *allocated_ptr = NULL;
phys_addr_t region_size = SZ_1K;
phys_addr_t gap_size = SZ_256;
phys_addr_t region_end;
/* * A test that tries to allocate memory when all memory is reserved. * Expect no allocation to happen.
*/ staticint alloc_all_reserved_generic_check(void)
{ void *allocated_ptr = NULL;
PREFIX_PUSH();
setup_memblock();
/* Simulate full memory */
memblock_reserve(memblock_start_of_DRAM(), MEM_SIZE);
/* * A test that tries to allocate memory when the memory is almost full, * with not enough space left for the new region: * * +-------+ * | new | * +-------+ * |-----------------------------+ | * | reserved | | * +-----------------------------+---+ * * Expect no allocation to happen.
*/ staticint alloc_no_space_generic_check(void)
{ void *allocated_ptr = NULL;
phys_addr_t available_size = SZ_256;
phys_addr_t reserved_size = MEM_SIZE - available_size;
/* * A test that tries to allocate memory when the memory is almost full, * but there is just enough space left: * * |---------------------------+---------| * | reserved | new | * +---------------------------+---------+ * * Expect to allocate memory and merge all the regions. The total size field * gets updated.
*/ staticint alloc_limited_space_generic_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL;
phys_addr_t available_size = SZ_256;
phys_addr_t reserved_size = MEM_SIZE - available_size;
/* * A test that tries to allocate memory when there is no available memory * registered (i.e. memblock.memory has only a dummy entry). * Expect no allocation to happen.
*/ staticint alloc_no_memory_generic_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL;
/* * A test that tries to allocate a region that is larger than the total size of * available memory (memblock.memory): * * +-----------------------------------+ * | new | * +-----------------------------------+ * | | * | | * +---------------------------------+ * * Expect no allocation to happen.
*/ staticint alloc_too_large_generic_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL;
/* * A simple test that tries to allocate a small memory region. * Expect to allocate an aligned region at the beginning of the available * memory.
*/ staticint alloc_bottom_up_simple_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL;
/* * A test that tries to allocate memory next to a reserved region that starts at * the misaligned address. Expect to create two separate entries, with the new * entry aligned to the provided alignment: * * + * | +----------+ +----------+ | * | | rgn1 | | rgn2 | | * +----+----------+---+----------+-----+ * ^ * | * Aligned address boundary * * The allocation direction is bottom-up, so the new region will be the second * entry in memory.reserved array. The previously reserved region does not get * modified. Region counter and total size get updated.
*/ staticint alloc_bottom_up_disjoint_check(void)
{ struct memblock_region *rgn1 = &memblock.reserved.regions[0]; struct memblock_region *rgn2 = &memblock.reserved.regions[1]; struct region r1; void *allocated_ptr = NULL;
phys_addr_t r2_size = SZ_16; /* Use custom alignment */
phys_addr_t alignment = SMP_CACHE_BYTES * 2;
phys_addr_t total_size;
phys_addr_t expected_start;
/* * A test that tries to allocate memory when there is enough space at * the beginning of the previously reserved block (i.e. first fit): * * |------------------+--------+ | * | r1 | r2 | | * +------------------+--------+---------+ * * Expect a merge of both regions. Only the region size gets updated.
*/ staticint alloc_bottom_up_before_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; void *allocated_ptr = NULL;
phys_addr_t r1_size = SZ_512;
phys_addr_t r2_size = SZ_128;
phys_addr_t total_size = r1_size + r2_size;
/* * A test that tries to allocate memory when there is not enough space at * the beginning of the previously reserved block (i.e. second fit): * * | +--------+--------------+ | * | | r1 | r2 | | * +----+--------+--------------+---------+ * * Expect a merge of both regions. Only the region size gets updated.
*/ staticint alloc_bottom_up_after_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[0]; struct region r1; void *allocated_ptr = NULL;
phys_addr_t r2_size = SZ_512;
phys_addr_t total_size;
PREFIX_PUSH();
setup_memblock();
/* * The first region starts at the aligned address to test region merging
*/
r1.base = memblock_start_of_DRAM() + SMP_CACHE_BYTES;
r1.size = SZ_64;
/* * A test that tries to allocate memory when there are two reserved regions, the * first one starting at the beginning of the available memory, with a gap too * small to fit the new region: * * |------------+ +--------+--------+ | * | r1 | | r2 | r3 | | * +------------+-----+--------+--------+--+ * * Expect to allocate after the second region, which starts at the higher * address, and merge them into one. The region counter and total size fields * get updated.
*/ staticint alloc_bottom_up_second_fit_check(void)
{ struct memblock_region *rgn = &memblock.reserved.regions[1]; struct region r1, r2; void *allocated_ptr = NULL;
phys_addr_t r3_size = SZ_1K;
phys_addr_t total_size;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.