Commit ad76bf1f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'memblock-v6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock

Pull memblock updates from Mike Rapoport:
 "Extend test coverage:

   - add tests that trigger reallocation of memblock structures from
     memblock itself via memblock_double_array()

   - add tests for memblock_alloc_exact_nid_raw() that verify that
     requested node and memory range constraints are respected"

* tag 'memblock-v6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock:
  memblock tests: remove completed TODO item
  memblock tests: add generic NUMA tests for memblock_alloc_exact_nid_raw
  memblock tests: add bottom-up NUMA tests for memblock_alloc_exact_nid_raw
  memblock tests: add top-down NUMA tests for memblock_alloc_exact_nid_raw
  memblock tests: introduce range tests for memblock_alloc_exact_nid_raw
  memblock test: Update TODO list
  memblock test: Add test to memblock_reserve() 129th region
  memblock test: Add test to memblock_add() 129th region
parents 6f1f5cae 80c2fe02
......@@ -7,7 +7,7 @@ CFLAGS += -I. -I../../include -Wall -O2 -fsanitize=address \
LDFLAGS += -fsanitize=address -fsanitize=undefined
TARGETS = main
TEST_OFILES = tests/alloc_nid_api.o tests/alloc_helpers_api.o tests/alloc_api.o \
tests/basic_api.o tests/common.o
tests/basic_api.o tests/common.o tests/alloc_exact_nid_api.o
DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o
OFILES = main.o $(DEP_OFILES) $(TEST_OFILES)
EXTR_SRC = ../../../mm/memblock.c
......
TODO
=====
1. Add tests trying to memblock_add() or memblock_reserve() 129th region.
This will trigger memblock_double_array(), make sure it succeeds.
*Important:* These tests require valid memory ranges, use dummy physical
memory block from common.c to implement them. It is also very
likely that the current MEM_SIZE won't be enough for these
test cases. Use realloc to adjust the size accordingly.
2. Add test cases using this functions (implement them for both directions):
+ memblock_alloc_raw()
+ memblock_alloc_exact_nid_raw()
+ memblock_alloc_try_nid_raw()
3. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
1. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
for the new region
......@@ -3,6 +3,7 @@
#include "tests/alloc_api.h"
#include "tests/alloc_helpers_api.h"
#include "tests/alloc_nid_api.h"
#include "tests/alloc_exact_nid_api.h"
#include "tests/common.h"
int main(int argc, char **argv)
......@@ -12,6 +13,7 @@ int main(int argc, char **argv)
memblock_alloc_checks();
memblock_alloc_helpers_checks();
memblock_alloc_nid_checks();
memblock_alloc_exact_nid_checks();
return 0;
}
// SPDX-License-Identifier: GPL-2.0-or-later
#include "alloc_exact_nid_api.h"
#include "alloc_nid_api.h"
#define FUNC_NAME "memblock_alloc_exact_nid_raw"
/*
* contains the fraction of MEM_SIZE contained in each node in basis point
* units (one hundredth of 1% or 1/10000)
*/
static const unsigned int node_fractions[] = {
2500, /* 1/4 */
625, /* 1/16 */
1250, /* 1/8 */
1250, /* 1/8 */
625, /* 1/16 */
625, /* 1/16 */
2500, /* 1/4 */
625, /* 1/16 */
};
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* has enough memory to allocate a region of the requested size.
* Expect to allocate an aligned region at the end of the requested node.
*/
static int alloc_exact_nid_top_down_numa_simple_check(void)
{
int nid_req = 3;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
ASSERT_LE(SZ_4, req_node->size);
size = req_node->size / SZ_4;
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
ASSERT_LE(req_node->base, new_rgn->base);
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* is partially reserved but has enough memory for the allocated region:
*
* | +---------------------------------------+ |
* | | requested | |
* +-----------+---------------------------------------+----------+
*
* | +------------------+ +-----+ |
* | | reserved | | new | |
* +-----------+------------------+--------------+-----+----------+
*
* Expect to allocate an aligned region at the end of the requested node. The
* region count and total size get updated.
*/
static int alloc_exact_nid_top_down_numa_part_reserved_check(void)
{
int nid_req = 4;
struct memblock_region *new_rgn = &memblock.reserved.regions[1];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
struct region r1;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
ASSERT_LE(SZ_8, req_node->size);
r1.base = req_node->base;
r1.size = req_node->size / SZ_2;
size = r1.size / SZ_4;
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
memblock_reserve(r1.base, r1.size);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
ASSERT_LE(req_node->base, new_rgn->base);
ASSERT_EQ(memblock.reserved.cnt, 2);
ASSERT_EQ(memblock.reserved.total_size, size + r1.size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region that spans over the min_addr
* and max_addr range and overlaps with two different nodes, where the first
* node is the requested node:
*
* min_addr
* | max_addr
* | |
* v v
* | +-----------------------+-----------+ |
* | | requested | node3 | |
* +-----------+-----------------------+-----------+--------------+
* + +
* | +-----------+ |
* | | rgn | |
* +-----------------------+-----------+--------------------------+
*
* Expect to drop the lower limit and allocate a memory region that ends at
* the end of the requested node.
*/
static int alloc_exact_nid_top_down_numa_split_range_low_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
phys_addr_t size = SZ_512;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t req_node_end;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
req_node_end = region_end(req_node);
min_addr = req_node_end - SZ_256;
max_addr = min_addr + size;
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, req_node_end - size);
ASSERT_LE(req_node->base, new_rgn->base);
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region that spans over the min_addr
* and max_addr range and overlaps with two different nodes, where the requested
* node ends before min_addr:
*
* min_addr
* | max_addr
* | |
* v v
* | +---------------+ +-------------+---------+ |
* | | requested | | node1 | node2 | |
* +----+---------------+--------+-------------+---------+----------+
* + +
* | +---------+ |
* | | rgn | |
* +----------+---------+-------------------------------------------+
*
* Expect to drop the lower limit and allocate a memory region that ends at
* the end of the requested node.
*/
static int alloc_exact_nid_top_down_numa_no_overlap_split_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
struct memblock_region *node2 = &memblock.memory.regions[6];
void *allocated_ptr = NULL;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
size = SZ_512;
min_addr = node2->base - SZ_256;
max_addr = min_addr + size;
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
ASSERT_LE(req_node->base, new_rgn->base);
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate memory within min_addr and max_add range when
* the requested node and the range do not overlap, and requested node ends
* before min_addr. The range overlaps with multiple nodes along node
* boundaries:
*
* min_addr
* | max_addr
* | |
* v v
* |-----------+ +----------+----...----+----------+ |
* | requested | | min node | ... | max node | |
* +-----------+-----------+----------+----...----+----------+------+
* + +
* | +-----+ |
* | | rgn | |
* +-----+-----+----------------------------------------------------+
*
* Expect to drop the lower limit and allocate a memory region that ends at
* the end of the requested node.
*/
static int alloc_exact_nid_top_down_numa_no_overlap_low_check(void)
{
int nid_req = 0;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
struct memblock_region *min_node = &memblock.memory.regions[2];
struct memblock_region *max_node = &memblock.memory.regions[5];
void *allocated_ptr = NULL;
phys_addr_t size = SZ_64;
phys_addr_t max_addr;
phys_addr_t min_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
min_addr = min_node->base;
max_addr = region_end(max_node);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, region_end(req_node) - size);
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* has enough memory to allocate a region of the requested size.
* Expect to allocate an aligned region at the beginning of the requested node.
*/
static int alloc_exact_nid_bottom_up_numa_simple_check(void)
{
int nid_req = 3;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
ASSERT_LE(SZ_4, req_node->size);
size = req_node->size / SZ_4;
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, req_node->base);
ASSERT_LE(region_end(new_rgn), region_end(req_node));
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* is partially reserved but has enough memory for the allocated region:
*
* | +---------------------------------------+ |
* | | requested | |
* +-----------+---------------------------------------+---------+
*
* | +------------------+-----+ |
* | | reserved | new | |
* +-----------+------------------+-----+------------------------+
*
* Expect to allocate an aligned region in the requested node that merges with
* the existing reserved region. The total size gets updated.
*/
static int alloc_exact_nid_bottom_up_numa_part_reserved_check(void)
{
int nid_req = 4;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
struct region r1;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t total_size;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
ASSERT_LE(SZ_8, req_node->size);
r1.base = req_node->base;
r1.size = req_node->size / SZ_2;
size = r1.size / SZ_4;
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
total_size = size + r1.size;
memblock_reserve(r1.base, r1.size);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, total_size);
ASSERT_EQ(new_rgn->base, req_node->base);
ASSERT_LE(region_end(new_rgn), region_end(req_node));
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, total_size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region that spans over the min_addr
* and max_addr range and overlaps with two different nodes, where the first
* node is the requested node:
*
* min_addr
* | max_addr
* | |
* v v
* | +-----------------------+-----------+ |
* | | requested | node3 | |
* +-----------+-----------------------+-----------+--------------+
* + +
* | +-----------+ |
* | | rgn | |
* +-----------+-----------+--------------------------------------+
*
* Expect to drop the lower limit and allocate a memory region at the beginning
* of the requested node.
*/
static int alloc_exact_nid_bottom_up_numa_split_range_low_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
phys_addr_t size = SZ_512;
phys_addr_t min_addr;
phys_addr_t max_addr;
phys_addr_t req_node_end;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
req_node_end = region_end(req_node);
min_addr = req_node_end - SZ_256;
max_addr = min_addr + size;
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, req_node->base);
ASSERT_LE(region_end(new_rgn), req_node_end);
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region that spans over the min_addr
* and max_addr range and overlaps with two different nodes, where the requested
* node ends before min_addr:
*
* min_addr
* | max_addr
* | |
* v v
* | +---------------+ +-------------+---------+ |
* | | requested | | node1 | node2 | |
* +----+---------------+--------+-------------+---------+---------+
* + +
* | +---------+ |
* | | rgn | |
* +----+---------+------------------------------------------------+
*
* Expect to drop the lower limit and allocate a memory region that starts at
* the beginning of the requested node.
*/
static int alloc_exact_nid_bottom_up_numa_no_overlap_split_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
struct memblock_region *node2 = &memblock.memory.regions[6];
void *allocated_ptr = NULL;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
size = SZ_512;
min_addr = node2->base - SZ_256;
max_addr = min_addr + size;
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, req_node->base);
ASSERT_LE(region_end(new_rgn), region_end(req_node));
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate memory within min_addr and max_add range when
* the requested node and the range do not overlap, and requested node ends
* before min_addr. The range overlaps with multiple nodes along node
* boundaries:
*
* min_addr
* | max_addr
* | |
* v v
* |-----------+ +----------+----...----+----------+ |
* | requested | | min node | ... | max node | |
* +-----------+-----------+----------+----...----+----------+------+
* + +
* |-----+ |
* | rgn | |
* +-----+----------------------------------------------------------+
*
* Expect to drop the lower limit and allocate a memory region that starts at
* the beginning of the requested node.
*/
static int alloc_exact_nid_bottom_up_numa_no_overlap_low_check(void)
{
int nid_req = 0;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
struct memblock_region *min_node = &memblock.memory.regions[2];
struct memblock_region *max_node = &memblock.memory.regions[5];
void *allocated_ptr = NULL;
phys_addr_t size = SZ_64;
phys_addr_t max_addr;
phys_addr_t min_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
min_addr = min_node->base;
max_addr = region_end(max_node);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, size);
ASSERT_EQ(new_rgn->base, req_node->base);
ASSERT_LE(region_end(new_rgn), region_end(req_node));
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* does not have enough memory to allocate a region of the requested size:
*
* | +-----+ |
* | | req | |
* +---+-----+----------------------------+
*
* +---------+
* | rgn |
* +---------+
*
* Expect no allocation to happen.
*/
static int alloc_exact_nid_numa_small_node_generic_check(void)
{
int nid_req = 1;
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
size = SZ_2 * req_node->size;
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_EQ(allocated_ptr, NULL);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* is fully reserved:
*
* | +---------+ |
* | |requested| |
* +--------------+---------+-------------+
*
* | +---------+ |
* | | reserved| |
* +--------------+---------+-------------+
*
* Expect no allocation to happen.
*/
static int alloc_exact_nid_numa_node_reserved_generic_check(void)
{
int nid_req = 2;
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
size = req_node->size;
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
memblock_reserve(req_node->base, req_node->size);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_EQ(allocated_ptr, NULL);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* is partially reserved and does not have enough contiguous memory for the
* allocated region:
*
* | +-----------------------+ |
* | | requested | |
* +-----------+-----------------------+----+
*
* | +----------+ |
* | | reserved | |
* +-----------------+----------+-----------+
*
* Expect no allocation to happen.
*/
static int alloc_exact_nid_numa_part_reserved_fail_generic_check(void)
{
int nid_req = 4;
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
struct region r1;
phys_addr_t size;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
ASSERT_LE(SZ_4, req_node->size);
size = req_node->size / SZ_2;
r1.base = req_node->base + (size / SZ_2);
r1.size = size;
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
memblock_reserve(r1.base, r1.size);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_EQ(allocated_ptr, NULL);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region that spans over the min_addr
* and max_addr range and overlaps with two different nodes, where the second
* node is the requested node:
*
* min_addr
* | max_addr
* | |
* v v
* | +--------------------------+---------+ |
* | | first node |requested| |
* +------+--------------------------+---------+----------------+
*
* Expect no allocation to happen.
*/
static int alloc_exact_nid_numa_split_range_high_generic_check(void)
{
int nid_req = 3;
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
void *allocated_ptr = NULL;
phys_addr_t size = SZ_512;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
min_addr = req_node->base - SZ_256;
max_addr = min_addr + size;
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_EQ(allocated_ptr, NULL);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate memory within min_addr and max_add range when
* the requested node and the range do not overlap, and requested node starts
* after max_addr. The range overlaps with multiple nodes along node
* boundaries:
*
* min_addr
* | max_addr
* | |
* v v
* | +----------+----...----+----------+ +-----------+ |
* | | min node | ... | max node | | requested | |
* +-----+----------+----...----+----------+--------+-----------+---+
*
* Expect no allocation to happen.
*/
static int alloc_exact_nid_numa_no_overlap_high_generic_check(void)
{
int nid_req = 7;
struct memblock_region *min_node = &memblock.memory.regions[2];
struct memblock_region *max_node = &memblock.memory.regions[5];
void *allocated_ptr = NULL;
phys_addr_t size = SZ_64;
phys_addr_t max_addr;
phys_addr_t min_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
min_addr = min_node->base;
max_addr = region_end(max_node);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_EQ(allocated_ptr, NULL);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate a memory region in a specific NUMA node that
* does not have enough memory to allocate a region of the requested size.
* Additionally, none of the nodes have enough memory to allocate the region:
*
* +-----------------------------------+
* | new |
* +-----------------------------------+
* |-------+-------+-------+-------+-------+-------+-------+-------|
* | node0 | node1 | node2 | node3 | node4 | node5 | node6 | node7 |
* +-------+-------+-------+-------+-------+-------+-------+-------+
*
* Expect no allocation to happen.
*/
static int alloc_exact_nid_numa_large_region_generic_check(void)
{
int nid_req = 3;
void *allocated_ptr = NULL;
phys_addr_t size = MEM_SIZE / SZ_2;
phys_addr_t min_addr;
phys_addr_t max_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_EQ(allocated_ptr, NULL);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate memory within min_addr and max_addr range when
* there are two reserved regions at the borders. The requested node starts at
* min_addr and ends at max_addr and is the same size as the region to be
* allocated:
*
* min_addr
* | max_addr
* | |
* v v
* | +-----------+-----------------------+-----------------------|
* | | node5 | requested | node7 |
* +------+-----------+-----------------------+-----------------------+
* + +
* | +----+-----------------------+----+ |
* | | r2 | new | r1 | |
* +-------------+----+-----------------------+----+------------------+
*
* Expect to merge all of the regions into one. The region counter and total
* size fields get updated.
*/
static int alloc_exact_nid_numa_reserved_full_merge_generic_check(void)
{
int nid_req = 6;
int nid_next = nid_req + 1;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
struct memblock_region *req_node = &memblock.memory.regions[nid_req];
struct memblock_region *next_node = &memblock.memory.regions[nid_next];
void *allocated_ptr = NULL;
struct region r1, r2;
phys_addr_t size = req_node->size;
phys_addr_t total_size;
phys_addr_t max_addr;
phys_addr_t min_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
r1.base = next_node->base;
r1.size = SZ_128;
r2.size = SZ_128;
r2.base = r1.base - (size + r2.size);
total_size = r1.size + r2.size + size;
min_addr = r2.base + r2.size;
max_addr = r1.base;
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
nid_req);
ASSERT_NE(allocated_ptr, NULL);
ASSERT_MEM_NE(allocated_ptr, 0, size);
ASSERT_EQ(new_rgn->size, total_size);
ASSERT_EQ(new_rgn->base, r2.base);
ASSERT_LE(new_rgn->base, req_node->base);
ASSERT_LE(region_end(req_node), region_end(new_rgn));
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, total_size);
test_pass_pop();
return 0;
}
/*
* A test that tries to allocate memory within min_addr and max_add range,
* where the total range can fit the region, but it is split between two nodes
* and everything else is reserved. Additionally, nid is set to NUMA_NO_NODE
* instead of requesting a specific node:
*
* +-----------+
* | new |
* +-----------+
* | +---------------------+-----------|
* | | prev node | next node |
* +------+---------------------+-----------+
* + +
* |----------------------+ +-----|
* | r1 | | r2 |
* +----------------------+-----------+-----+
* ^ ^
* | |
* | max_addr
* |
* min_addr
*
* Expect no allocation to happen.
*/
static int alloc_exact_nid_numa_split_all_reserved_generic_check(void)
{
void *allocated_ptr = NULL;
struct memblock_region *next_node = &memblock.memory.regions[7];
struct region r1, r2;
phys_addr_t size = SZ_256;
phys_addr_t max_addr;
phys_addr_t min_addr;
PREFIX_PUSH();
setup_numa_memblock(node_fractions);
r2.base = next_node->base + SZ_128;
r2.size = memblock_end_of_DRAM() - r2.base;
r1.size = MEM_SIZE - (r2.size + size);
r1.base = memblock_start_of_DRAM();
min_addr = r1.base + r1.size;
max_addr = r2.base;
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = memblock_alloc_exact_nid_raw(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
ASSERT_EQ(allocated_ptr, NULL);
test_pass_pop();
return 0;
}
/* Test case wrappers for NUMA tests */
static int alloc_exact_nid_numa_simple_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_exact_nid_top_down_numa_simple_check();
memblock_set_bottom_up(true);
alloc_exact_nid_bottom_up_numa_simple_check();
return 0;
}
static int alloc_exact_nid_numa_part_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_exact_nid_top_down_numa_part_reserved_check();
memblock_set_bottom_up(true);
alloc_exact_nid_bottom_up_numa_part_reserved_check();
return 0;
}
static int alloc_exact_nid_numa_split_range_low_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_exact_nid_top_down_numa_split_range_low_check();
memblock_set_bottom_up(true);
alloc_exact_nid_bottom_up_numa_split_range_low_check();
return 0;
}
static int alloc_exact_nid_numa_no_overlap_split_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_exact_nid_top_down_numa_no_overlap_split_check();
memblock_set_bottom_up(true);
alloc_exact_nid_bottom_up_numa_no_overlap_split_check();
return 0;
}
static int alloc_exact_nid_numa_no_overlap_low_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_exact_nid_top_down_numa_no_overlap_low_check();
memblock_set_bottom_up(true);
alloc_exact_nid_bottom_up_numa_no_overlap_low_check();
return 0;
}
static int alloc_exact_nid_numa_small_node_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_small_node_generic_check);
run_bottom_up(alloc_exact_nid_numa_small_node_generic_check);
return 0;
}
static int alloc_exact_nid_numa_node_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_node_reserved_generic_check);
run_bottom_up(alloc_exact_nid_numa_node_reserved_generic_check);
return 0;
}
static int alloc_exact_nid_numa_part_reserved_fail_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_part_reserved_fail_generic_check);
run_bottom_up(alloc_exact_nid_numa_part_reserved_fail_generic_check);
return 0;
}
static int alloc_exact_nid_numa_split_range_high_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_split_range_high_generic_check);
run_bottom_up(alloc_exact_nid_numa_split_range_high_generic_check);
return 0;
}
static int alloc_exact_nid_numa_no_overlap_high_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_no_overlap_high_generic_check);
run_bottom_up(alloc_exact_nid_numa_no_overlap_high_generic_check);
return 0;
}
static int alloc_exact_nid_numa_large_region_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_large_region_generic_check);
run_bottom_up(alloc_exact_nid_numa_large_region_generic_check);
return 0;
}
static int alloc_exact_nid_numa_reserved_full_merge_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_reserved_full_merge_generic_check);
run_bottom_up(alloc_exact_nid_numa_reserved_full_merge_generic_check);
return 0;
}
static int alloc_exact_nid_numa_split_all_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_exact_nid_numa_split_all_reserved_generic_check);
run_bottom_up(alloc_exact_nid_numa_split_all_reserved_generic_check);
return 0;
}
int __memblock_alloc_exact_nid_numa_checks(void)
{
test_print("Running %s NUMA tests...\n", FUNC_NAME);
alloc_exact_nid_numa_simple_check();
alloc_exact_nid_numa_part_reserved_check();
alloc_exact_nid_numa_split_range_low_check();
alloc_exact_nid_numa_no_overlap_split_check();
alloc_exact_nid_numa_no_overlap_low_check();
alloc_exact_nid_numa_small_node_check();
alloc_exact_nid_numa_node_reserved_check();
alloc_exact_nid_numa_part_reserved_fail_check();
alloc_exact_nid_numa_split_range_high_check();
alloc_exact_nid_numa_no_overlap_high_check();
alloc_exact_nid_numa_large_region_check();
alloc_exact_nid_numa_reserved_full_merge_check();
alloc_exact_nid_numa_split_all_reserved_check();
return 0;
}
int memblock_alloc_exact_nid_checks(void)
{
prefix_reset();
prefix_push(FUNC_NAME);
reset_memblock_attributes();
dummy_physical_memory_init();
memblock_alloc_exact_nid_range_checks();
memblock_alloc_exact_nid_numa_checks();
dummy_physical_memory_cleanup();
prefix_pop();
return 0;
}
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef _MEMBLOCK_ALLOC_EXACT_NID_H
#define _MEMBLOCK_ALLOC_EXACT_NID_H
#include "common.h"
int memblock_alloc_exact_nid_checks(void);
int __memblock_alloc_exact_nid_numa_checks(void);
#ifdef CONFIG_NUMA
static inline int memblock_alloc_exact_nid_numa_checks(void)
{
__memblock_alloc_exact_nid_numa_checks();
return 0;
}
#else
static inline int memblock_alloc_exact_nid_numa_checks(void)
{
return 0;
}
#endif /* CONFIG_NUMA */
#endif
......@@ -18,18 +18,29 @@ static const unsigned int node_fractions[] = {
625, /* 1/16 */
};
static inline const char * const get_memblock_alloc_try_nid_name(int flags)
static inline const char * const get_memblock_alloc_nid_name(int flags)
{
if (flags & TEST_F_EXACT)
return "memblock_alloc_exact_nid_raw";
if (flags & TEST_F_RAW)
return "memblock_alloc_try_nid_raw";
return "memblock_alloc_try_nid";
}
static inline void *run_memblock_alloc_try_nid(phys_addr_t size,
static inline void *run_memblock_alloc_nid(phys_addr_t size,
phys_addr_t align,
phys_addr_t min_addr,
phys_addr_t max_addr, int nid)
{
assert(!(alloc_nid_test_flags & TEST_F_EXACT) ||
(alloc_nid_test_flags & TEST_F_RAW));
/*
* TEST_F_EXACT should be checked before TEST_F_RAW since
* memblock_alloc_exact_nid_raw() performs raw allocations.
*/
if (alloc_nid_test_flags & TEST_F_EXACT)
return memblock_alloc_exact_nid_raw(size, align, min_addr,
max_addr, nid);
if (alloc_nid_test_flags & TEST_F_RAW)
return memblock_alloc_try_nid_raw(size, align, min_addr,
max_addr, nid);
......@@ -50,7 +61,7 @@ static inline void *run_memblock_alloc_try_nid(phys_addr_t size,
*
* Expect to allocate a region that ends at max_addr.
*/
static int alloc_try_nid_top_down_simple_check(void)
static int alloc_nid_top_down_simple_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -65,7 +76,7 @@ static int alloc_try_nid_top_down_simple_check(void)
min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
max_addr = min_addr + SZ_512;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
rgn_end = rgn->base + rgn->size;
......@@ -102,7 +113,7 @@ static int alloc_try_nid_top_down_simple_check(void)
*
* Expect to allocate an aligned region that ends before max_addr.
*/
static int alloc_try_nid_top_down_end_misaligned_check(void)
static int alloc_nid_top_down_end_misaligned_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -118,7 +129,7 @@ static int alloc_try_nid_top_down_end_misaligned_check(void)
min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
max_addr = min_addr + SZ_512 + misalign;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
rgn_end = rgn->base + rgn->size;
......@@ -153,7 +164,7 @@ static int alloc_try_nid_top_down_end_misaligned_check(void)
* Expect to allocate a region that starts at min_addr and ends at
* max_addr, given that min_addr is aligned.
*/
static int alloc_try_nid_exact_address_generic_check(void)
static int alloc_nid_exact_address_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -168,7 +179,7 @@ static int alloc_try_nid_exact_address_generic_check(void)
min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES;
max_addr = min_addr + size;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
rgn_end = rgn->base + rgn->size;
......@@ -205,7 +216,7 @@ static int alloc_try_nid_exact_address_generic_check(void)
* Expect to drop the lower limit and allocate a memory region which
* ends at max_addr (if the address is aligned).
*/
static int alloc_try_nid_top_down_narrow_range_check(void)
static int alloc_nid_top_down_narrow_range_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -219,7 +230,7 @@ static int alloc_try_nid_top_down_narrow_range_check(void)
min_addr = memblock_start_of_DRAM() + SZ_512;
max_addr = min_addr + SMP_CACHE_BYTES;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -257,7 +268,7 @@ static int alloc_try_nid_top_down_narrow_range_check(void)
*
* Expect no allocation to happen.
*/
static int alloc_try_nid_low_max_generic_check(void)
static int alloc_nid_low_max_generic_check(void)
{
void *allocated_ptr = NULL;
phys_addr_t size = SZ_1K;
......@@ -270,7 +281,7 @@ static int alloc_try_nid_low_max_generic_check(void)
min_addr = memblock_start_of_DRAM();
max_addr = min_addr + SMP_CACHE_BYTES;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -295,7 +306,7 @@ static int alloc_try_nid_low_max_generic_check(void)
*
* Expect a merge of both regions. Only the region size gets updated.
*/
static int alloc_try_nid_min_reserved_generic_check(void)
static int alloc_nid_min_reserved_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -315,7 +326,7 @@ static int alloc_try_nid_min_reserved_generic_check(void)
memblock_reserve(reserved_base, r1_size);
allocated_ptr = run_memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r2_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -347,7 +358,7 @@ static int alloc_try_nid_min_reserved_generic_check(void)
*
* Expect a merge of regions. Only the region size gets updated.
*/
static int alloc_try_nid_max_reserved_generic_check(void)
static int alloc_nid_max_reserved_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -365,7 +376,7 @@ static int alloc_try_nid_max_reserved_generic_check(void)
memblock_reserve(max_addr, r1_size);
allocated_ptr = run_memblock_alloc_try_nid(r2_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r2_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -400,7 +411,7 @@ static int alloc_try_nid_max_reserved_generic_check(void)
* updated. The total size field gets updated.
*/
static int alloc_try_nid_top_down_reserved_with_space_check(void)
static int alloc_nid_top_down_reserved_with_space_check(void)
{
struct memblock_region *rgn1 = &memblock.reserved.regions[1];
struct memblock_region *rgn2 = &memblock.reserved.regions[0];
......@@ -428,7 +439,7 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -465,7 +476,7 @@ static int alloc_try_nid_top_down_reserved_with_space_check(void)
* Expect to merge all of the regions into one. The region counter and total
* size fields get updated.
*/
static int alloc_try_nid_reserved_full_merge_generic_check(void)
static int alloc_nid_reserved_full_merge_generic_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -491,7 +502,7 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -527,7 +538,7 @@ static int alloc_try_nid_reserved_full_merge_generic_check(void)
* Expect to merge the new region with r2. The second region does not get
* updated. The total size counter gets updated.
*/
static int alloc_try_nid_top_down_reserved_no_space_check(void)
static int alloc_nid_top_down_reserved_no_space_check(void)
{
struct memblock_region *rgn1 = &memblock.reserved.regions[1];
struct memblock_region *rgn2 = &memblock.reserved.regions[0];
......@@ -555,7 +566,7 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -596,7 +607,7 @@ static int alloc_try_nid_top_down_reserved_no_space_check(void)
* Expect no allocation to happen.
*/
static int alloc_try_nid_reserved_all_generic_check(void)
static int alloc_nid_reserved_all_generic_check(void)
{
void *allocated_ptr = NULL;
struct region r1, r2;
......@@ -620,7 +631,7 @@ static int alloc_try_nid_reserved_all_generic_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -636,7 +647,7 @@ static int alloc_try_nid_reserved_all_generic_check(void)
* bigger than the end address of the available memory. Expect to allocate
* a region that ends before the end of the memory.
*/
static int alloc_try_nid_top_down_cap_max_check(void)
static int alloc_nid_top_down_cap_max_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -650,7 +661,7 @@ static int alloc_try_nid_top_down_cap_max_check(void)
min_addr = memblock_end_of_DRAM() - SZ_1K;
max_addr = memblock_end_of_DRAM() + SZ_256;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -673,7 +684,7 @@ static int alloc_try_nid_top_down_cap_max_check(void)
* smaller than the start address of the available memory. Expect to allocate
* a region that ends before the end of the memory.
*/
static int alloc_try_nid_top_down_cap_min_check(void)
static int alloc_nid_top_down_cap_min_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -687,7 +698,7 @@ static int alloc_try_nid_top_down_cap_min_check(void)
min_addr = memblock_start_of_DRAM() - SZ_256;
max_addr = memblock_end_of_DRAM();
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -719,7 +730,7 @@ static int alloc_try_nid_top_down_cap_min_check(void)
*
* Expect to allocate a region that ends before max_addr.
*/
static int alloc_try_nid_bottom_up_simple_check(void)
static int alloc_nid_bottom_up_simple_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -734,7 +745,7 @@ static int alloc_try_nid_bottom_up_simple_check(void)
min_addr = memblock_start_of_DRAM() + SMP_CACHE_BYTES * 2;
max_addr = min_addr + SZ_512;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
rgn_end = rgn->base + rgn->size;
......@@ -771,7 +782,7 @@ static int alloc_try_nid_bottom_up_simple_check(void)
*
* Expect to allocate an aligned region that ends before max_addr.
*/
static int alloc_try_nid_bottom_up_start_misaligned_check(void)
static int alloc_nid_bottom_up_start_misaligned_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -787,7 +798,7 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void)
min_addr = memblock_start_of_DRAM() + misalign;
max_addr = min_addr + SZ_512;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
rgn_end = rgn->base + rgn->size;
......@@ -824,7 +835,7 @@ static int alloc_try_nid_bottom_up_start_misaligned_check(void)
* Expect to drop the lower limit and allocate a memory region which
* starts at the beginning of the available memory.
*/
static int alloc_try_nid_bottom_up_narrow_range_check(void)
static int alloc_nid_bottom_up_narrow_range_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -838,7 +849,7 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void)
min_addr = memblock_start_of_DRAM() + SZ_512;
max_addr = min_addr + SMP_CACHE_BYTES;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -873,7 +884,7 @@ static int alloc_try_nid_bottom_up_narrow_range_check(void)
* updated. The total size field gets updated.
*/
static int alloc_try_nid_bottom_up_reserved_with_space_check(void)
static int alloc_nid_bottom_up_reserved_with_space_check(void)
{
struct memblock_region *rgn1 = &memblock.reserved.regions[1];
struct memblock_region *rgn2 = &memblock.reserved.regions[0];
......@@ -901,7 +912,7 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -942,7 +953,7 @@ static int alloc_try_nid_bottom_up_reserved_with_space_check(void)
* Other regions are not modified.
*/
static int alloc_try_nid_bottom_up_reserved_no_space_check(void)
static int alloc_nid_bottom_up_reserved_no_space_check(void)
{
struct memblock_region *rgn1 = &memblock.reserved.regions[2];
struct memblock_region *rgn2 = &memblock.reserved.regions[1];
......@@ -971,7 +982,7 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(r3_size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -1000,7 +1011,7 @@ static int alloc_try_nid_bottom_up_reserved_no_space_check(void)
* bigger than the end address of the available memory. Expect to allocate
* a region that starts at the min_addr.
*/
static int alloc_try_nid_bottom_up_cap_max_check(void)
static int alloc_nid_bottom_up_cap_max_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -1014,7 +1025,7 @@ static int alloc_try_nid_bottom_up_cap_max_check(void)
min_addr = memblock_start_of_DRAM() + SZ_1K;
max_addr = memblock_end_of_DRAM() + SZ_256;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -1037,7 +1048,7 @@ static int alloc_try_nid_bottom_up_cap_max_check(void)
* smaller than the start address of the available memory. Expect to allocate
* a region at the beginning of the available memory.
*/
static int alloc_try_nid_bottom_up_cap_min_check(void)
static int alloc_nid_bottom_up_cap_min_check(void)
{
struct memblock_region *rgn = &memblock.reserved.regions[0];
void *allocated_ptr = NULL;
......@@ -1051,7 +1062,7 @@ static int alloc_try_nid_bottom_up_cap_min_check(void)
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM() - SZ_256;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -1070,133 +1081,133 @@ static int alloc_try_nid_bottom_up_cap_min_check(void)
}
/* Test case wrappers for range tests */
static int alloc_try_nid_simple_check(void)
static int alloc_nid_simple_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_simple_check();
alloc_nid_top_down_simple_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_simple_check();
alloc_nid_bottom_up_simple_check();
return 0;
}
static int alloc_try_nid_misaligned_check(void)
static int alloc_nid_misaligned_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_end_misaligned_check();
alloc_nid_top_down_end_misaligned_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_start_misaligned_check();
alloc_nid_bottom_up_start_misaligned_check();
return 0;
}
static int alloc_try_nid_narrow_range_check(void)
static int alloc_nid_narrow_range_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_narrow_range_check();
alloc_nid_top_down_narrow_range_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_narrow_range_check();
alloc_nid_bottom_up_narrow_range_check();
return 0;
}
static int alloc_try_nid_reserved_with_space_check(void)
static int alloc_nid_reserved_with_space_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_reserved_with_space_check();
alloc_nid_top_down_reserved_with_space_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_reserved_with_space_check();
alloc_nid_bottom_up_reserved_with_space_check();
return 0;
}
static int alloc_try_nid_reserved_no_space_check(void)
static int alloc_nid_reserved_no_space_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_reserved_no_space_check();
alloc_nid_top_down_reserved_no_space_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_reserved_no_space_check();
alloc_nid_bottom_up_reserved_no_space_check();
return 0;
}
static int alloc_try_nid_cap_max_check(void)
static int alloc_nid_cap_max_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_cap_max_check();
alloc_nid_top_down_cap_max_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_cap_max_check();
alloc_nid_bottom_up_cap_max_check();
return 0;
}
static int alloc_try_nid_cap_min_check(void)
static int alloc_nid_cap_min_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_cap_min_check();
alloc_nid_top_down_cap_min_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_cap_min_check();
alloc_nid_bottom_up_cap_min_check();
return 0;
}
static int alloc_try_nid_min_reserved_check(void)
static int alloc_nid_min_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_min_reserved_generic_check);
run_bottom_up(alloc_try_nid_min_reserved_generic_check);
run_top_down(alloc_nid_min_reserved_generic_check);
run_bottom_up(alloc_nid_min_reserved_generic_check);
return 0;
}
static int alloc_try_nid_max_reserved_check(void)
static int alloc_nid_max_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_max_reserved_generic_check);
run_bottom_up(alloc_try_nid_max_reserved_generic_check);
run_top_down(alloc_nid_max_reserved_generic_check);
run_bottom_up(alloc_nid_max_reserved_generic_check);
return 0;
}
static int alloc_try_nid_exact_address_check(void)
static int alloc_nid_exact_address_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_exact_address_generic_check);
run_bottom_up(alloc_try_nid_exact_address_generic_check);
run_top_down(alloc_nid_exact_address_generic_check);
run_bottom_up(alloc_nid_exact_address_generic_check);
return 0;
}
static int alloc_try_nid_reserved_full_merge_check(void)
static int alloc_nid_reserved_full_merge_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_reserved_full_merge_generic_check);
run_bottom_up(alloc_try_nid_reserved_full_merge_generic_check);
run_top_down(alloc_nid_reserved_full_merge_generic_check);
run_bottom_up(alloc_nid_reserved_full_merge_generic_check);
return 0;
}
static int alloc_try_nid_reserved_all_check(void)
static int alloc_nid_reserved_all_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_reserved_all_generic_check);
run_bottom_up(alloc_try_nid_reserved_all_generic_check);
run_top_down(alloc_nid_reserved_all_generic_check);
run_bottom_up(alloc_nid_reserved_all_generic_check);
return 0;
}
static int alloc_try_nid_low_max_check(void)
static int alloc_nid_low_max_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_low_max_generic_check);
run_bottom_up(alloc_try_nid_low_max_generic_check);
run_top_down(alloc_nid_low_max_generic_check);
run_bottom_up(alloc_nid_low_max_generic_check);
return 0;
}
......@@ -1204,22 +1215,22 @@ static int alloc_try_nid_low_max_check(void)
static int memblock_alloc_nid_range_checks(void)
{
test_print("Running %s range tests...\n",
get_memblock_alloc_try_nid_name(alloc_nid_test_flags));
get_memblock_alloc_nid_name(alloc_nid_test_flags));
alloc_try_nid_simple_check();
alloc_try_nid_misaligned_check();
alloc_try_nid_narrow_range_check();
alloc_try_nid_reserved_with_space_check();
alloc_try_nid_reserved_no_space_check();
alloc_try_nid_cap_max_check();
alloc_try_nid_cap_min_check();
alloc_nid_simple_check();
alloc_nid_misaligned_check();
alloc_nid_narrow_range_check();
alloc_nid_reserved_with_space_check();
alloc_nid_reserved_no_space_check();
alloc_nid_cap_max_check();
alloc_nid_cap_min_check();
alloc_try_nid_min_reserved_check();
alloc_try_nid_max_reserved_check();
alloc_try_nid_exact_address_check();
alloc_try_nid_reserved_full_merge_check();
alloc_try_nid_reserved_all_check();
alloc_try_nid_low_max_check();
alloc_nid_min_reserved_check();
alloc_nid_max_reserved_check();
alloc_nid_exact_address_check();
alloc_nid_reserved_full_merge_check();
alloc_nid_reserved_all_check();
alloc_nid_low_max_check();
return 0;
}
......@@ -1229,7 +1240,7 @@ static int memblock_alloc_nid_range_checks(void)
* has enough memory to allocate a region of the requested size.
* Expect to allocate an aligned region at the end of the requested node.
*/
static int alloc_try_nid_top_down_numa_simple_check(void)
static int alloc_nid_top_down_numa_simple_check(void)
{
int nid_req = 3;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -1247,7 +1258,7 @@ static int alloc_try_nid_top_down_numa_simple_check(void)
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1280,7 +1291,7 @@ static int alloc_try_nid_top_down_numa_simple_check(void)
* Expect to allocate an aligned region at the end of the last node that has
* enough memory (in this case, nid = 6) after falling back to NUMA_NO_NODE.
*/
static int alloc_try_nid_top_down_numa_small_node_check(void)
static int alloc_nid_top_down_numa_small_node_check(void)
{
int nid_req = 1;
int nid_exp = 6;
......@@ -1299,7 +1310,7 @@ static int alloc_try_nid_top_down_numa_small_node_check(void)
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1333,7 +1344,7 @@ static int alloc_try_nid_top_down_numa_small_node_check(void)
* large enough and has enough unreserved memory (in this case, nid = 6) after
* falling back to NUMA_NO_NODE. The region count and total size get updated.
*/
static int alloc_try_nid_top_down_numa_node_reserved_check(void)
static int alloc_nid_top_down_numa_node_reserved_check(void)
{
int nid_req = 2;
int nid_exp = 6;
......@@ -1353,7 +1364,7 @@ static int alloc_try_nid_top_down_numa_node_reserved_check(void)
max_addr = memblock_end_of_DRAM();
memblock_reserve(req_node->base, req_node->size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1386,7 +1397,7 @@ static int alloc_try_nid_top_down_numa_node_reserved_check(void)
* Expect to allocate an aligned region at the end of the requested node. The
* region count and total size get updated.
*/
static int alloc_try_nid_top_down_numa_part_reserved_check(void)
static int alloc_nid_top_down_numa_part_reserved_check(void)
{
int nid_req = 4;
struct memblock_region *new_rgn = &memblock.reserved.regions[1];
......@@ -1408,7 +1419,7 @@ static int alloc_try_nid_top_down_numa_part_reserved_check(void)
max_addr = memblock_end_of_DRAM();
memblock_reserve(r1.base, r1.size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1444,7 +1455,7 @@ static int alloc_try_nid_top_down_numa_part_reserved_check(void)
* nid = NUMA_NODES - 1) after falling back to NUMA_NO_NODE. The region count
* and total size get updated.
*/
static int alloc_try_nid_top_down_numa_part_reserved_fallback_check(void)
static int alloc_nid_top_down_numa_part_reserved_fallback_check(void)
{
int nid_req = 4;
int nid_exp = NUMA_NODES - 1;
......@@ -1469,7 +1480,7 @@ static int alloc_try_nid_top_down_numa_part_reserved_fallback_check(void)
max_addr = memblock_end_of_DRAM();
memblock_reserve(r1.base, r1.size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1507,7 +1518,7 @@ static int alloc_try_nid_top_down_numa_part_reserved_fallback_check(void)
* Expect to drop the lower limit and allocate a memory region that ends at
* the end of the requested node.
*/
static int alloc_try_nid_top_down_numa_split_range_low_check(void)
static int alloc_nid_top_down_numa_split_range_low_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -1525,7 +1536,7 @@ static int alloc_try_nid_top_down_numa_split_range_low_check(void)
min_addr = req_node_end - SZ_256;
max_addr = min_addr + size;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1563,7 +1574,7 @@ static int alloc_try_nid_top_down_numa_split_range_low_check(void)
* Expect to drop the lower limit and allocate a memory region that
* ends at the end of the first node that overlaps with the range.
*/
static int alloc_try_nid_top_down_numa_split_range_high_check(void)
static int alloc_nid_top_down_numa_split_range_high_check(void)
{
int nid_req = 3;
int nid_exp = nid_req - 1;
......@@ -1582,7 +1593,7 @@ static int alloc_try_nid_top_down_numa_split_range_high_check(void)
min_addr = exp_node_end - SZ_256;
max_addr = min_addr + size;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1620,7 +1631,7 @@ static int alloc_try_nid_top_down_numa_split_range_high_check(void)
* Expect to drop the lower limit and allocate a memory region that ends at
* the end of the requested node.
*/
static int alloc_try_nid_top_down_numa_no_overlap_split_check(void)
static int alloc_nid_top_down_numa_no_overlap_split_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -1638,7 +1649,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_split_check(void)
min_addr = node2->base - SZ_256;
max_addr = min_addr + size;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1677,7 +1688,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_split_check(void)
* Expect to allocate a memory region at the end of the final node in
* the range after falling back to NUMA_NO_NODE.
*/
static int alloc_try_nid_top_down_numa_no_overlap_low_check(void)
static int alloc_nid_top_down_numa_no_overlap_low_check(void)
{
int nid_req = 0;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -1694,7 +1705,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_low_check(void)
min_addr = min_node->base;
max_addr = region_end(max_node);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1733,7 +1744,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_low_check(void)
* Expect to allocate a memory region at the end of the final node in
* the range after falling back to NUMA_NO_NODE.
*/
static int alloc_try_nid_top_down_numa_no_overlap_high_check(void)
static int alloc_nid_top_down_numa_no_overlap_high_check(void)
{
int nid_req = 7;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -1750,7 +1761,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_high_check(void)
min_addr = min_node->base;
max_addr = region_end(max_node);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1773,7 +1784,7 @@ static int alloc_try_nid_top_down_numa_no_overlap_high_check(void)
* has enough memory to allocate a region of the requested size.
* Expect to allocate an aligned region at the beginning of the requested node.
*/
static int alloc_try_nid_bottom_up_numa_simple_check(void)
static int alloc_nid_bottom_up_numa_simple_check(void)
{
int nid_req = 3;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -1791,7 +1802,7 @@ static int alloc_try_nid_bottom_up_numa_simple_check(void)
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1824,7 +1835,7 @@ static int alloc_try_nid_bottom_up_numa_simple_check(void)
* Expect to allocate an aligned region at the beginning of the first node that
* has enough memory (in this case, nid = 0) after falling back to NUMA_NO_NODE.
*/
static int alloc_try_nid_bottom_up_numa_small_node_check(void)
static int alloc_nid_bottom_up_numa_small_node_check(void)
{
int nid_req = 1;
int nid_exp = 0;
......@@ -1843,7 +1854,7 @@ static int alloc_try_nid_bottom_up_numa_small_node_check(void)
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1878,7 +1889,7 @@ static int alloc_try_nid_bottom_up_numa_small_node_check(void)
* after falling back to NUMA_NO_NODE. The region count and total size get
* updated.
*/
static int alloc_try_nid_bottom_up_numa_node_reserved_check(void)
static int alloc_nid_bottom_up_numa_node_reserved_check(void)
{
int nid_req = 2;
int nid_exp = 0;
......@@ -1898,7 +1909,7 @@ static int alloc_try_nid_bottom_up_numa_node_reserved_check(void)
max_addr = memblock_end_of_DRAM();
memblock_reserve(req_node->base, req_node->size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1931,7 +1942,7 @@ static int alloc_try_nid_bottom_up_numa_node_reserved_check(void)
* Expect to allocate an aligned region in the requested node that merges with
* the existing reserved region. The total size gets updated.
*/
static int alloc_try_nid_bottom_up_numa_part_reserved_check(void)
static int alloc_nid_bottom_up_numa_part_reserved_check(void)
{
int nid_req = 4;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -1955,7 +1966,7 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_check(void)
total_size = size + r1.size;
memblock_reserve(r1.base, r1.size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -1991,7 +2002,7 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_check(void)
* nid = 0) after falling back to NUMA_NO_NODE. The region count and total size
* get updated.
*/
static int alloc_try_nid_bottom_up_numa_part_reserved_fallback_check(void)
static int alloc_nid_bottom_up_numa_part_reserved_fallback_check(void)
{
int nid_req = 4;
int nid_exp = 0;
......@@ -2016,7 +2027,7 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_fallback_check(void)
max_addr = memblock_end_of_DRAM();
memblock_reserve(r1.base, r1.size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -2054,7 +2065,7 @@ static int alloc_try_nid_bottom_up_numa_part_reserved_fallback_check(void)
* Expect to drop the lower limit and allocate a memory region at the beginning
* of the requested node.
*/
static int alloc_try_nid_bottom_up_numa_split_range_low_check(void)
static int alloc_nid_bottom_up_numa_split_range_low_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -2072,7 +2083,7 @@ static int alloc_try_nid_bottom_up_numa_split_range_low_check(void)
min_addr = req_node_end - SZ_256;
max_addr = min_addr + size;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -2110,7 +2121,7 @@ static int alloc_try_nid_bottom_up_numa_split_range_low_check(void)
* Expect to drop the lower limit and allocate a memory region at the beginning
* of the first node that has enough memory.
*/
static int alloc_try_nid_bottom_up_numa_split_range_high_check(void)
static int alloc_nid_bottom_up_numa_split_range_high_check(void)
{
int nid_req = 3;
int nid_exp = 0;
......@@ -2130,7 +2141,7 @@ static int alloc_try_nid_bottom_up_numa_split_range_high_check(void)
min_addr = req_node->base - SZ_256;
max_addr = min_addr + size;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -2168,7 +2179,7 @@ static int alloc_try_nid_bottom_up_numa_split_range_high_check(void)
* Expect to drop the lower limit and allocate a memory region that starts at
* the beginning of the requested node.
*/
static int alloc_try_nid_bottom_up_numa_no_overlap_split_check(void)
static int alloc_nid_bottom_up_numa_no_overlap_split_check(void)
{
int nid_req = 2;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -2186,7 +2197,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_split_check(void)
min_addr = node2->base - SZ_256;
max_addr = min_addr + size;
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -2225,7 +2236,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_split_check(void)
* Expect to allocate a memory region at the beginning of the first node
* in the range after falling back to NUMA_NO_NODE.
*/
static int alloc_try_nid_bottom_up_numa_no_overlap_low_check(void)
static int alloc_nid_bottom_up_numa_no_overlap_low_check(void)
{
int nid_req = 0;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -2242,7 +2253,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_low_check(void)
min_addr = min_node->base;
max_addr = region_end(max_node);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -2281,7 +2292,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_low_check(void)
* Expect to allocate a memory region at the beginning of the first node
* in the range after falling back to NUMA_NO_NODE.
*/
static int alloc_try_nid_bottom_up_numa_no_overlap_high_check(void)
static int alloc_nid_bottom_up_numa_no_overlap_high_check(void)
{
int nid_req = 7;
struct memblock_region *new_rgn = &memblock.reserved.regions[0];
......@@ -2298,7 +2309,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_high_check(void)
min_addr = min_node->base;
max_addr = region_end(max_node);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -2330,7 +2341,7 @@ static int alloc_try_nid_bottom_up_numa_no_overlap_high_check(void)
*
* Expect no allocation to happen.
*/
static int alloc_try_nid_numa_large_region_generic_check(void)
static int alloc_nid_numa_large_region_generic_check(void)
{
int nid_req = 3;
void *allocated_ptr = NULL;
......@@ -2344,7 +2355,7 @@ static int alloc_try_nid_numa_large_region_generic_check(void)
min_addr = memblock_start_of_DRAM();
max_addr = memblock_end_of_DRAM();
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_EQ(allocated_ptr, NULL);
......@@ -2374,7 +2385,7 @@ static int alloc_try_nid_numa_large_region_generic_check(void)
* Expect to merge all of the regions into one. The region counter and total
* size fields get updated.
*/
static int alloc_try_nid_numa_reserved_full_merge_generic_check(void)
static int alloc_nid_numa_reserved_full_merge_generic_check(void)
{
int nid_req = 6;
int nid_next = nid_req + 1;
......@@ -2404,7 +2415,7 @@ static int alloc_try_nid_numa_reserved_full_merge_generic_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr, nid_req);
ASSERT_NE(allocated_ptr, NULL);
......@@ -2448,7 +2459,7 @@ static int alloc_try_nid_numa_reserved_full_merge_generic_check(void)
*
* Expect no allocation to happen.
*/
static int alloc_try_nid_numa_split_all_reserved_generic_check(void)
static int alloc_nid_numa_split_all_reserved_generic_check(void)
{
void *allocated_ptr = NULL;
struct memblock_region *next_node = &memblock.memory.regions[7];
......@@ -2472,7 +2483,7 @@ static int alloc_try_nid_numa_split_all_reserved_generic_check(void)
memblock_reserve(r1.base, r1.size);
memblock_reserve(r2.base, r2.size);
allocated_ptr = run_memblock_alloc_try_nid(size, SMP_CACHE_BYTES,
allocated_ptr = run_memblock_alloc_nid(size, SMP_CACHE_BYTES,
min_addr, max_addr,
NUMA_NO_NODE);
......@@ -2484,139 +2495,139 @@ static int alloc_try_nid_numa_split_all_reserved_generic_check(void)
}
/* Test case wrappers for NUMA tests */
static int alloc_try_nid_numa_simple_check(void)
static int alloc_nid_numa_simple_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_simple_check();
alloc_nid_top_down_numa_simple_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_simple_check();
alloc_nid_bottom_up_numa_simple_check();
return 0;
}
static int alloc_try_nid_numa_small_node_check(void)
static int alloc_nid_numa_small_node_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_small_node_check();
alloc_nid_top_down_numa_small_node_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_small_node_check();
alloc_nid_bottom_up_numa_small_node_check();
return 0;
}
static int alloc_try_nid_numa_node_reserved_check(void)
static int alloc_nid_numa_node_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_node_reserved_check();
alloc_nid_top_down_numa_node_reserved_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_node_reserved_check();
alloc_nid_bottom_up_numa_node_reserved_check();
return 0;
}
static int alloc_try_nid_numa_part_reserved_check(void)
static int alloc_nid_numa_part_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_part_reserved_check();
alloc_nid_top_down_numa_part_reserved_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_part_reserved_check();
alloc_nid_bottom_up_numa_part_reserved_check();
return 0;
}
static int alloc_try_nid_numa_part_reserved_fallback_check(void)
static int alloc_nid_numa_part_reserved_fallback_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_part_reserved_fallback_check();
alloc_nid_top_down_numa_part_reserved_fallback_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_part_reserved_fallback_check();
alloc_nid_bottom_up_numa_part_reserved_fallback_check();
return 0;
}
static int alloc_try_nid_numa_split_range_low_check(void)
static int alloc_nid_numa_split_range_low_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_split_range_low_check();
alloc_nid_top_down_numa_split_range_low_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_split_range_low_check();
alloc_nid_bottom_up_numa_split_range_low_check();
return 0;
}
static int alloc_try_nid_numa_split_range_high_check(void)
static int alloc_nid_numa_split_range_high_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_split_range_high_check();
alloc_nid_top_down_numa_split_range_high_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_split_range_high_check();
alloc_nid_bottom_up_numa_split_range_high_check();
return 0;
}
static int alloc_try_nid_numa_no_overlap_split_check(void)
static int alloc_nid_numa_no_overlap_split_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_no_overlap_split_check();
alloc_nid_top_down_numa_no_overlap_split_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_no_overlap_split_check();
alloc_nid_bottom_up_numa_no_overlap_split_check();
return 0;
}
static int alloc_try_nid_numa_no_overlap_low_check(void)
static int alloc_nid_numa_no_overlap_low_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_no_overlap_low_check();
alloc_nid_top_down_numa_no_overlap_low_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_no_overlap_low_check();
alloc_nid_bottom_up_numa_no_overlap_low_check();
return 0;
}
static int alloc_try_nid_numa_no_overlap_high_check(void)
static int alloc_nid_numa_no_overlap_high_check(void)
{
test_print("\tRunning %s...\n", __func__);
memblock_set_bottom_up(false);
alloc_try_nid_top_down_numa_no_overlap_high_check();
alloc_nid_top_down_numa_no_overlap_high_check();
memblock_set_bottom_up(true);
alloc_try_nid_bottom_up_numa_no_overlap_high_check();
alloc_nid_bottom_up_numa_no_overlap_high_check();
return 0;
}
static int alloc_try_nid_numa_large_region_check(void)
static int alloc_nid_numa_large_region_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_numa_large_region_generic_check);
run_bottom_up(alloc_try_nid_numa_large_region_generic_check);
run_top_down(alloc_nid_numa_large_region_generic_check);
run_bottom_up(alloc_nid_numa_large_region_generic_check);
return 0;
}
static int alloc_try_nid_numa_reserved_full_merge_check(void)
static int alloc_nid_numa_reserved_full_merge_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_numa_reserved_full_merge_generic_check);
run_bottom_up(alloc_try_nid_numa_reserved_full_merge_generic_check);
run_top_down(alloc_nid_numa_reserved_full_merge_generic_check);
run_bottom_up(alloc_nid_numa_reserved_full_merge_generic_check);
return 0;
}
static int alloc_try_nid_numa_split_all_reserved_check(void)
static int alloc_nid_numa_split_all_reserved_check(void)
{
test_print("\tRunning %s...\n", __func__);
run_top_down(alloc_try_nid_numa_split_all_reserved_generic_check);
run_bottom_up(alloc_try_nid_numa_split_all_reserved_generic_check);
run_top_down(alloc_nid_numa_split_all_reserved_generic_check);
run_bottom_up(alloc_nid_numa_split_all_reserved_generic_check);
return 0;
}
......@@ -2624,22 +2635,22 @@ static int alloc_try_nid_numa_split_all_reserved_check(void)
int __memblock_alloc_nid_numa_checks(void)
{
test_print("Running %s NUMA tests...\n",
get_memblock_alloc_try_nid_name(alloc_nid_test_flags));
get_memblock_alloc_nid_name(alloc_nid_test_flags));
alloc_try_nid_numa_simple_check();
alloc_try_nid_numa_small_node_check();
alloc_try_nid_numa_node_reserved_check();
alloc_try_nid_numa_part_reserved_check();
alloc_try_nid_numa_part_reserved_fallback_check();
alloc_try_nid_numa_split_range_low_check();
alloc_try_nid_numa_split_range_high_check();
alloc_nid_numa_simple_check();
alloc_nid_numa_small_node_check();
alloc_nid_numa_node_reserved_check();
alloc_nid_numa_part_reserved_check();
alloc_nid_numa_part_reserved_fallback_check();
alloc_nid_numa_split_range_low_check();
alloc_nid_numa_split_range_high_check();
alloc_try_nid_numa_no_overlap_split_check();
alloc_try_nid_numa_no_overlap_low_check();
alloc_try_nid_numa_no_overlap_high_check();
alloc_try_nid_numa_large_region_check();
alloc_try_nid_numa_reserved_full_merge_check();
alloc_try_nid_numa_split_all_reserved_check();
alloc_nid_numa_no_overlap_split_check();
alloc_nid_numa_no_overlap_low_check();
alloc_nid_numa_no_overlap_high_check();
alloc_nid_numa_large_region_check();
alloc_nid_numa_reserved_full_merge_check();
alloc_nid_numa_split_all_reserved_check();
return 0;
}
......@@ -2649,7 +2660,7 @@ static int memblock_alloc_nid_checks_internal(int flags)
alloc_nid_test_flags = flags;
prefix_reset();
prefix_push(get_memblock_alloc_try_nid_name(flags));
prefix_push(get_memblock_alloc_nid_name(flags));
reset_memblock_attributes();
dummy_physical_memory_init();
......@@ -2671,3 +2682,12 @@ int memblock_alloc_nid_checks(void)
return 0;
}
int memblock_alloc_exact_nid_range_checks(void)
{
alloc_nid_test_flags = (TEST_F_RAW | TEST_F_EXACT);
memblock_alloc_nid_range_checks();
return 0;
}
......@@ -5,6 +5,7 @@
#include "common.h"
int memblock_alloc_nid_checks(void);
int memblock_alloc_exact_nid_range_checks(void);
int __memblock_alloc_nid_numa_checks(void);
#ifdef CONFIG_NUMA
......
......@@ -423,6 +423,98 @@ static int memblock_add_near_max_check(void)
return 0;
}
/*
* A test that trying to add the 129th memory block.
* Expect to trigger memblock_double_array() to double the
* memblock.memory.max, find a new valid memory as
* memory.regions.
*/
static int memblock_add_many_check(void)
{
int i;
void *orig_region;
struct region r = {
.base = SZ_16K,
.size = SZ_16K,
};
phys_addr_t new_memory_regions_size;
phys_addr_t base, size = SZ_64;
phys_addr_t gap_size = SZ_64;
PREFIX_PUSH();
reset_memblock_regions();
memblock_allow_resize();
dummy_physical_memory_init();
/*
* We allocated enough memory by using dummy_physical_memory_init(), and
* split it into small block. First we split a large enough memory block
* as the memory region which will be choosed by memblock_double_array().
*/
base = PAGE_ALIGN(dummy_physical_memory_base());
new_memory_regions_size = PAGE_ALIGN(INIT_MEMBLOCK_REGIONS * 2 *
sizeof(struct memblock_region));
memblock_add(base, new_memory_regions_size);
/* This is the base of small memory block. */
base += new_memory_regions_size + gap_size;
orig_region = memblock.memory.regions;
for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
/*
* Add these small block to fulfill the memblock. We keep a
* gap between the nearby memory to avoid being merged.
*/
memblock_add(base, size);
base += size + gap_size;
ASSERT_EQ(memblock.memory.cnt, i + 2);
ASSERT_EQ(memblock.memory.total_size, new_memory_regions_size +
(i + 1) * size);
}
/*
* At there, memblock_double_array() has been succeed, check if it
* update the memory.max.
*/
ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
/* memblock_double_array() will reserve the memory it used. Check it. */
ASSERT_EQ(memblock.reserved.cnt, 1);
ASSERT_EQ(memblock.reserved.total_size, new_memory_regions_size);
/*
* Now memblock_double_array() works fine. Let's check after the
* double_array(), the memblock_add() still works as normal.
*/
memblock_add(r.base, r.size);
ASSERT_EQ(memblock.memory.regions[0].base, r.base);
ASSERT_EQ(memblock.memory.regions[0].size, r.size);
ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 2);
ASSERT_EQ(memblock.memory.total_size, INIT_MEMBLOCK_REGIONS * size +
new_memory_regions_size +
r.size);
ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
dummy_physical_memory_cleanup();
/*
* The current memory.regions is occupying a range of memory that
* allocated from dummy_physical_memory_init(). After free the memory,
* we must not use it. So restore the origin memory region to make sure
* the tests can run as normal and not affected by the double array.
*/
memblock.memory.regions = orig_region;
memblock.memory.cnt = INIT_MEMBLOCK_REGIONS;
test_pass_pop();
return 0;
}
static int memblock_add_checks(void)
{
prefix_reset();
......@@ -438,6 +530,7 @@ static int memblock_add_checks(void)
memblock_add_twice_check();
memblock_add_between_check();
memblock_add_near_max_check();
memblock_add_many_check();
prefix_pop();
......@@ -799,6 +892,96 @@ static int memblock_reserve_near_max_check(void)
return 0;
}
/*
* A test that trying to reserve the 129th memory block.
* Expect to trigger memblock_double_array() to double the
* memblock.memory.max, find a new valid memory as
* reserved.regions.
*/
static int memblock_reserve_many_check(void)
{
int i;
void *orig_region;
struct region r = {
.base = SZ_16K,
.size = SZ_16K,
};
phys_addr_t memory_base = SZ_128K;
phys_addr_t new_reserved_regions_size;
PREFIX_PUSH();
reset_memblock_regions();
memblock_allow_resize();
/* Add a valid memory region used by double_array(). */
dummy_physical_memory_init();
memblock_add(dummy_physical_memory_base(), MEM_SIZE);
for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
/* Reserve some fakes memory region to fulfill the memblock. */
memblock_reserve(memory_base, MEM_SIZE);
ASSERT_EQ(memblock.reserved.cnt, i + 1);
ASSERT_EQ(memblock.reserved.total_size, (i + 1) * MEM_SIZE);
/* Keep the gap so these memory region will not be merged. */
memory_base += MEM_SIZE * 2;
}
orig_region = memblock.reserved.regions;
/* This reserve the 129 memory_region, and makes it double array. */
memblock_reserve(memory_base, MEM_SIZE);
/*
* This is the memory region size used by the doubled reserved.regions,
* and it has been reserved due to it has been used. The size is used to
* calculate the total_size that the memblock.reserved have now.
*/
new_reserved_regions_size = PAGE_ALIGN((INIT_MEMBLOCK_REGIONS * 2) *
sizeof(struct memblock_region));
/*
* The double_array() will find a free memory region as the new
* reserved.regions, and the used memory region will be reserved, so
* there will be one more region exist in the reserved memblock. And the
* one more reserved region's size is new_reserved_regions_size.
*/
ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 2);
ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
new_reserved_regions_size);
ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
/*
* Now memblock_double_array() works fine. Let's check after the
* double_array(), the memblock_reserve() still works as normal.
*/
memblock_reserve(r.base, r.size);
ASSERT_EQ(memblock.reserved.regions[0].base, r.base);
ASSERT_EQ(memblock.reserved.regions[0].size, r.size);
ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 3);
ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
new_reserved_regions_size +
r.size);
ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
dummy_physical_memory_cleanup();
/*
* The current reserved.regions is occupying a range of memory that
* allocated from dummy_physical_memory_init(). After free the memory,
* we must not use it. So restore the origin memory region to make sure
* the tests can run as normal and not affected by the double array.
*/
memblock.reserved.regions = orig_region;
memblock.reserved.cnt = INIT_MEMBLOCK_RESERVED_REGIONS;
test_pass_pop();
return 0;
}
static int memblock_reserve_checks(void)
{
prefix_reset();
......@@ -813,6 +996,7 @@ static int memblock_reserve_checks(void)
memblock_reserve_twice_check();
memblock_reserve_between_check();
memblock_reserve_near_max_check();
memblock_reserve_many_check();
prefix_pop();
......
......@@ -5,8 +5,6 @@
#include <linux/memory_hotplug.h>
#include <linux/build_bug.h>
#define INIT_MEMBLOCK_REGIONS 128
#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
#define PREFIXES_MAX 15
#define DELIM ": "
#define BASIS 10000
......@@ -115,6 +113,11 @@ void dummy_physical_memory_cleanup(void)
free(memory_block.base);
}
phys_addr_t dummy_physical_memory_base(void)
{
return (phys_addr_t)memory_block.base;
}
static void usage(const char *prog)
{
BUILD_BUG_ON(ARRAY_SIZE(help_opts) != ARRAY_SIZE(long_opts) - 1);
......
......@@ -10,14 +10,19 @@
#include <linux/printk.h>
#include <../selftests/kselftest.h>
#define MEM_SIZE SZ_16K
#define MEM_SIZE SZ_32K
#define NUMA_NODES 8
#define INIT_MEMBLOCK_REGIONS 128
#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
enum test_flags {
/* No special request. */
TEST_F_NONE = 0x0,
/* Perform raw allocations (no zeroing of memory). */
TEST_F_RAW = 0x1,
/* Perform allocations on the exact node specified. */
TEST_F_EXACT = 0x2
};
/**
......@@ -124,6 +129,7 @@ void setup_memblock(void);
void setup_numa_memblock(const unsigned int node_fracs[]);
void dummy_physical_memory_init(void);
void dummy_physical_memory_cleanup(void);
phys_addr_t dummy_physical_memory_base(void);
void parse_args(int argc, char **argv);
void test_fail(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment